From: lehtonen Date: Tue, 10 Jan 2012 18:39:24 +0000 (+0000) Subject: "Creating 'stable' branch for Simantics codebase SCRUM-development from trunk@r23877... X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=a91266c64324bfa14e2f9c28546defaeda79318e;p=simantics%2Fsysdyn.git "Creating 'stable' branch for Simantics codebase SCRUM-development from trunk@r23877 to branches/stable on 2012-01-10. refs #3076" git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches@23905 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/stable/installer/.project b/stable/installer/.project new file mode 100644 index 00000000..dd9ed4ea --- /dev/null +++ b/stable/installer/.project @@ -0,0 +1,11 @@ + + + sysdyn-installer + + + + + + + + diff --git a/stable/installer/7za/7-zip.chm b/stable/installer/7za/7-zip.chm new file mode 100644 index 00000000..eee875ee Binary files /dev/null and b/stable/installer/7za/7-zip.chm differ diff --git a/stable/installer/7za/7z.sfx b/stable/installer/7za/7z.sfx new file mode 100644 index 00000000..97ff6055 Binary files /dev/null and b/stable/installer/7za/7z.sfx differ diff --git a/stable/installer/7za/7zS.sfx b/stable/installer/7za/7zS.sfx new file mode 100644 index 00000000..f37714d8 Binary files /dev/null and b/stable/installer/7za/7zS.sfx differ diff --git a/stable/installer/7za/7zSD.sfx b/stable/installer/7za/7zSD.sfx new file mode 100644 index 00000000..ad3915d7 Binary files /dev/null and b/stable/installer/7za/7zSD.sfx differ diff --git a/stable/installer/7za/7za.dll b/stable/installer/7za/7za.dll new file mode 100644 index 00000000..dcd0d3d5 Binary files /dev/null and b/stable/installer/7za/7za.dll differ diff --git a/stable/installer/7za/7za.exe b/stable/installer/7za/7za.exe new file mode 100644 index 00000000..12b9499a Binary files /dev/null and b/stable/installer/7za/7za.exe differ diff --git a/stable/installer/7za/7zr.exe b/stable/installer/7za/7zr.exe new file mode 100644 index 00000000..08acdc0e Binary files /dev/null and b/stable/installer/7za/7zr.exe differ diff --git a/stable/installer/7za/7zxa.dll b/stable/installer/7za/7zxa.dll new file mode 100644 index 00000000..fa5aa015 Binary files /dev/null and b/stable/installer/7za/7zxa.dll differ diff --git a/stable/installer/7za/Installer/config.txt b/stable/installer/7za/Installer/config.txt new file mode 100644 index 00000000..4200104f --- /dev/null +++ b/stable/installer/7za/Installer/config.txt @@ -0,0 +1,5 @@ +;!@Install@!UTF-8! +Title="Software 5.00" +BeginPrompt="Do you want to install the Software 5.00?" +RunProgram="7zr.exe" +;!@InstallEnd@! diff --git a/stable/installer/7za/Installer/cr.bat b/stable/installer/7za/Installer/cr.bat new file mode 100644 index 00000000..aa347978 --- /dev/null +++ b/stable/installer/7za/Installer/cr.bat @@ -0,0 +1,4 @@ +del archive.7z +del archive.exe +..\7zr a archive.7z ..\7zr.exe -m0=BCJ2 -m1=LZMA:d25:fb255 -m2=LZMA:d19 -m3=LZMA:d19 -mb0:1 -mb0s1:2 -mb0s2:3 -mx +copy /b ..\7zSD.sfx + config.txt + archive.7z archive.exe diff --git a/stable/installer/7za/Installer/readme.txt b/stable/installer/7za/Installer/readme.txt new file mode 100644 index 00000000..0da060d7 --- /dev/null +++ b/stable/installer/7za/Installer/readme.txt @@ -0,0 +1,98 @@ +7-Zip for installers 4.65 +------------------------- + +7-Zip is a file archiver for Windows 98/ME/NT/2000/2003/XP. + +7-Zip Copyright (C) 1999-2009 Igor Pavlov. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +7zr.exe is reduced version of 7za.exe of 7-Zip. +7zr.exe supports only 7z format with this codecs: LZMA, BCJ, BCJ2, Copy. + +Example of compressing command for installation packages: + +7zr a -t7z archive.7z * -m0=BCJ2 -m1=LZMA:d25:fb255 -m2=LZMA:d19 -m3=LZMA:d19 -mb0:1 -mb0s1:2 -mb0s2:3 -mx + + +7zSD.sfx is SFX module for installers (it uses msvcrt.dll) + +SFX modules for installers (7zS.sfx and 7zSD.sfx) allow to create installation program. +Such module extracts archive to temp folder and then runs specified program and removes +temp files after program finishing. Self-extract archive for installers must be created +as joining 3 files: SFX_Module, Installer_Config, 7z_Archive. +Installer_Config is optional file. You can use the following command to create installer +self-extract archive: + +copy /b 7zSD.sfx + config.txt + archive.7z archive.exe + +The smallest installation package size can be achivied, if installation files was +uncompressed before including to 7z archive. + +-y switch for installer module (at runtime) specifies quiet mode for extracting. + +Installer Config file format +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Config file contains commands for Installer. File begins from string +;!@Install@!UTF-8! and ends with ;!@InstallEnd@!. File must be written +in UTF-8 encoding. File contains string pairs: + +ID_String="Value" + +ID_String Description + +Title Title for messages +BeginPrompt Begin Prompt message +Progress Value can be "yes" or "no". Default value is "yes". +RunProgram Command for executing. Default value is "setup.exe". + Substring %%T will be replaced with path to temporary + folder, where files were extracted +Directory Directory prefix for "RunProgram". Default value is ".\\" +ExecuteFile Name of file for executing +ExecuteParameters Parameters for "ExecuteFile" + + +You can omit any values. + +There are two ways to run program: RunProgram and ExecuteFile. +Use RunProgram, if you want to run some program from .7z archive. +Use ExecuteFile, if you want to open some document from .7z archive or +if you want to execute some command from Windows. + +If you use RunProgram and if you specify empty directory prefix: Directory="", +the system searches for the executable file in the following sequence: + +1. The directory from which the application (installer) loaded. +2. The temporary folder, where files were extracted. +3. The Windows system directory. + + +Config file Examples +~~~~~~~~~~~~~~~~~~~~ + +;!@Install@!UTF-8! +Title="7-Zip 4.00" +BeginPrompt="Do you want to install the 7-Zip 4.00?" +RunProgram="setup.exe" +;!@InstallEnd@! + + + +;!@Install@!UTF-8! +Title="7-Zip 4.00" +BeginPrompt="Do you want to install the 7-Zip 4.00?" +ExecuteFile="7zip.msi" +;!@InstallEnd@! + + + +;!@Install@!UTF-8! +Title="7-Zip 4.01 Update" +BeginPrompt="Do you want to install the 7-Zip 4.01 Update?" +ExecuteFile="msiexec.exe" +ExecuteParameters="/i 7zip.msi REINSTALL=ALL REINSTALLMODE=vomus" +;!@InstallEnd@! + diff --git a/stable/installer/7za/copying.txt b/stable/installer/7za/copying.txt new file mode 100644 index 00000000..f3926a61 --- /dev/null +++ b/stable/installer/7za/copying.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +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 this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser 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 Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "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 +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY 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 +LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/stable/installer/7za/history.txt b/stable/installer/7za/history.txt new file mode 100644 index 00000000..c4afdb9f --- /dev/null +++ b/stable/installer/7za/history.txt @@ -0,0 +1,44 @@ +7-Zip Extra history +------------------- + +4.65 2009-02-03 +------------------------------ + - Some bugs were fixed. + + +4.38 beta 2006-04-13 +------------------------------ + - SFX for installers now supports new properties in config file: + Progress, Directory, ExecuteFile, ExecuteParameters. + + +4.34 beta 2006-02-27 +------------------------------ + - ISetProperties::SetProperties: + it's possible to specify desirable number of CPU threads: + PROPVARIANT: name=L"mt", vt = VT_UI4, ulVal = NumberOfThreads + If "mt" is not defined, 7za.dll will check number of processors in system to set + number of desirable threads. + Now 7za.dll can use: + 2 threads for LZMA compressing + N threads for BZip2 compressing + 4 threads for BZip2 decompressing + Other codecs use only one thread. + Note: 7za.dll can use additional "small" threads with low CPU load. + - It's possible to call ISetProperties::SetProperties to specify "mt" property for decoder. + + +4.33 beta 2006-02-05 +------------------------------ + - Compressing speed and Memory requirements were increased. + Default dictionary size was increased: Fastest: 64 KB, Fast: 1 MB, + Normal: 4 MB, Max: 16 MB, Ultra: 64 MB. + - 7z/LZMA now can use only these match finders: HC4, BT2, BT3, BT4 + + +4.27 2005-09-21 +------------------------------ + - Some GUIDs/interfaces were changed. + IStream.h: + ISequentialInStream::Read now works as old ReadPart + ISequentialOutStream::Write now works as old WritePart diff --git a/stable/installer/7za/license.txt b/stable/installer/7za/license.txt new file mode 100644 index 00000000..7b66cf7a --- /dev/null +++ b/stable/installer/7za/license.txt @@ -0,0 +1,30 @@ + 7-Zip Command line version + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + License for use and distribution + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + 7-Zip Copyright (C) 1999-2009 Igor Pavlov. + + 7za.exe is distributed under the GNU LGPL license + + Notes: + You can use 7-Zip on any computer, including a computer in a commercial + organization. You don't need to register or pay for 7-Zip. + + + GNU LGPL information + -------------------- + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA diff --git a/stable/installer/7za/readme.txt b/stable/installer/7za/readme.txt new file mode 100644 index 00000000..782494a7 --- /dev/null +++ b/stable/installer/7za/readme.txt @@ -0,0 +1,42 @@ +7-Zip Command line version 4.65 +------------------------------- + +7-Zip is a file archiver with high compression ratio. +7za.exe is a standalone command line version of 7-Zip. + +7-Zip Copyright (C) 1999-2009 Igor Pavlov. + +Features of 7za.exe: + - High compression ratio in new 7z format + - Supported formats: + - Packing / unpacking: 7z, ZIP, GZIP, BZIP2 and TAR + - Unpacking only: Z + - Highest compression ratio for ZIP and GZIP formats. + - Fast compression and decompression + - Strong AES-256 encryption in 7z and ZIP formats. + +7za.exe is a free software distributed under the GNU LGPL. +Read license.txt for more information. + +Source code of 7za.exe and 7-Zip can be found at +http://www.7-zip.org/ + +7za.exe can work in Windows 95/98/ME/NT/2000/XP/2003/Vista. + +There is also port of 7za.exe for POSIX systems like Unix (Linux, Solaris, OpenBSD, +FreeBSD, Cygwin, AIX, ...), MacOS X and BeOS: + +http://p7zip.sourceforge.net/ + + + This distributive packet contains the following files: + + 7za.exe - 7-Zip standalone command line version. + readme.txt - This file. + copying.txt - GNU LGPL license. + license.txt - License information. + 7-zip.chm - User's Manual in HTML Help format. + + +--- +End of document diff --git a/stable/installer/7za/upx.exe b/stable/installer/7za/upx.exe new file mode 100644 index 00000000..6266213c Binary files /dev/null and b/stable/installer/7za/upx.exe differ diff --git a/stable/installer/CustomLangpack_eng.xml b/stable/installer/CustomLangpack_eng.xml new file mode 100644 index 00000000..7d66c45b --- /dev/null +++ b/stable/installer/CustomLangpack_eng.xml @@ -0,0 +1,20 @@ + + + + + + + + + Sorry, the target directory cannot currently contain + spaces due to limitations imposed by the MinGW + C compiler used by OpenModelica. + + For more information on the issue, see + http://www.mingw.org/wiki/Getting_Started. + + + + + + diff --git a/stable/installer/EPL.html b/stable/installer/EPL.html new file mode 100644 index 00000000..eae8395e --- /dev/null +++ b/stable/installer/EPL.html @@ -0,0 +1,266 @@ + + + + +Eclipse Public License - Version 1.0 + + + + +

Licenses

+ +

Simantics System Dynamics product consists of two main components: Simantics and Open Modelica.

+

Simantics is distributed under Eclipse Public License (EPL), see below.

+

Open Modelica is distributed under Open Source Modelica Consortium Public License (OSMC-PL), see http://www.openmodelica.org/index.php/home/license/140.

+

You are not allowed to redistribute OpenModelica integrated with Simantics, as in the System Dynamics Tool, without a membership in OSMC or without a separate contract with a level 2 member of OSMC.

+ +
+ +

Eclipse Public License - v 1.0

+ +

THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE +PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR +DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS +AGREEMENT.

+ +

1. DEFINITIONS

+ +

"Contribution" means:

+ +

a) in the case of the initial Contributor, the initial +code and documentation distributed under this Agreement, and

+

b) in the case of each subsequent Contributor:

+

i) changes to the Program, and

+

ii) additions to the Program;

+

where such changes and/or additions to the Program +originate from and are distributed by that particular Contributor. A +Contribution 'originates' from a Contributor if it was added to the +Program by such Contributor itself or anyone acting on such +Contributor's behalf. Contributions do not include additions to the +Program which: (i) are separate modules of software distributed in +conjunction with the Program under their own license agreement, and (ii) +are not derivative works of the Program.

+ +

"Contributor" means any person or entity that distributes +the Program.

+ +

"Licensed Patents" mean patent claims licensable by a +Contributor which are necessarily infringed by the use or sale of its +Contribution alone or when combined with the Program.

+ +

"Program" means the Contributions distributed in accordance +with this Agreement.

+ +

"Recipient" means anyone who receives the Program under +this Agreement, including all Contributors.

+ +

2. GRANT OF RIGHTS

+ +

a) Subject to the terms of this Agreement, each +Contributor hereby grants Recipient a non-exclusive, worldwide, +royalty-free copyright license to reproduce, prepare derivative works +of, publicly display, publicly perform, distribute and sublicense the +Contribution of such Contributor, if any, and such derivative works, in +source code and object code form.

+ +

b) Subject to the terms of this Agreement, each +Contributor hereby grants Recipient a non-exclusive, worldwide, +royalty-free patent license under Licensed Patents to make, use, sell, +offer to sell, import and otherwise transfer the Contribution of such +Contributor, if any, in source code and object code form. This patent +license shall apply to the combination of the Contribution and the +Program if, at the time the Contribution is added by the Contributor, +such addition of the Contribution causes such combination to be covered +by the Licensed Patents. The patent license shall not apply to any other +combinations which include the Contribution. No hardware per se is +licensed hereunder.

+ +

c) Recipient understands that although each Contributor +grants the licenses to its Contributions set forth herein, no assurances +are provided by any Contributor that the Program does not infringe the +patent or other intellectual property rights of any other entity. Each +Contributor disclaims any liability to Recipient for claims brought by +any other entity based on infringement of intellectual property rights +or otherwise. As a condition to exercising the rights and licenses +granted hereunder, each Recipient hereby assumes sole responsibility to +secure any other intellectual property rights needed, if any. For +example, if a third party patent license is required to allow Recipient +to distribute the Program, it is Recipient's responsibility to acquire +that license before distributing the Program.

+ +

d) Each Contributor represents that to its knowledge it +has sufficient copyright rights in its Contribution, if any, to grant +the copyright license set forth in this Agreement.

+ +

3. REQUIREMENTS

+ +

A Contributor may choose to distribute the Program in object code +form under its own license agreement, provided that:

+ +

a) it complies with the terms and conditions of this +Agreement; and

+ +

b) its license agreement:

+ +

i) effectively disclaims on behalf of all Contributors +all warranties and conditions, express and implied, including warranties +or conditions of title and non-infringement, and implied warranties or +conditions of merchantability and fitness for a particular purpose;

+ +

ii) effectively excludes on behalf of all Contributors +all liability for damages, including direct, indirect, special, +incidental and consequential damages, such as lost profits;

+ +

iii) states that any provisions which differ from this +Agreement are offered by that Contributor alone and not by any other +party; and

+ +

iv) states that source code for the Program is available +from such Contributor, and informs licensees how to obtain it in a +reasonable manner on or through a medium customarily used for software +exchange.

+ +

When the Program is made available in source code form:

+ +

a) it must be made available under this Agreement; and

+ +

b) a copy of this Agreement must be included with each +copy of the Program.

+ +

Contributors may not remove or alter any copyright notices contained +within the Program.

+ +

Each Contributor must identify itself as the originator of its +Contribution, if any, in a manner that reasonably allows subsequent +Recipients to identify the originator of the Contribution.

+ +

4. COMMERCIAL DISTRIBUTION

+ +

Commercial distributors of software may accept certain +responsibilities with respect to end users, business partners and the +like. While this license is intended to facilitate the commercial use of +the Program, the Contributor who includes the Program in a commercial +product offering should do so in a manner which does not create +potential liability for other Contributors. Therefore, if a Contributor +includes the Program in a commercial product offering, such Contributor +("Commercial Contributor") hereby agrees to defend and +indemnify every other Contributor ("Indemnified Contributor") +against any losses, damages and costs (collectively "Losses") +arising from claims, lawsuits and other legal actions brought by a third +party against the Indemnified Contributor to the extent caused by the +acts or omissions of such Commercial Contributor in connection with its +distribution of the Program in a commercial product offering. The +obligations in this section do not apply to any claims or Losses +relating to any actual or alleged intellectual property infringement. In +order to qualify, an Indemnified Contributor must: a) promptly notify +the Commercial Contributor in writing of such claim, and b) allow the +Commercial Contributor to control, and cooperate with the Commercial +Contributor in, the defense and any related settlement negotiations. The +Indemnified Contributor may participate in any such claim at its own +expense.

+ +

For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have to +defend claims against the other Contributors related to those +performance claims and warranties, and if a court requires any other +Contributor to pay any damages as a result, the Commercial Contributor +must pay those damages.

+ +

5. NO WARRANTY

+ +

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS +PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS +OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, +ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY +OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and +distributing the Program and assumes all risks associated with its +exercise of rights under this Agreement , including but not limited to +the risks and costs of program errors, compliance with applicable laws, +damage to or loss of data, programs or equipment, and unavailability or +interruption of operations.

+ +

6. DISCLAIMER OF LIABILITY

+ +

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT +NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING +WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR +DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED +HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

+ +

7. GENERAL

+ +

If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this Agreement, and without further action +by the parties hereto, such provision shall be reformed to the minimum +extent necessary to make such provision valid and enforceable.

+ +

If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging that the +Program itself (excluding combinations of the Program with other +software or hardware) infringes such Recipient's patent(s), then such +Recipient's rights granted under Section 2(b) shall terminate as of the +date such litigation is filed.

+ +

All Recipient's rights under this Agreement shall terminate if it +fails to comply with any of the material terms or conditions of this +Agreement and does not cure such failure in a reasonable period of time +after becoming aware of such noncompliance. If all Recipient's rights +under this Agreement terminate, Recipient agrees to cease use and +distribution of the Program as soon as reasonably practicable. However, +Recipient's obligations under this Agreement and any licenses granted by +Recipient relating to the Program shall continue and survive.

+ +

Everyone is permitted to copy and distribute copies of this +Agreement, but in order to avoid inconsistency the Agreement is +copyrighted and may only be modified in the following manner. The +Agreement Steward reserves the right to publish new versions (including +revisions) of this Agreement from time to time. No one other than the +Agreement Steward has the right to modify this Agreement. The Eclipse +Foundation is the initial Agreement Steward. The Eclipse Foundation may +assign the responsibility to serve as the Agreement Steward to a +suitable separate entity. Each new version of the Agreement will be +given a distinguishing version number. The Program (including +Contributions) may always be distributed subject to the version of the +Agreement under which it was received. In addition, after a new version +of the Agreement is published, Contributor may elect to distribute the +Program (including its Contributions) under the new version. Except as +expressly stated in Sections 2(a) and 2(b) above, Recipient receives no +rights or licenses to the intellectual property of any Contributor under +this Agreement, whether expressly, by implication, estoppel or +otherwise. All rights in the Program not expressly granted under this +Agreement are reserved.

+ +

This Agreement is governed by the laws of the State of New York and +the intellectual property laws of the United States of America. No party +to this Agreement will bring a legal action under this Agreement more +than one year after the cause of action arose. Each party waives its +rights to a jury trial in any resulting litigation.

+ + + + \ No newline at end of file diff --git a/stable/installer/TargetDir.txt.unix b/stable/installer/TargetDir.txt.unix new file mode 100644 index 00000000..55c23358 --- /dev/null +++ b/stable/installer/TargetDir.txt.unix @@ -0,0 +1 @@ +${USER_HOME}/Simantics/Sysdyn/$APP_VER \ No newline at end of file diff --git a/stable/installer/TargetDir.txt.windows b/stable/installer/TargetDir.txt.windows new file mode 100644 index 00000000..ccd82001 --- /dev/null +++ b/stable/installer/TargetDir.txt.windows @@ -0,0 +1 @@ +C:\Simantics\Sysdyn\$APP_VER \ No newline at end of file diff --git a/stable/installer/build.properties.unix b/stable/installer/build.properties.unix new file mode 100644 index 00000000..71833353 --- /dev/null +++ b/stable/installer/build.properties.unix @@ -0,0 +1,7 @@ +izpack.home=/opt/IzPack +izpack.src=${izpack.home}/src +izpack.compiler=${izpack.home}/bin/compile +izpack2exe.home=${izpack.home}/utils/wrappers/izpack2exe +izpack2exe=${izpack2exe.home}/izpack2exe.py +sevenzip.executable=/usr/bin/7za +upx.executable=/usr/bin/upx diff --git a/stable/installer/build.properties.windows b/stable/installer/build.properties.windows new file mode 100644 index 00000000..4d6a2836 --- /dev/null +++ b/stable/installer/build.properties.windows @@ -0,0 +1,7 @@ +izpack.home=C:/Program Files/IzPack +izpack.src=${izpack.home}/src +izpack.compiler=${izpack.home}/bin/compile.bat +izpack2exe.home=${izpack.home}/utils/wrappers/izpack2exe +izpack2exe=${izpack2exe.home}/izpack2exe.exe +sevenzip.executable=${basedir}\\7za\\7za.exe +upx.executable=${basedir}\\7za\\upx.exe \ No newline at end of file diff --git a/stable/installer/build.xml b/stable/installer/build.xml new file mode 100644 index 00000000..7ac10e3f --- /dev/null +++ b/stable/installer/build.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/stable/installer/custom/NonBlankTargetPanel.java b/stable/installer/custom/NonBlankTargetPanel.java new file mode 100644 index 00000000..5a0f937d --- /dev/null +++ b/stable/installer/custom/NonBlankTargetPanel.java @@ -0,0 +1,51 @@ + +/* + * Created on 29.06.2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package com.izforge.izpack.panels; + +import com.izforge.izpack.installer.InstallData; +import com.izforge.izpack.installer.InstallerFrame; + + +/** + * @author fabrice mirabile + */ +public class NonBlankTargetPanel extends TargetPanel +{ + private static final long serialVersionUID = 3248705610571943817L; + + public NonBlankTargetPanel(InstallerFrame parent, InstallData idata) + { + super(parent, idata); + } + + public boolean isValidated() + { + String chosenPath = pathSelectionPanel.getPath(); + if(chosenPath == null || chosenPath.length() < 1 ) + return( false ); + if( chosenPath.indexOf(" ") >= 0 ) + { + emitError(parent.langpack.getString("installer.error"), + parent.langpack.getString("NonBlankTargetPanel.noBlanks")); + return( false ); + } + return(super.isValidated() ); + } + + public void panelActivate() + { + super.panelActivate(); + String chosenPath = pathSelectionPanel.getPath(); + if(chosenPath == null || chosenPath.length() < 1 ) + return; + if( chosenPath.indexOf(" ") >= 0 ) + pathSelectionPanel.setPath(""); + } + + +} \ No newline at end of file diff --git a/stable/installer/custom/build.xml b/stable/installer/custom/build.xml new file mode 100644 index 00000000..35c193fb --- /dev/null +++ b/stable/installer/custom/build.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/stable/installer/custom/izpack-src-build.xml b/stable/installer/custom/izpack-src-build.xml new file mode 100644 index 00000000..436cc5c2 --- /dev/null +++ b/stable/installer/custom/izpack-src-build.xml @@ -0,0 +1,1346 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sucessfully created: + ${dist.dir}/${installer.name}${ver}.${rel}.jar + + + + + + + + + + + + + + + + + + + + + + + Fixing linefeeds for several files in: + "${dist.src.dir}" + and + "${dist.bin.dir}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/stable/installer/default_shortcut_specification.xml b/stable/installer/default_shortcut_specification.xml new file mode 100644 index 00000000..091dca92 --- /dev/null +++ b/stable/installer/default_shortcut_specification.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/stable/installer/download b/stable/installer/download new file mode 100755 index 00000000..4288e4e2 --- /dev/null +++ b/stable/installer/download @@ -0,0 +1,10 @@ +#!/bin/bash + +pushd . +cd `dirname $0` +BUILD=$1 + +rm -f files/dist.zip +cp -v /var/lib/jenkins/jobs/${BUILD} files/dist.zip || exit -1 + +popd > /dev/null diff --git a/stable/installer/download.bat b/stable/installer/download.bat new file mode 100644 index 00000000..73752506 --- /dev/null +++ b/stable/installer/download.bat @@ -0,0 +1,17 @@ +@echo off + +setlocal +pushd . +cd %~dp0 +set BUILD=%1 +set JOB_NAME=%2 + +del /s /q dist +wget -O dist.zip "http://www.simantics.org/hudson/job/%JOB_NAME%/%BUILD%/artifact/build/dist/*zip*/dist.zip" +unzip -o dist.zip +del files\dist.zip +copy dist\*sdk*.zip files\dist.zip +del /s /q dist.zip dist + +popd +endlocal diff --git a/stable/installer/files/Microsoft.VC90.CRT.setup.exe b/stable/installer/files/Microsoft.VC90.CRT.setup.exe new file mode 100644 index 00000000..823345da Binary files /dev/null and b/stable/installer/files/Microsoft.VC90.CRT.setup.exe differ diff --git a/stable/installer/files/install_msvcrt.bat b/stable/installer/files/install_msvcrt.bat new file mode 100644 index 00000000..7d56badc --- /dev/null +++ b/stable/installer/files/install_msvcrt.bat @@ -0,0 +1,2 @@ +@echo off +"%~dp0Microsoft.VC90.CRT.setup.exe" /q \ No newline at end of file diff --git a/stable/installer/files/jre-6u29-windows-i586-iftw.exe b/stable/installer/files/jre-6u29-windows-i586-iftw.exe new file mode 100644 index 00000000..39a0d7b9 Binary files /dev/null and b/stable/installer/files/jre-6u29-windows-i586-iftw.exe differ diff --git a/stable/installer/installer.xml b/stable/installer/installer.xml new file mode 100644 index 00000000..db16f51e --- /dev/null +++ b/stable/installer/installer.xml @@ -0,0 +1,104 @@ + + + + Simantics System Dynamics + Sysdyn + 1.6 + + + + http://www.simantics.org + + 1.6 + no + yes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Simantics SDK requires an up-to-date version of the Java Runtime Environment version 6. +If your JRE is old, you can install JRE 6 update 29 by selecting this. +NOTE: Installing this will require network access for downloading Java components. +Other Java installers are available at http://www.java.com/en/download/manual.jsp. + + + + + + + + Microsoft Visual C++ Run-Time 9.0 libraries. +These are required by native Simantics components. +Nothing is done if these are already installed on your system. + + + + + + + + + The Simantics System Dynamics application. + + + + + + + + diff --git a/stable/installer/side.png b/stable/installer/side.png new file mode 100644 index 00000000..e5438045 Binary files /dev/null and b/stable/installer/side.png differ diff --git a/stable/installer/side.svg b/stable/installer/side.svg new file mode 100644 index 00000000..ffb16f8d --- /dev/null +++ b/stable/installer/side.svg @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + Simantics + + diff --git a/stable/installer/unzip.exe b/stable/installer/unzip.exe new file mode 100644 index 00000000..1e947195 Binary files /dev/null and b/stable/installer/unzip.exe differ diff --git a/stable/installer/userInputSpec.xml b/stable/installer/userInputSpec.xml new file mode 100644 index 00000000..200fb9d3 --- /dev/null +++ b/stable/installer/userInputSpec.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/stable/installer/wget.exe b/stable/installer/wget.exe new file mode 100644 index 00000000..1b15a042 Binary files /dev/null and b/stable/installer/wget.exe differ diff --git a/stable/org.simantics.h2d/.classpath b/stable/org.simantics.h2d/.classpath new file mode 100644 index 00000000..8a8f1668 --- /dev/null +++ b/stable/org.simantics.h2d/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/stable/org.simantics.h2d/.hgignore b/stable/org.simantics.h2d/.hgignore new file mode 100644 index 00000000..73df90f6 --- /dev/null +++ b/stable/org.simantics.h2d/.hgignore @@ -0,0 +1,5 @@ +syntax: regexp +^bin/ + +syntax: glob +*.svn/* \ No newline at end of file diff --git a/stable/org.simantics.h2d/.project b/stable/org.simantics.h2d/.project new file mode 100644 index 00000000..e91c226c --- /dev/null +++ b/stable/org.simantics.h2d/.project @@ -0,0 +1,28 @@ + + + org.simantics.h2d + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/stable/org.simantics.h2d/.settings/org.eclipse.jdt.core.prefs b/stable/org.simantics.h2d/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..aa42399f --- /dev/null +++ b/stable/org.simantics.h2d/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Sun Nov 08 17:02:25 EET 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/stable/org.simantics.h2d/META-INF/MANIFEST.MF b/stable/org.simantics.h2d/META-INF/MANIFEST.MF new file mode 100644 index 00000000..4dbd46e4 --- /dev/null +++ b/stable/org.simantics.h2d/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: H2d +Bundle-SymbolicName: org.simantics.h2d +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Require-Bundle: org.simantics.scenegraph;bundle-version="0.9.0", + gnu.trove2;bundle-version="2.0.4", + org.simantics.objmap;bundle-version="0.1.0" +Export-Package: org.simantics.h2d.action, + org.simantics.h2d.canvas, + org.simantics.h2d.diagram, + org.simantics.h2d.editor, + org.simantics.h2d.editor.impl, + org.simantics.h2d.element, + org.simantics.h2d.element.handler, + org.simantics.h2d.event, + org.simantics.h2d.event.handler, + org.simantics.h2d.node diff --git a/stable/org.simantics.h2d/build.properties b/stable/org.simantics.h2d/build.properties new file mode 100644 index 00000000..efa0dd21 --- /dev/null +++ b/stable/org.simantics.h2d/build.properties @@ -0,0 +1,16 @@ +############################################################################### +# Copyright (c) 2007, 2010 Association for Decentralized Information Management +# in Industry THTH ry. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# VTT Technical Research Centre of Finland - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . +src.includes = doc/ diff --git a/stable/org.simantics.h2d/doc/manual.mediawiki b/stable/org.simantics.h2d/doc/manual.mediawiki new file mode 100644 index 00000000..e69de29b diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/action/IAction.java b/stable/org.simantics.h2d/src/org/simantics/h2d/action/IAction.java new file mode 100644 index 00000000..2e049846 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/action/IAction.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.action; + +import org.simantics.h2d.event.handler.IEventHandler; +import org.simantics.scenegraph.g2d.G2DParentNode; + +/** + * Action is a non-instantenous user operation on diagram. + * @see org.simantics.h2d.editor.IDiagramEditor#addAction + * @author Hannu Niemistö + */ +public interface IAction extends IEventHandler { + void init(G2DParentNode parent); + void remove(); +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/canvas/EditorCanvas.java b/stable/org.simantics.h2d/src/org/simantics/h2d/canvas/EditorCanvas.java new file mode 100644 index 00000000..0d0fdab9 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/canvas/EditorCanvas.java @@ -0,0 +1,251 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.canvas; + +import java.awt.Canvas; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; +import java.awt.geom.Point2D; +import java.awt.image.VolatileImage; + +import org.simantics.h2d.editor.IDiagramEditor; +import org.simantics.h2d.event.ClickEvent; +import org.simantics.h2d.event.DragEvent; +import org.simantics.h2d.event.DragEventPhase; +import org.simantics.h2d.event.KeyboardEvent; +import org.simantics.h2d.event.Modifiers; +import org.simantics.h2d.event.ReleaseEvent; +import org.simantics.h2d.event.WheelEvent; +import org.simantics.scenegraph.g2d.G2DRenderingHints; + + +public class EditorCanvas extends Canvas { + + private static final long serialVersionUID = -387207508390377519L; + + IDiagramEditor editor; + EventHandler eventHandler = new EventHandler(); + //BufferedImage background; + + public EditorCanvas(IDiagramEditor editor) { + this.editor = editor; + editor.setCanvas(this); + + /*G2DSceneGraph sceneGraph = editor.getSceneGraph(); + addMouseListener(sceneGraph); + addMouseMotionListener(sceneGraph); + addMouseWheelListener(sceneGraph); + addKeyListener(sceneGraph); + */ + addMouseListener(eventHandler); + addMouseMotionListener(eventHandler); + addMouseWheelListener(eventHandler); + addKeyListener(eventHandler); + + addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + repaint(); + } + }); + + /*try { + background = ImageIO.read(new File("c:/paper.png")); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + }*/ + } + + @Override + public void update(Graphics g) { + paint(g); + } + + private VolatileImage doubleBuffer; + @Override + public void paint(Graphics _g) { + do { + if (doubleBuffer == null + || doubleBuffer.getWidth() != getWidth() + || doubleBuffer.getHeight() != getHeight() + || doubleBuffer.validate(getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE) + { + doubleBuffer = createVolatileImage(getWidth(), getHeight()); + editor.setViewDimensions(new Dimension(getWidth(), getHeight())); + } + + Graphics2D g = (Graphics2D)doubleBuffer.getGraphics(); + + g.setBackground(Color.WHITE); + g.setColor(Color.WHITE); + //g.setPaint(new GradientPaint(0.f, 0.f, Color.white, 2000.f, 1600.f, Color.BLUE, false)); + //g.setPaint(new TexturePaint(background, getBounds())); + g.fillRect(0, 0, doubleBuffer.getWidth(), doubleBuffer.getHeight()); + + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + g.setRenderingHint(G2DRenderingHints.KEY_CONTROL_BOUNDS, getBounds()); + + g.setClip(0, 0, getWidth(), getHeight()); + + editor.getSceneGraph().render(g); + g.dispose(); + } while (doubleBuffer.contentsLost()); + + _g.drawImage(doubleBuffer, 0, 0, this); + } + + class EventHandler implements MouseListener, MouseMotionListener, MouseWheelListener, KeyListener { + + DragEvent dragEvent; + + @Override + public void mouseClicked(MouseEvent e) { + ClickEvent event = new ClickEvent( + Modifiers.modifierString(e.getButton(), e.isControlDown(), e.isAltDown(), e.isShiftDown()), + editor.screenToDiagram(e.getPoint()), + e.getLocationOnScreen() + ); + event.pickedElements = dragEvent.pickedElements; + editor.handleEvent(event); + } + + @Override + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mousePressed(MouseEvent e) { + editor.getSceneGraph().mousePressed(e); + if(e.isConsumed()) + return; + dragEvent = new DragEvent( + Modifiers.modifierString(e.getButton(), e.isControlDown(), e.isAltDown(), e.isShiftDown()), + editor.screenToDiagram(e.getPoint()) + ); + dragEvent.pickedElements = editor.pickElements(dragEvent.start); + } + + @Override + public void mouseReleased(MouseEvent e) { + editor.getSceneGraph().mouseReleased(e); + if(e.isConsumed()) + return; + if(dragEvent != null && dragEvent.phase == DragEventPhase.dragUpdate) { + dragEvent.phase = DragEventPhase.dragEnd; + editor.handleEvent(dragEvent); + } + + if(dragEvent != null) { + ReleaseEvent event = new ReleaseEvent( + Modifiers.modifierString(e.getButton(), e.isControlDown(), e.isAltDown(), e.isShiftDown()), + editor.screenToDiagram(e.getPoint()), + e.getLocationOnScreen() + ); + + event.pickedElements = dragEvent.pickedElements; + editor.handleEvent(event); + } + } + + @Override + public void mouseDragged(MouseEvent e) { + editor.getSceneGraph().mouseDragged(e); + if(e.isConsumed()) + return; + currentPosition = e.getPoint(); + if(dragEvent != null) { // TODO why this is needed? + dragEvent.currentModifiers = + Modifiers.modifierString(e.getButton(), e.isControlDown(), e.isAltDown(), e.isShiftDown()); + dragEvent.current = editor.screenToDiagram(e.getPoint()); + } + editor.handleEvent(dragEvent); + + if(dragEvent != null && dragEvent.phase == DragEventPhase.dragBegin) { + dragEvent.phase = DragEventPhase.dragUpdate; + editor.handleEvent(dragEvent); + } + } + + Point2D currentPosition = new Point2D.Double(0.0, 0.0); + + @Override + public void mouseMoved(MouseEvent e) { + currentPosition = e.getPoint(); + } + + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + editor.handleEvent(new WheelEvent( + Modifiers.modifierString(e.getButton(), e.isControlDown(), e.isAltDown(), e.isShiftDown()), + editor.screenToDiagram(e.getPoint()), + e.getWheelRotation() + )); + } + + @Override + public void keyPressed(KeyEvent e) { + editor.getSceneGraph().keyPressed(e); + if(e.isConsumed()) + return; + + String keyText = KeyEvent.getKeyText(e.getKeyCode()); + if(e.getModifiers() != 0) + keyText = KeyEvent.getKeyModifiersText(e.getModifiers()) + + "+" + keyText; + KeyboardEvent event = new KeyboardEvent( + keyText, + editor.screenToDiagram(currentPosition) + ); + event.pickedElements = editor.pickElements(event.point); + if(editor.handleEvent(event)) + e.consume(); + } + + @Override + public void keyReleased(KeyEvent e) { + editor.getSceneGraph().keyReleased(e); + } + + @Override + public void keyTyped(KeyEvent e) { + editor.getSceneGraph().keyTyped(e); + } + } + + public IDiagramEditor getEditor() { + return editor; + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/diagram/Diagram.java b/stable/org.simantics.h2d/src/org/simantics/h2d/diagram/Diagram.java new file mode 100644 index 00000000..673a5be8 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/diagram/Diagram.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.diagram; + +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; + +import org.simantics.h2d.element.IElement; +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedValue; + +@GraphType("http://www.simantics.org/Sysdyn-1.0/Configuration") +public class Diagram implements IDiagram { + + @RelatedValue("http://www.simantics.org/Layer0-1.0/ConsistsOf") + public List elements = new Vector(); + ArrayList listeners = new ArrayList(); + + @Override + public void addElement(IElement element) { + elements.add(element); + for(IDiagramListener listener : listeners) + listener.elementAdded(element); + } + + @Override + public List getElements() { + return elements; + } + + @Override + public void addDiagramListener(IDiagramListener listener) { + listeners.add(listener); + } + + @Override + public void removeElement(IElement element) { + elements.remove(element); + for(IDiagramListener listener : listeners) + listener.elementRemoved(element); + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/diagram/IDiagram.java b/stable/org.simantics.h2d/src/org/simantics/h2d/diagram/IDiagram.java new file mode 100644 index 00000000..8263651b --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/diagram/IDiagram.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.diagram; + +import java.util.List; + +import org.simantics.h2d.element.IElement; + +/** + * Diagram is the whole that is edited in a diagram editor. + * @author Hannu Niemistö + */ +public interface IDiagram { + List getElements(); + void addElement(IElement element); + void removeElement(IElement element); + void addDiagramListener(IDiagramListener listener); +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/diagram/IDiagramListener.java b/stable/org.simantics.h2d/src/org/simantics/h2d/diagram/IDiagramListener.java new file mode 100644 index 00000000..9f061e00 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/diagram/IDiagramListener.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.diagram; + +import org.simantics.h2d.element.IElement; + +public interface IDiagramListener { + + void elementAdded(IElement element); + void elementRemoved(IElement element); + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/editor/IDiagramEditor.java b/stable/org.simantics.h2d/src/org/simantics/h2d/editor/IDiagramEditor.java new file mode 100644 index 00000000..987f400f --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/editor/IDiagramEditor.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.editor; + +import java.awt.Canvas; +import java.awt.Dimension; +import java.awt.geom.AffineTransform; +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.List; + +import org.simantics.h2d.action.IAction; +import org.simantics.h2d.diagram.IDiagram; +import org.simantics.h2d.element.IElement; +import org.simantics.h2d.event.IEvent; +import org.simantics.h2d.event.handler.IEventHandler; +import org.simantics.scenegraph.g2d.G2DSceneGraph; + +public interface IDiagramEditor { + + IDiagram getDiagram(); + + /** + * Returns the root of the scenegraph that renders the diagram. + */ + G2DSceneGraph getSceneGraph(); + + /** + * Handles an external event. + * @return True if the event was consumed. + */ + boolean handleEvent(IEvent event); + + /** + * Returns the current view transform (from diagram coordinates to screen coordinates) defined as: + *
diagramToScreen(p) = (p - offset) / scale
+ */ + AffineTransform getViewTransform(); + + /** + * Returns the current view offset. That is the diagram coordinates of the top left point of the canvas. + */ + Point2D getOffset(); + + /** + * Returns the current view scale. That is
lengthInDiagramCoordinates / lengthInScreenCoordinates
. + */ + double getScale(); + + /** + * Maps a point from screen coordinates to diagram coordinates. + */ + Point2D screenToDiagram(Point2D point); + + /** + * Sets a new view transform. + * @param offset New offset + * @param scale New scale + * + * @see #getOffset + * @see #getScale + */ + void setViewTransform(Point2D offset, double scale); + + void setViewDimensions(Dimension2D dimension); + Dimension getViewDimension(); + + // Events + void addEventHandler(int priority, String eventType, IEventHandler handler); + void addEventHandler(int priority, IEventHandler handler); + + void addAction(IAction action); + void removeAction(IAction action); + + void requestRepaint(); + void setCanvas(Canvas canvas); + + /** + * Returns current selection + */ + ISelection getSelection(); + + /** + * Returns all elements at the point. Pick uses a hard coded tolerance that is calculated in screen coordinates. + */ + List pickElements(Point2D point); + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/editor/ISelection.java b/stable/org.simantics.h2d/src/org/simantics/h2d/editor/ISelection.java new file mode 100644 index 00000000..f4f1426c --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/editor/ISelection.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.editor; + +import java.util.Collection; + +import org.simantics.h2d.element.IElement; + +public interface ISelection extends Iterable { + + boolean contains(IElement el); + boolean containsOneOf(Collection els); + void clear(); + void set(Collection els); + void set(IElement el); + boolean add(IElement el); + boolean addAll(Collection els); + boolean toggle(IElement el); + boolean remove(IElement el); + boolean isEmpty(); + int size(); + IElement getSingleElement(); + + void addSelectionListener(ISelectionListener listener); + void removeSelectionListener(ISelectionListener listener); + +} \ No newline at end of file diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/editor/ISelectionListener.java b/stable/org.simantics.h2d/src/org/simantics/h2d/editor/ISelectionListener.java new file mode 100644 index 00000000..3e6fe056 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/editor/ISelectionListener.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.editor; + +public interface ISelectionListener { + + void selectionChanged(ISelection selection); + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/editor/impl/DiagramEditor.java b/stable/org.simantics.h2d/src/org/simantics/h2d/editor/impl/DiagramEditor.java new file mode 100644 index 00000000..172cf500 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/editor/impl/DiagramEditor.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.editor.impl; + +import java.awt.Canvas; +import java.awt.Dimension; +import java.awt.geom.AffineTransform; +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JComponent; + +import org.simantics.h2d.action.IAction; +import org.simantics.h2d.diagram.IDiagram; +import org.simantics.h2d.diagram.IDiagramListener; +import org.simantics.h2d.editor.IDiagramEditor; +import org.simantics.h2d.editor.ISelection; +import org.simantics.h2d.element.IElement; +import org.simantics.h2d.event.IEvent; +import org.simantics.h2d.event.handler.IEventHandler; +import org.simantics.scenegraph.g2d.G2DSceneGraph; + +public class DiagramEditor implements IDiagramEditor { + + public static final double PICK_TOLERANCE = 5.0; + + IDiagram diagram; + + // Viewpoint + Point2D offset; + double scale; + AffineTransform viewTransform = new AffineTransform(); + Dimension dimension = new Dimension(800, 600); + + ISelection selection; + + ArrayList actionStack = new ArrayList(); + + SceneGraphManager sgManager; + EventHandlerManager eventHandlerManager = new EventHandlerManager(); + + Canvas canvas; + + public void setCanvas(Canvas canvas) { + this.canvas = canvas; + } + + public DiagramEditor(JComponent rootPane, IDiagram diagram) { + this.diagram = diagram; + sgManager = new SceneGraphManager(rootPane); + + setViewTransform(new Point2D.Double(), 13.0 / 48.0); + sgManager.setViewTransform(viewTransform); + + selection = new Selection(sgManager.selectionNode); + + for(IElement element : diagram.getElements()) + element.init(sgManager.elementsNode); + diagram.addDiagramListener(new IDiagramListener() { + + @Override + public void elementAdded(IElement element) { + element.init(sgManager.elementsNode); + } + + @Override + public void elementRemoved(IElement element) { + element.remove(); + } + + }); + } + + @Override + public G2DSceneGraph getSceneGraph() { + return sgManager.sceneGraph; + } + + @Override + public boolean handleEvent(IEvent event) { + for(int i=actionStack.size()-1;i>=0;--i) + if(actionStack.get(i).handle(this, event)) + return true; + return eventHandlerManager.handle(this, event); + } + + @Override + public void addEventHandler(int priority, String eventType, IEventHandler handler) { + eventHandlerManager.addEventHandler(priority, eventType, handler); + } + + @Override + public void addEventHandler(int priority, IEventHandler handler) { + eventHandlerManager.addEventHandler(priority, handler); + } + + @Override + public ISelection getSelection() { + return selection; + } + + @Override + public Point2D getOffset() { + return offset; + } + + @Override + public double getScale() { + return scale; + } + + @Override + public AffineTransform getViewTransform() { + return viewTransform; + } + + @Override + public void setViewTransform(Point2D offset, double scale) { + this.offset = offset; + this.scale = scale; + viewTransform.setTransform(1.0/scale, 0.0, 0.0, 1.0/scale, + -offset.getX()/scale, -offset.getY()/scale); + } + + @Override + public Point2D screenToDiagram(Point2D point) { + return new Point2D.Double(point.getX()*scale + offset.getX(), point.getY()*scale + offset.getY()); + } + + @Override + public IDiagram getDiagram() { + return diagram; + } + + @Override + public List pickElements(Point2D point) { + double tolerance = PICK_TOLERANCE*scale; + ArrayList result = new ArrayList(); + for(IElement element : getDiagram().getElements()) { + if(element.hitTest(point.getX(), point.getY(), tolerance)) + result.add(element); + } + return result; + } + + @Override + public void addAction(IAction action) { + actionStack.add(action); + action.init(sgManager.actionNode); + requestRepaint(); + } + + @Override + public void removeAction(IAction action) { + actionStack.remove(action); + action.remove(); + requestRepaint(); + } + + @Override + public Dimension getViewDimension() { + return dimension; + } + + @Override + public void setViewDimensions(Dimension2D dimension) { + this.dimension.setSize(dimension); + } + + @Override + public void requestRepaint() { + canvas.repaint(); + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/editor/impl/EventHandlerManager.java b/stable/org.simantics.h2d/src/org/simantics/h2d/editor/impl/EventHandlerManager.java new file mode 100644 index 00000000..76880963 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/editor/impl/EventHandlerManager.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.editor.impl; + +import gnu.trove.THashMap; + +import java.util.LinkedList; +import java.util.ListIterator; + +import org.simantics.h2d.editor.IDiagramEditor; +import org.simantics.h2d.event.IEvent; +import org.simantics.h2d.event.handler.IEventHandler; + +class EventHandlerManager implements IEventHandler { + LinkedList handlers = new LinkedList(); + + public void addEventHandler(int priority, String eventType, IEventHandler handler) { + ListIterator it = handlers.listIterator(); + while(it.hasNext()) { + PrioritizedEventHandler group = it.next(); + if(group.priority == priority) + group.put(eventType, handler); + else if(group.priority < priority) { + it.previous(); + break; + } + } + + // Add a new level + MapEventHandler map = new MapEventHandler(priority); + map.put(eventType, handler); + it.add(map); + } + + public void addEventHandler(int priority, IEventHandler handler) { + ListIterator it = handlers.listIterator(); + while(it.hasNext()) { + PrioritizedEventHandler group = it.next(); + if(group.priority == priority) + throw new IllegalArgumentException("Tried add an event handler of type of priority " + priority + + ", but this conflicts with an event handler(s) with the same priority."); + else if(group.priority < priority) { + it.previous(); + break; + } + } + + // Add a new level + it.add(new SingletonEventHandler(priority, handler)); + } + + static abstract class PrioritizedEventHandler { + public final int priority; + + public PrioritizedEventHandler(int priority) { + this.priority = priority; + } + + public abstract void put(String type, IEventHandler handler); + public abstract boolean handle(String type, IDiagramEditor editor, IEvent event); + + } + + static class SingletonEventHandler extends PrioritizedEventHandler { + + IEventHandler handler; + + public SingletonEventHandler(int priority, IEventHandler handler) { + super(priority); + this.handler = handler; + } + + @Override + public boolean handle(String type, IDiagramEditor editor, IEvent event) { + return handler.handle(editor, event); + } + + @Override + public void put(String type, IEventHandler handler) { + throw new IllegalArgumentException("Tried add an event handler of type " + type + " and priority " + priority + + ", but this conflicts with an event handler with the same priority."); + } + + } + + static class MapEventHandler extends PrioritizedEventHandler { + + THashMap handlers = new THashMap(); + public MapEventHandler(int priority) { + super(priority); + } + + @Override + public void put(String type, IEventHandler handler) { + if(handlers.contains(type)) + throw new IllegalArgumentException("Tried add an event handler of type " + type + " and priority " + priority + + ", but this conflicts with an event handler with the same priority and type."); + handlers.put(type, handler); + } + + @Override + public boolean handle(String type, IDiagramEditor editor, IEvent event) { + IEventHandler handler = handlers.get(type); + return handler != null && handler.handle(editor, event); + } + + } + + @Override + public boolean handle(IDiagramEditor editor, IEvent event) { + String type = event.getType(); + for(PrioritizedEventHandler level : handlers) { + if(level.handle(type, editor, event)) + return true; + } + return false; + } +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/editor/impl/SceneGraphManager.java b/stable/org.simantics.h2d/src/org/simantics/h2d/editor/impl/SceneGraphManager.java new file mode 100644 index 00000000..cf207c7b --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/editor/impl/SceneGraphManager.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.editor.impl; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; + +import javax.swing.JComponent; + +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.G2DSceneGraph; +import org.simantics.scenegraph.g2d.nodes.PageBorderNode; +import org.simantics.scenegraph.g2d.nodes.TransformNode; + +class SceneGraphManager { + G2DSceneGraph sceneGraph; + TransformNode diagramCoordinatesNode; + G2DParentNode elementsNode; + G2DParentNode selectionNode; + G2DParentNode actionNode; + + public SceneGraphManager(JComponent rootPane) { + sceneGraph = new G2DSceneGraph(); + //sceneGraph.setRootPane(rootPane); + diagramCoordinatesNode = sceneGraph.addNode(TransformNode.class); + + PageBorderNode border = diagramCoordinatesNode.addNode(PageBorderNode.class); + border.init(new Rectangle2D.Double(0.0, 0.0, 297.0, 210.0), new Rectangle2D.Double(10.0, 10.0, 277.0, 190.0), Boolean.TRUE); + + elementsNode = diagramCoordinatesNode.addNode(G2DParentNode.class); + elementsNode.setZIndex(0); + + selectionNode = diagramCoordinatesNode.addNode(G2DParentNode.class); + selectionNode.setZIndex(1); + + actionNode = diagramCoordinatesNode.addNode(G2DParentNode.class); + actionNode.setZIndex(2); + } + + void setViewTransform(AffineTransform viewTransform) { + diagramCoordinatesNode.setTransform(viewTransform); + } +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/editor/impl/Selection.java b/stable/org.simantics.h2d/src/org/simantics/h2d/editor/impl/Selection.java new file mode 100644 index 00000000..632d454a --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/editor/impl/Selection.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.editor.impl; + +import gnu.trove.THashSet; + +import java.awt.Color; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.simantics.h2d.editor.ISelection; +import org.simantics.h2d.editor.ISelectionListener; +import org.simantics.h2d.element.IElement; +import org.simantics.h2d.element.IElementListener; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.nodes.SelectionNode; + +class Selection implements ISelection { + static final AffineTransform IDENTITY = new AffineTransform(); + + THashSet elements = new THashSet(); + G2DParentNode selectionParentNode; + + CopyOnWriteArrayList listeners = + new CopyOnWriteArrayList(); + + static class SelectionUpdater implements IElementListener { + SelectionNode node; + IElement element; + + public SelectionUpdater(SelectionNode node, IElement element) { + this.node = node; + this.element = element; + + elementUpdated(element); + element.addListener(this); + } + + @Override + public void elementUpdated(IElement element) { + Rectangle2D bounds = new Rectangle2D.Double(); + element.getBounds(bounds); + node.init(IDENTITY, bounds, Color.GRAY); + } + + public void remove() { + element.removeListener(this); + } + + @Override + public void elementRemoved(IElement element) { + // TODO ? + } + + } + + ArrayList updaters = new ArrayList(); + + public Selection(G2DParentNode selectionParentNode) { + this.selectionParentNode = selectionParentNode; + } + + private void updateSceneGraph() { + // Clear old selection + selectionParentNode.removeNodes(); + for(SelectionUpdater updater : updaters) + updater.remove(); + updaters.clear(); + + // Create new selection + //System.out.println("selection: " + elements.size()); + for(IElement element : elements) + updaters.add(new SelectionUpdater(selectionParentNode.addNode(SelectionNode.class), element)); + + // Notify listeners + // TODO this is in wrong place + for(ISelectionListener listener : listeners) + listener.selectionChanged(this); + } + + public boolean contains(IElement el) { + return elements.contains(el); + } + + public boolean containsOneOf(Collection els) { + for(IElement el : els) + if(elements.contains(el)) + return true; + return false; + } + + public void clear() { + if(!elements.isEmpty()) { + elements.clear(); + updateSceneGraph(); + } + } + + public void set(Collection els) { + elements.clear(); + elements.addAll(els); + updateSceneGraph(); + } + + public void set(IElement el) { + elements.clear(); + elements.add(el); + updateSceneGraph(); + } + + public boolean add(IElement el) { + boolean result = elements.add(el); + updateSceneGraph(); + return result; + } + + public boolean addAll(Collection els) { + boolean result = elements.addAll(els); + updateSceneGraph(); + return result; + } + + public boolean toggle(IElement el) { + if(elements.contains(el)) { + elements.remove(el); + updateSceneGraph(); + return false; + } + else { + elements.add(el); + updateSceneGraph(); + return true; + } + } + + public boolean remove(IElement el) { + boolean result = elements.remove(el); + updateSceneGraph(); + return result; + } + + @Override + public Iterator iterator() { + return elements.iterator(); + } + + @Override + public boolean isEmpty() { + return elements.isEmpty(); + } + + @Override + public int size() { + return elements.size(); + } + + @Override + public IElement getSingleElement() { + for(IElement element : elements) + return element; + return null; + } + + @Override + public void addSelectionListener(ISelectionListener listener) { + listeners.add(listener); + } + + @Override + public void removeSelectionListener(ISelectionListener listener) { + listeners.remove(listener); + } +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/element/ChainingElementListener.java b/stable/org.simantics.h2d/src/org/simantics/h2d/element/ChainingElementListener.java new file mode 100644 index 00000000..ce5bc99e --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/element/ChainingElementListener.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.element; + + +class ChainingElementListener implements IElementListener { + IElementListener listener1; + IElementListener listener2; + + ChainingElementListener(IElementListener listener1, + IElementListener listener2) { + this.listener1 = listener1; + this.listener2 = listener2; + } + + @Override + public void elementUpdated(IElement element) { + listener1.elementUpdated(element); + listener2.elementUpdated(element); + } + + @Override + public void elementRemoved(IElement element) { + listener1.elementRemoved(element); + listener2.elementRemoved(element); + } + + static IElementListener addListener(IElementListener currentListener, IElementListener newListener) { + if(currentListener == null) + return newListener; + else + return new ChainingElementListener(currentListener, newListener); + } + + static IElementListener removeListener(IElementListener currentListener, IElementListener listenerToRemove) { + if(currentListener == null || currentListener == listenerToRemove) + return null; + else if(currentListener instanceof ChainingElementListener) { + ChainingElementListener chain = (ChainingElementListener)currentListener; + if(chain.listener2 == listenerToRemove) + return chain.listener1; + else { + IElementListener l = removeListener(chain.listener1, listenerToRemove); + if(l == null) + return chain.listener2; + chain.listener1 = l; + } + } + return currentListener; + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/element/Element.java b/stable/org.simantics.h2d/src/org/simantics/h2d/element/Element.java new file mode 100644 index 00000000..96bc2250 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/element/Element.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.element; + + +public abstract class Element implements IElement { + + IElementListener listener; + + @SuppressWarnings("unchecked") + @Override + public T getInterface(Class clazz) { + if(clazz.isInstance(this)) + return (T) this; + return null; + } + + protected void fireElementUpdated() { + if(listener != null) + listener.elementUpdated(this); + } + + @Override + public void addListener(IElementListener listener) { + this.listener = ChainingElementListener.addListener(this.listener, listener); + } + + @Override + public void removeListener(IElementListener listener) { + this.listener = ChainingElementListener.removeListener(this.listener, listener); + } + + @Override + public void remove() { + if(listener != null) + listener.elementRemoved(this); + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/element/IElement.java b/stable/org.simantics.h2d/src/org/simantics/h2d/element/IElement.java new file mode 100644 index 00000000..5a2e39ac --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/element/IElement.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.element; + +import java.awt.geom.Rectangle2D; + +import org.simantics.scenegraph.g2d.G2DParentNode; + +/** + * Element is a part of a diagram that has its own type and properties. + * @author Hannu Niemistö + */ +public interface IElement { + T getInterface(Class clazz); + + void init(G2DParentNode parent); + void remove(); + + /** + * Updates the parameter bounds so that it contains + * the bounding box of the element. + */ + void getBounds(Rectangle2D bounds); + + /** + * Returns true, if the interior of the element intersects + * a circle at (x,y) with radius tolerance. + * Returns false, if the element and a circle at (x,y) with + * radius sqrt(2)*tolerance are disjoint. Otherwise may return true + * or false depending on the implementation. + */ + boolean hitTest(double x, double y, double tolerance); + + void addListener(IElementListener listener); + void removeListener(IElementListener listener); + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/element/IElementListener.java b/stable/org.simantics.h2d/src/org/simantics/h2d/element/IElementListener.java new file mode 100644 index 00000000..438629dd --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/element/IElementListener.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.element; + + +public interface IElementListener { + /** + * Called when the publicy available properties of the elements are changed. + * @param element + */ + public void elementUpdated(IElement element); + + public void elementRemoved(IElement element); + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/Connectable.java b/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/Connectable.java new file mode 100644 index 00000000..5d03f160 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/Connectable.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.element.handler; + +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +import org.simantics.h2d.element.IElement; + + + +public interface Connectable extends IElementHandler, IElement { + + void getBounds(Rectangle2D bounds); + Point2D getOrigo(); + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/IElementHandler.java b/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/IElementHandler.java new file mode 100644 index 00000000..93c6a697 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/IElementHandler.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.element.handler; + +/** + * The base interface of all element handler interfaces. Needed only for + * documenting purposes. + * @author Hannu Niemistö + */ +public interface IElementHandler { +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/Movable.java b/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/Movable.java new file mode 100644 index 00000000..e8722c73 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/Movable.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.element.handler; + + + +public interface Movable extends IElementHandler { + + /** + * Moves the element by the given delta. + */ + void move(double deltaX, double deltaY); + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/Rotatable.java b/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/Rotatable.java new file mode 100644 index 00000000..386a97d1 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/Rotatable.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.element.handler; + + + +public interface Rotatable extends IElementHandler { + + /** + * Rotates the element amount times 90 degrees clockwise. + */ + void rotate(int amount); + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/ShadowDrawable.java b/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/ShadowDrawable.java new file mode 100644 index 00000000..d9245a00 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/element/handler/ShadowDrawable.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.element.handler; + +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; + +public interface ShadowDrawable { + + /** + * Draws the shadow of the element. + */ + void draw(Graphics2D g, AffineTransform transform); + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/ClickEvent.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/ClickEvent.java new file mode 100644 index 00000000..34957cd5 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/ClickEvent.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event; + +import java.awt.geom.Point2D; +import java.util.List; + +import org.simantics.h2d.element.IElement; + + +public class ClickEvent implements ILocatableEvent { + final public String modifiers; + + // Click location in diagram coordinates + final public Point2D point; + final public Point2D dispPoint; + + public List pickedElements; + + public ClickEvent(String modifiers, Point2D point, Point2D dispPoint) { + this.modifiers = modifiers; + this.dispPoint = dispPoint; + this.point = point; + } + + @Override + public String getType() { + return getType(modifiers); + } + + public static String getType(String modifiers) { + return "click(" + modifiers + ")"; + } + + @Override + public Point2D getLocation() { + return point; + } + + @Override + public List getPickedElements() { + return pickedElements; + } +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/DragEvent.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/DragEvent.java new file mode 100644 index 00000000..11bf28c5 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/DragEvent.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event; + +import java.awt.geom.Point2D; +import java.util.List; + +import org.simantics.h2d.element.IElement; + + +public class DragEvent implements ILocatableEvent { + public DragEventPhase phase; + + public String startModifiers; + public String currentModifiers; + + public Point2D start; + public Point2D current; + + public List pickedElements; + + public DragEvent(String startModifiers, Point2D start) { + this.phase = DragEventPhase.dragBegin; + this.startModifiers = startModifiers; + this.currentModifiers = startModifiers; + this.start = start; + this.current = start; + } + + @Override + public String getType() { + return getType(startModifiers); + } + + public static String getType(String modifiers) { + return "drag(" + modifiers + ")"; + } + + @Override + public Point2D getLocation() { + return start; + } + + @Override + public List getPickedElements() { + return pickedElements; + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/DragEventPhase.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/DragEventPhase.java new file mode 100644 index 00000000..714c9ad3 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/DragEventPhase.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event; + +public enum DragEventPhase { + dragBegin, dragUpdate, dragEnd +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/IDragHandler.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/IDragHandler.java new file mode 100644 index 00000000..07ef210c --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/IDragHandler.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event; + +public interface IDragHandler { + public void handleMove(); + public void handleRelease(); +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/IEvent.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/IEvent.java new file mode 100644 index 00000000..fa29389b --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/IEvent.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event; + +public interface IEvent { + String getType(); +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/ILocatableEvent.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/ILocatableEvent.java new file mode 100644 index 00000000..cbb0330e --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/ILocatableEvent.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event; + +import java.awt.geom.Point2D; +import java.util.List; + +import org.simantics.h2d.element.IElement; + +public interface ILocatableEvent extends IEvent { + Point2D getLocation(); + List getPickedElements(); +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/KeyboardEvent.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/KeyboardEvent.java new file mode 100644 index 00000000..26a7cccc --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/KeyboardEvent.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event; + +import java.awt.geom.Point2D; +import java.util.List; + +import org.simantics.h2d.element.IElement; + + +public class KeyboardEvent implements ILocatableEvent { + final public String key; + + // Click location in diagram coordinates + final public Point2D point; + + public List pickedElements; + + + public KeyboardEvent(String key, Point2D point) { + this.key = key; + this.point = point; + } + + + @Override + public String getType() { + return getType(key); + } + + public static String getType(String key) { + return "key(" + key + ")"; + } + + @Override + public Point2D getLocation() { + return point; + } + + @Override + public List getPickedElements() { + return pickedElements; + } +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/Modifiers.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/Modifiers.java new file mode 100644 index 00000000..d6005e6b --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/Modifiers.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event; + +import java.awt.event.MouseEvent; + +public class Modifiers { + + public static String modifierString( + int button, + boolean ctrl, + boolean alt, + boolean shift + ) { + StringBuilder b = new StringBuilder(); + if(ctrl) + b.append("ctrl+"); + if(alt) + b.append("alt+"); + if(shift) + b.append("shift+"); + if(button == MouseEvent.BUTTON1) + b.append("left"); + else if(button == MouseEvent.BUTTON2) + b.append("middle"); + else if(button == MouseEvent.BUTTON3) + b.append("right"); + return b.toString(); + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/ReleaseEvent.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/ReleaseEvent.java new file mode 100644 index 00000000..c6d57de3 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/ReleaseEvent.java @@ -0,0 +1,42 @@ +package org.simantics.h2d.event; + +import java.awt.geom.Point2D; +import java.util.List; + +import org.simantics.h2d.element.IElement; + +public class ReleaseEvent implements ILocatableEvent { + final public String modifiers; + + // Release location in diagram coordinates + final public Point2D point; + final public Point2D dispPoint; + + public List pickedElements; + + public ReleaseEvent(String modifiers, Point2D point, Point2D dispPoint) { + this.modifiers = modifiers; + this.dispPoint = dispPoint; + this.point = point; + } + + @Override + public Point2D getLocation() { + return point; + } + + @Override + public List getPickedElements() { + return pickedElements; + } + + @Override + public String getType() { + return getType(modifiers); + } + + public static String getType(String modifiers) { + return "release(" + modifiers + ")"; + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/WheelEvent.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/WheelEvent.java new file mode 100644 index 00000000..ee2de8a8 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/WheelEvent.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event; + +import java.awt.geom.Point2D; + + +public class WheelEvent implements IEvent { + final public String modifiers; + + // Click location in diagram coordinates + final public Point2D point; + + final public int amount; + + public WheelEvent(String modifiers, Point2D point, int amount) { + this.modifiers = modifiers; + this.point = point; + this.amount = amount; + } + + @Override + public String getType() { + return getType(modifiers); + } + + public static String getType(String modifiers) { + return "wheel(" + modifiers + ")"; + } +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/BoxSelection.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/BoxSelection.java new file mode 100644 index 00000000..ae5f9bbe --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/BoxSelection.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event.handler; + +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.h2d.editor.IDiagramEditor; +import org.simantics.h2d.editor.ISelection; +import org.simantics.h2d.element.IElement; +import org.simantics.h2d.event.DragEvent; +import org.simantics.h2d.node.RectangleNode; +import org.simantics.scenegraph.g2d.G2DParentNode; + +public class BoxSelection extends DragEventHandler { + + Rectangle2D rectangle = new Rectangle2D.Double(); + RectangleNode selectionNode; + + @Override + protected void update(IDiagramEditor editor, DragEvent event) { + rectangle.setFrameFromDiagonal(event.start, event.current); + editor.requestRepaint(); + } + + @Override + protected void end(IDiagramEditor editor, DragEvent event) { + Rectangle2D.Double elementBounds = new Rectangle2D.Double(); + ISelection selection = editor.getSelection(); + System.out.println(event.currentModifiers); + + Collection toBeSelected = new ArrayList(); + for(IElement element : editor.getDiagram().getElements()) { + element.getBounds(elementBounds); + if(rectangle.contains(elementBounds)) + toBeSelected.add(element); + } + + if(event.currentModifiers.equals("ctrl+")) + selection.addAll(toBeSelected); + else + selection.set(toBeSelected); + editor.requestRepaint(); + } + + @Override + public void init(G2DParentNode parent) { + selectionNode = parent.addNode(RectangleNode.class); + selectionNode.init(rectangle); + } + + @Override + public void remove() { + selectionNode.remove(); + selectionNode = null; + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/DefaultEventHandlers.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/DefaultEventHandlers.java new file mode 100644 index 00000000..cdf1af95 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/DefaultEventHandlers.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event.handler; + +import org.simantics.h2d.editor.IDiagramEditor; + +public class DefaultEventHandlers { + + private DefaultEventHandlers() {} + + public static void configure(IDiagramEditor editor) { + editor.addEventHandler(1, "click(left)", new PickSelection()); + editor.addEventHandler(1, "click(ctrl+left)", new ToggleSelection()); + editor.addEventHandler(1, "drag(shift+left)", new Pan()); + editor.addEventHandler(1, "drag(alt+shift+middle)", new Pan()); + editor.addEventHandler(1, "drag(alt+middle)", new Pan()); + editor.addEventHandler(1, "drag(shift+right)", new Pan()); + editor.addEventHandler(1, "wheel()", new Zoom()); + editor.addEventHandler(1, "key(1)", new ZoomToFit()); + editor.addEventHandler(1, "key(Period)", new RotateCounterclockwise()); + editor.addEventHandler(1, "key(Comma)", new RotateClockwise()); + editor.addEventHandler(1, "key(Ctrl+D)", new Delete()); + + editor.addEventHandler(0, new ElementEventDelegator()); + + editor.addEventHandler(-1, "drag(left)", new MoveSelected()); + editor.addEventHandler(-2, "drag(left)", new BoxSelection()); + editor.addEventHandler(-2, "drag(ctrl+left)", new BoxSelection()); + + // Prints all unhandled events + //editor.addEventHandler(-1000, new EventPrinter()); + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/Delete.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/Delete.java new file mode 100644 index 00000000..713d5650 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/Delete.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event.handler; + +import org.simantics.h2d.diagram.IDiagram; +import org.simantics.h2d.editor.IDiagramEditor; +import org.simantics.h2d.element.IElement; +import org.simantics.h2d.event.IEvent; + +public class Delete implements IEventHandler { + + @Override + public boolean handle(IDiagramEditor editor, IEvent event) { + IDiagram diagram = editor.getDiagram(); + for(IElement element : editor.getSelection()) { + diagram.removeElement(element); + } + editor.getSelection().clear(); + editor.requestRepaint(); + return true; + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/DragEventHandler.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/DragEventHandler.java new file mode 100644 index 00000000..1cf9af72 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/DragEventHandler.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event.handler; + +import org.simantics.h2d.action.IAction; +import org.simantics.h2d.editor.IDiagramEditor; +import org.simantics.h2d.event.DragEvent; +import org.simantics.h2d.event.IEvent; +import org.simantics.scenegraph.g2d.G2DParentNode; + +public abstract class DragEventHandler implements IAction { + + boolean isActive = false; + + protected boolean begin(IDiagramEditor editor, DragEvent event) { + return true; + } + + protected void update(IDiagramEditor editor, DragEvent event) { + } + + protected void end(IDiagramEditor editor, DragEvent event) { + } + + @Override + public boolean handle(IDiagramEditor editor, IEvent _event) { + if(_event instanceof DragEvent) { + DragEvent event = (DragEvent)_event; + + switch(event.phase) { + case dragBegin: + if(isActive) + return true; + if(begin(editor, event)) { + isActive = true; + editor.addAction(this); + return true; + } + else + return false; + + case dragUpdate: + if(!isActive) + return false; + update(editor, event); + return true; + + case dragEnd: + if(!isActive) + return false; + isActive = false; + editor.removeAction(this); + end(editor, event); + return true; + } + + } + return false; + } + + @Override + public void init(G2DParentNode parent) { + } + + @Override + public void remove() { + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/ElementEventDelegator.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/ElementEventDelegator.java new file mode 100644 index 00000000..21177468 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/ElementEventDelegator.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event.handler; + +import org.simantics.h2d.editor.IDiagramEditor; +import org.simantics.h2d.element.IElement; +import org.simantics.h2d.event.IEvent; +import org.simantics.h2d.event.ILocatableEvent; +import org.simantics.h2d.event.KeyboardEvent; + +public class ElementEventDelegator implements IEventHandler { + + @Override + public boolean handle(IDiagramEditor editor, IEvent _event) { + if(_event instanceof KeyboardEvent) { + IEventHandler uniqueHandler = null; + for(IElement element : editor.getSelection()) { + IEventHandler handler = element.getInterface(IEventHandler.class); + if(handler != null) { + if(uniqueHandler != null) + return true; // nobody cannot consume the event + uniqueHandler = handler; + } + } + if(uniqueHandler != null) + return uniqueHandler.handle(editor, _event); + } + else if(_event instanceof ILocatableEvent) { + ILocatableEvent event = (ILocatableEvent)_event; + for(IElement element : event.getPickedElements()) { + IEventHandler handler = element.getInterface(IEventHandler.class); + if(handler != null && handler.handle(editor, event)) + return true; + } + } + return false; + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/EventPrinter.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/EventPrinter.java new file mode 100644 index 00000000..8dbf80a8 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/EventPrinter.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event.handler; + +import org.simantics.h2d.editor.IDiagramEditor; +import org.simantics.h2d.event.IEvent; + +public class EventPrinter implements IEventHandler { + + @Override + public boolean handle(IDiagramEditor editor, IEvent event) { + System.out.println(event.getType()); + return false; + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/IEventHandler.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/IEventHandler.java new file mode 100644 index 00000000..d30f61b2 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/IEventHandler.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event.handler; + +import org.simantics.h2d.editor.IDiagramEditor; +import org.simantics.h2d.event.IEvent; + +public interface IEventHandler { + + boolean handle(IDiagramEditor editor, IEvent event); + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/MoveSelected.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/MoveSelected.java new file mode 100644 index 00000000..5726b8c2 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/MoveSelected.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event.handler; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.util.List; + +import org.simantics.h2d.editor.IDiagramEditor; +import org.simantics.h2d.editor.ISelection; +import org.simantics.h2d.element.IElement; +import org.simantics.h2d.element.handler.Movable; +import org.simantics.h2d.event.DragEvent; +import org.simantics.h2d.node.RectangleNode; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.nodes.TransformNode; + +public class MoveSelected extends DragEventHandler { + + double deltaX, deltaY; + TransformNode shadowNode; + ISelection selection; + + @Override + protected boolean begin(IDiagramEditor editor, DragEvent event) { + List pick = event.pickedElements; + if(pick.isEmpty()) + return false; + selection = editor.getSelection(); + boolean pickContainsSelected = false; + for(IElement element : pick) + if(selection.contains(element)) { + pickContainsSelected = true; + break; + } + if(!pickContainsSelected) { + selection.clear(); + selection.add(pick.get(0)); + } + return true; + } + + @Override + protected void update(IDiagramEditor editor, DragEvent event) { + deltaX = event.current.getX() - event.start.getX(); + deltaY = event.current.getY() - event.start.getY(); + shadowNode.setTransform(new AffineTransform(1.0, 0.0, 0.0, 1.0, deltaX, deltaY)); + editor.requestRepaint(); + } + + @Override + protected void end(IDiagramEditor editor, DragEvent event) { + for(IElement element : selection) + if(element instanceof Movable) { + ((Movable)element).move(deltaX, deltaY); + } + selection = null; + editor.requestRepaint(); + } + + @Override + public void init(G2DParentNode parent) { + shadowNode = parent.addNode(TransformNode.class); + + for(IElement element : selection) { + Rectangle2D elementBounds = new Rectangle2D.Double(); + element.getBounds(elementBounds); + RectangleNode shadow = shadowNode.addNode(RectangleNode.class); + shadow.init(elementBounds); + } + } + + @Override + public void remove() { + shadowNode.remove(); + shadowNode = null; + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/Pan.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/Pan.java new file mode 100644 index 00000000..a490e580 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/Pan.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event.handler; + +import java.awt.geom.Point2D; + +import org.simantics.h2d.editor.IDiagramEditor; +import org.simantics.h2d.event.DragEvent; + +public class Pan extends DragEventHandler { + + @Override + protected void update(IDiagramEditor editor, DragEvent event) { + Point2D offset = editor.getOffset(); + double scale = editor.getScale(); + editor.setViewTransform( + new Point2D.Double( + offset.getX() + event.start.getX() - event.current.getX(), + offset.getY() + event.start.getY() - event.current.getY() + ), + scale); + editor.requestRepaint(); + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/PickSelection.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/PickSelection.java new file mode 100644 index 00000000..199e0de0 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/PickSelection.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event.handler; + +import java.util.List; + +import org.simantics.h2d.editor.IDiagramEditor; +import org.simantics.h2d.editor.ISelection; +import org.simantics.h2d.element.IElement; +import org.simantics.h2d.event.ClickEvent; +import org.simantics.h2d.event.IEvent; + +public class PickSelection implements IEventHandler { + + @Override + public boolean handle(IDiagramEditor editor, IEvent _event) { + ClickEvent event = (ClickEvent)_event; + List pick = event.pickedElements; + ISelection selection = editor.getSelection(); + if(pick.isEmpty()) { + selection.clear(); + editor.requestRepaint(); + } + else { + if(selection.containsOneOf(pick)) { + if(pick.size() > 1 && selection.size()==1) { + /* + * If there are multiple elements under mouse and the current + * selection is exactly one of them then rotate thru all one + * element selection possibilities. + */ + IElement s = selection.getSingleElement(); + for(int i=0;i pick = event.pickedElements; + if(!pick.isEmpty()) { + editor.getSelection().toggle(pick.get(0)); + editor.requestRepaint(); + } + return true; + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/Zoom.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/Zoom.java new file mode 100644 index 00000000..0113bdfb --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/Zoom.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event.handler; + +import java.awt.geom.Point2D; + +import org.simantics.h2d.editor.IDiagramEditor; +import org.simantics.h2d.event.IEvent; +import org.simantics.h2d.event.WheelEvent; + +public class Zoom implements IEventHandler { + + public final static double ZOOM_PER_CLICK = 1.2; + + @Override + public boolean handle(IDiagramEditor editor, IEvent _event) { + final WheelEvent event = (WheelEvent)_event; + Point2D offset = editor.getOffset(); + double scale = editor.getScale(); + double scaleRatio = Math.pow(ZOOM_PER_CLICK, event.amount); + + editor.setViewTransform( + new Point2D.Double( + offset.getX() * scaleRatio + event.point.getX() * (1.0 - scaleRatio), + offset.getY() * scaleRatio + event.point.getY() * (1.0 - scaleRatio) + ), + scale * scaleRatio); + editor.requestRepaint(); + return true; + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/ZoomToFit.java b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/ZoomToFit.java new file mode 100644 index 00000000..7d0378b0 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/event/handler/ZoomToFit.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.event.handler; + +import java.awt.Dimension; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +import org.simantics.h2d.editor.IDiagramEditor; +import org.simantics.h2d.element.IElement; +import org.simantics.h2d.event.IEvent; + +public class ZoomToFit implements IEventHandler { + + @Override + public boolean handle(IDiagramEditor editor, IEvent event) { + Rectangle2D diagramBounds = null; + Rectangle2D elementBounds = new Rectangle2D.Double(); + for(IElement element : editor.getDiagram().getElements()) { + element.getBounds(elementBounds); + if(diagramBounds == null) { + diagramBounds = new Rectangle2D.Double(); + diagramBounds.setFrame(elementBounds); + } + else { + Rectangle2D.union(diagramBounds, elementBounds, diagramBounds); + } + } + if(diagramBounds != null) { + Dimension dimension = editor.getViewDimension(); + + double scale = Math.max( + diagramBounds.getWidth() / dimension.getWidth(), + diagramBounds.getHeight() / dimension.getHeight() + ); + + Point2D offset = new Point2D.Double( + diagramBounds.getCenterX() - dimension.getWidth() * scale * 0.5, + diagramBounds.getCenterY() - dimension.getHeight() * scale * 0.5 + ); + editor.setViewTransform(offset, scale); + } + editor.requestRepaint(); + return true; + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/node/FilledShapeNode.java b/stable/org.simantics.h2d/src/org/simantics/h2d/node/FilledShapeNode.java new file mode 100644 index 00000000..1732270a --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/node/FilledShapeNode.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.node; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Shape; +import java.awt.geom.Rectangle2D; + +import org.simantics.scenegraph.g2d.G2DNode; + +public class FilledShapeNode extends G2DNode { + + private static final long serialVersionUID = -7540487222025677413L; + + protected Shape shape = null; + protected Color color = Color.BLACK; + + @SyncField("shape") + public void setShape(Shape shape) { + this.shape = shape; + } + + @SyncField("color") + public void setColor(Color color) { + this.color = color; + } + + @Override + public void render(Graphics2D g2d) { + if(shape == null) return; + if(color != null) g2d.setColor(color); + + g2d.fill(shape); + } + + @Override + public Rectangle2D getBoundsInLocal() { + if(shape == null) + return null; + return shape.getBounds2D(); + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/node/ITextListener.java b/stable/org.simantics.h2d/src/org/simantics/h2d/node/ITextListener.java new file mode 100644 index 00000000..0dcd7681 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/node/ITextListener.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.node; + +public interface ITextListener { + + void textChanged(); + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/node/LineNode.java b/stable/org.simantics.h2d/src/org/simantics/h2d/node/LineNode.java new file mode 100644 index 00000000..d7ebb069 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/node/LineNode.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.node; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.Path2D; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +import org.simantics.scenegraph.g2d.G2DNode; + +public class LineNode extends G2DNode { + + private static final long serialVersionUID = 654692698101485672L; + + Point2D begin; + Point2D end; + protected Path2D path; + + @SyncField({"begin","end"}) + public void init(Point2D begin, Point2D end) { + this.begin = begin; + this.end = end; + update(); + } + + protected void update() { + path = new Path2D.Double(); + path.moveTo(begin.getX(), begin.getY()); + path.lineTo(end.getX(), end.getY()); + } + + @Override + public void render(Graphics2D g) { + if(path == null) return; + g.setColor(Color.BLACK); + double scale = g.getTransform().getScaleX(); + g.setStroke(new BasicStroke( (float)(1.0 / scale) )); + g.draw(path); + } + + @Override + public Rectangle2D getBoundsInLocal() { + Rectangle2D bounds = new Rectangle2D.Double(); + bounds.setFrameFromDiagonal(begin, end); + return bounds; + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/node/RectangleNode.java b/stable/org.simantics.h2d/src/org/simantics/h2d/node/RectangleNode.java new file mode 100644 index 00000000..da8daaa4 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/node/RectangleNode.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.node; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; + +import org.simantics.scenegraph.g2d.G2DNode; + +public class RectangleNode extends G2DNode { + + private static final long serialVersionUID = 654692698101485672L; + + protected Rectangle2D bounds = null; + + @SyncField("bounds") + public void init(Rectangle2D bounds) { + this.bounds = bounds; + } + + @Override + public void render(Graphics2D g) { + if(bounds == null) return; + g.transform(transform); + g.setColor(Color.BLACK); + double scale = g.getTransform().getScaleX(); + g.setStroke(new BasicStroke( (float)(1.0 / scale) )); + + g.draw(bounds); + } + + @Override + public Rectangle2D getBoundsInLocal() { + return bounds; + } + +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/node/ShapeNode.java b/stable/org.simantics.h2d/src/org/simantics/h2d/node/ShapeNode.java new file mode 100644 index 00000000..495fb614 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/node/ShapeNode.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.node; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.Shape; +import java.awt.Stroke; +import java.awt.geom.Rectangle2D; + +import org.simantics.scenegraph.g2d.G2DNode; +import org.simantics.scenegraph.utils.GeometryUtils; + +public class ShapeNode extends G2DNode { + + /** + * + */ + private static final long serialVersionUID = 8508750881358776559L; + + protected Shape shape = null; + protected Stroke stroke = new BasicStroke(1); + protected Color color = Color.BLACK; + protected boolean fill = false; + protected boolean scaleStroke = false; + protected boolean scaleShape = false; + + @SyncField("shape") + public void setShape(Shape shape) { + this.shape = shape; + repaint(); + } + + @SyncField("stroke") + public void setStroke(Stroke stroke) { + this.stroke = stroke; + } + + @SyncField("color") + public void setColor(Color color) { + this.color = color; + } + + @SyncField("fill") + public void setFill(boolean fill) { + this.fill = fill; + } + + @SyncField("scaleStroke") + public void setScaleStroke(boolean scaleStroke) { + this.scaleStroke = scaleStroke; + } + + @SyncField("scaleShape") + public void setScaleShape(boolean scaleShape) { + this.scaleShape = scaleShape; + } + + @Override + public void render(Graphics2D g2d) { + if(shape == null) return; + + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // FIXME + if(color != null) g2d.setColor(color); + if(stroke != null) { + if(scaleStroke && stroke instanceof BasicStroke) { + BasicStroke bs = GeometryUtils.scaleStroke(stroke, (float) (1.0 / GeometryUtils.getScale(g2d.getTransform()))); + g2d.setStroke(bs); + } else { + g2d.setStroke(stroke); + } + } + if(scaleShape) { + double xs = g2d.getTransform().getScaleX(); + double ys = g2d.getTransform().getScaleY(); + g2d.scale(1/xs, 1/ys); + } + + if(fill) { + g2d.fill(shape); + } else { + g2d.draw(shape); + } + + } + + @Override + public Rectangle2D getBoundsInLocal() { + return shape.getBounds2D(); + } +} diff --git a/stable/org.simantics.h2d/src/org/simantics/h2d/node/TextNode.java b/stable/org.simantics.h2d/src/org/simantics/h2d/node/TextNode.java new file mode 100644 index 00000000..6575c352 --- /dev/null +++ b/stable/org.simantics.h2d/src/org/simantics/h2d/node/TextNode.java @@ -0,0 +1,276 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.h2d.node; + +import java.awt.AWTEvent; +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.font.FontRenderContext; +import java.awt.geom.Line2D; +import java.awt.geom.Rectangle2D; + +import org.simantics.scenegraph.g2d.G2DNode; + +public class TextNode extends G2DNode { + + //static final FontRenderContext FRC = new FontRenderContext( + // new AffineTransform(1.0,0.0,0.0,1.0,0.0,0.0), true, true); + + private static final long serialVersionUID = 654692698101485672L; + + protected String text = null; + protected Font font = null; + protected Color color = null; + protected double x; + protected double y; + protected double scale; + + boolean editAllowed; + int caret = 0; + int selectionTail = 0; + + ITextListener textListener; + + /** + * Enables or disables edit mode. It also sets + * the caret at the end of text all selects the + * whole text (this is the usual convention when + * beginning to edit one line texts). + * @param editAllowed + */ + public void setEditMode(boolean editAllowed) { + this.editAllowed = editAllowed; + caret = text.length(); + selectionTail = 0; + } + + @SyncField({"text", "font", "color", "x", "y", "scale"}) + public void init(String text, Font font, Color color, double x, double y, double scale) { + this.text = text; + this.font = font; + this.color = color; + this.x = x; + this.y = y; + this.scale = scale; + } + + @SyncField({"color"}) + public void setColor(Color color) { + this.color = color; + } + + public String getText() { + return text; + } + + private double getLength(FontRenderContext frc, String str) { + Rectangle2D bounds = font.getStringBounds(str, frc); + return bounds.getWidth(); + } + + @Override + public void render(Graphics2D g) { + if(text == null || font == null || color == null) return; + g.setFont(font); + g.translate(x, y); + g.scale(scale, scale); + + if(editAllowed) { + FontRenderContext frc = g.getFontRenderContext(); + + int selectionMin = Math.min(caret, selectionTail); + int selectionMax = Math.max(caret, selectionTail); + double selectionMinPos = getLength(frc, text.substring(0, selectionMin)); + double selectionMaxPos = getLength(frc, text.substring(0, selectionMax)); + + // Selection background + g.setColor(new Color(0x316ac5)); + g.fill(new Rectangle2D.Double(selectionMinPos, -12.0, + selectionMaxPos-selectionMinPos, 12.0)); + + // Text + g.setColor(color); + g.drawString(text.substring(0, selectionMin), 0f, 0f); + g.drawString(text.substring(selectionMax), (float)selectionMaxPos, 0f); + + g.setColor(Color.WHITE); + g.drawString(text.substring(selectionMin, selectionMax), (float)selectionMinPos, 0f); + + // Caret + double caretPos = getLength(frc, text.substring(0, caret)); + //g.setXORMode(Color.BLACK); + g.setColor(Color.BLACK); + g.draw(new Line2D.Double(caretPos, 0, caretPos, -12.0)); + } + else { + g.setColor(color); + g.drawString(text, 0f, 0f); + } + } + + /** + * Replaces the current selection with the content or inserts + * the content at caret. After the insertion the caret + * will be at the end of inserted text and selection will + * be empty. + * @param content + */ + @SyncField("text") + protected void insert(String content) { + if(!content.contains(" ")) { + int selectionMin = Math.min(caret, selectionTail); + int selectionMax = Math.max(caret, selectionTail); + + String begin = text.substring(0, selectionMin); + String end = text.substring(selectionMax); + text = begin + content + end; + caret = selectionMin + content.length(); + selectionTail = caret; + } + } + + + @ServerSide + protected void fireTextChanged() { + if(textListener != null) + textListener.textChanged(); + } + + public void setTextListener(ITextListener listener) { + this.textListener = listener; + } + + private void handleKeyPressed(KeyEvent event) { + char c = event.getKeyChar(); + //System.out.println("Key pressed " + c + " " + event.getKeyCode()); + if(event.isControlDown()) + switch(event.getKeyCode()) { + case KeyEvent.VK_C: + if(caret != selectionTail) { + int selectionMin = Math.min(caret, selectionTail); + int selectionMax = Math.max(caret, selectionTail); + setCliboardContent(text.substring(selectionMin, selectionMax)); + } + break; + + case KeyEvent.VK_V: + { + String content = getCliboardContent(); + if(content != null) + insert(content); + } + break; + default: + return; + } + else if(event.isAltDown()) + return; + else + switch(event.getKeyCode()) { + case KeyEvent.VK_LEFT: + if(caret > 0) { + --caret; + if(!event.isShiftDown()) + selectionTail = caret; + } + break; + case KeyEvent.VK_RIGHT: + if(caret < text.length()) { + ++caret; + if(!event.isShiftDown()) + selectionTail = caret; + } + break; + case KeyEvent.VK_HOME: + caret = 0; + if(!event.isShiftDown()) + selectionTail = caret; + break; + case KeyEvent.VK_END: + caret = text.length(); + if(!event.isShiftDown()) + selectionTail = caret; + break; + + case KeyEvent.VK_BACK_SPACE: + if(caret == selectionTail && caret > 0) + --caret; + insert(""); + break; + + case KeyEvent.VK_DELETE: + if(caret == selectionTail && caret < text.length()) + ++caret; + insert(""); + break; + + default: + if(c == 65535 || Character.getType(c) == Character.CONTROL) + return; + //System.out.println("Char " + (int)c + " " + Character.getType(c)); + insert(new String(new char[] {c})); + } + // FIXME This is called even if just caret was moved. + // This is currently necessary for repaints. + fireTextChanged(); + event.consume(); + } + + private void handleMousePressed(MouseEvent event) { + // TODO + } + + @Override + public void handleEvent(AWTEvent event) { + if(editAllowed) { + if(caret > text.length()) + caret = text.length(); + switch(event.getID()) { + case KeyEvent.KEY_PRESSED: + handleKeyPressed((KeyEvent)event); + break; + case MouseEvent.MOUSE_PRESSED: + handleMousePressed((MouseEvent)event); + break; + } + } + } + + @Override + public Rectangle2D getBoundsInLocal() { + return null; + } + + public String getCliboardContent() { + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + Transferable clipData = clipboard.getContents(this); + try { + return (String) (clipData.getTransferData(DataFlavor.stringFlavor)); + } catch (Exception ee) { + return null; + } + } + + public void setCliboardContent(String content) { + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringSelection data = new StringSelection(content); + clipboard.setContents(data, data); + } +} diff --git a/stable/org.simantics.jfreechart.ontology/.classpath b/stable/org.simantics.jfreechart.ontology/.classpath new file mode 100644 index 00000000..8a8f1668 --- /dev/null +++ b/stable/org.simantics.jfreechart.ontology/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/stable/org.simantics.jfreechart.ontology/.project b/stable/org.simantics.jfreechart.ontology/.project new file mode 100644 index 00000000..36a196b0 --- /dev/null +++ b/stable/org.simantics.jfreechart.ontology/.project @@ -0,0 +1,34 @@ + + + org.simantics.jfreechart.ontology + + + + + + org.simantics.graph.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.simantics.graph.nature + + diff --git a/stable/org.simantics.jfreechart.ontology/.settings/org.eclipse.jdt.core.prefs b/stable/org.simantics.jfreechart.ontology/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..8fdbeb77 --- /dev/null +++ b/stable/org.simantics.jfreechart.ontology/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Mon Nov 14 12:29:34 EET 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/stable/org.simantics.jfreechart.ontology/META-INF/MANIFEST.MF b/stable/org.simantics.jfreechart.ontology/META-INF/MANIFEST.MF new file mode 100644 index 00000000..c792a6a0 --- /dev/null +++ b/stable/org.simantics.jfreechart.ontology/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: JFreeChart +Bundle-SymbolicName: org.simantics.jfreechart.ontology +Bundle-Version: 0.1.0.qualifier +Require-Bundle: org.simantics.layer0, + org.simantics.layer0x.ontology;bundle-version="1.0.0", + org.simantics.g2d.ontology;bundle-version="1.0.0", + org.simantics.diagram.ontology;bundle-version="2.1.0", + org.simantics.structural.ontology;bundle-version="1.1.0", + org.simantics.modeling.ontology;bundle-version="1.1.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Export-Package: org.simantics.sysdyn diff --git a/stable/org.simantics.jfreechart.ontology/build.properties b/stable/org.simantics.jfreechart.ontology/build.properties new file mode 100644 index 00000000..022de173 --- /dev/null +++ b/stable/org.simantics.jfreechart.ontology/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + graph.tg diff --git a/stable/org.simantics.jfreechart.ontology/graph.tg b/stable/org.simantics.jfreechart.ontology/graph.tg new file mode 100644 index 00000000..b48384c3 Binary files /dev/null and b/stable/org.simantics.jfreechart.ontology/graph.tg differ diff --git a/stable/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph b/stable/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph new file mode 100644 index 00000000..01933123 --- /dev/null +++ b/stable/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph @@ -0,0 +1,130 @@ +L0 = +L0X = +G2D = +DIA = +MOD = +STR = + +//##################################################################### +// Ontology for defining JFreeChart charts +//##################################################################### + +JFREE = : L0.Ontology + @L0.new + L0.HasResourceClass "org.simantics.sysdyn.JFreeChartResource" + +//##################################################################### +// Charts +//##################################################################### +JFREE.Chart -- JFREE.title --> JFREE.Title -- JFREE.subtitles --> L0.List -- JFREE.Chart.borderColor --> G2D.Color -- JFREE.Chart.visibleBorder --> L0.Boolean -- JFREE.Chart.borderWidth --> L0.Double -- JFREE.Chart.visibleLegend --> L0.Boolean -- JFREE.Chart.time --> L0.Double -- JFREE.visible --> L0.Boolean -- JFREE.Title.position --> L0.Boolean -- JFREE.Plot.domainAxis --> JFREE.Axis -- JFREE.Plot.rangeAxis --> JFREE.Axis -- JFREE.backgroundColor --> G2D.Color -- JFREE.Plot.visibleGrid --> L0.Boolean -- JFREE.Plot.rangeAxisList --> L0.List -- JFREE.Plot.visibleLabels --> L0.Boolean -- JFREE.color --> G2D.Color -- JFREE.Axis.min --> L0.Double -- JFREE.Axis.max --> L0.Double -- JFREE.Axis.visibleTickLabels --> L0.Boolean -- JFREE.Axis.visibleTickMarks --> L0.Boolean -- JFREE.Axis.visibleAxisLine --> L0.Boolean -- JFREE.Axis.visibleLabel --> L0.Boolean -- JFREE.Axis.rotateLabelDegrees --> L0.Double -- JFREE.Dataset.seriesList --> L0.List -- JFREE.Dataset.renderer --> JFREE.Renderer -- JFREE.Dataset.mapToDomainAxis --> JFREE.Axis -- JFREE.Dataset.mapToRangeAxis --> JFREE.Axis -- JFREE.color + >-- JFREE.variableRVI --> L0.String -- JFREE.variableFilter --> L0.StringArray -- JFREE.Series.rangeList --> L0.List -- JFREE.Series.lineWidth --> L0.Integer -- JFREE.Series.exploded --> L0.Boolean -- JFREE.Series.time --> L0.Double -- JFREE.ChartElement.component --> JFREE.Chart () { + public JFreeChartResource perform(ReadGraph graph) throws DatabaseException { + QueryControl qc = graph.getService(QueryControl.class); + return new JFreeChartResource(qc.getIndependentGraph(graph)); + } + }); + session.registerService(JFreeChartResource.class, ret); + } + return ret; + } + +} + diff --git a/stable/org.simantics.modelica/.classpath b/stable/org.simantics.modelica/.classpath new file mode 100644 index 00000000..8a8f1668 --- /dev/null +++ b/stable/org.simantics.modelica/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/stable/org.simantics.modelica/.project b/stable/org.simantics.modelica/.project new file mode 100644 index 00000000..2d4d7aa0 --- /dev/null +++ b/stable/org.simantics.modelica/.project @@ -0,0 +1,28 @@ + + + org.simantics.modelica + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/stable/org.simantics.modelica/.settings/org.eclipse.jdt.core.prefs b/stable/org.simantics.modelica/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..f25d3a62 --- /dev/null +++ b/stable/org.simantics.modelica/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Tue Jan 26 16:43:56 EET 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/stable/org.simantics.modelica/META-INF/MANIFEST.MF b/stable/org.simantics.modelica/META-INF/MANIFEST.MF new file mode 100644 index 00000000..80e82f4e --- /dev/null +++ b/stable/org.simantics.modelica/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Modelica +Bundle-SymbolicName: org.simantics.modelica;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Require-Bundle: gnu.trove2;bundle-version="2.0.4", + org.eclipse.osgi;bundle-version="3.6.0", + org.eclipse.core.runtime;bundle-version="3.6.0", + org.simantics.history;bundle-version="1.0.0", + org.simantics.databoard;bundle-version="0.6.3" +Export-Package: org.simantics.modelica, + org.simantics.modelica.data +Bundle-Activator: org.simantics.modelica.Activator +Bundle-ActivationPolicy: lazy +Bundle-Vendor: VTT Technical Research Centre of Finland diff --git a/stable/org.simantics.modelica/build.properties b/stable/org.simantics.modelica/build.properties new file mode 100644 index 00000000..11ab1db4 --- /dev/null +++ b/stable/org.simantics.modelica/build.properties @@ -0,0 +1,16 @@ +############################################################################### +# Copyright (c) 2010 Association for Decentralized Information Management in +# Industry THTH ry. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# VTT Technical Research Centre of Finland - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/stable/org.simantics.modelica/plugin.xml b/stable/org.simantics.modelica/plugin.xml new file mode 100644 index 00000000..56f10d09 --- /dev/null +++ b/stable/org.simantics.modelica/plugin.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/stable/org.simantics.modelica/src/org/simantics/modelica/Activator.java b/stable/org.simantics.modelica/src/org/simantics/modelica/Activator.java new file mode 100644 index 00000000..47ae2ec9 --- /dev/null +++ b/stable/org.simantics.modelica/src/org/simantics/modelica/Activator.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modelica; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + static BundleContext context; + + @Override + public void start(BundleContext context) throws Exception { + Activator.context = context; + } + + @Override + public void stop(BundleContext context) throws Exception { + Activator.context = null; + } + + public static BundleContext getContext() { + return context; + } + +} diff --git a/stable/org.simantics.modelica/src/org/simantics/modelica/IModelicaMonitor.java b/stable/org.simantics.modelica/src/org/simantics/modelica/IModelicaMonitor.java new file mode 100644 index 00000000..56e6cccf --- /dev/null +++ b/stable/org.simantics.modelica/src/org/simantics/modelica/IModelicaMonitor.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modelica; + +public interface IModelicaMonitor { + public void message(String message); + public void clearConsole(); + public void showConsole(); +} diff --git a/stable/org.simantics.modelica/src/org/simantics/modelica/InitWriter.java b/stable/org.simantics.modelica/src/org/simantics/modelica/InitWriter.java new file mode 100644 index 00000000..6b90a2f9 --- /dev/null +++ b/stable/org.simantics.modelica/src/org/simantics/modelica/InitWriter.java @@ -0,0 +1,182 @@ +package org.simantics.modelica; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.HashMap; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/** + * Class to change values of parameters in modelica init.xml files + * @author tlteemu + * + */ +public class InitWriter { + + /** + * Change the given init parameter values for XML init file + * @param file path to the init.xml file + * @param inits name-value map + * @return + */ + public static boolean writeXML(String file, HashMap inits) { + Document doc; + try { + doc = DocumentBuilderFactory.newInstance() + .newDocumentBuilder().parse(new InputSource(file)); + + + // Locate the node(s) + XPath xpath = XPathFactory.newInstance().newXPath(); + + for(String name : inits.keySet()) { + NodeList nodes = null; + try { + // First try normal variables + nodes = (NodeList)xpath.evaluate + ("//fmiModelDescription/ModelVariables/ScalarVariable[@name='" + name + "']/Real/@start", + doc, + XPathConstants.NODESET); + if(nodes.getLength() == 0) { + // If normal variables were not found, try if it is an experiment attribute + nodes = (NodeList)xpath.evaluate + ("//fmiModelDescription/DefaultExperiment/@" + name, + doc, + XPathConstants.NODESET); + } + } catch (XPathExpressionException e) { + + } + if (nodes != null) { + // make the change. There should be only one node. + for (int idx = 0; idx < nodes.getLength(); idx++) { + Node n = nodes.item(idx); + n.setNodeValue(inits.get(name).replaceAll("\"", "")); + } + } + } + + // Save the result + Transformer xformer = TransformerFactory.newInstance().newTransformer(); + xformer.transform + (new DOMSource(doc), new StreamResult(new File(file))); + + return true; + } catch (SAXException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } catch (TransformerConfigurationException e) { + e.printStackTrace(); + } catch (TransformerFactoryConfigurationError e) { + e.printStackTrace(); + } catch (TransformerException e) { + e.printStackTrace(); + } + + return false; + + } + + /** + * Change the given init parameter values for TXT init file + * @param file path to the init.xml file + * @param inits name-value map + * @return + */ + public static boolean writeTXT(String file, HashMap inits) { + HashMap initials = new HashMap(); + HashMap order = new HashMap(); + + InputStream is; + try { + is = new FileInputStream(file); + int orderNumber = 0; + while(true) { + String line = getLine(is); + if(line == null) + return false; + if(line.isEmpty()) + break; + if(line.contains("//")) { + String[] nn = line.split("//", 2); + String key = nn[1].trim(); + String value = nn[0].trim(); + if(inits.containsKey(key)) { + value = inits.get(key); + } + initials.put(key, value); + order.put(orderNumber, key); + } + orderNumber++; + } + is.close(); + + PrintStream s = new PrintStream(file); + for(int j = 0; j < orderNumber ; j++) { + String key = order.get(j); + if (key != null) { + s.println(initials.get(key) + " // " + key); + } else { + s.println("0.0"); + } + } + s.close(); + + return true; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return false; + } + + private static String getLine(InputStream stream) { + if(stream == null) + return null; + StringBuilder b = new StringBuilder(); + try { + while(true) { + int c = stream.read(); + if(c == -1) { + stream = null; + return b.toString(); + } + else if(c == '\n') + return b.toString(); + else if(c == '\r') + ; + else + b.append((char)c); + } + } catch (IOException e) { + return null; + } + + } +} \ No newline at end of file diff --git a/stable/org.simantics.modelica/src/org/simantics/modelica/ModelicaException.java b/stable/org.simantics.modelica/src/org/simantics/modelica/ModelicaException.java new file mode 100644 index 00000000..32c99c96 --- /dev/null +++ b/stable/org.simantics.modelica/src/org/simantics/modelica/ModelicaException.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modelica; + +public class ModelicaException extends Exception { + + private static final long serialVersionUID = 2712433918044442927L; + + public ModelicaException(String message) { + super(message); + } + +} diff --git a/stable/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java b/stable/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java new file mode 100644 index 00000000..fb5d4309 --- /dev/null +++ b/stable/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java @@ -0,0 +1,403 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modelica; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.net.URL; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Platform; +import org.osgi.framework.Bundle; + +/** + * Manager for OpenModelica compiler + * + * @author Teemu Lempinen + * + */ +public class ModelicaManager { + + public enum OSType { + APPLE, LINUX, SUN, WINDOWS, UNKNOWN + } + + /** + * Get operating system type + * @return OSType + */ + public static OSType calculateOS() { + String osName = System.getProperty("os.name"); + assert osName != null; + osName = osName.toLowerCase(); + if (osName.startsWith("mac os x")) + return OSType.APPLE; + if (osName.startsWith("windows")) + return OSType.WINDOWS; + if (osName.startsWith("linux")) + return OSType.LINUX; + if (osName.startsWith("sun")) + return OSType.SUN; + return OSType.UNKNOWN; + } + + /** + * Get modelica home folder. If modelica is installed, + * modelica home is in OPENMODELICAHOME environment variable. + * Otherwise it can be obtained from a bundled plugin. + * @return + */ + public static File getModelicaHome() { + + // Get modelica home from environment variable + String dir = System.getenv("OPENMODELICAHOME"); + File omhome = null; + + // Get operating system + String osName = System.getProperty("os.name"); + OSType os = calculateOS(); + + // operating system unknown + if (os == OSType.UNKNOWN) + throw new UnsatisfiedLinkError("unknown OS '" + osName + "' for running OpenModelica"); + + // If OPENMODELICAHOME is found, try to return the folder. + if(dir != null) { + switch (os) { + case APPLE: + case LINUX: + case SUN: + omhome = new File(dir); + if(omhome.isDirectory()) + return omhome; + else + break; + case WINDOWS: + omhome = new File(dir); + if(omhome.isDirectory()) + return omhome; + else + break; + } + } + + // OPENMODELICAHOMe was not found or the folder does not exist. Try built-in OpenModelica for windows + if(os.equals(OSType.WINDOWS)) { + + Bundle bundle = Platform.getBundle("org.simantics.openmodelica.win32"); + if (bundle != null) { + try{ + URL entry = bundle.getEntry("/"); + if(entry != null) { + URL fileURL = FileLocator.toFileURL(entry); + File root = new File( URLDecoder.decode(fileURL.getPath(), "UTF-8") ); + File f = new File(root, "OpenModelica1.7.0"); + return f; + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + + // OS was not windows or built-in OpenModelica did not work + switch (os) { + case APPLE: + case LINUX: + case SUN: + return new File("/usr/bin/omc"); + case WINDOWS: + return new File("c:/OpenModelica1.7.0"); + default: + throw new UnsatisfiedLinkError("Unsupported operating system: " + os); + } + } + + +/* + protected static File createTempDirectory() throws IOException { + final File temp = File.createTempFile("temp", Long.toString(System.nanoTime())); + if(!(temp.delete())) + throw new IOException("Could not delete temp file: " + temp.getAbsolutePath()); + if(!(temp.mkdir())) + throw new IOException("Could not create temp directory: " + temp.getAbsolutePath()); + return (temp); + } +*/ + +/* + protected static boolean recursiveDelete(File fileOrDir) { + if(fileOrDir.isDirectory()) + for(File innerFile: fileOrDir.listFiles()) + if(!recursiveDelete(innerFile)) + return false; + return fileOrDir.delete(); + } +*/ + +/* + protected static String readFile(File file) throws IOException { + InputStream stream = new FileInputStream(file); + byte[] buffer = new byte[(int)file.length()]; + stream.read(buffer); + stream.close(); + return new String(buffer); + } +*/ + + /** + * Prints the output of an ongoing process to IModelicaMonitor. + * @param process Process + * @param monitor IModelicaMonitor + */ + public static void printProcessOutput(final Process process, final IModelicaMonitor monitor) { + Thread thread = new Thread() { + @Override + public void run() { + InputStream stream = process.getInputStream(); + StringBuilder b = new StringBuilder(); + while(true) { + try { + int c; + + c = stream.read(); + + if(c <= 0) + break; + if((char)c != '\n') + b.append((char)c); + else { + System.out.println("OMC output: " + b.toString()); + String message = b.toString(); + message = message.trim(); + if(message.startsWith("\"")) + message = message.substring(1); + monitor.message(message); + b.delete(0, b.length()); + } + } catch (IOException e) { + System.err.println("Not able to read simulation output"); + e.printStackTrace(); + break; + } + } + } + }; + thread.run(); + + } + + /** + * Create input files for omc + * + * @param simulationDir Directory of the model + * @param modelName Model's name + * @param modelText Modelica code of the model + * @param inits Map containing initial values for omc + * @param additionalScript Additional script to be written in .mos script file + * @return SimulationLocation + * @throws IOException + */ + public static SimulationLocation createInputFiles(File simulationDir, String modelName, String modelText, HashMap inits, String additionalScript) throws IOException { + System.out.println(simulationDir.getAbsolutePath()); + modelName = modelName.replace(" ", ""); + File modelFile = new File(simulationDir, modelName + ".mo"); + File scriptFile = new File(simulationDir, modelName + ".mos"); + String outputFormat = inits.containsKey("outputFormat") ? inits.get("outputFormat") : "\"plt\""; + { + PrintStream s = new PrintStream(modelFile); + s.print(modelText); + s.close(); + } + + { + PrintStream s = new PrintStream(scriptFile); + if(additionalScript != null) + s.println(additionalScript); + s.println("loadFile(\"" + modelName + ".mo\");"); + s.print("buildModel("+modelName+ + ",startTime="+inits.get("start value")+ + ",stopTime="+inits.get("stop value")+ + ",method="+inits.get("method")+ + ",outputFormat="+ outputFormat + ); + if(inits.containsKey("tolerance")) { + s.print(",tolerance="+inits.get("tolerance")); + } + s.print(");\n"); + s.println("getErrorString();"); + s.close(); + } + + OSType os = calculateOS(); + String suffix = OSType.WINDOWS.equals(os) ? ".exe" : ""; + + return new SimulationLocation( + simulationDir, + new File(simulationDir, modelName + ".mos"), + new File(simulationDir, modelName + "_res." + outputFormat.substring(1, outputFormat.length()-1)), + new File(simulationDir, modelName + "_init.txt"), + new File(simulationDir, modelName + suffix) + ); + } + + /** + * Builds a model with omc. The location of required files is + * defined in simulationLocation. + * + * @param simulationLocation Location of model files + * @param monitor Monitor for printing build process output + * @throws ModelicaException + */ + public static void buildModel(SimulationLocation simulationLocation, IModelicaMonitor monitor) throws ModelicaException { + try { + + // Find OMC + File openModelicaHome = getModelicaHome(); + + // Create the build process + ProcessBuilder processBuilder = new ProcessBuilder( + openModelicaHome.getAbsolutePath() + "\\bin\\omc.exe", + simulationLocation.inputFile.getAbsolutePath() + ) + .directory(simulationLocation.simulationDir.getAbsoluteFile()) + .redirectErrorStream(true); + + // Set environment variables so that OMC can find itself + Map env = processBuilder.environment(); + + env.put("OPENMODELICAHOME", openModelicaHome.getAbsolutePath()); + env.put("OPENMODELICALIBRARY", openModelicaHome.getAbsolutePath() + "\\lib\\omlibrary"); + env.put("OMPATH", openModelicaHome.getAbsolutePath() + "\\bin"); + env.put("MINGW", openModelicaHome.getAbsolutePath() + "\\MinGW"); + env.put("PATH", env.get("PATH") + System.getProperty("path.separator") + openModelicaHome.getAbsolutePath() + "\\MinGW\\lib"); + + // Start the building process + Process process = processBuilder.start(); + + // Print process output + printProcessOutput(process, monitor); + + + if(!simulationLocation.exeFile.isFile()) + // If .exe file was not created, something went wrong + throw new ModelicaException(".exe file not created\nSee log at " + simulationLocation.simulationDir.getAbsolutePath()); + + } catch(IOException e) { + throw new ModelicaException(".exe file not created: " + e.getMessage()); + } + + } + + /** + * Runs a model that has been built to simulationLocation. + * Some initial values can be set for a compiled model without + * re-compiling it. + * + * @param simulationLocation Location of a built model + * @param monitor Monitor for printing process output + * @param inits Initial values for a simulation run + * @return Simulation process + * @throws IOException + */ + public static Process runModelica(SimulationLocation simulationLocation, IModelicaMonitor monitor, HashMap inits) throws IOException { + try { + + // Write new initial values (parameters) + writeInits(simulationLocation, inits); + + // Create simulation proecss + ProcessBuilder processBuilder = new ProcessBuilder( + simulationLocation.exeFile.getAbsolutePath() + ) + .directory(new File(simulationLocation.simulationDir.getAbsolutePath())) + .redirectErrorStream(true); + + // Set environment variables for the process + Map env = processBuilder.environment(); + File openModelicaHome = getModelicaHome(); + env.put("OPENMODELICAHOME", openModelicaHome.getAbsolutePath()); + env.put("OPENMODELICALIBRARY", openModelicaHome.getAbsolutePath() + "\\lib\\omlibrary\\msl31"); + env.put("OMPATH", openModelicaHome.getAbsolutePath() + "\\bin"); + env.put("MINGW", openModelicaHome.getAbsolutePath() + "\\MinGW"); + env.put("PATH", env.get("PATH") + System.getProperty("path.separator") + openModelicaHome.getAbsolutePath() + "\\bin" + + System.getProperty("path.separator") + openModelicaHome.getAbsolutePath() + "\\MinGW\\lib"); + + // Simulate model + Process process = processBuilder.start(); + + return process; + } catch(IOException e) { + e.printStackTrace(); + } + return null; + } + + /** + * Write initial values to inits-file. File can be either + * xml-file or the old txt-file + * @param simulationLocation Location of the model + * @param inits Map containing inits that are changed + */ + private static void writeInits(SimulationLocation simulationLocation, HashMap inits) { + /* How the correct input file format should be investigated: + try { + + List command = new ArrayList(); + command.add(getModelicaHome().getAbsolutePath() + "\\bin\\omc.exe"); + command.add("+version"); + + ProcessBuilder builder = new ProcessBuilder(command); + Map environ = builder.environment(); + environ.put("OPENMODELICAHOME", getModelicaHome().getAbsolutePath()); + + builder.directory(new File(System.getenv("temp"))); + + Process process; + process = builder.start(); + + InputStream is = process.getInputStream(); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + String line; + while ((line = br.readLine()) != null) { + System.out.println("OpenModelica Version: " + line); + } + + } catch (IOException e) { + e.printStackTrace(); + } + */ + + // OpenModelica version number has stayed the same after changing the + // init format to nightly builds. + if(simulationLocation.initFile.getAbsolutePath().endsWith(".txt")) { + File xmlTest = new File(simulationLocation.initFile.getAbsolutePath().replace(".txt", ".xml")); + if(xmlTest.exists()) { + simulationLocation.initFile = xmlTest; + } + } + + if(simulationLocation.initFile.getAbsolutePath().endsWith(".txt")) { + InitWriter.writeTXT(simulationLocation.initFile.getAbsolutePath(), inits); + } else { + InitWriter.writeXML(simulationLocation.initFile.getAbsolutePath(), inits); + + } + } +} diff --git a/stable/org.simantics.modelica/src/org/simantics/modelica/SimulationLocation.java b/stable/org.simantics.modelica/src/org/simantics/modelica/SimulationLocation.java new file mode 100644 index 00000000..85452a9d --- /dev/null +++ b/stable/org.simantics.modelica/src/org/simantics/modelica/SimulationLocation.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modelica; + +import java.io.File; + +public class SimulationLocation { + public File simulationDir; + public File inputFile; + public File outputFile; + public File initFile; + public File exeFile; + + public SimulationLocation(File simulationDir, File inputFile, + File outputFile, File initFile, File exeFile) { + this.simulationDir = simulationDir; + this.inputFile = inputFile; + this.outputFile = outputFile; + this.initFile = initFile; + this.exeFile = exeFile; + } +} \ No newline at end of file diff --git a/stable/org.simantics.modelica/src/org/simantics/modelica/data/CSVSimulationResult.java b/stable/org.simantics.modelica/src/org/simantics/modelica/data/CSVSimulationResult.java new file mode 100644 index 00000000..1c3b1e2f --- /dev/null +++ b/stable/org.simantics.modelica/src/org/simantics/modelica/data/CSVSimulationResult.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modelica.data; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; + +/** + * class for supporting csv-format simulation results + * @author Teemu Lempinen + * + */ +public class CSVSimulationResult extends SimulationResult { + + HashMap valueMap = new HashMap(); + + /** + * Overridden method to support csv-formatted simulation results + */ + @Override + public void read(InputStream stream) { + errors.clear(); + + // First line contains the variable names in format "name" (including quotes); + String line = getLine(stream); + if(line == null) + return; + + line = line.substring(1, line.lastIndexOf("\"")); + String[] names = line.split("\",\""); + + // Create lists for receiving values for each variable. Names still with quotes. + for(String name : names) { + if(!name.isEmpty()) + valueMap.put(name, new DataSet(name, new double[numberOfTimeSteps], new double[numberOfTimeSteps])); + } + + int row = 0; + // Data sets + while((line = getLine(stream)) != null) { + if(line.isEmpty()) + break; + String[] values = line.split(","); + for(int valueIndex = 0; valueIndex list = errors.get(names[valueIndex]); + if(list == null) { + list = new ArrayList(); + errors.put(names[valueIndex], list); + } + list.add(new TimeValuePair(values[0], values[valueIndex])); + } + } + } + row++; + } + + // Add time values for each dataset and add them to variables. + for(DataSet ds : valueMap.values()) { + ds.times = valueMap.get("time").values; + variables.add(ds); + } + } +} diff --git a/stable/org.simantics.modelica/src/org/simantics/modelica/data/DataSet.java b/stable/org.simantics.modelica/src/org/simantics/modelica/data/DataSet.java new file mode 100644 index 00000000..c1c4bae9 --- /dev/null +++ b/stable/org.simantics.modelica/src/org/simantics/modelica/data/DataSet.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modelica.data; + +/** + * Simulation result for one variable. + * @author Hannu Niemistö + */ +public class DataSet { + public String name; + public double[] times; + public double[] values; + + public DataSet(String name, double[] times, double[] values) { + this.name = name; + this.times = times; + this.values = values; + } +} diff --git a/stable/org.simantics.modelica/src/org/simantics/modelica/data/DoubleMatrix.java b/stable/org.simantics.modelica/src/org/simantics/modelica/data/DoubleMatrix.java new file mode 100644 index 00000000..d8ace791 --- /dev/null +++ b/stable/org.simantics.modelica/src/org/simantics/modelica/data/DoubleMatrix.java @@ -0,0 +1,38 @@ +package org.simantics.modelica.data; + +/** + * Copied from Hannu's DoubleMatrix in org.simantics.modelica.data + * + * To be replaced with the original when SysDyn and Modelica tools + * are synchronized to use the same OpenModelica plugin + * + * @author Teemu Lempinen + * + */ +public class DoubleMatrix extends Matrix { + public final int rows; + public final int columns; + public final double[] data; + + public DoubleMatrix(String name, int rows, int columns) { + super(name); + this.rows = rows; + this.columns = columns; + this.data = new double[rows*columns]; + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder(); + b.append("double " + name + "(" + rows + "," + columns + ")\n"); + for(int i=0;i 0) + b.append(' '); + b.append(data[i*rows + j]); + } + b.append('\n'); + } + return b.toString(); + } +} diff --git a/stable/org.simantics.modelica/src/org/simantics/modelica/data/IntMatrix.java b/stable/org.simantics.modelica/src/org/simantics/modelica/data/IntMatrix.java new file mode 100644 index 00000000..6f3d6d4e --- /dev/null +++ b/stable/org.simantics.modelica/src/org/simantics/modelica/data/IntMatrix.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modelica.data; + +/** + * Copied from Hannu's IntMatrix in org.simantics.modelica.data + * + * To be replaced with the original when SysDyn and Modelica tools + * are synchronized to use the same OpenModelica plugin + * + * @author Teemu Lempinen + * + */ +public class IntMatrix extends Matrix { + public final int rows; + public final int columns; + public final int[] data; + + public IntMatrix(String name, int rows, int columns) { + super(name); + this.rows = rows; + this.columns = columns; + this.data = new int[rows*columns]; + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder(); + b.append("int " + name + "(" + rows + "," + columns + ")\n"); + for(int i=0;i 0) + b.append(' '); + b.append(data[i*rows + j]); + } + b.append('\n'); + } + return b.toString(); + } +} diff --git a/stable/org.simantics.modelica/src/org/simantics/modelica/data/Mat4Reader.java b/stable/org.simantics.modelica/src/org/simantics/modelica/data/Mat4Reader.java new file mode 100644 index 00000000..0d896368 --- /dev/null +++ b/stable/org.simantics.modelica/src/org/simantics/modelica/data/Mat4Reader.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modelica.data; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +/** + * Copied from Hannu's Mat4Reader in org.simantics.modelica.data + * + * To be replaced with the original when SysDyn and Modelica tools + * are synchronized to use the same OpenModelica plugin + * + * @author Teemu Lempinen + * + */ +public class Mat4Reader { + + InputStream in; + + public Mat4Reader(InputStream in) { + this.in = in; + } + + private final int getInt() throws IOException { + int ch1 = in.read(); + int ch2 = in.read(); + int ch3 = in.read(); + int ch4 = in.read(); + return ((ch1 << 0) + (ch2 << 8) + (ch3 << 16) + (ch4 << 24)); + } + + private final long getLong() throws IOException { + int ch1 = in.read(); + int ch2 = in.read(); + int ch3 = in.read(); + int ch4 = in.read(); + int ch5 = in.read(); + int ch6 = in.read(); + int ch7 = in.read(); + int ch8 = in.read(); + return ((((long)ch1) << 0) + (((long)ch2) << 8) + (((long)ch3) << 16) + (((long)ch4) << 24) + + (((long)ch5) << 32) + (((long)ch6) << 40) + (((long)ch7) << 48) + (((long)ch8) << 56)); + } + + private final double getDouble() throws IOException { + return Double.longBitsToDouble(getLong()); + } + + private String getString(int length) throws IOException { + byte[] buffer = new byte[length]; + int pos = 0; + while(pos < length) + pos += in.read(buffer, pos, length-pos); + return new String(buffer, "UTF-8"); + } + + public Matrix readMatrix() throws IOException { + int type = getInt(); + int rows = getInt(); + int columns = getInt(); + int imagf = getInt(); + int namlen = getInt(); + + String name = getString(namlen-1); + in.read(); + + if(imagf > 0) + throw new IOException("Imaginary part of the matrix is not supported (matrix " + name + ")."); + + switch(type) { + case 0: { + DoubleMatrix matrix = new DoubleMatrix(name, rows, columns); + int size = rows*columns; + double[] data = matrix.data; + for(int i=0;i read(InputStream in) throws IOException { + Mat4Reader reader = new Mat4Reader(in); + reader.readMatrix(); // Header + StringMatrix names = (StringMatrix)reader.readMatrix(); // Variable names + reader.readMatrix(); // Variable descriptions + IntMatrix info = (IntMatrix)reader.readMatrix(); // Data info + if(info.rows != 4 || info.columns != names.rows ) + throw new IOException("Invalid result data."); + int[] infoData = info.data; + /*for(int i=0;i result = new HashMap(); + double[] valueData = values.data; + int rows = values.rows; + //System.out.println("cols="+values.columns+", rows=" +values.rows+ ", data.length="+valueData.length); + for(int i=0;i 0 ? sc-1 : 1-sc; + //System.out.println("i=" + i + ", sc=" + sc + ", c=" + c); + for(int j=0;j valueMap = null; + try { + valueMap = Mat4Reader.read(stream); + } catch (IOException e) { + e.printStackTrace(); + return; + } + + DataSet ds; + double[] times = valueMap.get("time"); + for(String key : valueMap.keySet()) { + ds = new DataSet(key, times, valueMap.get(key)); + variables.add(ds); + } + } +} diff --git a/stable/org.simantics.modelica/src/org/simantics/modelica/data/Matrix.java b/stable/org.simantics.modelica/src/org/simantics/modelica/data/Matrix.java new file mode 100644 index 00000000..1e68c1b6 --- /dev/null +++ b/stable/org.simantics.modelica/src/org/simantics/modelica/data/Matrix.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modelica.data; + +/** + * Copied from Hannu's Matrix in org.simantics.modelica.data + * + * To be replaced with the original when SysDyn and Modelica tools + * are synchronized to use the same OpenModelica plugin + * + * @author Teemu Lempinen + * + */ +public abstract class Matrix { + public final String name; + + public Matrix(String name) { + this.name = name; + } +} diff --git a/stable/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java b/stable/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java new file mode 100644 index 00000000..766d4c2c --- /dev/null +++ b/stable/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java @@ -0,0 +1,391 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modelica.data; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.LineNumberReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/** + * Class that reads OpenModelica result files. + * + * SimulationResult class reads plt-files. Extended classes read other types. + * + * Will be replaced with a common OpenModelica plugin + * @author Hannu Niemistö + */ +public class SimulationResult { + + List variables = new ArrayList(); + List initials = new ArrayList(); + protected int numberOfTimeSteps = 0; + + /** + * Private class used in displaying errors + */ + class TimeValuePair { + public String time; + public String value; + + public TimeValuePair(String time, String value) { + this.time = time; + this.value = value; + } + } + + HashMap> errors = new HashMap>(); + + /** + * Get the next line in the plt-file + * @param stream plt-file input stream + * @return next line in the stream + */ + static String getLine(InputStream stream) { + if(stream == null) + return null; + StringBuilder b = new StringBuilder(); + try { + while(true) { + int c = stream.read(); + if(c == -1) { + stream = null; + return b.toString(); + } + else if(c == '\n') + return b.toString(); + else if(c == '\r') + ; + else + b.append((char)c); + } + } catch (IOException e) { + return null; + } + + } + + + /** + * Read parameters that are located in the inits-file to the simulation result. + * Supports both txt and xml type inits. + * + * @param file inits-file + * @throws FileNotFoundException + * @throws IOException + */ + public void readInits(File file) throws FileNotFoundException, IOException { + + if(file.getName().endsWith("txt")) { + InputStream is = new FileInputStream(file); + readInitsTXT(is); + is.close(); + } else if(file.getName().endsWith("xml")) { + readInitsXML(file.getAbsolutePath()); + } + } + + /** + * Read xml inits + * + * @param file xml-formatted inits file + */ + public void readInitsXML(String file) { + Document doc; + try { + doc = DocumentBuilderFactory.newInstance() + .newDocumentBuilder().parse(new InputSource(file)); + + XPath xpath = XPathFactory.newInstance().newXPath(); + + double[] times = new double[2]; + Node node; + // Find start time + node = (Node)xpath.evaluate + ("//fmiModelDescription/DefaultExperiment/@startTime", + doc, + XPathConstants.NODE); + times[0] = Double.parseDouble(node.getNodeValue()); + // Find end time + node = (Node)xpath.evaluate + ("//fmiModelDescription/DefaultExperiment/@stopTime", + doc, + XPathConstants.NODE); + times[1] = Double.parseDouble(node.getNodeValue()); + + NodeList nodes; + + // Find parameters and constants + nodes = (NodeList)xpath.evaluate + ("//fmiModelDescription/ModelVariables/ScalarVariable[@variability='parameter']", + doc, + XPathConstants.NODESET); + + // Add parameters and constants to initials + for (int idx = 0; idx < nodes.getLength(); idx++) { + Node n = nodes.item(idx); + String name = n.getAttributes().getNamedItem("name").getNodeValue(); + addToInitials(name, n, times); + + } + + // Find all alias variables + NodeList allAliasVariables = (NodeList)xpath.evaluate + ("//fmiModelDescription/ModelVariables/ScalarVariable[@alias='alias']", + doc, + XPathConstants.NODESET); + + for(int i = 0; i < allAliasVariables.getLength(); i++) { + Node n = allAliasVariables.item(i); + String name = n.getAttributes().getNamedItem("name").getNodeValue(); + + // Find the original variable + Node aliasVariableProperty = n.getAttributes().getNamedItem("aliasVariable"); + String aliasVariableName = aliasVariableProperty.getNodeValue(); + n = (Node)xpath.evaluate + ("//fmiModelDescription/ModelVariables/ScalarVariable[@name='" + aliasVariableName +"' and @variability='parameter']", + doc, + XPathConstants.NODE); + // Add the value of the original value to initials with the name of the alias variable + if(n != null) + addToInitials(name, n, times); + } + + + } catch (SAXException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } catch (TransformerFactoryConfigurationError e) { + e.printStackTrace(); + } catch (XPathExpressionException e) { + e.printStackTrace(); + } + } + + /** + * Adds a new dataset to initials using start name, value from + * node and times. + * + * @param name Name for the dataset to be added to initials + * @param node Node containing the start value attribute + * @param times Array of times (length == 2) + */ + private void addToInitials(String name, Node node, double[] times) { + // Find the start value for this + double[] values; + NodeList children; + children = node.getChildNodes(); + for(int i = 0; i < children.getLength(); i++) { + Node child = children.item(i); + if(child.getNodeName().equals("Real")) { + Double d = Double.parseDouble(child.getAttributes().getNamedItem("start").getNodeValue()); + values = new double[] {d,d}; + initials.add( + new DataSet(name, + times , + values)); + break; + } + } + } + + /** + * Read txt inits + * @param stream txt-formatted init file + */ + public void readInitsTXT(InputStream stream) { + HashMap mappedInitials = new HashMap(); + while(true) { + String line = getLine(stream); + if(line == null) + return; + if(line.isEmpty()) + break; + + if(line.contains("//")) { + String[] nn = line.split("//", 2); + try { + double value = Double.parseDouble(nn[0].trim()); + String key = nn[1].trim(); + mappedInitials.put(key, value); + } catch (NumberFormatException nfe) { + continue; // Not a valid double + } + + } + + } + + double startTime = mappedInitials.get("start value"); + double stopTime = mappedInitials.get("stop value"); + double[] times = new double[] {startTime, stopTime}; + + for(String key : mappedInitials.keySet()) { + double d = mappedInitials.get(key); + double[] values = new double[] {d, d}; + initials.add(new DataSet(key, times , values)); + } + } + + + final static Pattern p1 = Pattern.compile("DataSet: ([^ ]*)"); + + /** + * Read result file + * + * @param file result file + * @throws FileNotFoundException + * @throws IOException + */ + public void read(File file) throws FileNotFoundException, IOException { + // First check the number of time steps + FileReader fr = new FileReader(file); + LineNumberReader lnr = new LineNumberReader(fr); + lnr.skip(Long.MAX_VALUE); + numberOfTimeSteps = lnr.getLineNumber() - 1; // minus the first row, which is for names + lnr.close(); + fr.close(); + + InputStream is = new FileInputStream(file); + read(is); + is.close(); + } + + + /** + * Read result file. The basic implementation supports + * plt-formatted results. Overridden to support other formats. + * @param stream FileInputStream for the result file + */ + public void read(InputStream stream) { + while(true) { + String line = getLine(stream); + if(line == null) + return; + if(line.isEmpty()) + break; + } + + // Data sets + while(true) { + Matcher matcher = p1.matcher(getLine(stream)); + if(!matcher.matches()) + return; + String name = matcher.group(1); + + double[] dtimes = new double[numberOfTimeSteps]; + double[] dvalues = new double[numberOfTimeSteps]; + int i = 0; + while(true) { + String line = getLine(stream); + if(line == null) + return; + if(line.isEmpty()) + break; + String[] nn = line.split(", ", 2); + dtimes[i] = Double.parseDouble(nn[0]); + dvalues[i] = Double.parseDouble(nn[1]); + i++; + } + + variables.add(new DataSet(name, dtimes, dvalues)); + } + } + + /** + * Filter result set + */ + public void filter() { + ArrayList newVariables = new ArrayList(); + for(DataSet dataSet : variables) { + if(!dataSet.name.contains("$") && !dataSet.name.contains("der(")) + newVariables.add(dataSet); + } + variables = newVariables; + } + + /** + * Get datasets for the variables in this result + * @return variable datasets + */ + public List getVariableDataSets() { + return variables; + } + + /** + * Get datasets for the initial values in this simulation + * @return initial value datasets + */ + public List getInitialValueDataSets() { + return initials; + } + + /** + * Gets DataSet for variable. Loops first the variables and then initials. + * @param name the name of the variable + * @return DataSet for the variable or null if DataSet not found + */ + public DataSet getDataSet(String name) { + for(DataSet set : variables) + if(set.name.equals(name)) + return set; + for(DataSet set : initials) + if(set.name.equals(name)) + return set; + return null; + } + + + /** + * Return errors encountered during reading of the results. + * + * @return + */ + public String getResultReadErrors() { + StringBuilder errorString = new StringBuilder(); + if(!errors.isEmpty()) { + errorString.append("Number format errors (Time, Value):\n"); + for(String key : errors.keySet()) { + errorString.append("\n" + key + ":\n"); + for(TimeValuePair tv : errors.get(key)) { + errorString.append(" " + tv.time + ", " + tv.value + "\n"); + } + } + } + return errorString.toString(); + } +} diff --git a/stable/org.simantics.modelica/src/org/simantics/modelica/data/StringMatrix.java b/stable/org.simantics.modelica/src/org/simantics/modelica/data/StringMatrix.java new file mode 100644 index 00000000..8cfbea02 --- /dev/null +++ b/stable/org.simantics.modelica/src/org/simantics/modelica/data/StringMatrix.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modelica.data; + +/** + * Copied from Hannu's StringMatrix in org.simantics.modelica.data + * + * To be replaced with the original when SysDyn and Modelica tools + * are synchronized to use the same OpenModelica plugin + * + * @author Teemu Lempinen + * + */ +public class StringMatrix extends Matrix { + public final int rows; + public final String[] data; + + public StringMatrix(String name, int rows) { + super(name); + this.rows = rows; + this.data = new String[rows]; + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder(); + b.append("char " + name + "(" + rows + ")\n"); + for(String row : data) + b.append(row + "\n"); + return b.toString(); + } +} diff --git a/stable/org.simantics.objmap/.classpath b/stable/org.simantics.objmap/.classpath new file mode 100644 index 00000000..23e107f9 --- /dev/null +++ b/stable/org.simantics.objmap/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/stable/org.simantics.objmap/.hgignore b/stable/org.simantics.objmap/.hgignore new file mode 100644 index 00000000..73df90f6 --- /dev/null +++ b/stable/org.simantics.objmap/.hgignore @@ -0,0 +1,5 @@ +syntax: regexp +^bin/ + +syntax: glob +*.svn/* \ No newline at end of file diff --git a/stable/org.simantics.objmap/.project b/stable/org.simantics.objmap/.project new file mode 100644 index 00000000..82c191c2 --- /dev/null +++ b/stable/org.simantics.objmap/.project @@ -0,0 +1,28 @@ + + + org.simantics.objmap + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/stable/org.simantics.objmap/.settings/org.eclipse.jdt.core.prefs b/stable/org.simantics.objmap/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..fc058b8d --- /dev/null +++ b/stable/org.simantics.objmap/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Wed Nov 11 10:38:27 EET 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/stable/org.simantics.objmap/META-INF/MANIFEST.MF b/stable/org.simantics.objmap/META-INF/MANIFEST.MF new file mode 100644 index 00000000..2b3664f7 --- /dev/null +++ b/stable/org.simantics.objmap/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Objmap +Bundle-SymbolicName: org.simantics.objmap +Bundle-Version: 0.1.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Require-Bundle: gnu.trove2;bundle-version="2.0.4", + org.apache.log4j;bundle-version="1.2.15", + org.simantics.layer0;bundle-version="1.0.0", + org.simantics.db.common;bundle-version="1.1.0" +Export-Package: org.simantics.objmap, + org.simantics.objmap.annotations, + org.simantics.objmap.annotations.meta, + org.simantics.objmap.rules, + org.simantics.objmap.rules.adapters, + org.simantics.objmap.rules.domain, + org.simantics.objmap.rules.factory, + org.simantics.objmap.rules.range, + org.simantics.objmap.schema +Bundle-Vendor: VTT Technical Research Centre of Finland diff --git a/stable/org.simantics.objmap/build.properties b/stable/org.simantics.objmap/build.properties new file mode 100644 index 00000000..de6a2f5c --- /dev/null +++ b/stable/org.simantics.objmap/build.properties @@ -0,0 +1,17 @@ +############################################################################### +# Copyright (c) 2007, 2010 Association for Decentralized Information Management +# in Industry THTH ry. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# VTT Technical Research Centre of Finland - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . +src.includes = doc/,\ + examples/ diff --git a/stable/org.simantics.objmap/doc/bidirectionalModel.graphml b/stable/org.simantics.objmap/doc/bidirectionalModel.graphml new file mode 100644 index 00000000..2a52aa11 --- /dev/null +++ b/stable/org.simantics.objmap/doc/bidirectionalModel.graphml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + Intermediate model + + + + + + + + + + + + Database + + + + + + + + + + + + Editor + + + + + + + + + + + + + reads + + + + + + + + + + + + + visualizes + + + + + + + + + + + + + modifies + + + + + + + + + + + + + writes + + + + + + + + + diff --git a/stable/org.simantics.objmap/doc/bidirectionalModel.png b/stable/org.simantics.objmap/doc/bidirectionalModel.png new file mode 100644 index 00000000..77bcc302 Binary files /dev/null and b/stable/org.simantics.objmap/doc/bidirectionalModel.png differ diff --git a/stable/org.simantics.objmap/doc/main.mediawiki b/stable/org.simantics.objmap/doc/main.mediawiki new file mode 100644 index 00000000..97c2fb31 --- /dev/null +++ b/stable/org.simantics.objmap/doc/main.mediawiki @@ -0,0 +1,26 @@ +'''org.simantics.objmap''' is a framework for bidirectional synchronization between Simantics database and Java objects. + +See [[org.simantics.template_Manual|Manual]] for details. + += Dependencies= + +* [[org.simantics.db]] +* gnu.trove2 + +There is a plan to split the plugin into two plugins such that the other will be database-independent and contain all annotations. + +=Download= + +{| style="background-color: #e9e9e9; border: 1px solid #aaaaaa; width: 75%;" +| '''Version''' +| '''Date''' +| '''Download''' +|- style="background-color: #f9f9f9; " | +| 0.1.0 +| 12.11.2009 +| [[Media:org.simantics.objmap-0.1.0.zip|org.simantics.objmap-0.1.0.zip]] +|} + +=Current Development= +The current version is released mostly for comments and is not yet ready for deployment. The development plan is at the end of the [[org.simantics.objmap_Manual#TODO|manual]]. + diff --git a/stable/org.simantics.objmap/doc/manual.mediawiki b/stable/org.simantics.objmap/doc/manual.mediawiki new file mode 100644 index 00000000..c3bab964 --- /dev/null +++ b/stable/org.simantics.objmap/doc/manual.mediawiki @@ -0,0 +1,167 @@ += Introduction = + +When implementing an editor in Simantics platform, it is very common that the graph representation cannot be directly used, but the editor needs to create an intermediate model of the subgraph it edits. Some reasons for this: +* Accessing the database directly is not fast enough. +* An editor using the database directly holds frequently long read locks and cannot operate during write transactions. +* The editor needs to store auxiliary objects attached to the model. +* Editor modifies the intermediate model speculatively before the modification is committed to the database or canceled. +* The modifications in database cannot be applied in the editor immediately (for example during rendering). +* Third-party component requires certain classes to be used. +* Editor needs to be backend agnostic and cannot directly use database api. + +There are two different approaches for implementing the intermediate model: +; Triangle model +: The editor modifies the database directly and the changes in the database are eventually propagated to the intermediate model. The editor doesn't change the intermediate model directly. +[[Image:triangleModel.png]] +; Bidirectional model +: The editor operates only using the intermediate model and modifications are updated from intermediate model to the database and vice versa. +[[Image:bidirectionalModel.png]] + +By experience, the triangle model is easier to implement correctly in particular when resources are linked to each other in complex fashion. The org.simantics.objmap-plugin tries to make the implementation of bidirectional model easier by providing a framework for defining declaratively the update procedure between database and intermediate model. It can also be used with triangle model only for one direction or with hybrid model where some operations are implemented using the intermediate model and other modifying the database directly. + += Design principles = + +; Symmetric +: For every operation from database to Java objects there is a corresponding operation from Java objects to database. This makes the framework easier to learn and undestand. +; Non-intrusive +: The Java objects used with the framework do not need to implement any specific interface or follow some specific naming convention. The mapping schema can be defined using annotations or separately from the class definition. +; Support for different use scenarios +:* bidirectional / unidirectional +:* one shot / continuous +:* automatic listening / manual updating +; One-to-one +: For every resource there is a single corresponding Java object and vise versa. This makes the framework easier to understand. It is not a transformation framework. + += Concepts = + +''Mapping'' consists of a set of resources called a ''domain'', a set of Java objects called a ''range'' and a collection of ''links''. Each link is attached to exactly one domain and range element and each domain and range element has at most one link attached to it. Additionally the link has a ''link type'' that contains requirements for the domain and range elements in the same link. + +[[Image:objectMappingTerminology.png]] + +A mapping is ''up-to-date'' if every domain and range element has a link and all links satisfy the requirements of their link types. The links of up-to-date mapping form a bijection from domain to range. + +A ''mapping schema'' associates all domain and range elements with a link type. It is used to add new domain and range elements to the mapping. + += Mapping interface = + +The plugin represents a mapping with interface org.simantics.objmap.IMapping. The interface is symmetric in the sense that every operation on the domain of the mapping has also a counterpart that operates on the range. Typically, if one of the operations requires a read graph, its counterpart requires a write graph. We will describe only the methods operating on the domain of the mapping: + + Set getDomain(); + +Returns the domain of the mapping. All set operations are supported. Adding a new domain element does not automatically create a link to it. Removal of a domain element removes also a link and the target element, but does not remove the element from the database. + + Collection updateDomain(WriteGraph g) throws MappingException; + +Updates all domain elements whose counterpart is modified and creates new domain elements for previously added range elements. Returns the collection of domain elements that were modified or created in the update process. + + Object get(Resource domainElement); + +Returns the counterpart of a domain element or null if the element does not belong to the domain or does not have a link. + + Object map(ReadGraph g, Resource domainElement) throws MappingException; + +A convenience method that adds a domain element to the mapping and immediately updates the mapping and returns the corresponding range element. + + void domainModified(Resource domainElement); + +Tells the mapping that the domain element has been modified. + + boolean isDomainModified(); + +Tells if some domain elements have been modified or added. + + Collection getConflictingDomainElements(); + +Returns a collection of domain elements which have been modified and also their counterparts in the mapping are modified. These elements are in conflict in the sense that the updating domain and range in different orders may produce different results. + + void addMappingListener(IMappingListener listener); + void removeMappingListener(IMappingListener listener); + +Adds or removes a listener for domain and range modifications. + += Defining a mapping schema = + +The primary way for defining a mapping schema is to use Java annotations. The current annotation support is still lacking. Only the following annotations are supported: +; GraphType(uri) +: Specifies the domain type that the class corresponds to. +; RelatedValue(uri) +: Specifies a correspondence between a field and functional property. +; RelatedElement(uri) +: Specifies a correspondence between a field and functional relation +; RelatedElements(uri) +: Specifies a correspondence between a field and a relation. The type of the field has to be a collection. + +== Example == + +Suppose we have the following annotated classes: + @GraphType("http://www.simantics.org/Sysdyn#Configuration") + static class Configuration { + @RelatedElements("http://www.vtt.fi/Simantics/Layer0/1.0/Relations#ConsistsOf") + Collection components; + } + + static abstract class Component { + } + + @GraphType("http://www.simantics.org/Sysdyn#Dependency") + static class Dependency extends Component { + @RelatedElement("http://www.simantics.org/Sysdyn#HasTail") + Variable tail; + @RelatedElement("http://www.simantics.org/Sysdyn#HasHead") + Auxiliary head; + } + + static abstract class Variable extends Component { + @RelatedValue("http://www.vtt.fi/Simantics/Layer0/1.0/Relations#HasName") + String name; + } + + @GraphType("http://www.simantics.org/Sysdyn#Auxiliary") + static class Auxiliary extends Variable { + } + +Them the schema can be defined as follows: + SimpleSchema schema = new SimpleSchema(); + schema.addLinkType(MappingSchemas.fromAnnotations(g, Configuration.class)); + schema.addLinkType(MappingSchemas.fromAnnotations(g, Dependency.class)); + schema.addLinkType(MappingSchemas.fromAnnotations(g, Auxiliary.class)); + += Using the mapping interface = + +Assume that a mapping scheme scheme has already been defined and modelRoot is the root resource of the model that the editor edits. Then the model is created as follows: + IMapping mapping = Mappings.create(scheme); + in read transaction { + MyModel model = (MyModel)mapping.map(graph, modelRoot); + } + +There are different ways how the mapping can be updated. The following code forces update for all domain elements. + in read transaction { + for(Resource r : mapping.getDomain()) + mapping.domainModified(r); + mapping.updateRange(graph); + } + +If the range elements have some kind of "dirty" flags, the update can be optimized: + in write transaction { + for(Object obj : mapping.getRange()) + if(obj implements MyObject && ((MyObject)obj).isDirty()) + mapping.rangeModified(obj); + mapping.updateDomain(graph); + } + +Often the editor has to update some auxiliary structures when the mapping modifies the range. This can be implemented for example as: + for(Object obj : mapping.updateRange(graph)) + if(obj implements MyObject) + ((MyObject)obj).updateAuxiliary(); + +The most convenient way for updating the target would be to add graph request listeners for each domain element in the mapping. This is not yet implemented although the current interface should support this without modifications. Currently the only way to listen the database changes is to listen the request that is used to call the updateRange-method. + += Development plan = + +By priority: +* Automatic listening of database changes: marks domain elements modified. +* More complete annotations +* Utilizing declarations in ontologies: for example full URIs of relations are not needed because relations are declared in types. Also the validity of annotation can be checked. +* A separate plugin containing only mapping annotations so that the plugin can be used without introducing a dependency to org.simantics.db. +* Composition annotation that can be used to remove elements whose parents are removed or update elements whose parents are marked modified. +* Support for copy-paste and other extra mapping issues. diff --git a/stable/org.simantics.objmap/doc/objectMappingTerminology.graphml b/stable/org.simantics.objmap/doc/objectMappingTerminology.graphml new file mode 100644 index 00000000..c3cc6b27 --- /dev/null +++ b/stable/org.simantics.objmap/doc/objectMappingTerminology.graphml @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + mapping + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + domain element + + + + + + + + + + + link + + + + + + + + + + + range element + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + link type + + + + + + + + + + + + + + + + + + + diff --git a/stable/org.simantics.objmap/doc/objectMappingTerminology.png b/stable/org.simantics.objmap/doc/objectMappingTerminology.png new file mode 100644 index 00000000..e9ee1fba Binary files /dev/null and b/stable/org.simantics.objmap/doc/objectMappingTerminology.png differ diff --git a/stable/org.simantics.objmap/doc/triangleModel.graphml b/stable/org.simantics.objmap/doc/triangleModel.graphml new file mode 100644 index 00000000..9ab3b29f --- /dev/null +++ b/stable/org.simantics.objmap/doc/triangleModel.graphml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + Intermediate model + + + + + + + + + + + + Database + + + + + + + + + + + + Editor + + + + + + + + + + + reads + + + + + + + + + + + visualizes + + + + + + + + + + + modifies + + + + + + + + + diff --git a/stable/org.simantics.objmap/doc/triangleModel.png b/stable/org.simantics.objmap/doc/triangleModel.png new file mode 100644 index 00000000..0918ef8a Binary files /dev/null and b/stable/org.simantics.objmap/doc/triangleModel.png differ diff --git a/stable/org.simantics.objmap/examples/org/simantics/objmap/examples/SysdynExample.java b/stable/org.simantics.objmap/examples/org/simantics/objmap/examples/SysdynExample.java new file mode 100644 index 00000000..bb6df661 --- /dev/null +++ b/stable/org.simantics.objmap/examples/org/simantics/objmap/examples/SysdynExample.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.examples; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.IMappingSchema; +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedElement; +import org.simantics.objmap.annotations.RelatedElements; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.objmap.schema.MappingSchemas; +import org.simantics.objmap.schema.SimpleSchema; + +public class SysdynExample { + + @GraphType("http://www.simantics.org/Sysdyn-1.1/Configuration") + static class Configuration { + @RelatedElements("http://www.simantics.org/Layer0-1.0/ConsistsOf") + Collection components; + } + + static abstract class Component { + } + + @GraphType("http://www.simantics.org/Sysdyn-1.1/Dependency") + static class Dependency extends Component { + @RelatedElement("http://www.simantics.org/Sysdyn-1.1/HasTail") + Variable tail; + @RelatedElement("http://www.simantics.org/Sysdyn-1.1/HasHead") + Auxiliary head; + } + + static abstract class Variable extends Component { + @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName") + String name; + } + + @GraphType("http://www.simantics.org/Sysdyn-1.1/Auxiliary") + static class Auxiliary extends Variable { + } + + public static IMappingSchema createSchema(ReadGraph g) throws DatabaseException, InstantiationException, IllegalAccessException { + SimpleSchema schema = new SimpleSchema(); + schema.addLinkType(MappingSchemas.fromAnnotations(g, Configuration.class)); + schema.addLinkType(MappingSchemas.fromAnnotations(g, Dependency.class)); + schema.addLinkType(MappingSchemas.fromAnnotations(g, Auxiliary.class)); + return schema; + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/IFunction.java b/stable/org.simantics.objmap/src/org/simantics/objmap/IFunction.java new file mode 100644 index 00000000..8a7f9fea --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/IFunction.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap; + +/** + * A generic function object that throws MappingExceptions. + * + * @author Hannu Niemistö + * + * @param Domain of the function + * @param Range of the function + */ +public interface IFunction { + R get(D element) throws MappingException; +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/ILinkType.java b/stable/org.simantics.objmap/src/org/simantics/objmap/ILinkType.java new file mode 100644 index 00000000..91a985a5 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/ILinkType.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; + +/** + * Contains rules for how a link should be created and maintained. + * @author Hannu Niemistö + */ +public interface ILinkType extends IMappingRule { + /** + * Creates a domain element based on known range element. + */ + Resource createDomainElement(WriteGraph g, Object rangeElement) throws MappingException; + + /** + * Creates a range element based on known domain element. + */ + Object createRangeElement(ReadGraph g, Resource domainElement) throws MappingException; +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/IMapping.java b/stable/org.simantics.objmap/src/org/simantics/objmap/IMapping.java new file mode 100644 index 00000000..bb22a3b6 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/IMapping.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap; + +import java.util.Collection; +import java.util.Set; + +import org.simantics.db.Disposable; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; + +/** + * A mapping consists of domain (a set of resources), range (a set of Java objects) and + * a set of links relating them. The mapping is used to propagate modifications of + * domain elements to range and vice versa. + * + * @see Manual + * + * @author Hannu Niemistö + */ +public interface IMapping extends Disposable { + + /** + * Returns the domain of the mapping. All set operations are supported. + * Adding a new domain element does not automatically create a link to it. + * Removal of a domain element removes also a link and the target element, + * but does not remove the element from the database. + */ + Set getDomain(); + + /** + * Returns the range of the mapping. All set operations are supported. + * Adding a new range element does not automatically create a link to it. + * Removal of a range element removes also a link and the domain element, + * but does not remove the domain element from the database. + */ + Set getRange(); + + /** + * Updates all domain elements whose counterpart is modified and creates new + * domain elements for previously added range elements. Returns the + * collection of domain elements that were modified or created in the update + * process. + */ + Collection updateDomain(WriteGraph g) throws MappingException; + + /** + * Updates all range elements whose counterpart is modified and creates new + * range elements for previously added domain elements. Returns the + * collection of range elements that were modified or created in the update + * process. + */ + Collection updateRange(ReadGraph g) throws MappingException; + + /** + * Returns the counterpart of a domain element or null if the element does + * not belong to the domain or does not have a link. + */ + Object get(Resource domainElement); + + /** + * Returns the counterpart of a range element or null if the element does + * not belong to the range or does not have a link. + */ + Resource inverseGet(Object rangeElement); + + /** + * A convenience method that adds a domain element to the mapping and + * immediately updates the mapping and returns the corresponding range + * element. + */ + Object map(ReadGraph g, Resource domainElement) throws MappingException; + + /** + * A convenience method that adds a range element to the mapping and + * immediately updates the mapping and returns the corresponding domain + * element. + */ + Resource inverseMap(WriteGraph g, Object rangeElement) + throws MappingException; + + /** + * Tells the mapping that the domain element has been modified. + */ + void domainModified(Resource domainElement); + + /** + * Tells the mapping that the range element has been modified. + */ + void rangeModified(Object rangeElement); + + /** + * Tells if some domain elements have been modified or added. + */ + boolean isDomainModified(); + + /** + * Tells if some range elements have been modified or added. + */ + boolean isRangeModified(); + + /** + * Returns a collection of domain elements which have been modified and also + * their counterparts in the mapping are modified. These elements are in + * conflict in the sense that the updating domain and range in different + * orders may produce different results. + */ + Collection getConflictingDomainElements(); + + /** + * Returns a collection of range elements which have been modified and also + * their counterparts in the mapping are modified. These elements are in + * conflict in the sense that the updating domain and range in different + * orders may produce different results. + */ + Collection getConflictingRangeElements(); + + /** + * Adds a listener for domain and range modifications. + */ + void addMappingListener(IMappingListener listener); + + /** + * Removes a previously added listener. + */ + void removeMappingListener(IMappingListener listener); + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/IMappingListener.java b/stable/org.simantics.objmap/src/org/simantics/objmap/IMappingListener.java new file mode 100644 index 00000000..b7c39700 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/IMappingListener.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap; + +/** + * Listens modifications in a mapping. + * @author Hannu Niemistö + */ +public interface IMappingListener { + /** + * Called when some domain element is modified or created + * and the mapping was previously up to date. + */ + void domainModified(); + + /** + * Called when some range element is modified or created + * and the mapping was previously up to date. + */ + void rangeModified(); +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/IMappingRule.java b/stable/org.simantics.objmap/src/org/simantics/objmap/IMappingRule.java new file mode 100644 index 00000000..75f3bb5d --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/IMappingRule.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; + +/** + * A rule for how domain and range elements are related to each other. + * @author Hannu Niemistö + */ +public interface IMappingRule { + /** + * Modifies the domain element so that it corresponds to the range element. + * @param g write transaction + * @param map unidirectional view of the current mapping + * @param domainElement the domain element that is updated + * @param rangeElement the range element that corresponds to the domain element + * @return true if the rule made some modifications + * @throws MappingException + */ + boolean updateDomain(WriteGraph g, IFunction map, Resource domainElement, Object rangeElement) throws MappingException; + + /** + * Modifies the range element so that it corresponds to the domain element. + * @param g read transaction + * @param map unidirectional view of the current mapping + * @param domainElement the domain element that corresponds to the range element + * @param rangeElement the range element that is updated + * @return true if the rule made some modifications + * @throws MappingException + */ + boolean updateRange(ReadGraph g, IFunction map, Resource domainElement, Object rangeElement) throws MappingException; +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/IMappingSchema.java b/stable/org.simantics.objmap/src/org/simantics/objmap/IMappingSchema.java new file mode 100644 index 00000000..a403954c --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/IMappingSchema.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + +/** + * Specifies the link types of new elements added to a mapping. + * @author Hannu Niemistö + */ +public interface IMappingSchema { + /** + * @return Link type that should be used for the element. + */ + ILinkType linkTypeOfDomainElement(ReadGraph g, Resource element) throws MappingException; + + /** + * @return Link type that should be used for the element. + */ + ILinkType linkTypeOfRangeElement(Object element) throws MappingException; +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/MappingException.java b/stable/org.simantics.objmap/src/org/simantics/objmap/MappingException.java new file mode 100644 index 00000000..290345e7 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/MappingException.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap; + +import org.simantics.db.exception.DatabaseException; + +/** + * An exception thrown for any error during mapping methods. + * @author Hannu Niemistö + */ +public class MappingException extends DatabaseException { + + private static final long serialVersionUID = -4026122899414272427L; + + public MappingException() { + super(); + } + + public MappingException(String message, Throwable cause) { + super(message, cause); + } + + public MappingException(String message) { + super(message); + } + + public MappingException(Throwable cause) { + super(cause); + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/Mappings.java b/stable/org.simantics.objmap/src/org/simantics/objmap/Mappings.java new file mode 100644 index 00000000..a0153d0c --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/Mappings.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap; + +import org.simantics.objmap.impl.Mapping; +import org.simantics.objmap.impl.UnidirectionalMapping; + +/** + * Static utility methods for mappings. + * @author Hannu Niemistö + */ +public class Mappings { + private Mappings() {} + + /** + * Creates a new mapping based on the given mapping schema. + * The created mapping is not thread-safe and will not + * listen database changes automatically. + */ + public static IMapping createWithoutListening(IMappingSchema schema) { + return new Mapping(schema, false); + } + + /** + * Creates a new mapping based on the given mapping schema. + * The created mapping is not thread-safe. It listens database + * changes automatically. + */ + public static IMapping createWithListening(IMappingSchema schema) { + return new Mapping(schema, true); + } + + /** + * Creates a mapping that supports only the direction from domain to range. + * Does not listen the database. + */ + public static IMapping createUnidirectional(IMappingSchema schema) { + return new UnidirectionalMapping(schema); + } +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/Composition.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/Composition.java new file mode 100644 index 00000000..e260c948 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/Composition.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD,ElementType.METHOD}) +public @interface Composition { +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/GraphType.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/GraphType.java new file mode 100644 index 00000000..532539b9 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/GraphType.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Specifies the domain type that the class corresponds to. + * @author Hannu Niemistö + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface GraphType { + String value(); +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/OptionalRelatedElements.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/OptionalRelatedElements.java new file mode 100644 index 00000000..da747929 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/OptionalRelatedElements.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.simantics.objmap.annotations.factories.OptionalRelatedElementsRuleFactory; +import org.simantics.objmap.annotations.meta.HasFieldRuleFactory; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@HasFieldRuleFactory(OptionalRelatedElementsRuleFactory.class) +public @interface OptionalRelatedElements { + String value(); + boolean composition() default false; +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedElement.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedElement.java new file mode 100644 index 00000000..901db265 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedElement.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.simantics.objmap.annotations.factories.RelatedElementRuleFactory; +import org.simantics.objmap.annotations.meta.HasFieldRuleFactory; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@HasFieldRuleFactory(RelatedElementRuleFactory.class) +public @interface RelatedElement { + String value(); +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedElements.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedElements.java new file mode 100644 index 00000000..d7e68859 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedElements.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.simantics.objmap.annotations.factories.RelatedElementsRuleFactory; +import org.simantics.objmap.annotations.meta.HasFieldRuleFactory; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@HasFieldRuleFactory(RelatedElementsRuleFactory.class) +public @interface RelatedElements { + String value(); + boolean composition() default false; +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedOrderedSetElements.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedOrderedSetElements.java new file mode 100644 index 00000000..21b3e171 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedOrderedSetElements.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.simantics.objmap.annotations.factories.RelatedOrderedSetElementsRuleFactory; +import org.simantics.objmap.annotations.meta.HasFieldRuleFactory; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@HasFieldRuleFactory(RelatedOrderedSetElementsRuleFactory.class) +public @interface RelatedOrderedSetElements { + boolean composition() default false; +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedValue.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedValue.java new file mode 100644 index 00000000..23d3e9a8 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/RelatedValue.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.simantics.objmap.annotations.factories.RelatedValueRuleFactory; +import org.simantics.objmap.annotations.meta.HasFieldRuleFactory; +import org.simantics.objmap.rules.adapters.IdentityAdapter; +import org.simantics.objmap.rules.adapters.ValueAdapter; + +/** + * Specifies a correspondence between a field and + * functional property. + * @author Hannu Niemistö + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@HasFieldRuleFactory(RelatedValueRuleFactory.class) +public @interface RelatedValue { + String value(); + Class adapter() default IdentityAdapter.class; +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/UpdateMethod.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/UpdateMethod.java new file mode 100644 index 00000000..f8431f52 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/UpdateMethod.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.simantics.objmap.annotations.factories.UpdateMethodFactory; +import org.simantics.objmap.annotations.meta.HasMethodRuleFactory; + +/** + * Specifies that the annotated method should be called + * to update range object. + * @author Hannu Niemistö + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +@HasMethodRuleFactory(UpdateMethodFactory.class) +public @interface UpdateMethod { +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/DataTypeUtils.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/DataTypeUtils.java new file mode 100644 index 00000000..97cbf184 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/DataTypeUtils.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations.factories; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.layer0.Layer0; + +public class DataTypeUtils { + + public static Resource dataTypeOfClass(ReadGraph g, Class clazz) { + Layer0 b = Layer0.getInstance(g); + if(clazz.equals(Double.class) || clazz.equals(double.class)) + return b.Double; + else if(clazz.equals(String.class)) + return b.String; + else if(clazz.equals(Integer.class) || clazz.equals(int.class)) + return b.Integer; + else if(clazz.equals(Float.class) || clazz.equals(float.class)) + return b.Float; + else if(clazz.equals(Boolean.class) || clazz.equals(boolean.class)) + return b.Boolean; + else if(clazz.equals(Long.class) || clazz.equals(long.class)) + return b.Long; + else if(clazz.equals(Byte.class) || clazz.equals(byte.class)) + return b.Byte; + + else if(clazz.equals(double[].class)) + return b.DoubleArray; + else if(clazz.equals(int[].class)) + return b.IntegerArray; + else if(clazz.equals(byte[].class)) + return b.ByteArray; + else if(clazz.equals(float[].class)) + return b.FloatArray; + else if(clazz.equals(boolean[].class)) + return b.BooleanArray; + else if(clazz.equals(String[].class)) + return b.StringArray; + else if(clazz.equals(long[].class)) + return b.LongArray; + else { + System.out.println("Couldn't find a data type for " + clazz); + return null; + } + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/OptionalRelatedElementsRuleFactory.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/OptionalRelatedElementsRuleFactory.java new file mode 100644 index 00000000..20692388 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/OptionalRelatedElementsRuleFactory.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations.factories; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.util.Collections; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.exception.ValidationException; +import org.simantics.objmap.IMappingRule; +import org.simantics.objmap.annotations.OptionalRelatedElements; +import org.simantics.objmap.rules.MappedElementsRule; +import org.simantics.objmap.rules.domain.RelatedObjectsAccessor; +import org.simantics.objmap.rules.factory.IFieldRuleFactory; +import org.simantics.objmap.rules.range.FieldAccessorWithDefault; + +public class OptionalRelatedElementsRuleFactory implements IFieldRuleFactory { + + @Override + public IMappingRule create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException { + OptionalRelatedElements annotation = (OptionalRelatedElements)_annotation; + return new MappedElementsRule( + new RelatedObjectsAccessor(g.getResource(annotation.value()), + annotation.composition()), + new FieldAccessorWithDefault(field, Collections.emptyList()) + ); + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedElementRuleFactory.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedElementRuleFactory.java new file mode 100644 index 00000000..6d128eac --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedElementRuleFactory.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations.factories; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.exception.ValidationException; +import org.simantics.objmap.IMappingRule; +import org.simantics.objmap.annotations.RelatedElement; +import org.simantics.objmap.rules.MappedElementRule; +import org.simantics.objmap.rules.domain.RelatedObjectAccessor; +import org.simantics.objmap.rules.factory.IFieldRuleFactory; +import org.simantics.objmap.rules.range.FieldAccessor; + +public class RelatedElementRuleFactory implements IFieldRuleFactory { + + @Override + public IMappingRule create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException { + RelatedElement annotation = (RelatedElement)_annotation; + return new MappedElementRule( + new RelatedObjectAccessor(g.getResource(annotation.value())), + new FieldAccessor(field) + ); + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedElementsRuleFactory.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedElementsRuleFactory.java new file mode 100644 index 00000000..44127853 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedElementsRuleFactory.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations.factories; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.exception.ValidationException; +import org.simantics.objmap.IMappingRule; +import org.simantics.objmap.annotations.RelatedElements; +import org.simantics.objmap.rules.MappedElementsRule; +import org.simantics.objmap.rules.domain.RelatedObjectsAccessor; +import org.simantics.objmap.rules.factory.IFieldRuleFactory; +import org.simantics.objmap.rules.range.FieldAccessor; + +public class RelatedElementsRuleFactory implements IFieldRuleFactory { + + @Override + public IMappingRule create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException { + RelatedElements annotation = (RelatedElements)_annotation; + return new MappedElementsRule( + new RelatedObjectsAccessor(g.getResource(annotation.value()), + annotation.composition()), + new FieldAccessor>(field) + ); + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedOrderedSetElementsRuleFactory.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedOrderedSetElementsRuleFactory.java new file mode 100644 index 00000000..fb78847e --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedOrderedSetElementsRuleFactory.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations.factories; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.exception.ValidationException; +import org.simantics.objmap.IMappingRule; +import org.simantics.objmap.annotations.RelatedOrderedSetElements; +import org.simantics.objmap.rules.MappedElementsRule; +import org.simantics.objmap.rules.domain.RelatedOrderedSetElementsAccessor; +import org.simantics.objmap.rules.factory.IFieldRuleFactory; +import org.simantics.objmap.rules.range.FieldAccessor; + +public class RelatedOrderedSetElementsRuleFactory implements IFieldRuleFactory { + + @Override + public IMappingRule create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException { + RelatedOrderedSetElements annotation = (RelatedOrderedSetElements)_annotation; + return new MappedElementsRule( + new RelatedOrderedSetElementsAccessor(annotation.composition()), + new FieldAccessor>(field) + ); + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedValueRuleFactory.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedValueRuleFactory.java new file mode 100644 index 00000000..828bb59f --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedValueRuleFactory.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations.factories; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.exception.ValidationException; +import org.simantics.objmap.IMappingRule; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.objmap.rules.ValueRule; +import org.simantics.objmap.rules.adapters.IdentityAdapter; +import org.simantics.objmap.rules.adapters.ValueAdapter; +import org.simantics.objmap.rules.domain.RelatedValueAccessor; +import org.simantics.objmap.rules.factory.IFieldRuleFactory; +import org.simantics.objmap.rules.range.AdaptedRangeAccessor; +import org.simantics.objmap.rules.range.FieldAccessor; +import org.simantics.objmap.rules.range.IRangeAccessor; + +public class RelatedValueRuleFactory implements IFieldRuleFactory { + + @Override + public IMappingRule create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, + ValidationException, ServiceException { + RelatedValue annotation = (RelatedValue) _annotation; + Class adapterClass = annotation.adapter(); + IRangeAccessor rangeAccessor = new FieldAccessor(field); + Resource valueType; + if (adapterClass == IdentityAdapter.class) { + valueType = DataTypeUtils.dataTypeOfClass(g, field.getType()); + } else { + try { + ValueAdapter adapter = adapterClass.newInstance(); + rangeAccessor = new AdaptedRangeAccessor(rangeAccessor, adapter); + valueType = adapter.rangeTypeToDomainType(g, field.getType()); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + return new ValueRule(new RelatedValueAccessor(g.getResource(annotation.value()), valueType), rangeAccessor); + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/UpdateMethodFactory.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/UpdateMethodFactory.java new file mode 100644 index 00000000..5cab576f --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/factories/UpdateMethodFactory.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations.factories; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; + +import org.apache.log4j.Logger; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.IFunction; +import org.simantics.objmap.IMappingRule; +import org.simantics.objmap.MappingException; +import org.simantics.objmap.rules.factory.IMethodRuleFactory; + +public class UpdateMethodFactory implements IMethodRuleFactory { + + static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + + @Override + public IMappingRule create(ReadGraph g, + Annotation annotation, + final Method method) + throws DatabaseException { + method.setAccessible(true); + return new IMappingRule() { + + @Override + public boolean updateRange(ReadGraph g, IFunction map, + Resource domainElement, Object rangeElement) + throws MappingException { + LOGGER.info(" UpdateMethodFactory.updateRange"); + try { + return (Boolean)method.invoke(rangeElement, g, domainElement); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } + + @Override + public boolean updateDomain(WriteGraph g, IFunction map, + Resource domainElement, Object rangeElement) + throws MappingException { + return false; + } + }; + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/meta/HasClassRuleFactory.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/meta/HasClassRuleFactory.java new file mode 100644 index 00000000..304c8e2f --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/meta/HasClassRuleFactory.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations.meta; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.simantics.objmap.rules.factory.IClassRuleFactory; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.ANNOTATION_TYPE) +public @interface HasClassRuleFactory { + Class value(); +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/meta/HasFieldRuleFactory.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/meta/HasFieldRuleFactory.java new file mode 100644 index 00000000..877606af --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/meta/HasFieldRuleFactory.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations.meta; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.simantics.objmap.rules.factory.IFieldRuleFactory; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.ANNOTATION_TYPE) +public @interface HasFieldRuleFactory { + Class value(); +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/meta/HasMethodRuleFactory.java b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/meta/HasMethodRuleFactory.java new file mode 100644 index 00000000..ecdc521b --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/annotations/meta/HasMethodRuleFactory.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.annotations.meta; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.simantics.objmap.rules.factory.IMethodRuleFactory; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.ANNOTATION_TYPE) +public @interface HasMethodRuleFactory { + Class value(); +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/impl/Link.java b/stable/org.simantics.objmap/src/org/simantics/objmap/impl/Link.java new file mode 100644 index 00000000..42aed779 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/impl/Link.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +/** + * + */ +package org.simantics.objmap.impl; + +import org.simantics.db.Resource; +import org.simantics.objmap.ILinkType; + +/** + * An indication that the domain element corresponds to the range element + * in the mapping. The link type describes how source and target objects + * are updated. There are additionally flags for dirtiness of the link. + * @author Hannu Niemistö + */ +public class Link { + public ILinkType type; + public Resource domainElement; + public Object rangeElement; + + public boolean domainModified = false; + public boolean rangeModified = false; + public boolean removed = false; + + public Link(ILinkType type, Resource domainElement, Object rangeElement) { + this.type = type; + this.domainElement = domainElement; + this.rangeElement = rangeElement; + } +} \ No newline at end of file diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/impl/Mapping.java b/stable/org.simantics.objmap/src/org/simantics/objmap/impl/Mapping.java new file mode 100644 index 00000000..cf4c33c9 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/impl/Mapping.java @@ -0,0 +1,424 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.impl; + +import gnu.trove.THashMap; +import gnu.trove.TObjectIdentityHashingStrategy; + +import java.util.AbstractSet; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; + +import org.apache.log4j.Logger; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.IFunction; +import org.simantics.objmap.ILinkType; +import org.simantics.objmap.IMapping; +import org.simantics.objmap.IMappingListener; +import org.simantics.objmap.IMappingSchema; +import org.simantics.objmap.MappingException; + +/** + * An implementation of IMapping. The class should not be created + * directly but using methods in Mappings. + * @see org.simantics.objmap.Mappings + * @author Hannu Niemistö + */ +public class Mapping implements IMapping { + + static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + + private static final TObjectIdentityHashingStrategy IDENTITY_HASHING = + new TObjectIdentityHashingStrategy(); + + IMappingSchema schema; + + THashMap domain = new THashMap(); + THashMap range = new THashMap(IDENTITY_HASHING); + ArrayList listeners = new ArrayList(); + + ArrayList modifiedDomainLinks = new ArrayList(); + ArrayList modifiedRangeLinks = new ArrayList(); + boolean disposed = false; + + boolean listensDomain; + + public Mapping(IMappingSchema schema, boolean listensDomain) { + this.schema = schema; + this.listensDomain = listensDomain; + } + + private void removeLink(Link link) { + if(link.domainModified) + modifiedDomainLinks.remove(link); + if(link.rangeModified) + modifiedRangeLinks.remove(link); + link.removed = true; + } + + private void createDomain(WriteGraph g, Link link) throws MappingException { + LOGGER.info(" createDomain for " + link.rangeElement); + ILinkType type = schema.linkTypeOfRangeElement(link.rangeElement); + Resource domainElement = type.createDomainElement(g, link.rangeElement); + + link.type = type; + link.domainElement = domainElement; + domain.put(domainElement, link); + + // TODO Should we do this only if the mapping is listening? + domainModified(link); + } + + private void createRange(ReadGraph g, Link link) throws MappingException { + ILinkType type = schema.linkTypeOfDomainElement(g, link.domainElement); + Object rangeElement = type.createRangeElement(g, link.domainElement); + + link.type = type; + link.rangeElement = rangeElement; + range.put(rangeElement, link); + } + + Set domainSet = new AbstractSet() { + + public boolean add(Resource e) { + if(domain.containsKey(e)) + return false; + Link link = new Link(null, e, null); + domain.put(e, link); + modifiedDomainLinks.add(link); + return true; + } + + public boolean contains(Object o) { + return domain.contains(o); + } + + public boolean remove(Object o) { + Link link = domain.remove(o); + if(link == null) + return false; + removeLink(link); + if(link.rangeElement != null) + range.remove(link.rangeElement); + return true; + } + + @Override + public Iterator iterator() { + // FIXME does not implement Iterator.remove correctly + return domain.keySet().iterator(); + } + + @Override + public int size() { + return domain.size(); + } + + }; + + Set rangeSet = new AbstractSet() { + + public boolean add(Object e) { + if(range.containsKey(e)) + return false; + Link link = new Link(null, null, e); + range.put(e, link); + modifiedRangeLinks.add(link); + return true; + } + + public boolean contains(Object o) { + return range.contains(o); + } + + public boolean remove(Object o) { + Link link = range.remove(o); + if(link == null) + return false; + removeLink(link); + if(link.domainElement != null) + domain.remove(link.domainElement); + return true; + } + + @Override + public Iterator iterator() { + // FIXME does not implement Iterator.remove correctly + return range.keySet().iterator(); + } + + @Override + public int size() { + return range.size(); + } + + }; + + class DomainToRange implements IFunction { + + ReadGraph g; + + public DomainToRange(ReadGraph g) { + this.g = g; + } + + @Override + public Object get(Resource element) throws MappingException { + Link link = domain.get(element); + if(link == null) { + link = new Link(null, element, null); + link.domainModified = true; + modifiedDomainLinks.add(link); + domain.put(element, link); + createRange(g, link); + } + else if(link.type == null) + createRange(g, link); + return link.rangeElement; + } + + }; + + class RangeToDomain implements IFunction { + + WriteGraph g; + + public RangeToDomain(WriteGraph g) { + this.g = g; + } + + @Override + public Resource get(Object element) throws MappingException { + Link link = range.get(element); + if(link == null) { + link = new Link(null, null, element); + link.rangeModified = true; + modifiedRangeLinks.add(link); + range.put(element, link); + createDomain(g, link); + } + else if(link.type == null) + createDomain(g, link); + return link.domainElement; + } + + }; + + @Override + public Set getDomain() { + return domainSet; + } + + @Override + public Set getRange() { + return rangeSet; + } + + @Override + public synchronized Collection updateDomain(WriteGraph g) throws MappingException { + LOGGER.info("Mapping.updateDomain"); + RangeToDomain map = new RangeToDomain(g); + ArrayList updated = new ArrayList(); + while(!modifiedRangeLinks.isEmpty()) { + LOGGER.info(" modifiedRangeLinks.size() = " + modifiedRangeLinks.size()); + + Link link = modifiedRangeLinks.remove(modifiedRangeLinks.size()-1); + link.rangeModified = false; + /*if(link.domainModified) { + link.domainModified = false; + modifiedDomainLinks.remove(link); + }*/ + + if(link.type == null) { + createDomain(g, link); + } + + if(link.type.updateDomain(g, map, link.domainElement, link.rangeElement)) + updated.add(link.domainElement); + } + return updated; + } + + @Override + public synchronized Collection updateRange(ReadGraph g) throws MappingException { + LOGGER.info("Mapping.updateRange"); + DomainToRange map = new DomainToRange(g); + ArrayList updated = new ArrayList(); + while(!modifiedDomainLinks.isEmpty()) { + LOGGER.info(" modifiedDomainLinks.size() = " + modifiedDomainLinks.size()); + + Link link = modifiedDomainLinks.remove(modifiedDomainLinks.size()-1); + link.domainModified = false; + /*if(link.rangeModified) { + link.rangeModified = false; + modifiedRangeLinks.remove(link); + }*/ + + if(link.type == null) { + createRange(g, link); + } + + if(listensDomain) { + RangeUpdateRequest request = new RangeUpdateRequest(link, map, this); + try { + g.syncRequest(request, request); + } catch (DatabaseException e) { + throw new MappingException(e); + } + // TODO check if really modified + updated.add(link.rangeElement); + } + else + if(link.type.updateRange(g, map, link.domainElement, link.rangeElement)) + updated.add(link.rangeElement); + } + return updated; + } + + @Override + public Object get(Resource domainElement) { + Link link = domain.get(domainElement); + if(link == null) + return null; + return link.rangeElement; + } + + @Override + public Resource inverseGet(Object rangeElement) { + Link link = range.get(rangeElement); + if(link == null) + return null; + return link.domainElement; + } + + @Override + public Resource inverseMap(WriteGraph g, Object rangeElement) throws MappingException { + getRange().add(rangeElement); + updateDomain(g); + return inverseGet(rangeElement); + } + + @Override + public Object map(ReadGraph g, Resource domainElement) throws MappingException { + getDomain().add(domainElement); + updateRange(g); + return get(domainElement); + } + + void domainModified(Link link) { + if(!link.domainModified) { + synchronized(modifiedDomainLinks) { + LOGGER.info(" domainModified for " + link.rangeElement); + link.domainModified = true; + modifiedDomainLinks.add(link); + if(modifiedDomainLinks.size() == 1) { + for(IMappingListener listener : listeners) + listener.domainModified(); + } + } + } + } + + @Override + public void domainModified(Resource domainElement) { + Link link = domain.get(domainElement); + if(link != null) + domainModified(link); + } + + void rangeModified(Link link) { + if(!link.rangeModified) { + synchronized(modifiedRangeLinks) { + link.rangeModified = true; + modifiedRangeLinks.add(link); + if(modifiedRangeLinks.size() == 1) { + for(IMappingListener listener : listeners) + listener.rangeModified(); + } + } + } + } + + @Override + public void rangeModified(Object rangeElement) { + Link link = range.get(rangeElement); + if(link != null) + rangeModified(link); + } + + @Override + public boolean isDomainModified() { + return !modifiedDomainLinks.isEmpty(); + } + + @Override + public boolean isRangeModified() { + return !modifiedRangeLinks.isEmpty(); + } + + @Override + public void addMappingListener(IMappingListener listener) { + listeners.add(listener); + } + + @Override + public void removeMappingListener(IMappingListener listener) { + listeners.remove(listener); + } + + @Override + public Collection getConflictingDomainElements() { + ArrayList result = new ArrayList(); + if(modifiedDomainLinks.size() < modifiedRangeLinks.size()) { + for(Link link : modifiedDomainLinks) + if(link.rangeModified) + result.add(link.domainElement); + } + else { + for(Link link : modifiedRangeLinks) + if(link.domainModified) + result.add(link.domainElement); + } + return result; + } + + @Override + public Collection getConflictingRangeElements() { + ArrayList result = new ArrayList(); + if(modifiedDomainLinks.size() < modifiedRangeLinks.size()) { + for(Link link : modifiedDomainLinks) + if(link.rangeModified) + result.add(link.rangeElement); + } + else { + for(Link link : modifiedRangeLinks) + if(link.domainModified) + result.add(link.rangeElement); + } + return result; + } + + @Override + public void dispose() { + disposed = true; + } + + public boolean isDisposed() { + return disposed; + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/impl/RangeUpdateRequest.java b/stable/org.simantics.objmap/src/org/simantics/objmap/impl/RangeUpdateRequest.java new file mode 100644 index 00000000..3268d9e2 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/impl/RangeUpdateRequest.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.impl; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.SyncListener; +import org.simantics.db.request.Read; +import org.simantics.objmap.IFunction; +import org.simantics.objmap.MappingException; + +public class RangeUpdateRequest implements Read, SyncListener { + + Link link; + /* + * Note that this map uses a read request that it has got from caller and + * not the one that is used in updateRange. This is intentional. + */ + IFunction map; // map==null is used to flag that request is performed once + Mapping mapping; // mapping==null is used as a flag the request disposed + + public RangeUpdateRequest(Link link, IFunction map, Mapping mapping) { + this.link = link; + this.map = map; + this.mapping = mapping; + } + + @Override + public Boolean perform(ReadGraph g) throws DatabaseException { + if(map != null) { + link.type.updateRange(g, map, link.domainElement, link.rangeElement); + map = null; + return Boolean.TRUE; + } + else if(mapping != null) { + mapping.domainModified(link); + mapping = null; + return Boolean.FALSE; + } + else + return null; + } + + @Override + public void exception(ReadGraph graph, Throwable throwable) + throws DatabaseException { + if(throwable instanceof DatabaseException) + throw (DatabaseException)throwable; + else + throw new MappingException(throwable); + } + + @Override + public void execute(ReadGraph graph, Boolean result) + throws DatabaseException { + } + + @Override + public boolean isDisposed() { + return mapping == null || link.removed || mapping.isDisposed(); + } + + + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/impl/UnidirectionalMapping.java b/stable/org.simantics.objmap/src/org/simantics/objmap/impl/UnidirectionalMapping.java new file mode 100644 index 00000000..fd41f405 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/impl/UnidirectionalMapping.java @@ -0,0 +1,265 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.impl; + +import gnu.trove.THashMap; +import gnu.trove.TObjectIdentityHashingStrategy; + +import java.util.AbstractSet; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.objmap.IFunction; +import org.simantics.objmap.ILinkType; +import org.simantics.objmap.IMapping; +import org.simantics.objmap.IMappingListener; +import org.simantics.objmap.IMappingSchema; +import org.simantics.objmap.MappingException; + +/** + * An implementation of IMapping. The class should not be created + * directly but using methods in Mappings. + * @see org.simantics.objmap.Mappings + * @author Hannu Niemistö + */ +public class UnidirectionalMapping implements IMapping { + + private static final TObjectIdentityHashingStrategy IDENTITY_HASHING = + new TObjectIdentityHashingStrategy(); + + IMappingSchema schema; + + THashMap domain = new THashMap(); + ArrayList listeners = new ArrayList(); + + ArrayList modifiedDomainLinks = new ArrayList(); + boolean disposed = false; + + public UnidirectionalMapping(IMappingSchema schema) { + this.schema = schema; + } + + private void removeLink(Link link) { + if(link.domainModified) + modifiedDomainLinks.remove(link); + link.removed = true; + } + + private void createDomain(WriteGraph g, Link link) throws MappingException { + ILinkType type = schema.linkTypeOfRangeElement(link.rangeElement); + Resource domainElement = type.createDomainElement(g, link.rangeElement); + + link.type = type; + link.domainElement = domainElement; + domain.put(domainElement, link); + } + + private void createRange(ReadGraph g, Link link) throws MappingException { + ILinkType type = schema.linkTypeOfDomainElement(g, link.domainElement); + Object rangeElement = type.createRangeElement(g, link.domainElement); + + link.type = type; + link.rangeElement = rangeElement; + } + + Set domainSet = new AbstractSet() { + + public boolean add(Resource e) { + if(domain.containsKey(e)) + return false; + Link link = new Link(null, e, null); + domain.put(e, link); + modifiedDomainLinks.add(link); + return true; + } + + public boolean contains(Object o) { + return domain.contains(o); + } + + public boolean remove(Object o) { + Link link = domain.remove(o); + if(link == null) + return false; + removeLink(link); + return true; + } + + @Override + public Iterator iterator() { + // FIXME does not implement Iterator.remove correctly + return domain.keySet().iterator(); + } + + @Override + public int size() { + return domain.size(); + } + + }; + + class DomainToRange implements IFunction { + + ReadGraph g; + + public DomainToRange(ReadGraph g) { + this.g = g; + } + + @Override + public Object get(Resource element) throws MappingException { + Link link = domain.get(element); + if(link == null) { + ILinkType type = schema.linkTypeOfDomainElement(g, element); + Object rangeElement = type.createRangeElement(g, element); + + link = new Link(type, element, rangeElement); + domain.put(element, link); + link.domainModified = true; + modifiedDomainLinks.add(link); + + return rangeElement; + } + else { + if(link.type == null) + createRange(g, link); + return link.rangeElement; + } + } + + }; + + @Override + public Set getDomain() { + return domainSet; + } + + @Override + public Set getRange() { + throw new UnsupportedOperationException(); + } + + @Override + public Collection updateDomain(WriteGraph g) throws MappingException { + throw new UnsupportedOperationException(); + } + + @Override + public Collection updateRange(ReadGraph g) throws MappingException { + DomainToRange map = new DomainToRange(g); + ArrayList updated = new ArrayList(); + while(!modifiedDomainLinks.isEmpty()) { + Link link = modifiedDomainLinks.remove(modifiedDomainLinks.size()-1); + link.domainModified = false; + if(link.type == null) { + createRange(g, link); + } + + link.type.updateRange(g, map, link.domainElement, link.rangeElement); + updated.add(link.rangeElement); + } + return updated; + } + + @Override + public Object get(Resource domainElement) { + Link link = domain.get(domainElement); + if(link == null) + return null; + return link.rangeElement; + } + + @Override + public Resource inverseGet(Object rangeElement) { + throw new UnsupportedOperationException(); + } + + @Override + public Resource inverseMap(WriteGraph g, Object rangeElement) throws MappingException { + throw new UnsupportedOperationException(); + } + + @Override + public Object map(ReadGraph g, Resource domainElement) throws MappingException { + getDomain().add(domainElement); + updateRange(g); + return get(domainElement); + } + + void domainModified(Link link) { + if(!link.domainModified) { + link.domainModified = true; + modifiedDomainLinks.add(link); + if(modifiedDomainLinks.size() == 1) { + for(IMappingListener listener : listeners) + listener.domainModified(); + } + } + } + + @Override + public void domainModified(Resource domainElement) { + Link link = domain.get(domainElement); + if(link != null) + domainModified(link); + } + + @Override + public boolean isDomainModified() { + return !modifiedDomainLinks.isEmpty(); + } + + @Override + public boolean isRangeModified() { + throw new UnsupportedOperationException(); + } + + @Override + public void addMappingListener(IMappingListener listener) { + listeners.add(listener); + } + + @Override + public void removeMappingListener(IMappingListener listener) { + listeners.remove(listener); + } + + @Override + public Collection getConflictingDomainElements() { + throw new UnsupportedOperationException(); + } + + @Override + public Collection getConflictingRangeElements() { + throw new UnsupportedOperationException(); + } + + @Override + public void dispose() { + disposed = true; + } + + public boolean isDisposed() { + return disposed; + } + + @Override + public void rangeModified(Object rangeElement) { + throw new UnsupportedOperationException(); + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/MappedElementRule.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/MappedElementRule.java new file mode 100644 index 00000000..9ce33598 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/MappedElementRule.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules; + +import org.apache.log4j.Logger; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.objmap.IFunction; +import org.simantics.objmap.IMappingRule; +import org.simantics.objmap.MappingException; +import org.simantics.objmap.rules.domain.IDomainAccessor; +import org.simantics.objmap.rules.range.IRangeAccessor; + +/** + * A rule that synchronizes collection of elements between + * domain and range accessors. Elements are mapped from + * between domain and range during the synchronization. + * @author Hannu Niemistö + */ +public class MappedElementRule implements IMappingRule { + + static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + + IDomainAccessor domainAccessor; + IRangeAccessor rangeAccessor; + + public MappedElementRule(IDomainAccessor domainAccessor, + IRangeAccessor rangeAccessor) { + this.domainAccessor = domainAccessor; + this.rangeAccessor = rangeAccessor; + } + + @Override + public boolean updateDomain(WriteGraph g, IFunction map, + Resource domainElement, Object rangeElement) + throws MappingException { + LOGGER.info(" MappedElementRule.updateDomain"); + Object value = rangeAccessor.get(rangeElement); + Resource mappedValue = value == null ? null : map.get(value); + return domainAccessor.set(g, domainElement, mappedValue); + } + + @Override + public boolean updateRange(ReadGraph g, IFunction map, + Resource domainElement, Object rangeElement) + throws MappingException { + LOGGER.info(" MappedElementRule.updateRange"); + Resource value = domainAccessor.get(g, domainElement); + Object mappedValue = value == null ? null : map.get(value); + return rangeAccessor.set(rangeElement, mappedValue); + } +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/MappedElementsRule.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/MappedElementsRule.java new file mode 100644 index 00000000..750926d4 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/MappedElementsRule.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules; + +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.log4j.Logger; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.objmap.IFunction; +import org.simantics.objmap.IMappingRule; +import org.simantics.objmap.MappingException; +import org.simantics.objmap.rules.domain.IDomainAccessor; +import org.simantics.objmap.rules.range.IRangeAccessor; + +/** + * A rule that synchronizes collection of elements between + * domain and range accessors. Elements are mapped from + * between domain and range during the synchronization. + * @author Hannu Niemistö + */ +public class MappedElementsRule implements IMappingRule { + + static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + + IDomainAccessor> domainAccessor; + IRangeAccessor> rangeAccessor; + + public MappedElementsRule(IDomainAccessor> domainAccessor, + IRangeAccessor> rangeAccessor) { + this.domainAccessor = domainAccessor; + this.rangeAccessor = rangeAccessor; + } + + @Override + public boolean updateDomain(WriteGraph g, IFunction map, + Resource domainElement, Object rangeElement) + throws MappingException { + LOGGER.info(" MappedElementsRule.updateDomain"); + // Snapshot the accessed range value for concurrency safety. + // NOTE: still assumes that the accessed collection is concurrent or + // synchronized for toArray to be atomic. + Collection value = rangeAccessor.get(rangeElement); + Object[] rangeSnapshot = value.toArray(); + ArrayList mappedValue = new ArrayList(rangeSnapshot.length); + for (Object obj : rangeSnapshot) + mappedValue.add(map.get(obj)); + return domainAccessor.set(g, domainElement, mappedValue); + } + + @Override + public boolean updateRange(ReadGraph g, IFunction map, + Resource domainElement, Object rangeElement) + throws MappingException { + LOGGER.info(" MappedElementsRule.updateRange"); + Collection value = domainAccessor.get(g, domainElement); + ArrayList mappedValue = new ArrayList(value.size()); + for(Resource r : value) + mappedValue.add(map.get(r)); + return rangeAccessor.set(rangeElement, mappedValue); + } +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/ValueRule.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/ValueRule.java new file mode 100644 index 00000000..8135d2d0 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/ValueRule.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules; + +import org.apache.log4j.Logger; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.objmap.IFunction; +import org.simantics.objmap.IMappingRule; +import org.simantics.objmap.MappingException; +import org.simantics.objmap.rules.domain.IDomainAccessor; +import org.simantics.objmap.rules.range.IRangeAccessor; + +/** + * A rule that synchronizes values between domain and + * range accessors. + * @author Hannu Niemistö + */ +public class ValueRule implements IMappingRule { + + static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + + IDomainAccessor domainAccessor; + IRangeAccessor rangeAccessor; + + public ValueRule(IDomainAccessor domainAccessor, + IRangeAccessor rangeAccessor) { + this.domainAccessor = domainAccessor; + this.rangeAccessor = rangeAccessor; + } + + @Override + public boolean updateDomain(WriteGraph g, IFunction map, + Resource domainElement, Object rangeElement) + throws MappingException { + LOGGER.info(" ValueRule.updateDomain"); + Object value = rangeAccessor.get(rangeElement); + return domainAccessor.set(g, domainElement, value); + } + + @Override + public boolean updateRange(ReadGraph g, IFunction map, + Resource domainElement, Object rangeElement) + throws MappingException { + LOGGER.info(" ValueRule.updateRange"); + Object value = domainAccessor.get(g, domainElement); + return rangeAccessor.set(rangeElement, value); + } +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java new file mode 100644 index 00000000..913357b2 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java @@ -0,0 +1,23 @@ +package org.simantics.objmap.rules.adapters; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + +public enum IdentityAdapter implements ValueAdapter { + INSTANCE; + + @Override + public Object domainToRange(Object domainValue) { + return domainValue; + } + + @Override + public Object rangeToDomain(Object rangeValue) { + return rangeValue; + } + + @Override + public Resource rangeTypeToDomainType(ReadGraph graph, Class rangeType) { + return null; + } +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java new file mode 100644 index 00000000..85e40169 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java @@ -0,0 +1,10 @@ +package org.simantics.objmap.rules.adapters; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + +public interface ValueAdapter { + Resource rangeTypeToDomainType(ReadGraph graph, Class rangeType); + Object domainToRange(Object domainValue); + Object rangeToDomain(Object rangeValue); +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/IDomainAccessor.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/IDomainAccessor.java new file mode 100644 index 00000000..4dc94dd0 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/IDomainAccessor.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules.domain; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.objmap.MappingException; + +/** + * Provides access to some property of domain elements. + * @author Hannu Niemistö + */ +public interface IDomainAccessor { + T get(ReadGraph g, Resource element) throws MappingException; + boolean set(WriteGraph g, Resource element, T value) throws MappingException; +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/MappingUtils.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/MappingUtils.java new file mode 100644 index 00000000..927d0121 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/MappingUtils.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules.domain; + +import java.util.Arrays; +import java.util.Collection; + +import org.apache.log4j.Logger; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; + +/** + * Static utility methods for rule implementations. + * @author Hannu Niemistö + */ +public class MappingUtils { + + static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + + /** + * Adds and removes statements to/from the database so that objects + * will be exactly the objects connected to subject by predicate. + * Returns true if the method made modifications to the database. + */ + public static boolean synchronizeStatements(WriteGraph g, Resource subject, Resource predicate, Resource[] objects, + boolean deleteExtraObjects) + throws DatabaseException { + Collection currentObjects0 = g.getObjects(subject, predicate); + Resource[] currentObjects = currentObjects0.toArray(new Resource[currentObjects0.size()]); + + Arrays.sort(objects); + Arrays.sort(currentObjects); + + boolean modified = false; + int i=0, j=0; + if(currentObjects.length > 0 && objects.length > 0) + while(true) { + int cmp = currentObjects[i].compareTo(objects[j]); + if(cmp < 0) { + LOGGER.info(" remove statement"); + if(deleteExtraObjects) + g.deny(currentObjects[i]); + else + g.denyStatement(subject, predicate, currentObjects[i]); + modified = true; + ++i; + if(i >= currentObjects.length) + break; + } + else if(cmp > 0) { + LOGGER.info(" add statement"); + g.claim(subject, predicate, objects[j]); + modified = true; + ++j; + if(j >= objects.length) + break; + } + else { + ++i; ++j; + if(i >= currentObjects.length) + break; + if(j >= objects.length) + break; + } + } + while(i < currentObjects.length) { + if(deleteExtraObjects) + g.deny(currentObjects[i]); + else + g.denyStatement(subject, predicate, currentObjects[i]); + modified = true; + ++i; + } + while(j < objects.length) { + g.claim(subject, predicate, objects[j]); + modified = true; + ++j; + } + return modified; + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedObjectAccessor.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedObjectAccessor.java new file mode 100644 index 00000000..10761d6c --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedObjectAccessor.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules.domain; + +import org.apache.log4j.Logger; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.MappingException; + +/** + * Accesses a resource attached to the element by given functional relation. + * @author Hannu Niemistö + */ +public class RelatedObjectAccessor implements IDomainAccessor { + + static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + + Resource relation; + + public RelatedObjectAccessor(Resource relation) { + this.relation = relation; + } + + @Override + public Resource get(ReadGraph g, Resource element) throws MappingException { + try { + LOGGER.info(" RelatedObjectAccessor.get"); + return g.getPossibleObject(element, relation); + } catch (DatabaseException e) { + throw new MappingException(e); + } + } + + @Override + public boolean set(WriteGraph g, Resource element, Resource value) + throws MappingException { + try { + LOGGER.info(" RelatedObjectAccessor.set"); + Resource resource = g.getPossibleObject(element, relation); + if(resource == null) { + if(value == null) + return false; + g.claim(element, relation, value); + return true; + } + else if(resource.equals(value)) + return false; + else { + g.deny(element, relation); + if(value != null) + g.claim(element, relation, value); + return true; + } + } catch (DatabaseException e) { + throw new MappingException(e); + } + + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedObjectsAccessor.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedObjectsAccessor.java new file mode 100644 index 00000000..c7b6cabb --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedObjectsAccessor.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules.domain; + +import java.util.Collection; + +import org.apache.log4j.Logger; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.MappingException; + +/** + * Accesses the set of objects attached to the element by the given relation. + * @author Hannu Niemistö + */ +public class RelatedObjectsAccessor implements IDomainAccessor> { + + static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + + Resource relation; + boolean deleteExtraObjects; + + public RelatedObjectsAccessor(Resource relation, boolean deleteExtraObjects) { + super(); + this.relation = relation; + this.deleteExtraObjects = deleteExtraObjects; + } + + @Override + public Collection get(ReadGraph g, Resource element) throws MappingException { + try { + LOGGER.info(" RelatedObjectsAccessor.get"); + return g.getObjects(element, relation); + } catch (DatabaseException e) { + throw new MappingException(e); + } + } + + @Override + public boolean set(WriteGraph g, Resource element, Collection value) + throws MappingException { + try { + LOGGER.info(" RelatedObjectsAccessor.set"); + return MappingUtils.synchronizeStatements(g, element, relation, + value.toArray(new Resource[value.size()]), deleteExtraObjects); + } catch (DatabaseException e) { + throw new MappingException(e); + } + + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedOrderedSetElementsAccessor.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedOrderedSetElementsAccessor.java new file mode 100644 index 00000000..a92d2d27 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedOrderedSetElementsAccessor.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules.domain; + +import java.util.Collection; + +import org.apache.log4j.Logger; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.MappingException; + +/** + * Accesses the set of objects attached to the element by the given relation. + * @author Hannu Niemistö + */ +public class RelatedOrderedSetElementsAccessor implements IDomainAccessor> { + + static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + + boolean deleteExtraObjects; + + public RelatedOrderedSetElementsAccessor(boolean deleteExtraObjects) { + super(); + this.deleteExtraObjects = deleteExtraObjects; + } + + @Override + public Collection get(ReadGraph g, Resource element) throws MappingException { + try { + LOGGER.info(" RelatedOrderedSetElementsAccessor.get"); + return OrderedSetUtils.toList(g, element); + } catch (DatabaseException e) { + throw new MappingException(e); + } + } + + @Override + public boolean set(WriteGraph g, Resource element, Collection value) + throws MappingException { + try { + LOGGER.info(" RelatedOrderedSetElementsAccessor.set"); + return OrderedSetUtils.set(g, element, value); + // FIXME Implement deleteExtraObjects + } catch (DatabaseException e) { + throw new MappingException(e); + } + + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedValueAccessor.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedValueAccessor.java new file mode 100644 index 00000000..4cf7ecde --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/domain/RelatedValueAccessor.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules.domain; + +import org.apache.log4j.Logger; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.objmap.MappingException; + +/** + * Accesses a value attached to the element by given functional relation. + * @author Hannu Niemist� + */ +public class RelatedValueAccessor implements IDomainAccessor { + + static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + + Resource relation; + Resource valueType; + + public RelatedValueAccessor(Resource relation, Resource valueType) { + this.relation = relation; + this.valueType = valueType; + } + + @Override + public Object get(ReadGraph g, Resource element) throws MappingException { + try { + LOGGER.info(" RelatedValueAccessor.get"); + Resource valueResource = g.getPossibleObject(element, relation); + if(valueResource == null) + return null; + return g.getValue(valueResource); + } catch (DatabaseException e) { + throw new MappingException(e); + } + } + + @Override + public boolean set(WriteGraph g, Resource element, Object value) + throws MappingException { + try { + LOGGER.info(" RelatedValueAccessor.set"); + Resource valueResource = g.getPossibleObject(element, relation); + if(valueResource == null) { + if(value == null) + return false; + valueResource = g.newResource(); + g.claim(valueResource, Layer0.getInstance(g).InstanceOf, null, + valueType); + g.claim(element, relation, valueResource); + g.claimValue(valueResource, value); + return true; + } + else { + if(value == null) { + g.deny(valueResource); + return true; + } + Object currentValue = g.getValue(valueResource); + if(currentValue.equals(value)) + return false; + g.claimValue(valueResource, value); + return true; + } + } catch (DatabaseException e) { + throw new MappingException(e); + } + + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/factory/IClassRuleFactory.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/factory/IClassRuleFactory.java new file mode 100644 index 00000000..b9b69065 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/factory/IClassRuleFactory.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules.factory; + +import java.lang.annotation.Annotation; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.IMappingRule; + +public interface IClassRuleFactory { + IMappingRule create(ReadGraph g, Annotation annotation, Class clazz) throws DatabaseException; +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/factory/IFieldRuleFactory.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/factory/IFieldRuleFactory.java new file mode 100644 index 00000000..02688e02 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/factory/IFieldRuleFactory.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules.factory; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.IMappingRule; + +public interface IFieldRuleFactory { + IMappingRule create(ReadGraph g, Annotation annotation, Field field) throws DatabaseException; +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/factory/IMethodRuleFactory.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/factory/IMethodRuleFactory.java new file mode 100644 index 00000000..32bb98b7 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/factory/IMethodRuleFactory.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules.factory; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.IMappingRule; + +public interface IMethodRuleFactory { + IMappingRule create(ReadGraph g, Annotation annotation, Method method) throws DatabaseException; +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/range/AdaptedRangeAccessor.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/range/AdaptedRangeAccessor.java new file mode 100644 index 00000000..a6df00b0 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/range/AdaptedRangeAccessor.java @@ -0,0 +1,25 @@ +package org.simantics.objmap.rules.range; + +import org.simantics.objmap.MappingException; +import org.simantics.objmap.rules.adapters.ValueAdapter; + +public class AdaptedRangeAccessor implements IRangeAccessor { + IRangeAccessor baseAccessor; + ValueAdapter adapter; + + public AdaptedRangeAccessor(IRangeAccessor baseAccessror, + ValueAdapter adapter) { + this.baseAccessor = baseAccessror; + this.adapter = adapter; + } + + @Override + public Object get(Object element) throws MappingException { + return adapter.rangeToDomain(baseAccessor.get(element)); + } + + @Override + public boolean set(Object element, Object value) throws MappingException { + return baseAccessor.set(element, adapter.domainToRange(value)); + } +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/range/FieldAccessor.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/range/FieldAccessor.java new file mode 100644 index 00000000..53d0d875 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/range/FieldAccessor.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules.range; + +import java.lang.reflect.Field; + +import org.apache.log4j.Logger; +import org.simantics.objmap.MappingException; + +/** + * Accesses the given field of the element. + * @author Hannu Niemistö + */ +public class FieldAccessor implements IRangeAccessor { + + static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + + Field field; + + public FieldAccessor(Field field) { + this.field = field; + } + + @Override + public T get(Object element) throws MappingException { + try { + T result = (T)field.get(element); + + if(LOGGER.isInfoEnabled()) + LOGGER.info(" FieldAccessor.get " + + field.getName() + " -> " + result + ); + + return result; + } catch (IllegalArgumentException e) { + throw new MappingException(e); + } catch (IllegalAccessException e) { + throw new MappingException(e); + } + } + + @Override + public boolean set(Object element, T value) throws MappingException { + try { + Object currentValue = field.get(element); + + if(LOGGER.isInfoEnabled()) + LOGGER.info(" FieldAccessor.set " + + field.getName() + " " + currentValue + + " -> " + value + ); + + if(value == null + ? (currentValue == null || field.getType().isPrimitive()) + : value.equals(currentValue)) + return false; + field.set(element, value); + return true; + } catch (IllegalArgumentException e) { + throw new MappingException(e); + } catch (IllegalAccessException e) { + throw new MappingException(e); + } + } +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/range/FieldAccessorWithDefault.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/range/FieldAccessorWithDefault.java new file mode 100644 index 00000000..688de95c --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/range/FieldAccessorWithDefault.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules.range; + +import java.lang.reflect.Field; + +import org.simantics.objmap.MappingException; + +/** + * Accesses the given field of the element. + * @author Hannu Niemist� + */ +public class FieldAccessorWithDefault extends FieldAccessor { + + T defaultValue; + + public FieldAccessorWithDefault(Field field, T defaultValue) { + super(field); + this.defaultValue = defaultValue; + } + + @Override + public T get(Object element) throws MappingException { + T value = super.get(element); + if(value == null) + return defaultValue; + else + return value; + } +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/rules/range/IRangeAccessor.java b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/range/IRangeAccessor.java new file mode 100644 index 00000000..01625a1c --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/rules/range/IRangeAccessor.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.rules.range; + +import org.simantics.objmap.MappingException; + +/** + * Provides access to some property of range elements. + * @author Hannu Niemistö + */ +public interface IRangeAccessor { + T get(Object element) throws MappingException; + boolean set(Object element, T value) throws MappingException; +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/schema/MappingSchemas.java b/stable/org.simantics.objmap/src/org/simantics/objmap/schema/MappingSchemas.java new file mode 100644 index 00000000..09984fe6 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/schema/MappingSchemas.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.schema; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.IMappingRule; +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.objmap.annotations.meta.HasClassRuleFactory; +import org.simantics.objmap.annotations.meta.HasFieldRuleFactory; +import org.simantics.objmap.annotations.meta.HasMethodRuleFactory; + +/** + * Static utility methods for mapping schemas + * @author Hannu Niemistö + */ +public class MappingSchemas { + + /** + * Creates a new SimpleLinkType based on the annotations in the given class. + * @throws IllegalAccessException + * @throws InstantiationException + * @see GraphType + * @see RelatedValue + */ + public static SimpleLinkType fromAnnotations(ReadGraph g, Class clazz) throws DatabaseException, InstantiationException, IllegalAccessException { + GraphType graphType = clazz.getAnnotation(GraphType.class); + + ArrayList rules = new ArrayList(); + collectRulesFromAnnotations(g, clazz, rules); + + return new SimpleLinkType( + g.getResource(graphType.value()), + clazz, rules); + } + + public static void collectRulesFromAnnotations(ReadGraph g, Class clazz, Collection rules) throws DatabaseException, InstantiationException, IllegalAccessException { + Class superclass = clazz.getSuperclass(); + if(superclass != null) + collectRulesFromAnnotations(g, superclass, rules); + + for(Annotation annotation : clazz.getAnnotations()) { + HasClassRuleFactory factory = + annotation.annotationType().getAnnotation(HasClassRuleFactory.class); + if(factory != null) { + rules.add(factory.value().newInstance() + .create(g, annotation, clazz)); + } + } + + for(Field f : clazz.getDeclaredFields()) { + f.setAccessible(true); + + for(Annotation annotation : f.getAnnotations()) { + HasFieldRuleFactory factory = + annotation.annotationType().getAnnotation(HasFieldRuleFactory.class); + if(factory != null) { + rules.add(factory.value().newInstance() + .create(g, annotation, f)); + } + } + } + + for(Method m : clazz.getDeclaredMethods()) { + m.setAccessible(true); + + for(Annotation annotation : m.getAnnotations()) { + HasMethodRuleFactory factory = + annotation.annotationType().getAnnotation(HasMethodRuleFactory.class); + if(factory != null) { + rules.add(factory.value().newInstance() + .create(g, annotation, m)); + } + } + } + } + +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/schema/SimpleLinkType.java b/stable/org.simantics.objmap/src/org/simantics/objmap/schema/SimpleLinkType.java new file mode 100644 index 00000000..1b9a0354 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/schema/SimpleLinkType.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.schema; + +import java.util.ArrayList; + +import org.apache.log4j.Logger; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.objmap.IFunction; +import org.simantics.objmap.ILinkType; +import org.simantics.objmap.IMappingRule; +import org.simantics.objmap.MappingException; + +/** + * A link type that is associated with single domain and range type (class). + * SimpleLinkType is composed of simpler rules whose combination determines + * its update policy. + * @author Hannu Niemist� + */ +public class SimpleLinkType implements ILinkType { + + static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + + Resource domainType; + Class rangeType; + ArrayList rules; + + public SimpleLinkType(Resource domainType, Class rangeType, + ArrayList rules) { + this.domainType = domainType; + this.rangeType = rangeType; + this.rules = rules; + } + + public SimpleLinkType(Resource domainType, Class rangeType) { + this(domainType, rangeType, new ArrayList()); + } + + /** + * Adds a new rule to this link type that is enforced + * during updates. + */ + public void addRule(IMappingRule rule) { + rules.add(rule); + } + + @Override + public Resource createDomainElement(WriteGraph g, Object rangeElement) + throws MappingException { + try { + if(LOGGER.isInfoEnabled()) + LOGGER.info("SimpleLinkType.createDomainElement " + + rangeElement.toString() + ); + Resource result = g.newResource(); + g.claim(result, Layer0.getInstance(g).InstanceOf, null, domainType); + return result; + } catch(DatabaseException e) { + throw new MappingException(e); + } + } + @Override + public Object createRangeElement(ReadGraph g, Resource domainElement) + throws MappingException { + try { + if(LOGGER.isInfoEnabled()) + try { + LOGGER.info("SimpleLinkType.createRangeElement " + + NameUtils.getSafeName(g, domainElement) + ); + } catch(DatabaseException e) { + throw new MappingException(e); + } + return rangeType.newInstance(); + } catch (InstantiationException e) { + throw new MappingException(e); + } catch (IllegalAccessException e) { + throw new MappingException(e); + } + } + @Override + public boolean updateDomain(WriteGraph g, IFunction map, + Resource domainElement, Object rangeElement) + throws MappingException { + if(LOGGER.isInfoEnabled()) + try { + LOGGER.info("SimpleLinkType.updateDomain " + + NameUtils.getSafeName(g, domainElement) + " " + + rangeElement.toString() + ); + } catch(DatabaseException e) { + throw new MappingException(e); + } + + boolean updated = false; + for(IMappingRule rule : rules) + updated |= rule.updateDomain(g, map, domainElement, rangeElement); + return updated; + } + @Override + public boolean updateRange(ReadGraph g, IFunction map, + Resource domainElement, Object rangeElement) + throws MappingException { + if(LOGGER.isInfoEnabled()) + try { + LOGGER.info("SimpleLinkType.updateRange " + + NameUtils.getSafeName(g, domainElement) + " " + + rangeElement.toString() + ); + } catch(DatabaseException e) { + throw new MappingException(e); + } + + boolean updated = false; + for(IMappingRule rule : rules) + updated |= rule.updateRange(g, map, domainElement, rangeElement); + return updated; + } +} diff --git a/stable/org.simantics.objmap/src/org/simantics/objmap/schema/SimpleSchema.java b/stable/org.simantics.objmap/src/org/simantics/objmap/schema/SimpleSchema.java new file mode 100644 index 00000000..5c15c009 --- /dev/null +++ b/stable/org.simantics.objmap/src/org/simantics/objmap/schema/SimpleSchema.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.schema; + +import gnu.trove.THashMap; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.ILinkType; +import org.simantics.objmap.IMappingSchema; +import org.simantics.objmap.MappingException; + +/** + * An implementation of IMappingSchema that contains + * only SimpleLinkTypes. The link type of any domain + * element is based solely on its type in database and + * the link type of any range element is based on its class. + * @author Hannu Niemistö + */ +public class SimpleSchema implements IMappingSchema { + + THashMap domainLinkTypes = + new THashMap(); + THashMap, SimpleLinkType> rangeLinkTypes = + new THashMap, SimpleLinkType>(); + + public void addLinkType(SimpleLinkType linkType) { + domainLinkTypes.put(linkType.domainType, linkType); + rangeLinkTypes.put(linkType.rangeType, linkType); + } + + @Override + public ILinkType linkTypeOfDomainElement(ReadGraph g, Resource element) throws MappingException { + try { + + for(Resource type : g.getTypes(element)) { + + ILinkType linkType = domainLinkTypes.get(type); + if(linkType != null) return linkType; + + } + + throw new MappingException("Didn't find a link type for " + + NameUtils.getSafeName(g, element) + "."); + + } catch (DatabaseException e) { + throw new MappingException(e); + } + } + + @Override + public ILinkType linkTypeOfRangeElement(Object element) throws MappingException { + ILinkType type = rangeLinkTypes.get(element.getClass()); + if(type == null) + throw new MappingException("Didn't find a link type for " + element + "."); + return type; + } + +} diff --git a/stable/org.simantics.sysdyn.feature/.project b/stable/org.simantics.sysdyn.feature/.project new file mode 100644 index 00000000..60643f3e --- /dev/null +++ b/stable/org.simantics.sysdyn.feature/.project @@ -0,0 +1,17 @@ + + + org.simantics.sysdyn.feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/stable/org.simantics.sysdyn.feature/build.properties b/stable/org.simantics.sysdyn.feature/build.properties new file mode 100644 index 00000000..9e94676a --- /dev/null +++ b/stable/org.simantics.sysdyn.feature/build.properties @@ -0,0 +1,13 @@ +############################################################################### +# Copyright (c) 2010 Association for Decentralized Information Management in +# Industry THTH ry. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# VTT Technical Research Centre of Finland - initial API and implementation +############################################################################### +bin.includes = feature.xml +root=rootfiles/ \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.feature/feature.xml b/stable/org.simantics.sysdyn.feature/feature.xml new file mode 100644 index 00000000..38362c28 --- /dev/null +++ b/stable/org.simantics.sysdyn.feature/feature.xml @@ -0,0 +1,123 @@ + + + + + + [Enter Feature Description here.] + + + + [Enter Copyright Description here.] + + + + [Enter License Description here.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/stable/org.simantics.sysdyn.feature/rootfiles/puzzle_green.ico b/stable/org.simantics.sysdyn.feature/rootfiles/puzzle_green.ico new file mode 100644 index 00000000..61e3f866 Binary files /dev/null and b/stable/org.simantics.sysdyn.feature/rootfiles/puzzle_green.ico differ diff --git a/stable/org.simantics.sysdyn.ontology/.classpath b/stable/org.simantics.sysdyn.ontology/.classpath new file mode 100644 index 00000000..8a8f1668 --- /dev/null +++ b/stable/org.simantics.sysdyn.ontology/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/stable/org.simantics.sysdyn.ontology/.project b/stable/org.simantics.sysdyn.ontology/.project new file mode 100644 index 00000000..b975ea97 --- /dev/null +++ b/stable/org.simantics.sysdyn.ontology/.project @@ -0,0 +1,34 @@ + + + org.simantics.sysdyn.ontology + + + + + + org.simantics.graph.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.simantics.graph.nature + + diff --git a/stable/org.simantics.sysdyn.ontology/.settings/org.eclipse.jdt.core.prefs b/stable/org.simantics.sysdyn.ontology/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..888b17ed --- /dev/null +++ b/stable/org.simantics.sysdyn.ontology/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Thu Jul 22 15:15:41 EEST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/stable/org.simantics.sysdyn.ontology/META-INF/MANIFEST.MF b/stable/org.simantics.sysdyn.ontology/META-INF/MANIFEST.MF new file mode 100644 index 00000000..86466a56 --- /dev/null +++ b/stable/org.simantics.sysdyn.ontology/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: http://www.simantics.org/Sysdyn +Bundle-SymbolicName: org.simantics.sysdyn.ontology +Bundle-Version: 1.1.0.qualifier +Require-Bundle: org.simantics.layer0, + org.simantics.diagram.ontology;bundle-version="1.0.0", + org.simantics.structural.ontology;bundle-version="1.0.0", + org.simantics.modeling.ontology;bundle-version="1.0.0", + org.simantics.g2d.ontology;bundle-version="1.0.0", + org.simantics.project.ontology;bundle-version="1.0.0", + org.simantics.viewpoint.ontology;bundle-version="1.0.0", + org.simantics.layer0x.ontology;bundle-version="1.0.0", + org.simantics.issues.ontology;bundle-version="1.1.0", + org.simantics.jfreechart.ontology;bundle-version="0.1.0", + org.simantics.action.ontology;bundle-version="1.0.0", + org.simantics.image2.ontology;bundle-version="1.1.0", + org.simantics.color.ontology;bundle-version="1.0.0", + org.simantics.simulation.ontology;bundle-version="1.0.0", + org.simantics.silk.ontology;bundle-version="1.0.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Export-Package: org.simantics.sysdyn +Bundle-Vendor: VTT Technical Reserarch Centre of Finland diff --git a/stable/org.simantics.sysdyn.ontology/build.properties b/stable/org.simantics.sysdyn.ontology/build.properties new file mode 100644 index 00000000..098c3fd7 --- /dev/null +++ b/stable/org.simantics.sysdyn.ontology/build.properties @@ -0,0 +1,18 @@ +############################################################################### +# Copyright (c) 2010 Association for Decentralized Information Management in +# Industry THTH ry. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# VTT Technical Research Centre of Finland - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + graphs/*.tg,\ + graph.tg +src.includes = graph/ diff --git a/stable/org.simantics.sysdyn.ontology/graph.tg b/stable/org.simantics.sysdyn.ontology/graph.tg new file mode 100644 index 00000000..2e39e029 Binary files /dev/null and b/stable/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/stable/org.simantics.sysdyn.ontology/graph/ChartViewpoints.pgraph b/stable/org.simantics.sysdyn.ontology/graph/ChartViewpoints.pgraph new file mode 100644 index 00000000..44b844d0 --- /dev/null +++ b/stable/org.simantics.sysdyn.ontology/graph/ChartViewpoints.pgraph @@ -0,0 +1,117 @@ +L0 = +VP = +PROJECT = +MOD = +IMAGE = +COLOR = +ACT = +JFREE = +SYSDYN = + +/////////////////////////////////////////////// +// XY Line axis: axis and variables viewpoint +/////////////////////////////////////////////// +CBC = SYSDYN.ChartAxisAndVariablesBrowseContext : VP.BrowseContext +CAC = SYSDYN.ChartAxisAndVariablesActionContext : VP.BrowseContext + +CBC.AxisChildRule : VP.ChildRule +CBC.VariableChildRule : VP.ChildRule +CBC.SeriesLabelRule : VP.LabelRule +CBC.AxisLabelRule : VP.LabelRule +CBC.SeriesLabelDecorationRule : VP.LabelDecorationRule + +CBC + @VP.customChildRule JFREE.Chart CBC.AxisChildRule + JFREE.Axis : VP.ResourceNodeType + @VP.customChildRule JFREE.Axis CBC.VariableChildRule + JFREE.Series : VP.ResourceNodeType + +CBC + @VP.customLabelRule JFREE.Axis CBC.AxisLabelRule + @VP.customLabelRule JFREE.Series CBC.SeriesLabelRule + +CBC + @VP.customLabelDecorationRule JFREE.Series CBC.SeriesLabelDecorationRule + +CBC + @VP.dropActionContribution JFREE.Axis CAC.Actions.SeriesDropAction 1.0 + @VP.dropActionContribution JFREE.Series CAC.Actions.SeriesDropAction 1.0 + @VP.dropActionContribution JFREE.Axis CAC.Actions.AxisDropAction 2.0 + @VP.dropActionContribution JFREE.Series CAC.Actions.AxisDropAction 2.0 + +CBC + VP.BrowseContext.HasVisualsContribution _ : VP.VisualsContribution + VP.VisualsContribution.HasNodeType JFREE.Chart + VP.VisualsContribution.HasRule VP.PassThruSorterRule + VP.BrowseContext.HasVisualsContribution _ : VP.VisualsContribution + VP.VisualsContribution.HasNodeType JFREE.Axis + VP.VisualsContribution.HasRule VP.PassThruSorterRule + + +CAC.Actions : L0.Library +CAC.Actions.SeriesDropAction : ACT.DropAction +CAC.Actions.AxisDropAction : ACT.DropAction + + +/////////////////////////////////////////////// +// Bar chart: Variables viewpoint +/////////////////////////////////////////////// +BSBC = SYSDYN.BarSeriesBrowseContext : VP.BrowseContext +BSAC = SYSDYN.BarSeriesActionContext : VP.BrowseContext + +BSBC.SeriesChildRule : VP.ChildRule +BSBC.SeriesLabelRule : VP.LabelRule +BSBC.SeriesLabelDecorationRule : VP.LabelDecorationRule + +BSBC + @VP.customChildRule JFREE.Chart BSBC.SeriesChildRule + JFREE.Series + +BSBC + @VP.customLabelRule JFREE.Series BSBC.SeriesLabelRule + +BSBC + @VP.customLabelDecorationRule JFREE.Series BSBC.SeriesLabelDecorationRule + +//BSBC +// @VP.dropActionContribution JFREE.Series BSAC.Actions.SeriesDropAction 1.0 + +BSBC + VP.BrowseContext.HasVisualsContribution _ : VP.VisualsContribution + VP.VisualsContribution.HasNodeType JFREE.Chart + VP.VisualsContribution.HasRule VP.PassThruSorterRule + +BSAC.Actions : L0.Library +//BSAC.Actions.SeriesDropAction : ACT.DropAction + + +/////////////////////////////////////////////// +// Pie chart: Variables viewpoint +/////////////////////////////////////////////// +PSBC = SYSDYN.PieSeriesBrowseContext : VP.BrowseContext +PSAC = SYSDYN.PieSeriesActionContext : VP.BrowseContext + +PSBC.SeriesChildRule : VP.ChildRule +PSBC.SeriesLabelRule : VP.LabelRule +PSBC.SeriesLabelDecorationRule : VP.LabelDecorationRule + +PSBC + @VP.customChildRule JFREE.Chart PSBC.SeriesChildRule + JFREE.Series + +PSBC + @VP.customLabelRule JFREE.Series PSBC.SeriesLabelRule + +PSBC + @VP.customLabelDecorationRule JFREE.Series PSBC.SeriesLabelDecorationRule + +//PSBC +// @VP.dropActionContribution JFREE.Series PSAC.Actions.SeriesDropAction 1.0 + +PSBC + VP.BrowseContext.HasVisualsContribution _ : VP.VisualsContribution + VP.VisualsContribution.HasNodeType JFREE.Chart + VP.VisualsContribution.HasRule VP.PassThruSorterRule + +PSAC.Actions : L0.Library +//PSAC.Actions.SeriesDropAction : ACT.DropAction diff --git a/stable/org.simantics.sysdyn.ontology/graph/GeneralSymbols.pgraph b/stable/org.simantics.sysdyn.ontology/graph/GeneralSymbols.pgraph new file mode 100644 index 00000000..2c700f19 --- /dev/null +++ b/stable/org.simantics.sysdyn.ontology/graph/GeneralSymbols.pgraph @@ -0,0 +1,14 @@ +L0 = +G2D = +DIA = +SYSDYN = + +GENERAL = SYSDYN.SymbolReferences.GeneralSymbols : DIA.SymbolReferenceLibrary + L0.HasDescription "General graphical components" + +SYSDYN.AdditionalSymbols : L0.Library + +SYSDYN.AdditionalSymbols.Text """ : L0.String diff --git a/stable/org.simantics.sysdyn.ontology/graph/Profiles.pgraph b/stable/org.simantics.sysdyn.ontology/graph/Profiles.pgraph new file mode 100644 index 00000000..45a75dfc --- /dev/null +++ b/stable/org.simantics.sysdyn.ontology/graph/Profiles.pgraph @@ -0,0 +1,41 @@ +L0 = +L0X = +DIA = +SYSDYN = + +PROFILES = SYSDYN.Profiles : L0.Library + + +// TEMPLATE +groupStyleEntry : L0.Template + @template %subject %style %group + %subject : DIA.GroupStyleProfileEntry + DIA.ProfileEntry.HasStyle %style + DIA.ProfileEntry.HasGroup %group + + +// PROFILES +SYSDYN.SimulationPlaybackProfile +L0X = +G2D = +STR = +DIA = +SIMU = +MOD = +PROJ = +JFREE = + +//##################################################################### +// Defines ontology and attaches it to SimanticsDomain +//##################################################################### + +SYSDYN = : L0.Ontology + @L0.new + L0.HasResourceClass "org.simantics.sysdyn.SysdynResource" + +SYSDYN.ImportedOntologies : PROJ.NamespaceRequirement + L0.HasDescription "Specifies the ontologies required by a Sysdyn project." + PROJ.RequiresNamespace + "http://www.simantics.org/Sysdyn-1.1" : L0.URI + "http://www.simantics.org/Layer0-1.0" : L0.URI + +SYSDYN.SharedFunctionOntology -- SYSDYN.DelayExpression.expression --> L0.String -- SYSDYN.DelayExpression.order --> L0.Integer -- SYSDYN.DelayExpression.delayTime --> L0.String -- SYSDYN.DelayExpression.initialValue --> L0.String +SYSDYN = + +FL = : SYSDYN.SysdynModelicaFunctionLibrary + + +FL.xidz : SYSDYN.SysdynModelicaFunction + L0.HasDescription "X if divided by zero" + SYSDYN.HasModelicaFunctionCode """ input Real a; + input Real b; + input Real x; + output Real z; +algorithm + if b > 0.0 or b < 0.0 then + z := a / b; + else + z := x; + end if;""" + +FL.zidz : SYSDYN.SysdynModelicaFunction + L0.HasDescription "Zero if divided by zero" + SYSDYN.HasModelicaFunctionCode """ input Real a; + input Real b; + output Real z; +algorithm + z := xidz(a,b,0.0);""" + +FL.interpolate : SYSDYN.SysdynModelicaFunction + L0.HasDescription "Interpolate function for two-dimensional table" + SYSDYN.HasModelicaFunctionCode """ input Real u "input value (first column of table)"; + input Real table[:, :] "table to be interpolated"; + output Real y "interpolated input value (icol column of table)"; +algorithm + y := interpolateFull(u, table, 2);""" + + +FL.interpolateFull : SYSDYN.SysdynModelicaFunction + L0.HasDescription "The full interpolate function" + SYSDYN.HasModelicaFunctionCode """ input Real u "input value (first column of table)"; + input Real table[:, :] "table to be interpolated"; + input Integer icol "column of table to be interpolated"; + output Real y "interpolated input value (icol column of table)"; +protected + Integer i; + Integer n "number of rows of table"; + Real u1; + Real u2; + Real y1; + Real y2; +algorithm + n := size(table, 1); + if n <= 1 then + y := table[1, icol]; + else + /* Search interval */ + if u <= table[1, 1] then + i := 1; + else + i := 2; + while i < n and u > table[i, 1] loop + i := i + 1; + end while; + i := i - 1; + end if; + + /* Get interpolation data */ + u1 := table[i, 1]; + u2 := table[i + 1, 1]; + y1 := table[i, icol]; + y2 := table[i + 1, icol]; + /* Interpolate */ + if u1 >= u2 then + y := y1; + /* since not possible to throw error */ + else + y := y1 + (y2 - y1)*(u - u1)/(u2 - u1); + end if; + end if;""" \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ontology/graph/Sysdyn_ModelBrowser_Viewpoint.pgraph b/stable/org.simantics.sysdyn.ontology/graph/Sysdyn_ModelBrowser_Viewpoint.pgraph new file mode 100644 index 00000000..a5129dc0 --- /dev/null +++ b/stable/org.simantics.sysdyn.ontology/graph/Sysdyn_ModelBrowser_Viewpoint.pgraph @@ -0,0 +1,108 @@ +L0 = +VP = +SIMU = +PROJECT = +IMAGE = +ACT = +MOD = +STR = +SYSDYN = +SILK = + +SBC = SYSDYN.ProjectBrowseContext : VP.BrowseContext +SAC = SYSDYN.ProjectActionContext : VP.BrowseContext + +MBC = MOD.ModelingBrowseContext : VP.BrowseContext + VP.BrowseContext.IsIncludedIn PROJECT.ProjectBrowseContext +MAC = MOD.ModelingActionContext : VP.BrowseContext + VP.BrowseContext.IsIncludedIn PROJECT.ProjectActionContext + +BuiltinFunctions = +SBC.BuiltinFunctions : VP.ResourceNodeType +SBC.ModuleTypeChildRule : VP.ChildRule +SBC.ModuleContentChildRule : VP.ChildRule +SBC.ModuleTypeLabelRule : VP.LabelRule + +MBC + // Function libraries + // Functions folder + @VP.relationChildRuleWithFolder MOD.StructuralModel L0.ConsistsOf SYSDYN.SysdynModelicaFunction + SBC.FunctionsFolder : VP.ResourceNodeType + @VP.relationChildRule SBC.FunctionsFolder L0.ConsistsOf SYSDYN.SysdynModelicaFunctionLibrary + // Function libraries + @VP.relationChildRule SYSDYN.SysdynModelicaFunctionLibrary L0.ConsistsOf SYSDYN.SysdynModelicaFunctionLibrary + @VP.relationChildRule SYSDYN.SysdynModelicaFunctionLibrary L0.ConsistsOf SYSDYN.SysdynModelicaFunction + // Built-in functions + VP.BrowseContext.HasChildContribution _ : VP.ChildContribution + VP.ChildContribution.HasParentNodeType SBC.FunctionsFolder + VP.ChildContribution.HasChildNodeType SBC.BuiltinFunctions + VP.ChildContribution.HasRule _ : VP.ConstantChildRule + VP.ConstantChildRule.HasChild BuiltinFunctions + @VP.relationChildRule SBC.BuiltinFunctions L0.ConsistsOf SYSDYN.SysdynModelicaFunctionLibrary + @VP.relationChildRule SBC.BuiltinFunctions L0.ConsistsOf SYSDYN.SysdynModelicaFunction + // Shared functions linked to a model + @VP.relationChildRuleWithFolder SBC.FunctionsFolder L0.IsLinkedTo SYSDYN.SharedFunctionOntology + SBC.SharedFunctionsFolder : VP.ResourceNodeType + + + //Modules + @VP.equalContentChildRule MOD.StructuralModel + SBC.ModulesFolder : VP.ResourceNodeType + @VP.customChildRule SBC.ModulesFolder SBC.ModuleTypeChildRule + SBC.ModuleSymbol : VP.ResourceNodeType + @VP.customChildRule SBC.ModuleSymbol SBC.ModuleContentChildRule STR.Component + + +// Labels +MBC + @VP.constantLabelRule SBC.FunctionsFolder "Functions" + @VP.constantLabelRule SBC.SharedFunctionsFolder "Shared Functions" + @VP.constantLabelRule SBC.ModulesFolder "Modules" + @VP.customLabelRule SBC.BuiltinFunctions VP.ResourceNameLabelRule + @VP.customLabelRule SBC.ModuleSymbol SBC.ModuleTypeLabelRule + + +// Images +MBC + @VP.constantImageRule SBC.FunctionsFolder SILK.folder + @VP.constantImageRule SBC.SharedFunctionsFolder SILK.folder + @VP.constantImageRule SYSDYN.SysdynModelicaFunction SILK.brick + @VP.constantImageRule SBC.ModulesFolder SILK.folder + @VP.constantImageRule SBC.ModuleSymbol SILK.bricks + @VP.constantImageRule SBC.BuiltinFunctions SILK.folder + +// Modifiers +MBC + @VP.customLabelRule SYSDYN.SysdynModelicaFunction VP.ResourceNameModifierRule + + +// Actions +ACTIONS = SAC.Actions : L0.Library + +// NEW -Actions +ACTIONS.NewModuleType : ACT.Action +ACTIONS.NewEnumeration : ACT.Action +ACTIONS.NewFunction : ACT.Action +ACTIONS.NewFunctionLibrary : ACT.Action +ACTIONS.NewSharedFunctionLibrary : ACT.Action +ACTIONS.OpenWorkbook : ACT.Action + + +MAC + @VP.actionContribution "Module" SBC.ModulesFolder SILK.bricks VP.NewActionCategory ACTIONS.NewModuleType + VP.BrowseContext.HasActionContribution _ : VP.ActionContribution + L0.HasLabel "Open Workbook" + VP.ActionContribution.HasImage SILK.brick + VP.ActionContribution.HasNodeType MBC.Configuration + VP.ActionContribution.HasAction ACTIONS.OpenWorkbook + + @VP.actionContribution "Enumeration" MBC.Configuration SILK.brick VP.NewActionCategory ACTIONS.NewEnumeration + //@VP.actionContribution "Open Workbook" MBC.Configuration SILK.brick VP.NewActionCategory ACTIONS.OpenWorkbook + @VP.actionContribution "Enumeration" SBC.ModuleSymbol SILK.brick VP.NewActionCategory ACTIONS.NewEnumeration + @VP.actionContribution "Function" SBC.FunctionsFolder SILK.brick VP.NewActionCategory ACTIONS.NewFunction + @VP.actionContribution "Function" SYSDYN.SysdynModelicaFunctionLibrary SILK.brick VP.NewActionCategory ACTIONS.NewFunction + @VP.actionContribution "Function" SYSDYN.SharedFunctionOntology SILK.brick VP.NewActionCategory ACTIONS.NewFunction + @VP.actionContribution "Function Library" SBC.FunctionsFolder SILK.folder VP.NewActionCategory ACTIONS.NewFunctionLibrary + @VP.actionContribution "Function Library" SYSDYN.SysdynModelicaFunctionLibrary SILK.folder VP.NewActionCategory ACTIONS.NewFunctionLibrary + @VP.actionContribution "Function Library" SYSDYN.SharedFunctionOntology SILK.folder VP.NewActionCategory ACTIONS.NewFunctionLibrary + @VP.actionContribution "Shared Function Library" SBC.SharedFunctionsFolder SILK.folder VP.NewActionCategory ACTIONS.NewSharedFunctionLibrary \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ontology/graph/Validation.pgraph b/stable/org.simantics.sysdyn.ontology/graph/Validation.pgraph new file mode 100644 index 00000000..2b3d9476 --- /dev/null +++ b/stable/org.simantics.sysdyn.ontology/graph/Validation.pgraph @@ -0,0 +1,109 @@ +L0 = +L0X = +ISSUE = +SYSDYN = + +VALIDATIONS = SYSDYN.Validations : L0.Library + +SYSDYN.SysdynIssue +SYSDYN = + +VF = : SYSDYN.SysdynModelicaFunctionLibrary + +/* +VF.DELAYFIXED : SYSDYN.SysdynModelicaFunction + L0.HasDescription """DELAY FIXED( inputVar , dtime , init ) + -> delay(inputVar, dtime) + init -value is ignored.""" + SYSDYN.HasModelicaFunctionCode """ input Real inputVar; + input Real dtime; + input Real init; + input Real t = time; + output Real z; +protected + parameter Real parameterDTime = dtime; +algorithm + z := if time < parameterDTime then init else delay(inputVar, parameterDTime);""" +*/ + +VF.IFTHENELSE : SYSDYN.SysdynModelicaFunction + L0.HasDescription """IF THEN ELSE( cond , ontrue , onfalse ) + -> if cond then ontrue else onfalse""" + SYSDYN.HasModelicaFunctionCode """ input Boolean cond; + input Real ontrue; + input Real onfalse; + output Real z; +algorithm + z := if cond then ontrue else onfalse;""" + +VF.MAX : SYSDYN.SysdynModelicaFunction + L0.HasDescription """MAX(a, b) + Returns the larger of a and b.""" + SYSDYN.HasModelicaFunctionCode """ input Real a; + input Real b; + output Real z; +algorithm + z := if a > b then a else b;""" + +VF.MIN : SYSDYN.SysdynModelicaFunction + L0.HasDescription """MIN(a, b) + Returns the smaller of a and b.""" + SYSDYN.HasModelicaFunctionCode """ input Real a; + input Real b; + output Real z; +algorithm + z := if a < b then a else b;""" + +VF.XIDZ : SYSDYN.SysdynModelicaFunction + L0.HasDescription """XIDZ(a, b, x) + x if divided by zero, a/b otherwise.""" + SYSDYN.HasModelicaFunctionCode """ input Real a; + input Real b; + input Real x; + output Real z; +algorithm + z := xidz(a, b, x);""" + +VF.ZIDZ : SYSDYN.SysdynModelicaFunction + L0.HasDescription """XIDZ(a, b) + Zero if divided by zero, a/b otherwise.""" + SYSDYN.HasModelicaFunctionCode """ input Real a; + input Real b; + output Real z; +algorithm + z := zidz(a, b);""" + +VF.ABS : SYSDYN.SysdynModelicaFunction + L0.HasDescription """ABS(x) + Returns the absolute value of x.""" + SYSDYN.HasModelicaFunctionCode """ input Real x; + output Real z; +algorithm + z := abs(x);""" + +VF.SQRT : SYSDYN.SysdynModelicaFunction + L0.HasDescription """SQRT(x) + Returns the square root of x.""" + SYSDYN.HasModelicaFunctionCode """ input Real x; + output Real z; +algorithm + z := sqrt(x);""" + +VF.MODULO : SYSDYN.SysdynModelicaFunction + L0.HasDescription """MODULO(a, b) + Returns the remainder when a is divided by b. """ + SYSDYN.HasModelicaFunctionCode """ input Real a; + input Real b; + output Real z; +algorithm + z := mod(a, b);""" + +VF.PULSE : SYSDYN.SysdynModelicaFunction + L0.HasDescription """PULSE(start, width) + Returns 1.0 starting at time start and lasting for interval width. 0.0 is returned at other times.""" + SYSDYN.HasModelicaFunctionCode """ input Real start; + input Real width; + input Real t = time; + output Real z; +algorithm + z := if t >= start and (t - start) <= width then 1.0 else 0.0;""" + +VF.RAMP : SYSDYN.SysdynModelicaFunction + L0.HasDescription """RAMP(slope, startTime, endTime) + Returns 0 until the start time and then slopes upward until end time and then holds constant.""" + SYSDYN.HasModelicaFunctionCode """ input Real slope; + input Real startTime; + input Real endTime; + input Real t = time; + output Real z; +algorithm + z := + if t > startTime then + if t < endTime then + slope * (t - startTime) + else + slope * (endTime - startTime) + else + 0;""" + +VF.STEP : SYSDYN.SysdynModelicaFunction + L0.HasDescription """STEP(height, stepTime) + Returns 0.0 until the step time and then returns height.""" + SYSDYN.HasModelicaFunctionCode """ input Real height; + input Real stepTime; + input Real t = time; + output Real z; +algorithm + z := if t >= stepTime then height else 0.0;""" + +/* Continuous built-in common mathematical functions */ + +VF.EXP : SYSDYN.SysdynModelicaFunction + L0.HasDescription """ + """ + SYSDYN.HasModelicaFunctionCode """ input Real x; + output Real z; +algorithm + z := exp(x);""" + +VF.SIN : SYSDYN.SysdynModelicaFunction + L0.HasDescription """SIN(x) + Returns the sine of x.""" + SYSDYN.HasModelicaFunctionCode """ input Real x; + output Real z; +algorithm + z := sin(x);""" + +VF.SINH : SYSDYN.SysdynModelicaFunction + L0.HasDescription """SINH(x) + Returns the hyperbolic sine of x.""" + SYSDYN.HasModelicaFunctionCode """ input Real x; + output Real z; +algorithm + z := sinh(x);""" + +VF.COS : SYSDYN.SysdynModelicaFunction + L0.HasDescription """COS(x) + Returns the cosine of x.""" + SYSDYN.HasModelicaFunctionCode """ input Real x; + output Real z; +algorithm + z := cos(x);""" + +VF.COSH : SYSDYN.SysdynModelicaFunction + L0.HasDescription """COSH(x) + Returns the hyperbolic cosine of x.""" + SYSDYN.HasModelicaFunctionCode """ input Real x; + output Real z; +algorithm + z := cosh(x);""" + +VF.TAN : SYSDYN.SysdynModelicaFunction + L0.HasDescription """TAN(x) + Returns the tangent of x.""" + SYSDYN.HasModelicaFunctionCode """ input Real x; + output Real z; +algorithm + z := tan(x);""" + +VF.TANH : SYSDYN.SysdynModelicaFunction + L0.HasDescription """TANH(x) + Returns the hyperbolic tangent of x.""" + SYSDYN.HasModelicaFunctionCode """ input Real x; + output Real z; +algorithm + z := tanh(x);""" + +VF.LN : SYSDYN.SysdynModelicaFunction + L0.HasDescription """LN(x) + Returns the natural logarithm of x. + In modelica log(x) is the natural logarighm and log10(x) is base 10 logarighm.""" + SYSDYN.HasModelicaFunctionCode """ input Real x; + output Real z; +algorithm + z := log(x);""" + \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ontology/graph/WorkModel.pgraph b/stable/org.simantics.sysdyn.ontology/graph/WorkModel.pgraph new file mode 100644 index 00000000..e74c5e93 --- /dev/null +++ b/stable/org.simantics.sysdyn.ontology/graph/WorkModel.pgraph @@ -0,0 +1,759 @@ +L0 = +L0X = +G2D = +STR = +DIA = +SIMU = +MOD = +SYSDYN = +PROJ = + +//###################################################################### +//# Example work model with two modules +//###################################################################### + +/* +WM = : PROJ.Project + @L0.new +*/ + +WM = : PROJ.Project + @L0.new + + +TAGS = WM.Tags : L0.Library + + +WM.dependency : L0.Template + @template %type %head %tail %angle + %type + @L0.tag TAGS.AdminIsVisible + @L0.tag TAGS.AdminIsFocusable + STR.HasConnectionType SYSDYN.SysdynConnectionType + SYSDYN.angle %angle + DIA.HasArrowConnector _ : DIA.Connector + SYSDYN.HasHeadTerminal %head + DIA.AreConnected _ : DIA.Connector + SYSDYN.HasTailTerminal %tail + DIA.IsPlainConnectorOf %type + +WM.flow : L0.Template + @template %type %head %tail + %type + @L0.tag TAGS.AdminIsVisible + @L0.tag TAGS.AdminIsFocusable + STR.HasConnectionType SYSDYN.SysdynConnectionType + DIA.HasArrowConnector _ : DIA.Connector + SYSDYN.HasHeadTerminal %head + DIA.AreConnected _ : DIA.Connector + SYSDYN.HasTailTerminal %tail + DIA.IsPlainConnectorOf %type + +WM.conf_dependency : L0.Template + @template %type %head %tail + %type + @L0.tag MOD.Mapped + SYSDYN.HasHead %head + SYSDYN.HasTail %tail + +WM.conf_dependency_ref : L0.Template + @template %type %head %tail %ref + %type + @L0.tag MOD.Mapped + SYSDYN.HasHead %head + SYSDYN.HasTail %tail + SYSDYN.RefersTo %ref + + + +WM.WorkSymbol qr{\s+}, 1], + [Comment => qr{#.*\n?$}m, 1], + [AddOp => qr{[+-]} ], + [MulOp => qr{[*/]} ], + [Number => qr{(\d\.)+} ], + [Equals => qr{=} ], + [Lt => qr{<} ], + [Gt => qr{>} ], + [OpenParen => qr{\(} ], + [CloseParen => qr{\)} ], + [Comma => qr{,} ], + [If => qr{IFTHENELSE} ], + [Xls => qr{GETXLSCONSTANTS} ], + [XlsData => qr{GETXLSDATA} ], + [TimeShift => qr{TIMESHIFT} ], + [VectorMap => qr{VECTORELMMAP} ], + [Sum => qr{SUM} ], + [Integ => qr{INTEG} ], + [Str => qr{'[^']+'} ], + [Array => qr{[0-9\w]+\[[^\]]+\]} ], + [Variable => qr{[0-9\w]+} ], +); + +sub parseEquation($) { + my $input = shift; + my @tokens; + pos($input) = 0; + + while(pos($input) < length $input){ + my $matched = 0; + for my $t (@token_def){ + my ($name, $re, $ignore_flag) = @$t; + if ($input =~ m/\G($re)/gc){ + $matched = 1; + next if $ignore_flag; + push @tokens, [$name, $1]; + next; + } + } + unless($matched) { + print "Syntax error at position " . pos($input).": $input\n"; + return; + } + } + return token2str(\@tokens); +} + +sub match { + my $tokens = shift; + my $expected_token = shift; + if ($tokens->[0][0] eq $expected_token){ + my $current = shift @$tokens; + return $current->[1]; + } else { + print "Syntax error: expected $expected_token, got $tokens->[0][0]\n"; + } +} + +sub lookahead { + my $tokens = shift; + my @expected = @_; + no warnings 'uninitialized'; + for (0 .. $#expected){ + return 0 if $tokens->[$_][0] ne $expected[$_]; + } + return 1; +} + +# +# Parse vensim equations and convert to modelica equations +# NOTE: This is not a bullet proof solution, but does parse correctly formed Vensim equations +# FIXME: Find corresponding modelica version for the functions that are currently not transformed +# +sub token2str { + my $tokens = shift; + my $rval = ""; + + if (lookahead($tokens, 'Integ')){ + # Stock. + match($tokens, 'Integ'); + match($tokens, 'OpenParen'); + my $a = token2str($tokens); + match($tokens, 'Comma'); + my $b = token2str($tokens); + match($tokens, 'CloseParen'); +# $rval = "INTEG($a, $b)"; # Integ function will be replaced with stock component, and it has only initial value ? + $rval = $b; # FIXME! + } elsif (lookahead($tokens, 'If')){ + match($tokens, 'If'); + match($tokens, 'OpenParen'); + my $check = token2str($tokens); + match($tokens, 'Comma'); + my $then = token2str($tokens); + match($tokens, 'Comma'); + my $else = ""; + if (lookahead($tokens, 'If')){ + match($tokens, 'If'); + match($tokens, 'OpenParen'); + my $subcheck = token2str($tokens); + match($tokens, 'Comma'); + my $subthen = token2str($tokens); + match($tokens, 'Comma'); + my $subelse = token2str($tokens); # TODO doesn't support elseif yet.. + match($tokens, 'CloseParen'); + $else = "elseif $subcheck then $subthen else $subelse"; + } else { + $else = "else ".token2str($tokens).""; + } + match($tokens, 'CloseParen'); + $rval = "if $check then $then ".$else.""; # Apparently, end if is not used inside equations.. + } elsif (lookahead($tokens, 'Xls')){ + match($tokens, 'Xls'); + match($tokens, 'OpenParen'); + my $a = match($tokens, 'Str'); + match($tokens, 'Comma'); + my $b = match($tokens, 'Str'); + match($tokens, 'Comma'); + my $c = match($tokens, 'Str'); + match($tokens, 'CloseParen'); + $rval = "XLS_CONSTANT($a, $b, $c)"; + } elsif (lookahead($tokens, 'XlsData')){ + match($tokens, 'XlsData'); + match($tokens, 'OpenParen'); + my $a = match($tokens, 'Str'); + match($tokens, 'Comma'); + my $b = match($tokens, 'Str'); + match($tokens, 'Comma'); + my $c = match($tokens, 'Str'); + match($tokens, 'Comma'); + my $d = match($tokens, 'Str'); + match($tokens, 'CloseParen'); + $rval = "XLS_DATA($a, $b, $c, $d)"; + } elsif (lookahead($tokens, 'VectorMap')){ + match($tokens, 'VectorMap'); + match($tokens, 'OpenParen'); + my $a = token2str($tokens); # Should be a variable, but we can use token2str to parse it anyway + match($tokens, 'Comma'); + my $b = token2str($tokens); # Should be a number, but we can use token2str to parse it anyway + match($tokens, 'CloseParen'); + $rval = "VECTOR_MAP($a, $b)"; # + } elsif (lookahead($tokens, 'TimeShift')){ + match($tokens, 'TimeShift'); + match($tokens, 'OpenParen'); + my $var = token2str($tokens); # Should be a variable, but we can use token2str to parse it anyway + match($tokens, 'Comma'); + my $num = token2str($tokens); # Should be a number, but we can use token2str to parse it anyway + match($tokens, 'CloseParen'); + $rval = "delay($var, $num)"; # FIXME: Not sure if this is correct.. + } elsif (lookahead($tokens, 'Sum')){ + match($tokens, 'Sum'); + match($tokens, 'OpenParen'); + my $var = token2str($tokens); # Should be a variable, but we can use token2str to parse it anyway + match($tokens, 'CloseParen'); + $rval = "sum($var)"; + } elsif (lookahead($tokens, 'Array')){ + my $var = match($tokens, 'Array'); + $rval = $var; + } elsif (lookahead($tokens, 'Variable')){ + my $var = match($tokens, 'Variable'); + $rval = $var; + } elsif (lookahead($tokens, 'AddOp')){ + my $op = match($tokens, 'AddOp'); + $rval = $op; + } elsif (lookahead($tokens, 'MulOp')){ + my $op = match($tokens, 'MulOp'); + $rval = $op; + } elsif (lookahead($tokens, 'Number')){ + my $n = match($tokens, 'Number'); + $rval = $n; + } elsif (lookahead($tokens, 'Equals')){ + my $n = match($tokens, 'Equals'); + $rval = $n.$n; # In modelica we must use two times = (This should be used only in if statements..) + } elsif (lookahead($tokens, 'Lt')){ + my $n = match($tokens, 'Lt'); + $rval = $n; + } elsif (lookahead($tokens, 'Gt')){ + my $n = match($tokens, 'Gt'); + $rval = $n; + } elsif (lookahead($tokens, 'OpenParen')){ + match($tokens, 'OpenParen'); + my $inner = token2str($tokens); + match($tokens, 'CloseParen'); + $rval = "($inner)"; + } else { + return ""; + } + my $next = token2str($tokens); + return $rval.$next; +} + +# And finally the actual program + +my $sourcefile = $ARGV[0]; +my $targetfile = $ARGV[1]; + +open(DAT, $sourcefile) || die("Could not open source file for reading!"); +my @raw_data=; +close(DAT); + +my $elements = {}; + +# 1. Parse equations + +my $text = join("\n", @raw_data); +while($text =~ m/(.*)(:=|=|:)([^~]*)~([^~]*)~([^\|]*)/mg) { + my $var = trim($1); + my $op = $2; + my $equation = trim($3); + my $unit = trim($4); + my $comment = trim($5); # May include also "~ :SUPPLEMENTARY" + + $var =~ s/\[.*//g; # Remove the array part from the end ( foo[bar] => foo ) + + $equation =~ s/[\n\s\\]//g; # Remove white spaces, line breaks and backslashes (backslash seems to be used to break equation into two lines). + my $type = ""; + # FIXME: No idea what is the exact difference of these: +# if($op =~ m/^:=$/) { +# $type = "VARIABLE"; +# } elsif($op =~ m/^:$/) { +# $type = "CONSTANT"; +# } else { +# $type = "EQUATION"; +# } + $type = "auxiliary"; + if($equation =~ m/^\s*INTEG\(/) { # If equation is integral, the element type is stock. + $type = "stock"; + } + # TODO: is there any way to detect valve? + + # Convert equation to modelica format + my $modelica_equation = parseEquation($equation); + if($modelica_equation =~ m/^\+if/) { # FIXME: Not sure why "+ IF THEN ELSE" is used in Vensim.. + $modelica_equation =~ s/^\+//g; + } + $modelica_equation =~ s/\+-/-/g; # For some reason there is +- ... which means same as - + if($elements->{$var}) { + push(@{$elements->{$var}->{'equations'}}, $modelica_equation); + } else { + my @eq = ($modelica_equation); + $elements->{$var} = {name => $var, + type => $type, + equations => \@eq, + unit => $unit, + comment => $comment}; + } +} + +my $diagrams = {}; +my $connections = {}; +my $ghost_symbols = {}; +my $types = {}; + +# 2. Parse diagram layout +# i.e., the part after this: +# \\\---/// Sketch information - do not modify anything except names +# V300 Do not put anything below this section - it will be ignored +# + +my $diagram; +foreach my $row (@raw_data) { + # Lines starting with * indicates new diagram configuration.. + if($row =~ m/^\*\w/) { + $diagram = trim($row); + $diagram =~ s/^(\*)//; + } + if($diagram) { + if($row =~ m/^1\d*,/) { + my @data = split(/,/, $row); + my $type = $data[0]; + my $id = $data[1]; + if($type == 1) { + # Connection + # 1,6,1,5,1,0,0,0,0,64,0,-1--1--1,,1|(729,352)| + # 1,546,138,3,0,0,0,0,0,64,1,-1--1--1,,1|(-1642,-250)| <- this connection is not visible in vensim? + # Flow + # 1,33,35,8,4,0,0,22,0,0,0,-1--1--1,,1|(456,528)| + + my $target = $data[2]; + my $source = $data[3]; + my $foo = $data[4]; # If this is 100, the flow direction must be changed (Yeah, wtf?) + my $t = $data[9] == 64 ? "dependency" : "flow"; + my $hidden = $data[10] == 1 ? 1 : 0; # TODO: Not sure if this is correct + if($t eq "flow" && $foo == 100) { + my $tmp = $target; + $target = $source; + $source = $tmp; + } + + $connections->{$diagram} = {} unless($connections->{$diagram}); + $connections->{$diagram}->{$id} = {source => $source, target => $target, type => $t, hidden => $hidden}; + } elsif($type == 10) { + # Element + # 10,1,TotalPopulation,417,269,47,65,3,131,0,0,0,0,0,0 <- not sure, might be stock (but actually is auxiliary9 + # 10,11,TotalPopulationT1,417,610,47,65,3,131,0,0,0,0,0,0 <- what is this? + # 10,274,LungCsIVNoD,-1050,1269,40,20,3,3,0,0,0,0,0,0 <- level aka stock? + # 10,2,LungCs01,-1109,-650,79,18,3,131,0,0,0,0,0,0 <- stock + # 10,786,LungCSmokersPercentageOfPopulation,-700,-835,147,21,8,131,0,0,0,0,0,0 <- input? + # 10,63,LungCProgress0102Rate,-1248,-541,91,9,8,3,0,0,0,0,0,0 <- aux ? + # 10,125,LungCModelPopCorrectionRate,1582,65,105,9,8,3,0,0,0,0,0,0 <- constant (FIXME: seems to be identical with aux) + # 10,152,LungCTreated1PopCorr,287,269,102,9,40,3,1,0,-1,0,0,0 <- valve + + my $name = $data[2]; + my $x = $data[3]; + my $y = $data[4]; + my $width = $data[5]; + my $height = $data[6]; + my $foo = $data[7]; + my $bar = $data[8]; # 131 for stock, 3 for aux + my $t = "unknown"; #$data[11] == -1 ? "valve" : "stock"; # -1 for valve, 0 for stock ? + my $ghost = 0; + if($#data > 15) { # Ghost symbols contains more parameters.. + # 10,505,LungCs01Diagnosis, -808,-633, 64,9,40,3,0,0,-1,0,0,0 + # 10,590,LungCs01Diagnosis, 2614,1033, 73,9,8, 2,0,3,-1,0,0,0,128-128-128,0-0-0,|12||128-128-128 + $ghost = 1; + } + + if($foo == 3 && $bar == 3) { + $t = "stock"; + } elsif($foo == 3 && $bar == 131) { + $t = "auxiliary"; # FIXME: + } elsif($foo == 8 && $bar == 131) { + $t = "auxiliary"; + } elsif($foo == 40 && $bar == 3) { + $t = "valve"; + } elsif($bar == 3) { + $t = "auxiliary"; + } else { + $t = "valve"; + } + if(!$ghost) { + $types->{$name} = $t; + } + + $diagrams->{$diagram} = {} unless($diagrams->{$diagram}); + $diagrams->{$diagram}->{$id} = { + id => $id, + name => $name, + x => $x, + y => $y, + width => $width, + height => $height, + type => $t, + ghost => $ghost + }; + if($t eq "valve" && $ghost_symbols->{$id}) { + $diagrams->{$diagram}->{($ghost_symbols->{$id})} = $diagrams->{$diagram}->{$id}; + } + } elsif($type == 11) { + # Valve + # 11,48,48,-1348,-887,6,8,34,3,0,0,1,0,0,0 + my $x = $data[3]; + my $y = $data[4]; + + # This data is very much related to the valve symbol on the next line .. + $ghost_symbols->{$id+1} = $id; + } elsif($type == 12) { + # Textbox (can be ignored, the string is on the next line) + # 12,2,0,430,56,114,34,8,132,0,0,-1,0,0,0 + # Cloud + # 12,45,48,-1553,-888,10,8,0,3,0,0,-1,0,0,0 + + my $x = $data[3]; + my $y = $data[4]; + my $foo = $data[7]; + my $bar = $data[8]; # 132 for textbox, 3 for cloud + if($bar == 3) { + $diagrams->{$diagram} = {} unless($diagrams->{$diagram}); + $diagrams->{$diagram}->{$id} = { + id => $id, + name => "Cloud".$id, # Cloud does not have name, but we can generate one + x => $x, + y => $y, + type => 'cloud', + ghost => 0}; + $types->{"Cloud".$id} = 'cloud'; + } + } + } else { + # Comment or something... + } + } +} + +# 3. Generate .pgraph file +my $generated_elements = {}; +my $generated_symbols = {}; + +# Create combined configuration +my $output = ""; +foreach my $key (keys (%$diagrams)) { + my $d = $key; + $d =~ s/\s+//g; + my $WC = "CMC"; + + my $tmp = $diagrams->{$key}; + foreach my $id (keys (%$tmp)) { + my $n = $tmp->{$id}->{'name'}; + if($tmp->{$id}->{'ghost'} == 1) { # Ghost does not contain correct element type + next; + } + my $type = $tmp->{$id}->{'type'}; + no warnings 'uninitialized'; + $type = "stock" if($elements->{$n}->{'type'} eq "stock"); + + if($type eq "cloud") { + # Cloud is not a real element, thus it is not present in elements array.. + $output .= $WC.".".$tmp->{$id}->{'name'}." : SYSDYN.Cloud\n"; + $output .= "\n"; + } elsif($elements->{$n} && $elements->{$n}->{'name'} && !$generated_elements->{$elements->{$n}->{'name'}}) { + if($type eq "valve") { + $output .= $WC.".".$elements->{$n}->{'name'}." : SYSDYN.Valve\n"; + $output .= " \@L0.tag MOD.Mapped\n"; + $output .= " SYSDYN.HasExpressions _ : SYSDYN.Expressions\n"; + $output .= " \@L0.orderedSet\n"; + my $equations = $elements->{$n}->{'equations'}; + foreach my $equation (@$equations) { + $output .= " _ : SYSDYN.NormalExpression\n"; + $output .= " SYSDYN.HasEquation \"".$equation."\" \n"; + } + } elsif($type eq "stock") { + $output .= $WC.".".$elements->{$n}->{'name'}." : SYSDYN.Stock\n"; + $output .= " \@L0.tag MOD.Mapped\n"; + $output .= " SYSDYN.HasExpressions _ : SYSDYN.Expressions\n"; + $output .= " \@L0.orderedSet\n"; + my $equations = $elements->{$n}->{'equations'}; + foreach my $equation (@$equations) { + $output .= " _ : SYSDYN.StockExpression\n"; + $output .= " SYSDYN.HasInitialEquation \"".$equation."\" \n"; + } + $output .= "\n"; + } elsif($type eq "auxiliary") { + $output .= $WC.".".$elements->{$n}->{'name'}." : SYSDYN.Auxiliary\n"; + $output .= " \@L0.tag MOD.Mapped\n"; + $output .= " SYSDYN.HasExpressions _ : SYSDYN.Expressions\n"; + $output .= " \@L0.orderedSet\n"; + my $equations = $elements->{$n}->{'equations'}; + foreach my $equation (@$equations) { + $output .= " _ : SYSDYN.NormalExpression\n"; + $output .= " SYSDYN.HasEquation \"".$equation."\" \n"; + } + $output .= "\n"; + } else { + print("Unknown element type: $type\n"); + } + } + $generated_elements->{$elements->{$n}->{'name'}} = 1; + } + + my $c = $connections->{$key}; + foreach my $id (keys (%$c)) { + my $source = $tmp->{$c->{$id}->{'source'}}->{'name'}; + my $target = $tmp->{$c->{$id}->{'target'}}->{'name'}; + if($source && $target) { + if($c->{$id}->{'type'} eq "flow") { + $output .= $WC.".f".$id." : SYSDYN.Flow\n"; + $output .= " \@WM.conf_dependency ".$WC.".".$source." ".$WC.".".$target."\n"; + } elsif($c->{$id}->{'type'} eq "dependency") { + $output .= $WC.".d".$id." : SYSDYN.Dependency\n"; + $output .= " \@WM.conf_dependency ".$WC.".".$source." ".$WC.".".$target."\n"; + } else { + print("Unknown connection type ".$c->{$id}->{'type'}."\n"); + } + } else { + print("WARNING: "); + print("No source element for connection #".$c->{$id}->{'source'}." -> $target\n") if($target); + print("No target element for connection $source -> #".$c->{$id}->{'target'}."\n") if($source); + } + } + $output .= "\n"; +} + +# Create combined diagram +my $max_x = 0; # FIXME: Assumes that there are positive locations.. +foreach my $key (keys (%$diagrams)) { + my $d = $key; + $d =~ s/\s+//g; + + my $WC = "CMC"; + my $tmp = $diagrams->{$key}; + unless($key eq "Population") { + $output .= $d."ConfigurationDiagram : SYSDYN.ConfigurationDiagram {$id}->{'name'}; + my $suffix = "Element".$tmp->{$id}->{'id'}; # id field in hash might be different than $id (see parsing of type 11 and type 10 elements) + + if(!$generated_symbols->{$n.$suffix}) { + my $x = sprintf("%.1f", $tmp->{$id}->{'x'} / 5 + $offset_x); # Scale + my $y = sprintf("%.1f", $tmp->{$id}->{'y'} / 5); # Scale + $max_x = $x if(($tmp->{$id}->{'x'} / 5 + $offset_x) > $max_x) ; + my $type = $types->{$n}; # Type lookup contains correct type (ghosts does not..) + $type = "stock" if($elements->{$n}->{'type'} eq "stock"); + + if($type eq "stock") { + $output .= " ".$n.$suffix." : SYSDYN.StockSymbol\n"; + $output .= " MOD.ElementToComponent ".$WC.".$n\n"; + $output .= " DIA.HasTransform [1.0, 0.0, 0.0, 1.0, ".$x.", ".$y."] : G2D.Transform\n"; + } elsif($type eq "auxiliary") { + $output .= " ".$n.$suffix." : SYSDYN.AuxiliarySymbol\n"; + $output .= " MOD.ElementToComponent ".$WC.".$n\n"; + $output .= " DIA.HasTransform [1.0, 0.0, 0.0, 1.0, ".$x.", ".$y."] : G2D.Transform\n"; + } elsif($type eq "valve") { + $output .= " ".$n.$suffix." : SYSDYN.ValveSymbol\n"; + $output .= " MOD.ElementToComponent ".$WC.".$n\n"; + $output .= " DIA.HasTransform [1.0, 0.0, 0.0, 1.0, ".$x.", ".$y."] : G2D.Transform\n"; + } elsif($type eq "input") { + $output .= " ".$n.$suffix." : SYSDYN.InputSymbol\n"; + $output .= " MOD.ElementToComponent ".$WC.".$n\n"; + $output .= " DIA.HasTransform [1.0, 0.0, 0.0, 1.0, ".$x.", ".$y."] : G2D.Transform\n"; + } elsif($type eq "cloud") { + $output .= " ".$n.$suffix." : SYSDYN.CloudSymbol\n"; + $output .= " MOD.ElementToComponent ".$WC.".$n\n"; + $output .= " DIA.HasTransform [1.0, 0.0, 0.0, 1.0, ".$x.", ".$y."] : G2D.Transform\n"; + } else { + print("Unknown element type $type\n"); + } + } + $generated_symbols->{$n.$suffix} = 1; + } + + my $c = $connections->{$key}; + foreach my $id (keys (%$c)) { + my $source = $tmp->{$c->{$id}->{'source'}}->{'name'}; + my $target = $tmp->{$c->{$id}->{'target'}}->{'name'}; + if($source && $target) { + my $source_suffix = "Element".$tmp->{$c->{$id}->{'source'}}->{'id'}; + my $target_suffix = "Element".$tmp->{$c->{$id}->{'target'}}->{'id'}; + + if($c->{$id}->{'hidden'} == 0) { + if($c->{$id}->{'type'} eq "flow") { + $output .= " _ : SYSDYN.FlowConnection\n"; + $output .= " MOD.DiagramConnectionToConnection ".$WC.".f".$id."\n"; + $output .= " \@WM.flow ".$source.$source_suffix." ".$target.$target_suffix."\n"; + } elsif($c->{$id}->{'type'} eq "dependency") { + $output .= " _ : SYSDYN.DependencyConnection\n"; + $output .= " MOD.DiagramConnectionToConnection ".$WC.".d".$id."\n"; + $output .= " \@WM.dependency ".$source.$source_suffix." ".$target.$target_suffix." -0.1\n"; + } else { + print("Unknown element type ".$c->{$id}->{'type'}."\n"); + } + } + } + } + $output .= "\n"; +} + +my $header = < +G2D = +STR = +DIA = +SIMU = +MOD = +SYSDYN = +PROJ = + +//###################################################################### +//# Example work model with two modules +//###################################################################### + +WM = : PROJ.Project + PROJ.HasFeature _ : PROJ.FeatureSpec + PROJ.HasGroupId "org.simantics.sysdyn.feature.group" + L0.PartOf + +TAGS = WM.Tags : L0.Library + +WM.dependency : L0.Template + \@template %type %head %tail %angle + %type + \@L0.tag TAGS.AdminIsVisible + \@L0.tag TAGS.AdminIsFocusable + STR.HasConnectionType SYSDYN.SysdynConnectionType + SYSDYN.angle %angle + DIA.HasArrowConnector _ : DIA.Connector + SYSDYN.HasHeadTerminal %head + DIA.AreConnected _ : DIA.Connector + SYSDYN.HasTailTerminal %tail + DIA.IsPlainConnectorOf %type + +WM.flow : L0.Template + \@template %type %head %tail + %type + \@L0.tag TAGS.AdminIsVisible + \@L0.tag TAGS.AdminIsFocusable + STR.HasConnectionType SYSDYN.SysdynConnectionType + DIA.HasArrowConnector _ : DIA.Connector + SYSDYN.HasHeadTerminal %head + DIA.AreConnected _ : DIA.Connector + SYSDYN.HasTailTerminal %tail + DIA.IsPlainConnectorOf %type + +WM.conf_dependency : L0.Template + \@template %type %head %tail + %type + \@L0.tag MOD.Mapped + SYSDYN.HasHead %head + SYSDYN.HasTail %tail + +WM.conf_dependency_ref : L0.Template + \@template %type %head %tail %ref + %type + \@L0.tag MOD.Mapped + SYSDYN.HasHead %head + SYSDYN.HasTail %tail + SYSDYN.RefersTo %ref + +WM.CancerModel : SYSDYN.SysdynModel + L0.HasLabel "Cancer Model" + SIMU.HasConfiguration CMC + SYSDYN.HasStartTime 0.0 + SYSDYN.HasStopTime 24.0 + +WM.CancerModel.Experiment : SYSDYN.Experiment + L0.HasLabel "Experiment" + +CMC = WM.CancerModel.CancerModelConfiguration : SYSDYN.Configuration + L0.HasLabel "CancerModelConfiguration" + +END + +open(OUTPUT, ">$targetfile") || die("Could not open target file for writing!"); +print OUTPUT $header; +print OUTPUT $output; +close(OUTPUT); + +print("Simantics graph configuration saved successfully to file $targetfile\n"); diff --git a/stable/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java b/stable/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java new file mode 100644 index 00000000..dda9fead --- /dev/null +++ b/stable/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java @@ -0,0 +1,900 @@ +package org.simantics.sysdyn; + +import org.simantics.db.Resource; +import org.simantics.db.ReadGraph; +import org.simantics.db.request.Read; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.QueryControl; + +public class SysdynResource { + + public final Resource AdditionalSymbols; + public final Resource AdditionalSymbols_Text; + public final Resource AllElementsGroup; + public final Resource ArrayIndexes; + public final Resource ArrayIndexes_Inverse; + public final Resource Auxiliary; + public final Resource AuxiliarySymbol; + public final Resource AvailableSharedFunctionLibraries; + public final Resource AvailableVariableIndexes; + public final Resource BarSeriesActionContext; + public final Resource BarSeriesActionContext_Actions; + public final Resource BarSeriesBrowseContext; + public final Resource BarSeriesBrowseContext_SeriesChildRule; + public final Resource BarSeriesBrowseContext_SeriesLabelDecorationRule; + public final Resource BarSeriesBrowseContext_SeriesLabelRule; + public final Resource BasicExperiment; + public final Resource Bottom; + public final Resource Browser; + public final Resource Built$in_Functions; + public final Resource Built$in_Functions_Vensim_Functions; + public final Resource Built$in_Functions_Vensim_Functions_ABS; + public final Resource Built$in_Functions_Vensim_Functions_COS; + public final Resource Built$in_Functions_Vensim_Functions_COSH; + public final Resource Built$in_Functions_Vensim_Functions_EXP; + public final Resource Built$in_Functions_Vensim_Functions_IFTHENELSE; + public final Resource Built$in_Functions_Vensim_Functions_LN; + public final Resource Built$in_Functions_Vensim_Functions_MAX; + public final Resource Built$in_Functions_Vensim_Functions_MIN; + public final Resource Built$in_Functions_Vensim_Functions_MODULO; + public final Resource Built$in_Functions_Vensim_Functions_PULSE; + public final Resource Built$in_Functions_Vensim_Functions_RAMP; + public final Resource Built$in_Functions_Vensim_Functions_SIN; + public final Resource Built$in_Functions_Vensim_Functions_SINH; + public final Resource Built$in_Functions_Vensim_Functions_SQRT; + public final Resource Built$in_Functions_Vensim_Functions_STEP; + public final Resource Built$in_Functions_Vensim_Functions_TAN; + public final Resource Built$in_Functions_Vensim_Functions_TANH; + public final Resource Built$in_Functions_Vensim_Functions_XIDZ; + public final Resource Built$in_Functions_Vensim_Functions_ZIDZ; + public final Resource Built$in_Functions_interpolate; + public final Resource Built$in_Functions_interpolateFull; + public final Resource Built$in_Functions_xidz; + public final Resource Built$in_Functions_zidz; + public final Resource Center; + public final Resource ChartAxisAndVariablesActionContext; + public final Resource ChartAxisAndVariablesActionContext_Actions; + public final Resource ChartAxisAndVariablesActionContext_Actions_AxisDropAction; + public final Resource ChartAxisAndVariablesActionContext_Actions_SeriesDropAction; + public final Resource ChartAxisAndVariablesBrowseContext; + public final Resource ChartAxisAndVariablesBrowseContext_AxisChildRule; + public final Resource ChartAxisAndVariablesBrowseContext_AxisLabelRule; + public final Resource ChartAxisAndVariablesBrowseContext_SeriesLabelDecorationRule; + public final Resource ChartAxisAndVariablesBrowseContext_SeriesLabelRule; + public final Resource ChartAxisAndVariablesBrowseContext_VariableChildRule; + public final Resource Cloud; + public final Resource CloudSymbol; + public final Resource Configuration; + public final Resource ConfigurationDiagram; + public final Resource ConfigurationDiagramTemplate; + public final Resource ConstantExpression; + public final Resource DefaultProfile; + public final Resource DefaultRealization; + public final Resource DelayExpression; + public final Resource DelayExpression_delayTime; + public final Resource DelayExpression_delayTime_Inverse; + public final Resource DelayExpression_expression; + public final Resource DelayExpression_expression_Inverse; + public final Resource DelayExpression_initialValue; + public final Resource DelayExpression_initialValue_Inverse; + public final Resource DelayExpression_order; + public final Resource DelayExpression_order_Inverse; + public final Resource Dependency; + public final Resource DependencyConnection; + public final Resource DiagramToCompositeMapping; + public final Resource Enumeration; + public final Resource EnumerationIndex; + public final Resource EnumerationIndexes; + public final Resource EnumerationIndexes_Inverse; + public final Resource EnumerationReplacement; + public final Resource Experiment; + public final Resource ExportModuleTree; + public final Resource Expression; + public final Resource Expressions; + public final Resource Expressions_Inverse; + public final Resource ExternalFiles; + public final Resource ExternalFunctionFile; + public final Resource Flow; + public final Resource FlowConnection; + public final Resource FunctionTree; + public final Resource GameExperiment; + public final Resource HasActiveExpression; + public final Resource HasActiveExpression_Inverse; + public final Resource HasArrayIndexes; + public final Resource HasArrayIndexes_Inverse; + public final Resource HasArrayRange; + public final Resource HasArrayRange_Inverse; + public final Resource HasDefaultInputValue; + public final Resource HasDefaultInputValue_Inverse; + public final Resource HasEnumerationIndexes; + public final Resource HasEnumerationIndexes_Inverse; + public final Resource HasEquation; + public final Resource HasEquationOrEmpty; + public final Resource HasEquationOrEmpty_Inverse; + public final Resource HasEquation_Inverse; + public final Resource HasExpressions; + public final Resource HasExpressions_Inverse; + public final Resource HasExternalFile; + public final Resource HasExternalFile_Inverse; + public final Resource HasHead; + public final Resource HasHeadTerminal; + public final Resource HasInitialEquation; + public final Resource HasInitialEquation_Inverse; + public final Resource HasLookup; + public final Resource HasLookup_Inverse; + public final Resource HasMaxX; + public final Resource HasMaxX_Inverse; + public final Resource HasMaxY; + public final Resource HasMaxY_Inverse; + public final Resource HasMinX; + public final Resource HasMinX_Inverse; + public final Resource HasMinY; + public final Resource HasMinY_Inverse; + public final Resource HasModelicaFunctionCode; + public final Resource HasModelicaFunctionCode_Inverse; + public final Resource HasOutputInterval; + public final Resource HasOutputInterval_Inverse; + public final Resource HasParameterFile; + public final Resource HasParameterFile_Inverse; + public final Resource HasRangeEnd; + public final Resource HasRangeEnd_Inverse; + public final Resource HasRangeStart; + public final Resource HasRangeStart_Inverse; + public final Resource HasRangeStep; + public final Resource HasRangeStep_Inverse; + public final Resource HasRedeclaration; + public final Resource HasRedeclaration_Inverse; + public final Resource HasResult; + public final Resource HasResultFile; + public final Resource HasResultFile_Inverse; + public final Resource HasResult_Inverse; + public final Resource HasSolver; + public final Resource HasSolver_Inverse; + public final Resource HasStartTime; + public final Resource HasStartTime_Inverse; + public final Resource HasStopTime; + public final Resource HasStopTime_Inverse; + public final Resource HasTail; + public final Resource HasTailTerminal; + public final Resource HasTextLocation; + public final Resource HasTextLocation_Inverse; + public final Resource HasTolerance; + public final Resource HasTolerance_Inverse; + public final Resource HasUnit; + public final Resource HasUnit_Inverse; + public final Resource HasValveOrientation; + public final Resource HasValveOrientation_Inverse; + public final Resource HistoryRealization; + public final Resource Horizontal; + public final Resource ImportModuleTree; + public final Resource ImportedOntologies; + public final Resource IndependentVariable; + public final Resource Input; + public final Resource InputSymbol; + public final Resource IsHeadOf; + public final Resource IsHeadOfTerminal; + public final Resource IsOutput; + public final Resource IsReplaceable; + public final Resource IsReplaceable_Inverse; + public final Resource IsTailOf; + public final Resource IsTailOfTerminal; + public final Resource IssueStyle; + public final Resource Left; + public final Resource Location; + public final Resource LookupExpression; + public final Resource ModelBrowser; + public final Resource Module; + public final Resource ModuleSymbol; + public final Resource NormalExpression; + public final Resource Orientation; + public final Resource ParameterExpression; + public final Resource PieSeriesActionContext; + public final Resource PieSeriesActionContext_Actions; + public final Resource PieSeriesBrowseContext; + public final Resource PieSeriesBrowseContext_SeriesChildRule; + public final Resource PieSeriesBrowseContext_SeriesLabelDecorationRule; + public final Resource PieSeriesBrowseContext_SeriesLabelRule; + public final Resource PlaybackExperiment; + public final Resource Polarity; + public final Resource PolarityLocation; + public final Resource PolarityLocation_Inverse; + public final Resource Polarity_Inverse; + public final Resource Profiles; + public final Resource Profiles_IssueWarnings; + public final Resource Profiles_SimulationPlaybackColours; + public final Resource ProjectActionContext; + public final Resource ProjectActionContext_Actions; + public final Resource ProjectActionContext_Actions_NewEnumeration; + public final Resource ProjectActionContext_Actions_NewFunction; + public final Resource ProjectActionContext_Actions_NewFunctionLibrary; + public final Resource ProjectActionContext_Actions_NewModuleType; + public final Resource ProjectActionContext_Actions_NewSharedFunctionLibrary; + public final Resource ProjectActionContext_Actions_OpenWorkbook; + public final Resource ProjectBrowseContext; + public final Resource ProjectBrowseContext_BuiltinFunctions; + public final Resource ProjectBrowseContext_FunctionsFolder; + public final Resource ProjectBrowseContext_ModuleContentChildRule; + public final Resource ProjectBrowseContext_ModuleSymbol; + public final Resource ProjectBrowseContext_ModuleTypeChildRule; + public final Resource ProjectBrowseContext_ModuleTypeLabelRule; + public final Resource ProjectBrowseContext_ModulesFolder; + public final Resource ProjectBrowseContext_SharedFunctionsFolder; + public final Resource Redeclaration; + public final Resource RefersTo; + public final Resource ReplacedEnumeration; + public final Resource ReplacedEnumeration_Inverse; + public final Resource ReplacingEnumeration; + public final Resource ReplacingEnumeration_Inverse; + public final Resource Result; + public final Resource Right; + public final Resource SelectedSharedFunctionLibraries; + public final Resource SharedFunctionOntology; + public final Resource SharedModuleOntolofgy; + public final Resource ShowEnumerationIndexInCharts; + public final Resource ShowEnumerationIndexInCharts_Inverse; + public final Resource ShowResult; + public final Resource SimulateOnChangeExperiment; + public final Resource SimulationPlaybackProfile; + public final Resource SimulationPlaybackStyle; + public final Resource Stock; + public final Resource StockExpression; + public final Resource StockSymbol; + public final Resource SymbolReferences; + public final Resource SymbolReferences_BasicSymbols; + public final Resource SymbolReferences_GeneralSymbols; + public final Resource Symbols; + public final Resource SysdynConnectionType; + public final Resource SysdynDiagramModelingRules; + public final Resource SysdynIssue; + public final Resource SysdynModel; + public final Resource SysdynModelicaFunction; + public final Resource SysdynModelicaFunctionLibrary; + public final Resource SysdynModuleLibrary; + public final Resource SysdynOperationBrowser; + public final Resource SysdynTerminal; + public final Resource Top; + public final Resource UsedVariableIndexes; + public final Resource Validations; + public final Resource Validations_Dependencies; + public final Resource Validations_Dependencies_DependencyConnectionsIssueSource; + public final Resource Validations_Dependencies_MissingDependencyConnectionsIssueSource; + public final Resource Validations_Dependencies_dependencySynchronizer; + public final Resource Validations_Dependencies_dependencyValidator; + public final Resource Validations_Dependencies_missingDependencyValidator; + public final Resource Validations_Dependencies_missingLinkIssueDescription; + public final Resource Validations_Dependencies_noSuchVariableIssueDescription; + public final Resource Validations_Dependencies_unusedDependencyIssueDescription; + public final Resource Validations_DependencyConstraint; + public final Resource Validations_ExpressionConstraint; + public final Resource Validations_ExpressionIssue; + public final Resource Validations_Expressions; + public final Resource Validations_Expressions_ExpressionIssueSource; + public final Resource Validations_Expressions_expressionIssueDescription; + public final Resource Validations_Expressions_expressionSynchronizer; + public final Resource Validations_Expressions_expressionValidator; + public final Resource Validations_Functions; + public final Resource Validations_Functions_baseRealizationFunction; + public final Resource Validations_MissingDependencyConstraint; + public final Resource Validations_MissingLinkIssue; + public final Resource Validations_NoSuchVariableIssue; + public final Resource Validations_UnusedDependencyIssue; + public final Resource Validations_constraint; + public final Resource Validations_issue; + public final Resource Validations_listeningConstraint; + public final Resource Valve; + public final Resource ValveSymbol; + public final Resource Variable; + public final Resource Variable_Type; + public final Resource Variable_Type_Inverse; + public final Resource Vertical; + public final Resource WithLookupExpression; + public final Resource angle; + public final Resource angle_Inverse; + + public static class URIs { + public static final String AdditionalSymbols = "http://www.simantics.org/Sysdyn-1.1/AdditionalSymbols"; + public static final String AdditionalSymbols_Text = "http://www.simantics.org/Sysdyn-1.1/AdditionalSymbols/Text"; + public static final String AllElementsGroup = "http://www.simantics.org/Sysdyn-1.1/AllElementsGroup"; + public static final String ArrayIndexes = "http://www.simantics.org/Sysdyn-1.1/ArrayIndexes"; + public static final String ArrayIndexes_Inverse = "http://www.simantics.org/Sysdyn-1.1/ArrayIndexes/Inverse"; + public static final String Auxiliary = "http://www.simantics.org/Sysdyn-1.1/Auxiliary"; + public static final String AuxiliarySymbol = "http://www.simantics.org/Sysdyn-1.1/AuxiliarySymbol"; + public static final String AvailableSharedFunctionLibraries = "http://www.simantics.org/Sysdyn-1.1/AvailableSharedFunctionLibraries"; + public static final String AvailableVariableIndexes = "http://www.simantics.org/Sysdyn-1.1/AvailableVariableIndexes"; + public static final String BarSeriesActionContext = "http://www.simantics.org/Sysdyn-1.1/BarSeriesActionContext"; + public static final String BarSeriesActionContext_Actions = "http://www.simantics.org/Sysdyn-1.1/BarSeriesActionContext/Actions"; + public static final String BarSeriesBrowseContext = "http://www.simantics.org/Sysdyn-1.1/BarSeriesBrowseContext"; + public static final String BarSeriesBrowseContext_SeriesChildRule = "http://www.simantics.org/Sysdyn-1.1/BarSeriesBrowseContext/SeriesChildRule"; + public static final String BarSeriesBrowseContext_SeriesLabelDecorationRule = "http://www.simantics.org/Sysdyn-1.1/BarSeriesBrowseContext/SeriesLabelDecorationRule"; + public static final String BarSeriesBrowseContext_SeriesLabelRule = "http://www.simantics.org/Sysdyn-1.1/BarSeriesBrowseContext/SeriesLabelRule"; + public static final String BasicExperiment = "http://www.simantics.org/Sysdyn-1.1/BasicExperiment"; + public static final String Bottom = "http://www.simantics.org/Sysdyn-1.1/Bottom"; + public static final String Browser = "http://www.simantics.org/Sysdyn-1.1/Browser"; + public static final String Built$in_Functions = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions"; + public static final String Built$in_Functions_Vensim_Functions = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions"; + public static final String Built$in_Functions_Vensim_Functions_ABS = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/ABS"; + public static final String Built$in_Functions_Vensim_Functions_COS = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/COS"; + public static final String Built$in_Functions_Vensim_Functions_COSH = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/COSH"; + public static final String Built$in_Functions_Vensim_Functions_EXP = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/EXP"; + public static final String Built$in_Functions_Vensim_Functions_IFTHENELSE = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/IFTHENELSE"; + public static final String Built$in_Functions_Vensim_Functions_LN = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/LN"; + public static final String Built$in_Functions_Vensim_Functions_MAX = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/MAX"; + public static final String Built$in_Functions_Vensim_Functions_MIN = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/MIN"; + public static final String Built$in_Functions_Vensim_Functions_MODULO = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/MODULO"; + public static final String Built$in_Functions_Vensim_Functions_PULSE = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/PULSE"; + public static final String Built$in_Functions_Vensim_Functions_RAMP = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/RAMP"; + public static final String Built$in_Functions_Vensim_Functions_SIN = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/SIN"; + public static final String Built$in_Functions_Vensim_Functions_SINH = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/SINH"; + public static final String Built$in_Functions_Vensim_Functions_SQRT = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/SQRT"; + public static final String Built$in_Functions_Vensim_Functions_STEP = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/STEP"; + public static final String Built$in_Functions_Vensim_Functions_TAN = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/TAN"; + public static final String Built$in_Functions_Vensim_Functions_TANH = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/TANH"; + public static final String Built$in_Functions_Vensim_Functions_XIDZ = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/XIDZ"; + public static final String Built$in_Functions_Vensim_Functions_ZIDZ = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/ZIDZ"; + public static final String Built$in_Functions_interpolate = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/interpolate"; + public static final String Built$in_Functions_interpolateFull = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/interpolateFull"; + public static final String Built$in_Functions_xidz = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/xidz"; + public static final String Built$in_Functions_zidz = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/zidz"; + public static final String Center = "http://www.simantics.org/Sysdyn-1.1/Center"; + public static final String ChartAxisAndVariablesActionContext = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesActionContext"; + public static final String ChartAxisAndVariablesActionContext_Actions = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesActionContext/Actions"; + public static final String ChartAxisAndVariablesActionContext_Actions_AxisDropAction = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesActionContext/Actions/AxisDropAction"; + public static final String ChartAxisAndVariablesActionContext_Actions_SeriesDropAction = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesActionContext/Actions/SeriesDropAction"; + public static final String ChartAxisAndVariablesBrowseContext = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesBrowseContext"; + public static final String ChartAxisAndVariablesBrowseContext_AxisChildRule = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesBrowseContext/AxisChildRule"; + public static final String ChartAxisAndVariablesBrowseContext_AxisLabelRule = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesBrowseContext/AxisLabelRule"; + public static final String ChartAxisAndVariablesBrowseContext_SeriesLabelDecorationRule = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesBrowseContext/SeriesLabelDecorationRule"; + public static final String ChartAxisAndVariablesBrowseContext_SeriesLabelRule = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesBrowseContext/SeriesLabelRule"; + public static final String ChartAxisAndVariablesBrowseContext_VariableChildRule = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesBrowseContext/VariableChildRule"; + public static final String Cloud = "http://www.simantics.org/Sysdyn-1.1/Cloud"; + public static final String CloudSymbol = "http://www.simantics.org/Sysdyn-1.1/CloudSymbol"; + public static final String Configuration = "http://www.simantics.org/Sysdyn-1.1/Configuration"; + public static final String ConfigurationDiagram = "http://www.simantics.org/Sysdyn-1.1/ConfigurationDiagram"; + public static final String ConfigurationDiagramTemplate = "http://www.simantics.org/Sysdyn-1.1/ConfigurationDiagramTemplate"; + public static final String ConstantExpression = "http://www.simantics.org/Sysdyn-1.1/ConstantExpression"; + public static final String DefaultProfile = "http://www.simantics.org/Sysdyn-1.1/DefaultProfile"; + public static final String DefaultRealization = "http://www.simantics.org/Sysdyn-1.1/DefaultRealization"; + public static final String DelayExpression = "http://www.simantics.org/Sysdyn-1.1/DelayExpression"; + public static final String DelayExpression_delayTime = "http://www.simantics.org/Sysdyn-1.1/DelayExpression/delayTime"; + public static final String DelayExpression_delayTime_Inverse = "http://www.simantics.org/Sysdyn-1.1/DelayExpression/delayTime/Inverse"; + public static final String DelayExpression_expression = "http://www.simantics.org/Sysdyn-1.1/DelayExpression/expression"; + public static final String DelayExpression_expression_Inverse = "http://www.simantics.org/Sysdyn-1.1/DelayExpression/expression/Inverse"; + public static final String DelayExpression_initialValue = "http://www.simantics.org/Sysdyn-1.1/DelayExpression/initialValue"; + public static final String DelayExpression_initialValue_Inverse = "http://www.simantics.org/Sysdyn-1.1/DelayExpression/initialValue/Inverse"; + public static final String DelayExpression_order = "http://www.simantics.org/Sysdyn-1.1/DelayExpression/order"; + public static final String DelayExpression_order_Inverse = "http://www.simantics.org/Sysdyn-1.1/DelayExpression/order/Inverse"; + public static final String Dependency = "http://www.simantics.org/Sysdyn-1.1/Dependency"; + public static final String DependencyConnection = "http://www.simantics.org/Sysdyn-1.1/DependencyConnection"; + public static final String DiagramToCompositeMapping = "http://www.simantics.org/Sysdyn-1.1/DiagramToCompositeMapping"; + public static final String Enumeration = "http://www.simantics.org/Sysdyn-1.1/Enumeration"; + public static final String EnumerationIndex = "http://www.simantics.org/Sysdyn-1.1/EnumerationIndex"; + public static final String EnumerationIndexes = "http://www.simantics.org/Sysdyn-1.1/EnumerationIndexes"; + public static final String EnumerationIndexes_Inverse = "http://www.simantics.org/Sysdyn-1.1/EnumerationIndexes/Inverse"; + public static final String EnumerationReplacement = "http://www.simantics.org/Sysdyn-1.1/EnumerationReplacement"; + public static final String Experiment = "http://www.simantics.org/Sysdyn-1.1/Experiment"; + public static final String ExportModuleTree = "http://www.simantics.org/Sysdyn-1.1/ExportModuleTree"; + public static final String Expression = "http://www.simantics.org/Sysdyn-1.1/Expression"; + public static final String Expressions = "http://www.simantics.org/Sysdyn-1.1/Expressions"; + public static final String Expressions_Inverse = "http://www.simantics.org/Sysdyn-1.1/Expressions/Inverse"; + public static final String ExternalFiles = "http://www.simantics.org/Sysdyn-1.1/ExternalFiles"; + public static final String ExternalFunctionFile = "http://www.simantics.org/Sysdyn-1.1/ExternalFunctionFile"; + public static final String Flow = "http://www.simantics.org/Sysdyn-1.1/Flow"; + public static final String FlowConnection = "http://www.simantics.org/Sysdyn-1.1/FlowConnection"; + public static final String FunctionTree = "http://www.simantics.org/Sysdyn-1.1/FunctionTree"; + public static final String GameExperiment = "http://www.simantics.org/Sysdyn-1.1/GameExperiment"; + public static final String HasActiveExpression = "http://www.simantics.org/Sysdyn-1.1/HasActiveExpression"; + public static final String HasActiveExpression_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasActiveExpression/Inverse"; + public static final String HasArrayIndexes = "http://www.simantics.org/Sysdyn-1.1/HasArrayIndexes"; + public static final String HasArrayIndexes_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasArrayIndexes/Inverse"; + public static final String HasArrayRange = "http://www.simantics.org/Sysdyn-1.1/HasArrayRange"; + public static final String HasArrayRange_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasArrayRange/Inverse"; + public static final String HasDefaultInputValue = "http://www.simantics.org/Sysdyn-1.1/HasDefaultInputValue"; + public static final String HasDefaultInputValue_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasDefaultInputValue/Inverse"; + public static final String HasEnumerationIndexes = "http://www.simantics.org/Sysdyn-1.1/HasEnumerationIndexes"; + public static final String HasEnumerationIndexes_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasEnumerationIndexes/Inverse"; + public static final String HasEquation = "http://www.simantics.org/Sysdyn-1.1/HasEquation"; + public static final String HasEquationOrEmpty = "http://www.simantics.org/Sysdyn-1.1/HasEquationOrEmpty"; + public static final String HasEquationOrEmpty_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasEquationOrEmpty/Inverse"; + public static final String HasEquation_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasEquation/Inverse"; + public static final String HasExpressions = "http://www.simantics.org/Sysdyn-1.1/HasExpressions"; + public static final String HasExpressions_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasExpressions/Inverse"; + public static final String HasExternalFile = "http://www.simantics.org/Sysdyn-1.1/HasExternalFile"; + public static final String HasExternalFile_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasExternalFile/Inverse"; + public static final String HasHead = "http://www.simantics.org/Sysdyn-1.1/HasHead"; + public static final String HasHeadTerminal = "http://www.simantics.org/Sysdyn-1.1/HasHeadTerminal"; + public static final String HasInitialEquation = "http://www.simantics.org/Sysdyn-1.1/HasInitialEquation"; + public static final String HasInitialEquation_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasInitialEquation/Inverse"; + public static final String HasLookup = "http://www.simantics.org/Sysdyn-1.1/HasLookup"; + public static final String HasLookup_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasLookup/Inverse"; + public static final String HasMaxX = "http://www.simantics.org/Sysdyn-1.1/HasMaxX"; + public static final String HasMaxX_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasMaxX/Inverse"; + public static final String HasMaxY = "http://www.simantics.org/Sysdyn-1.1/HasMaxY"; + public static final String HasMaxY_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasMaxY/Inverse"; + public static final String HasMinX = "http://www.simantics.org/Sysdyn-1.1/HasMinX"; + public static final String HasMinX_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasMinX/Inverse"; + public static final String HasMinY = "http://www.simantics.org/Sysdyn-1.1/HasMinY"; + public static final String HasMinY_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasMinY/Inverse"; + public static final String HasModelicaFunctionCode = "http://www.simantics.org/Sysdyn-1.1/HasModelicaFunctionCode"; + public static final String HasModelicaFunctionCode_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasModelicaFunctionCode/Inverse"; + public static final String HasOutputInterval = "http://www.simantics.org/Sysdyn-1.1/HasOutputInterval"; + public static final String HasOutputInterval_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasOutputInterval/Inverse"; + public static final String HasParameterFile = "http://www.simantics.org/Sysdyn-1.1/HasParameterFile"; + public static final String HasParameterFile_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasParameterFile/Inverse"; + public static final String HasRangeEnd = "http://www.simantics.org/Sysdyn-1.1/HasRangeEnd"; + public static final String HasRangeEnd_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasRangeEnd/Inverse"; + public static final String HasRangeStart = "http://www.simantics.org/Sysdyn-1.1/HasRangeStart"; + public static final String HasRangeStart_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasRangeStart/Inverse"; + public static final String HasRangeStep = "http://www.simantics.org/Sysdyn-1.1/HasRangeStep"; + public static final String HasRangeStep_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasRangeStep/Inverse"; + public static final String HasRedeclaration = "http://www.simantics.org/Sysdyn-1.1/HasRedeclaration"; + public static final String HasRedeclaration_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasRedeclaration/Inverse"; + public static final String HasResult = "http://www.simantics.org/Sysdyn-1.1/HasResult"; + public static final String HasResultFile = "http://www.simantics.org/Sysdyn-1.1/HasResultFile"; + public static final String HasResultFile_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasResultFile/Inverse"; + public static final String HasResult_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasResult/Inverse"; + public static final String HasSolver = "http://www.simantics.org/Sysdyn-1.1/HasSolver"; + public static final String HasSolver_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasSolver/Inverse"; + public static final String HasStartTime = "http://www.simantics.org/Sysdyn-1.1/HasStartTime"; + public static final String HasStartTime_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasStartTime/Inverse"; + public static final String HasStopTime = "http://www.simantics.org/Sysdyn-1.1/HasStopTime"; + public static final String HasStopTime_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasStopTime/Inverse"; + public static final String HasTail = "http://www.simantics.org/Sysdyn-1.1/HasTail"; + public static final String HasTailTerminal = "http://www.simantics.org/Sysdyn-1.1/HasTailTerminal"; + public static final String HasTextLocation = "http://www.simantics.org/Sysdyn-1.1/HasTextLocation"; + public static final String HasTextLocation_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasTextLocation/Inverse"; + public static final String HasTolerance = "http://www.simantics.org/Sysdyn-1.1/HasTolerance"; + public static final String HasTolerance_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasTolerance/Inverse"; + public static final String HasUnit = "http://www.simantics.org/Sysdyn-1.1/HasUnit"; + public static final String HasUnit_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasUnit/Inverse"; + public static final String HasValveOrientation = "http://www.simantics.org/Sysdyn-1.1/HasValveOrientation"; + public static final String HasValveOrientation_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasValveOrientation/Inverse"; + public static final String HistoryRealization = "http://www.simantics.org/Sysdyn-1.1/HistoryRealization"; + public static final String Horizontal = "http://www.simantics.org/Sysdyn-1.1/Horizontal"; + public static final String ImportModuleTree = "http://www.simantics.org/Sysdyn-1.1/ImportModuleTree"; + public static final String ImportedOntologies = "http://www.simantics.org/Sysdyn-1.1/ImportedOntologies"; + public static final String IndependentVariable = "http://www.simantics.org/Sysdyn-1.1/IndependentVariable"; + public static final String Input = "http://www.simantics.org/Sysdyn-1.1/Input"; + public static final String InputSymbol = "http://www.simantics.org/Sysdyn-1.1/InputSymbol"; + public static final String IsHeadOf = "http://www.simantics.org/Sysdyn-1.1/IsHeadOf"; + public static final String IsHeadOfTerminal = "http://www.simantics.org/Sysdyn-1.1/IsHeadOfTerminal"; + public static final String IsOutput = "http://www.simantics.org/Sysdyn-1.1/IsOutput"; + public static final String IsReplaceable = "http://www.simantics.org/Sysdyn-1.1/IsReplaceable"; + public static final String IsReplaceable_Inverse = "http://www.simantics.org/Sysdyn-1.1/IsReplaceable/Inverse"; + public static final String IsTailOf = "http://www.simantics.org/Sysdyn-1.1/IsTailOf"; + public static final String IsTailOfTerminal = "http://www.simantics.org/Sysdyn-1.1/IsTailOfTerminal"; + public static final String IssueStyle = "http://www.simantics.org/Sysdyn-1.1/IssueStyle"; + public static final String Left = "http://www.simantics.org/Sysdyn-1.1/Left"; + public static final String Location = "http://www.simantics.org/Sysdyn-1.1/Location"; + public static final String LookupExpression = "http://www.simantics.org/Sysdyn-1.1/LookupExpression"; + public static final String ModelBrowser = "http://www.simantics.org/Sysdyn-1.1/ModelBrowser"; + public static final String Module = "http://www.simantics.org/Sysdyn-1.1/Module"; + public static final String ModuleSymbol = "http://www.simantics.org/Sysdyn-1.1/ModuleSymbol"; + public static final String NormalExpression = "http://www.simantics.org/Sysdyn-1.1/NormalExpression"; + public static final String Orientation = "http://www.simantics.org/Sysdyn-1.1/Orientation"; + public static final String ParameterExpression = "http://www.simantics.org/Sysdyn-1.1/ParameterExpression"; + public static final String PieSeriesActionContext = "http://www.simantics.org/Sysdyn-1.1/PieSeriesActionContext"; + public static final String PieSeriesActionContext_Actions = "http://www.simantics.org/Sysdyn-1.1/PieSeriesActionContext/Actions"; + public static final String PieSeriesBrowseContext = "http://www.simantics.org/Sysdyn-1.1/PieSeriesBrowseContext"; + public static final String PieSeriesBrowseContext_SeriesChildRule = "http://www.simantics.org/Sysdyn-1.1/PieSeriesBrowseContext/SeriesChildRule"; + public static final String PieSeriesBrowseContext_SeriesLabelDecorationRule = "http://www.simantics.org/Sysdyn-1.1/PieSeriesBrowseContext/SeriesLabelDecorationRule"; + public static final String PieSeriesBrowseContext_SeriesLabelRule = "http://www.simantics.org/Sysdyn-1.1/PieSeriesBrowseContext/SeriesLabelRule"; + public static final String PlaybackExperiment = "http://www.simantics.org/Sysdyn-1.1/PlaybackExperiment"; + public static final String Polarity = "http://www.simantics.org/Sysdyn-1.1/Polarity"; + public static final String PolarityLocation = "http://www.simantics.org/Sysdyn-1.1/PolarityLocation"; + public static final String PolarityLocation_Inverse = "http://www.simantics.org/Sysdyn-1.1/PolarityLocation/Inverse"; + public static final String Polarity_Inverse = "http://www.simantics.org/Sysdyn-1.1/Polarity/Inverse"; + public static final String Profiles = "http://www.simantics.org/Sysdyn-1.1/Profiles"; + public static final String Profiles_IssueWarnings = "http://www.simantics.org/Sysdyn-1.1/Profiles/IssueWarnings"; + public static final String Profiles_SimulationPlaybackColours = "http://www.simantics.org/Sysdyn-1.1/Profiles/SimulationPlaybackColours"; + public static final String ProjectActionContext = "http://www.simantics.org/Sysdyn-1.1/ProjectActionContext"; + public static final String ProjectActionContext_Actions = "http://www.simantics.org/Sysdyn-1.1/ProjectActionContext/Actions"; + public static final String ProjectActionContext_Actions_NewEnumeration = "http://www.simantics.org/Sysdyn-1.1/ProjectActionContext/Actions/NewEnumeration"; + public static final String ProjectActionContext_Actions_NewFunction = "http://www.simantics.org/Sysdyn-1.1/ProjectActionContext/Actions/NewFunction"; + public static final String ProjectActionContext_Actions_NewFunctionLibrary = "http://www.simantics.org/Sysdyn-1.1/ProjectActionContext/Actions/NewFunctionLibrary"; + public static final String ProjectActionContext_Actions_NewModuleType = "http://www.simantics.org/Sysdyn-1.1/ProjectActionContext/Actions/NewModuleType"; + public static final String ProjectActionContext_Actions_NewSharedFunctionLibrary = "http://www.simantics.org/Sysdyn-1.1/ProjectActionContext/Actions/NewSharedFunctionLibrary"; + public static final String ProjectActionContext_Actions_OpenWorkbook = "http://www.simantics.org/Sysdyn-1.1/ProjectActionContext/Actions/OpenWorkbook"; + public static final String ProjectBrowseContext = "http://www.simantics.org/Sysdyn-1.1/ProjectBrowseContext"; + public static final String ProjectBrowseContext_BuiltinFunctions = "http://www.simantics.org/Sysdyn-1.1/ProjectBrowseContext/BuiltinFunctions"; + public static final String ProjectBrowseContext_FunctionsFolder = "http://www.simantics.org/Sysdyn-1.1/ProjectBrowseContext/FunctionsFolder"; + public static final String ProjectBrowseContext_ModuleContentChildRule = "http://www.simantics.org/Sysdyn-1.1/ProjectBrowseContext/ModuleContentChildRule"; + public static final String ProjectBrowseContext_ModuleSymbol = "http://www.simantics.org/Sysdyn-1.1/ProjectBrowseContext/ModuleSymbol"; + public static final String ProjectBrowseContext_ModuleTypeChildRule = "http://www.simantics.org/Sysdyn-1.1/ProjectBrowseContext/ModuleTypeChildRule"; + public static final String ProjectBrowseContext_ModuleTypeLabelRule = "http://www.simantics.org/Sysdyn-1.1/ProjectBrowseContext/ModuleTypeLabelRule"; + public static final String ProjectBrowseContext_ModulesFolder = "http://www.simantics.org/Sysdyn-1.1/ProjectBrowseContext/ModulesFolder"; + public static final String ProjectBrowseContext_SharedFunctionsFolder = "http://www.simantics.org/Sysdyn-1.1/ProjectBrowseContext/SharedFunctionsFolder"; + public static final String Redeclaration = "http://www.simantics.org/Sysdyn-1.1/Redeclaration"; + public static final String RefersTo = "http://www.simantics.org/Sysdyn-1.1/RefersTo"; + public static final String ReplacedEnumeration = "http://www.simantics.org/Sysdyn-1.1/ReplacedEnumeration"; + public static final String ReplacedEnumeration_Inverse = "http://www.simantics.org/Sysdyn-1.1/ReplacedEnumeration/Inverse"; + public static final String ReplacingEnumeration = "http://www.simantics.org/Sysdyn-1.1/ReplacingEnumeration"; + public static final String ReplacingEnumeration_Inverse = "http://www.simantics.org/Sysdyn-1.1/ReplacingEnumeration/Inverse"; + public static final String Result = "http://www.simantics.org/Sysdyn-1.1/Result"; + public static final String Right = "http://www.simantics.org/Sysdyn-1.1/Right"; + public static final String SelectedSharedFunctionLibraries = "http://www.simantics.org/Sysdyn-1.1/SelectedSharedFunctionLibraries"; + public static final String SharedFunctionOntology = "http://www.simantics.org/Sysdyn-1.1/SharedFunctionOntology"; + public static final String SharedModuleOntolofgy = "http://www.simantics.org/Sysdyn-1.1/SharedModuleOntolofgy"; + public static final String ShowEnumerationIndexInCharts = "http://www.simantics.org/Sysdyn-1.1/ShowEnumerationIndexInCharts"; + public static final String ShowEnumerationIndexInCharts_Inverse = "http://www.simantics.org/Sysdyn-1.1/ShowEnumerationIndexInCharts/Inverse"; + public static final String ShowResult = "http://www.simantics.org/Sysdyn-1.1/ShowResult"; + public static final String SimulateOnChangeExperiment = "http://www.simantics.org/Sysdyn-1.1/SimulateOnChangeExperiment"; + public static final String SimulationPlaybackProfile = "http://www.simantics.org/Sysdyn-1.1/SimulationPlaybackProfile"; + public static final String SimulationPlaybackStyle = "http://www.simantics.org/Sysdyn-1.1/SimulationPlaybackStyle"; + public static final String Stock = "http://www.simantics.org/Sysdyn-1.1/Stock"; + public static final String StockExpression = "http://www.simantics.org/Sysdyn-1.1/StockExpression"; + public static final String StockSymbol = "http://www.simantics.org/Sysdyn-1.1/StockSymbol"; + public static final String SymbolReferences = "http://www.simantics.org/Sysdyn-1.1/SymbolReferences"; + public static final String SymbolReferences_BasicSymbols = "http://www.simantics.org/Sysdyn-1.1/SymbolReferences/BasicSymbols"; + public static final String SymbolReferences_GeneralSymbols = "http://www.simantics.org/Sysdyn-1.1/SymbolReferences/GeneralSymbols"; + public static final String Symbols = "http://www.simantics.org/Sysdyn-1.1/Symbols"; + public static final String SysdynConnectionType = "http://www.simantics.org/Sysdyn-1.1/SysdynConnectionType"; + public static final String SysdynDiagramModelingRules = "http://www.simantics.org/Sysdyn-1.1/SysdynDiagramModelingRules"; + public static final String SysdynIssue = "http://www.simantics.org/Sysdyn-1.1/SysdynIssue"; + public static final String SysdynModel = "http://www.simantics.org/Sysdyn-1.1/SysdynModel"; + public static final String SysdynModelicaFunction = "http://www.simantics.org/Sysdyn-1.1/SysdynModelicaFunction"; + public static final String SysdynModelicaFunctionLibrary = "http://www.simantics.org/Sysdyn-1.1/SysdynModelicaFunctionLibrary"; + public static final String SysdynModuleLibrary = "http://www.simantics.org/Sysdyn-1.1/SysdynModuleLibrary"; + public static final String SysdynOperationBrowser = "http://www.simantics.org/Sysdyn-1.1/SysdynOperationBrowser"; + public static final String SysdynTerminal = "http://www.simantics.org/Sysdyn-1.1/SysdynTerminal"; + public static final String Top = "http://www.simantics.org/Sysdyn-1.1/Top"; + public static final String UsedVariableIndexes = "http://www.simantics.org/Sysdyn-1.1/UsedVariableIndexes"; + public static final String Validations = "http://www.simantics.org/Sysdyn-1.1/Validations"; + public static final String Validations_Dependencies = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies"; + public static final String Validations_Dependencies_DependencyConnectionsIssueSource = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/DependencyConnectionsIssueSource"; + public static final String Validations_Dependencies_MissingDependencyConnectionsIssueSource = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/MissingDependencyConnectionsIssueSource"; + public static final String Validations_Dependencies_dependencySynchronizer = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/dependencySynchronizer"; + public static final String Validations_Dependencies_dependencyValidator = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/dependencyValidator"; + public static final String Validations_Dependencies_missingDependencyValidator = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/missingDependencyValidator"; + public static final String Validations_Dependencies_missingLinkIssueDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/missingLinkIssueDescription"; + public static final String Validations_Dependencies_noSuchVariableIssueDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/noSuchVariableIssueDescription"; + public static final String Validations_Dependencies_unusedDependencyIssueDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Dependencies/unusedDependencyIssueDescription"; + public static final String Validations_DependencyConstraint = "http://www.simantics.org/Sysdyn-1.1/Validations/DependencyConstraint"; + public static final String Validations_ExpressionConstraint = "http://www.simantics.org/Sysdyn-1.1/Validations/ExpressionConstraint"; + public static final String Validations_ExpressionIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/ExpressionIssue"; + public static final String Validations_Expressions = "http://www.simantics.org/Sysdyn-1.1/Validations/Expressions"; + public static final String Validations_Expressions_ExpressionIssueSource = "http://www.simantics.org/Sysdyn-1.1/Validations/Expressions/ExpressionIssueSource"; + public static final String Validations_Expressions_expressionIssueDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Expressions/expressionIssueDescription"; + public static final String Validations_Expressions_expressionSynchronizer = "http://www.simantics.org/Sysdyn-1.1/Validations/Expressions/expressionSynchronizer"; + public static final String Validations_Expressions_expressionValidator = "http://www.simantics.org/Sysdyn-1.1/Validations/Expressions/expressionValidator"; + public static final String Validations_Functions = "http://www.simantics.org/Sysdyn-1.1/Validations/Functions"; + public static final String Validations_Functions_baseRealizationFunction = "http://www.simantics.org/Sysdyn-1.1/Validations/Functions/baseRealizationFunction"; + public static final String Validations_MissingDependencyConstraint = "http://www.simantics.org/Sysdyn-1.1/Validations/MissingDependencyConstraint"; + public static final String Validations_MissingLinkIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/MissingLinkIssue"; + public static final String Validations_NoSuchVariableIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/NoSuchVariableIssue"; + public static final String Validations_UnusedDependencyIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/UnusedDependencyIssue"; + public static final String Validations_constraint = "http://www.simantics.org/Sysdyn-1.1/Validations/constraint"; + public static final String Validations_issue = "http://www.simantics.org/Sysdyn-1.1/Validations/issue"; + public static final String Validations_listeningConstraint = "http://www.simantics.org/Sysdyn-1.1/Validations/listeningConstraint"; + public static final String Valve = "http://www.simantics.org/Sysdyn-1.1/Valve"; + public static final String ValveSymbol = "http://www.simantics.org/Sysdyn-1.1/ValveSymbol"; + public static final String Variable = "http://www.simantics.org/Sysdyn-1.1/Variable"; + public static final String Variable_Type = "http://www.simantics.org/Sysdyn-1.1/Variable/Type"; + public static final String Variable_Type_Inverse = "http://www.simantics.org/Sysdyn-1.1/Variable/Type/Inverse"; + public static final String Vertical = "http://www.simantics.org/Sysdyn-1.1/Vertical"; + public static final String WithLookupExpression = "http://www.simantics.org/Sysdyn-1.1/WithLookupExpression"; + public static final String angle = "http://www.simantics.org/Sysdyn-1.1/angle"; + public static final String angle_Inverse = "http://www.simantics.org/Sysdyn-1.1/angle/Inverse"; + } + + public static Resource getResourceOrNull(ReadGraph graph, String uri) { + try { + return graph.getResource(uri); + } catch(DatabaseException e) { + System.err.println(e.getMessage()); + return null; + } + } + + public SysdynResource(ReadGraph graph) { + AdditionalSymbols = getResourceOrNull(graph, URIs.AdditionalSymbols); + AdditionalSymbols_Text = getResourceOrNull(graph, URIs.AdditionalSymbols_Text); + AllElementsGroup = getResourceOrNull(graph, URIs.AllElementsGroup); + ArrayIndexes = getResourceOrNull(graph, URIs.ArrayIndexes); + ArrayIndexes_Inverse = getResourceOrNull(graph, URIs.ArrayIndexes_Inverse); + Auxiliary = getResourceOrNull(graph, URIs.Auxiliary); + AuxiliarySymbol = getResourceOrNull(graph, URIs.AuxiliarySymbol); + AvailableSharedFunctionLibraries = getResourceOrNull(graph, URIs.AvailableSharedFunctionLibraries); + AvailableVariableIndexes = getResourceOrNull(graph, URIs.AvailableVariableIndexes); + BarSeriesActionContext = getResourceOrNull(graph, URIs.BarSeriesActionContext); + BarSeriesActionContext_Actions = getResourceOrNull(graph, URIs.BarSeriesActionContext_Actions); + BarSeriesBrowseContext = getResourceOrNull(graph, URIs.BarSeriesBrowseContext); + BarSeriesBrowseContext_SeriesChildRule = getResourceOrNull(graph, URIs.BarSeriesBrowseContext_SeriesChildRule); + BarSeriesBrowseContext_SeriesLabelDecorationRule = getResourceOrNull(graph, URIs.BarSeriesBrowseContext_SeriesLabelDecorationRule); + BarSeriesBrowseContext_SeriesLabelRule = getResourceOrNull(graph, URIs.BarSeriesBrowseContext_SeriesLabelRule); + BasicExperiment = getResourceOrNull(graph, URIs.BasicExperiment); + Bottom = getResourceOrNull(graph, URIs.Bottom); + Browser = getResourceOrNull(graph, URIs.Browser); + Built$in_Functions = getResourceOrNull(graph, URIs.Built$in_Functions); + Built$in_Functions_Vensim_Functions = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions); + Built$in_Functions_Vensim_Functions_ABS = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_ABS); + Built$in_Functions_Vensim_Functions_COS = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_COS); + Built$in_Functions_Vensim_Functions_COSH = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_COSH); + Built$in_Functions_Vensim_Functions_EXP = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_EXP); + Built$in_Functions_Vensim_Functions_IFTHENELSE = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_IFTHENELSE); + Built$in_Functions_Vensim_Functions_LN = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_LN); + Built$in_Functions_Vensim_Functions_MAX = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_MAX); + Built$in_Functions_Vensim_Functions_MIN = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_MIN); + Built$in_Functions_Vensim_Functions_MODULO = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_MODULO); + Built$in_Functions_Vensim_Functions_PULSE = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_PULSE); + Built$in_Functions_Vensim_Functions_RAMP = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_RAMP); + Built$in_Functions_Vensim_Functions_SIN = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_SIN); + Built$in_Functions_Vensim_Functions_SINH = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_SINH); + Built$in_Functions_Vensim_Functions_SQRT = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_SQRT); + Built$in_Functions_Vensim_Functions_STEP = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_STEP); + Built$in_Functions_Vensim_Functions_TAN = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_TAN); + Built$in_Functions_Vensim_Functions_TANH = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_TANH); + Built$in_Functions_Vensim_Functions_XIDZ = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_XIDZ); + Built$in_Functions_Vensim_Functions_ZIDZ = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_ZIDZ); + Built$in_Functions_interpolate = getResourceOrNull(graph, URIs.Built$in_Functions_interpolate); + Built$in_Functions_interpolateFull = getResourceOrNull(graph, URIs.Built$in_Functions_interpolateFull); + Built$in_Functions_xidz = getResourceOrNull(graph, URIs.Built$in_Functions_xidz); + Built$in_Functions_zidz = getResourceOrNull(graph, URIs.Built$in_Functions_zidz); + Center = getResourceOrNull(graph, URIs.Center); + ChartAxisAndVariablesActionContext = getResourceOrNull(graph, URIs.ChartAxisAndVariablesActionContext); + ChartAxisAndVariablesActionContext_Actions = getResourceOrNull(graph, URIs.ChartAxisAndVariablesActionContext_Actions); + ChartAxisAndVariablesActionContext_Actions_AxisDropAction = getResourceOrNull(graph, URIs.ChartAxisAndVariablesActionContext_Actions_AxisDropAction); + ChartAxisAndVariablesActionContext_Actions_SeriesDropAction = getResourceOrNull(graph, URIs.ChartAxisAndVariablesActionContext_Actions_SeriesDropAction); + ChartAxisAndVariablesBrowseContext = getResourceOrNull(graph, URIs.ChartAxisAndVariablesBrowseContext); + ChartAxisAndVariablesBrowseContext_AxisChildRule = getResourceOrNull(graph, URIs.ChartAxisAndVariablesBrowseContext_AxisChildRule); + ChartAxisAndVariablesBrowseContext_AxisLabelRule = getResourceOrNull(graph, URIs.ChartAxisAndVariablesBrowseContext_AxisLabelRule); + ChartAxisAndVariablesBrowseContext_SeriesLabelDecorationRule = getResourceOrNull(graph, URIs.ChartAxisAndVariablesBrowseContext_SeriesLabelDecorationRule); + ChartAxisAndVariablesBrowseContext_SeriesLabelRule = getResourceOrNull(graph, URIs.ChartAxisAndVariablesBrowseContext_SeriesLabelRule); + ChartAxisAndVariablesBrowseContext_VariableChildRule = getResourceOrNull(graph, URIs.ChartAxisAndVariablesBrowseContext_VariableChildRule); + Cloud = getResourceOrNull(graph, URIs.Cloud); + CloudSymbol = getResourceOrNull(graph, URIs.CloudSymbol); + Configuration = getResourceOrNull(graph, URIs.Configuration); + ConfigurationDiagram = getResourceOrNull(graph, URIs.ConfigurationDiagram); + ConfigurationDiagramTemplate = getResourceOrNull(graph, URIs.ConfigurationDiagramTemplate); + ConstantExpression = getResourceOrNull(graph, URIs.ConstantExpression); + DefaultProfile = getResourceOrNull(graph, URIs.DefaultProfile); + DefaultRealization = getResourceOrNull(graph, URIs.DefaultRealization); + DelayExpression = getResourceOrNull(graph, URIs.DelayExpression); + DelayExpression_delayTime = getResourceOrNull(graph, URIs.DelayExpression_delayTime); + DelayExpression_delayTime_Inverse = getResourceOrNull(graph, URIs.DelayExpression_delayTime_Inverse); + DelayExpression_expression = getResourceOrNull(graph, URIs.DelayExpression_expression); + DelayExpression_expression_Inverse = getResourceOrNull(graph, URIs.DelayExpression_expression_Inverse); + DelayExpression_initialValue = getResourceOrNull(graph, URIs.DelayExpression_initialValue); + DelayExpression_initialValue_Inverse = getResourceOrNull(graph, URIs.DelayExpression_initialValue_Inverse); + DelayExpression_order = getResourceOrNull(graph, URIs.DelayExpression_order); + DelayExpression_order_Inverse = getResourceOrNull(graph, URIs.DelayExpression_order_Inverse); + Dependency = getResourceOrNull(graph, URIs.Dependency); + DependencyConnection = getResourceOrNull(graph, URIs.DependencyConnection); + DiagramToCompositeMapping = getResourceOrNull(graph, URIs.DiagramToCompositeMapping); + Enumeration = getResourceOrNull(graph, URIs.Enumeration); + EnumerationIndex = getResourceOrNull(graph, URIs.EnumerationIndex); + EnumerationIndexes = getResourceOrNull(graph, URIs.EnumerationIndexes); + EnumerationIndexes_Inverse = getResourceOrNull(graph, URIs.EnumerationIndexes_Inverse); + EnumerationReplacement = getResourceOrNull(graph, URIs.EnumerationReplacement); + Experiment = getResourceOrNull(graph, URIs.Experiment); + ExportModuleTree = getResourceOrNull(graph, URIs.ExportModuleTree); + Expression = getResourceOrNull(graph, URIs.Expression); + Expressions = getResourceOrNull(graph, URIs.Expressions); + Expressions_Inverse = getResourceOrNull(graph, URIs.Expressions_Inverse); + ExternalFiles = getResourceOrNull(graph, URIs.ExternalFiles); + ExternalFunctionFile = getResourceOrNull(graph, URIs.ExternalFunctionFile); + Flow = getResourceOrNull(graph, URIs.Flow); + FlowConnection = getResourceOrNull(graph, URIs.FlowConnection); + FunctionTree = getResourceOrNull(graph, URIs.FunctionTree); + GameExperiment = getResourceOrNull(graph, URIs.GameExperiment); + HasActiveExpression = getResourceOrNull(graph, URIs.HasActiveExpression); + HasActiveExpression_Inverse = getResourceOrNull(graph, URIs.HasActiveExpression_Inverse); + HasArrayIndexes = getResourceOrNull(graph, URIs.HasArrayIndexes); + HasArrayIndexes_Inverse = getResourceOrNull(graph, URIs.HasArrayIndexes_Inverse); + HasArrayRange = getResourceOrNull(graph, URIs.HasArrayRange); + HasArrayRange_Inverse = getResourceOrNull(graph, URIs.HasArrayRange_Inverse); + HasDefaultInputValue = getResourceOrNull(graph, URIs.HasDefaultInputValue); + HasDefaultInputValue_Inverse = getResourceOrNull(graph, URIs.HasDefaultInputValue_Inverse); + HasEnumerationIndexes = getResourceOrNull(graph, URIs.HasEnumerationIndexes); + HasEnumerationIndexes_Inverse = getResourceOrNull(graph, URIs.HasEnumerationIndexes_Inverse); + HasEquation = getResourceOrNull(graph, URIs.HasEquation); + HasEquationOrEmpty = getResourceOrNull(graph, URIs.HasEquationOrEmpty); + HasEquationOrEmpty_Inverse = getResourceOrNull(graph, URIs.HasEquationOrEmpty_Inverse); + HasEquation_Inverse = getResourceOrNull(graph, URIs.HasEquation_Inverse); + HasExpressions = getResourceOrNull(graph, URIs.HasExpressions); + HasExpressions_Inverse = getResourceOrNull(graph, URIs.HasExpressions_Inverse); + HasExternalFile = getResourceOrNull(graph, URIs.HasExternalFile); + HasExternalFile_Inverse = getResourceOrNull(graph, URIs.HasExternalFile_Inverse); + HasHead = getResourceOrNull(graph, URIs.HasHead); + HasHeadTerminal = getResourceOrNull(graph, URIs.HasHeadTerminal); + HasInitialEquation = getResourceOrNull(graph, URIs.HasInitialEquation); + HasInitialEquation_Inverse = getResourceOrNull(graph, URIs.HasInitialEquation_Inverse); + HasLookup = getResourceOrNull(graph, URIs.HasLookup); + HasLookup_Inverse = getResourceOrNull(graph, URIs.HasLookup_Inverse); + HasMaxX = getResourceOrNull(graph, URIs.HasMaxX); + HasMaxX_Inverse = getResourceOrNull(graph, URIs.HasMaxX_Inverse); + HasMaxY = getResourceOrNull(graph, URIs.HasMaxY); + HasMaxY_Inverse = getResourceOrNull(graph, URIs.HasMaxY_Inverse); + HasMinX = getResourceOrNull(graph, URIs.HasMinX); + HasMinX_Inverse = getResourceOrNull(graph, URIs.HasMinX_Inverse); + HasMinY = getResourceOrNull(graph, URIs.HasMinY); + HasMinY_Inverse = getResourceOrNull(graph, URIs.HasMinY_Inverse); + HasModelicaFunctionCode = getResourceOrNull(graph, URIs.HasModelicaFunctionCode); + HasModelicaFunctionCode_Inverse = getResourceOrNull(graph, URIs.HasModelicaFunctionCode_Inverse); + HasOutputInterval = getResourceOrNull(graph, URIs.HasOutputInterval); + HasOutputInterval_Inverse = getResourceOrNull(graph, URIs.HasOutputInterval_Inverse); + HasParameterFile = getResourceOrNull(graph, URIs.HasParameterFile); + HasParameterFile_Inverse = getResourceOrNull(graph, URIs.HasParameterFile_Inverse); + HasRangeEnd = getResourceOrNull(graph, URIs.HasRangeEnd); + HasRangeEnd_Inverse = getResourceOrNull(graph, URIs.HasRangeEnd_Inverse); + HasRangeStart = getResourceOrNull(graph, URIs.HasRangeStart); + HasRangeStart_Inverse = getResourceOrNull(graph, URIs.HasRangeStart_Inverse); + HasRangeStep = getResourceOrNull(graph, URIs.HasRangeStep); + HasRangeStep_Inverse = getResourceOrNull(graph, URIs.HasRangeStep_Inverse); + HasRedeclaration = getResourceOrNull(graph, URIs.HasRedeclaration); + HasRedeclaration_Inverse = getResourceOrNull(graph, URIs.HasRedeclaration_Inverse); + HasResult = getResourceOrNull(graph, URIs.HasResult); + HasResultFile = getResourceOrNull(graph, URIs.HasResultFile); + HasResultFile_Inverse = getResourceOrNull(graph, URIs.HasResultFile_Inverse); + HasResult_Inverse = getResourceOrNull(graph, URIs.HasResult_Inverse); + HasSolver = getResourceOrNull(graph, URIs.HasSolver); + HasSolver_Inverse = getResourceOrNull(graph, URIs.HasSolver_Inverse); + HasStartTime = getResourceOrNull(graph, URIs.HasStartTime); + HasStartTime_Inverse = getResourceOrNull(graph, URIs.HasStartTime_Inverse); + HasStopTime = getResourceOrNull(graph, URIs.HasStopTime); + HasStopTime_Inverse = getResourceOrNull(graph, URIs.HasStopTime_Inverse); + HasTail = getResourceOrNull(graph, URIs.HasTail); + HasTailTerminal = getResourceOrNull(graph, URIs.HasTailTerminal); + HasTextLocation = getResourceOrNull(graph, URIs.HasTextLocation); + HasTextLocation_Inverse = getResourceOrNull(graph, URIs.HasTextLocation_Inverse); + HasTolerance = getResourceOrNull(graph, URIs.HasTolerance); + HasTolerance_Inverse = getResourceOrNull(graph, URIs.HasTolerance_Inverse); + HasUnit = getResourceOrNull(graph, URIs.HasUnit); + HasUnit_Inverse = getResourceOrNull(graph, URIs.HasUnit_Inverse); + HasValveOrientation = getResourceOrNull(graph, URIs.HasValveOrientation); + HasValveOrientation_Inverse = getResourceOrNull(graph, URIs.HasValveOrientation_Inverse); + HistoryRealization = getResourceOrNull(graph, URIs.HistoryRealization); + Horizontal = getResourceOrNull(graph, URIs.Horizontal); + ImportModuleTree = getResourceOrNull(graph, URIs.ImportModuleTree); + ImportedOntologies = getResourceOrNull(graph, URIs.ImportedOntologies); + IndependentVariable = getResourceOrNull(graph, URIs.IndependentVariable); + Input = getResourceOrNull(graph, URIs.Input); + InputSymbol = getResourceOrNull(graph, URIs.InputSymbol); + IsHeadOf = getResourceOrNull(graph, URIs.IsHeadOf); + IsHeadOfTerminal = getResourceOrNull(graph, URIs.IsHeadOfTerminal); + IsOutput = getResourceOrNull(graph, URIs.IsOutput); + IsReplaceable = getResourceOrNull(graph, URIs.IsReplaceable); + IsReplaceable_Inverse = getResourceOrNull(graph, URIs.IsReplaceable_Inverse); + IsTailOf = getResourceOrNull(graph, URIs.IsTailOf); + IsTailOfTerminal = getResourceOrNull(graph, URIs.IsTailOfTerminal); + IssueStyle = getResourceOrNull(graph, URIs.IssueStyle); + Left = getResourceOrNull(graph, URIs.Left); + Location = getResourceOrNull(graph, URIs.Location); + LookupExpression = getResourceOrNull(graph, URIs.LookupExpression); + ModelBrowser = getResourceOrNull(graph, URIs.ModelBrowser); + Module = getResourceOrNull(graph, URIs.Module); + ModuleSymbol = getResourceOrNull(graph, URIs.ModuleSymbol); + NormalExpression = getResourceOrNull(graph, URIs.NormalExpression); + Orientation = getResourceOrNull(graph, URIs.Orientation); + ParameterExpression = getResourceOrNull(graph, URIs.ParameterExpression); + PieSeriesActionContext = getResourceOrNull(graph, URIs.PieSeriesActionContext); + PieSeriesActionContext_Actions = getResourceOrNull(graph, URIs.PieSeriesActionContext_Actions); + PieSeriesBrowseContext = getResourceOrNull(graph, URIs.PieSeriesBrowseContext); + PieSeriesBrowseContext_SeriesChildRule = getResourceOrNull(graph, URIs.PieSeriesBrowseContext_SeriesChildRule); + PieSeriesBrowseContext_SeriesLabelDecorationRule = getResourceOrNull(graph, URIs.PieSeriesBrowseContext_SeriesLabelDecorationRule); + PieSeriesBrowseContext_SeriesLabelRule = getResourceOrNull(graph, URIs.PieSeriesBrowseContext_SeriesLabelRule); + PlaybackExperiment = getResourceOrNull(graph, URIs.PlaybackExperiment); + Polarity = getResourceOrNull(graph, URIs.Polarity); + PolarityLocation = getResourceOrNull(graph, URIs.PolarityLocation); + PolarityLocation_Inverse = getResourceOrNull(graph, URIs.PolarityLocation_Inverse); + Polarity_Inverse = getResourceOrNull(graph, URIs.Polarity_Inverse); + Profiles = getResourceOrNull(graph, URIs.Profiles); + Profiles_IssueWarnings = getResourceOrNull(graph, URIs.Profiles_IssueWarnings); + Profiles_SimulationPlaybackColours = getResourceOrNull(graph, URIs.Profiles_SimulationPlaybackColours); + ProjectActionContext = getResourceOrNull(graph, URIs.ProjectActionContext); + ProjectActionContext_Actions = getResourceOrNull(graph, URIs.ProjectActionContext_Actions); + ProjectActionContext_Actions_NewEnumeration = getResourceOrNull(graph, URIs.ProjectActionContext_Actions_NewEnumeration); + ProjectActionContext_Actions_NewFunction = getResourceOrNull(graph, URIs.ProjectActionContext_Actions_NewFunction); + ProjectActionContext_Actions_NewFunctionLibrary = getResourceOrNull(graph, URIs.ProjectActionContext_Actions_NewFunctionLibrary); + ProjectActionContext_Actions_NewModuleType = getResourceOrNull(graph, URIs.ProjectActionContext_Actions_NewModuleType); + ProjectActionContext_Actions_NewSharedFunctionLibrary = getResourceOrNull(graph, URIs.ProjectActionContext_Actions_NewSharedFunctionLibrary); + ProjectActionContext_Actions_OpenWorkbook = getResourceOrNull(graph, URIs.ProjectActionContext_Actions_OpenWorkbook); + ProjectBrowseContext = getResourceOrNull(graph, URIs.ProjectBrowseContext); + ProjectBrowseContext_BuiltinFunctions = getResourceOrNull(graph, URIs.ProjectBrowseContext_BuiltinFunctions); + ProjectBrowseContext_FunctionsFolder = getResourceOrNull(graph, URIs.ProjectBrowseContext_FunctionsFolder); + ProjectBrowseContext_ModuleContentChildRule = getResourceOrNull(graph, URIs.ProjectBrowseContext_ModuleContentChildRule); + ProjectBrowseContext_ModuleSymbol = getResourceOrNull(graph, URIs.ProjectBrowseContext_ModuleSymbol); + ProjectBrowseContext_ModuleTypeChildRule = getResourceOrNull(graph, URIs.ProjectBrowseContext_ModuleTypeChildRule); + ProjectBrowseContext_ModuleTypeLabelRule = getResourceOrNull(graph, URIs.ProjectBrowseContext_ModuleTypeLabelRule); + ProjectBrowseContext_ModulesFolder = getResourceOrNull(graph, URIs.ProjectBrowseContext_ModulesFolder); + ProjectBrowseContext_SharedFunctionsFolder = getResourceOrNull(graph, URIs.ProjectBrowseContext_SharedFunctionsFolder); + Redeclaration = getResourceOrNull(graph, URIs.Redeclaration); + RefersTo = getResourceOrNull(graph, URIs.RefersTo); + ReplacedEnumeration = getResourceOrNull(graph, URIs.ReplacedEnumeration); + ReplacedEnumeration_Inverse = getResourceOrNull(graph, URIs.ReplacedEnumeration_Inverse); + ReplacingEnumeration = getResourceOrNull(graph, URIs.ReplacingEnumeration); + ReplacingEnumeration_Inverse = getResourceOrNull(graph, URIs.ReplacingEnumeration_Inverse); + Result = getResourceOrNull(graph, URIs.Result); + Right = getResourceOrNull(graph, URIs.Right); + SelectedSharedFunctionLibraries = getResourceOrNull(graph, URIs.SelectedSharedFunctionLibraries); + SharedFunctionOntology = getResourceOrNull(graph, URIs.SharedFunctionOntology); + SharedModuleOntolofgy = getResourceOrNull(graph, URIs.SharedModuleOntolofgy); + ShowEnumerationIndexInCharts = getResourceOrNull(graph, URIs.ShowEnumerationIndexInCharts); + ShowEnumerationIndexInCharts_Inverse = getResourceOrNull(graph, URIs.ShowEnumerationIndexInCharts_Inverse); + ShowResult = getResourceOrNull(graph, URIs.ShowResult); + SimulateOnChangeExperiment = getResourceOrNull(graph, URIs.SimulateOnChangeExperiment); + SimulationPlaybackProfile = getResourceOrNull(graph, URIs.SimulationPlaybackProfile); + SimulationPlaybackStyle = getResourceOrNull(graph, URIs.SimulationPlaybackStyle); + Stock = getResourceOrNull(graph, URIs.Stock); + StockExpression = getResourceOrNull(graph, URIs.StockExpression); + StockSymbol = getResourceOrNull(graph, URIs.StockSymbol); + SymbolReferences = getResourceOrNull(graph, URIs.SymbolReferences); + SymbolReferences_BasicSymbols = getResourceOrNull(graph, URIs.SymbolReferences_BasicSymbols); + SymbolReferences_GeneralSymbols = getResourceOrNull(graph, URIs.SymbolReferences_GeneralSymbols); + Symbols = getResourceOrNull(graph, URIs.Symbols); + SysdynConnectionType = getResourceOrNull(graph, URIs.SysdynConnectionType); + SysdynDiagramModelingRules = getResourceOrNull(graph, URIs.SysdynDiagramModelingRules); + SysdynIssue = getResourceOrNull(graph, URIs.SysdynIssue); + SysdynModel = getResourceOrNull(graph, URIs.SysdynModel); + SysdynModelicaFunction = getResourceOrNull(graph, URIs.SysdynModelicaFunction); + SysdynModelicaFunctionLibrary = getResourceOrNull(graph, URIs.SysdynModelicaFunctionLibrary); + SysdynModuleLibrary = getResourceOrNull(graph, URIs.SysdynModuleLibrary); + SysdynOperationBrowser = getResourceOrNull(graph, URIs.SysdynOperationBrowser); + SysdynTerminal = getResourceOrNull(graph, URIs.SysdynTerminal); + Top = getResourceOrNull(graph, URIs.Top); + UsedVariableIndexes = getResourceOrNull(graph, URIs.UsedVariableIndexes); + Validations = getResourceOrNull(graph, URIs.Validations); + Validations_Dependencies = getResourceOrNull(graph, URIs.Validations_Dependencies); + Validations_Dependencies_DependencyConnectionsIssueSource = getResourceOrNull(graph, URIs.Validations_Dependencies_DependencyConnectionsIssueSource); + Validations_Dependencies_MissingDependencyConnectionsIssueSource = getResourceOrNull(graph, URIs.Validations_Dependencies_MissingDependencyConnectionsIssueSource); + Validations_Dependencies_dependencySynchronizer = getResourceOrNull(graph, URIs.Validations_Dependencies_dependencySynchronizer); + Validations_Dependencies_dependencyValidator = getResourceOrNull(graph, URIs.Validations_Dependencies_dependencyValidator); + Validations_Dependencies_missingDependencyValidator = getResourceOrNull(graph, URIs.Validations_Dependencies_missingDependencyValidator); + Validations_Dependencies_missingLinkIssueDescription = getResourceOrNull(graph, URIs.Validations_Dependencies_missingLinkIssueDescription); + Validations_Dependencies_noSuchVariableIssueDescription = getResourceOrNull(graph, URIs.Validations_Dependencies_noSuchVariableIssueDescription); + Validations_Dependencies_unusedDependencyIssueDescription = getResourceOrNull(graph, URIs.Validations_Dependencies_unusedDependencyIssueDescription); + Validations_DependencyConstraint = getResourceOrNull(graph, URIs.Validations_DependencyConstraint); + Validations_ExpressionConstraint = getResourceOrNull(graph, URIs.Validations_ExpressionConstraint); + Validations_ExpressionIssue = getResourceOrNull(graph, URIs.Validations_ExpressionIssue); + Validations_Expressions = getResourceOrNull(graph, URIs.Validations_Expressions); + Validations_Expressions_ExpressionIssueSource = getResourceOrNull(graph, URIs.Validations_Expressions_ExpressionIssueSource); + Validations_Expressions_expressionIssueDescription = getResourceOrNull(graph, URIs.Validations_Expressions_expressionIssueDescription); + Validations_Expressions_expressionSynchronizer = getResourceOrNull(graph, URIs.Validations_Expressions_expressionSynchronizer); + Validations_Expressions_expressionValidator = getResourceOrNull(graph, URIs.Validations_Expressions_expressionValidator); + Validations_Functions = getResourceOrNull(graph, URIs.Validations_Functions); + Validations_Functions_baseRealizationFunction = getResourceOrNull(graph, URIs.Validations_Functions_baseRealizationFunction); + Validations_MissingDependencyConstraint = getResourceOrNull(graph, URIs.Validations_MissingDependencyConstraint); + Validations_MissingLinkIssue = getResourceOrNull(graph, URIs.Validations_MissingLinkIssue); + Validations_NoSuchVariableIssue = getResourceOrNull(graph, URIs.Validations_NoSuchVariableIssue); + Validations_UnusedDependencyIssue = getResourceOrNull(graph, URIs.Validations_UnusedDependencyIssue); + Validations_constraint = getResourceOrNull(graph, URIs.Validations_constraint); + Validations_issue = getResourceOrNull(graph, URIs.Validations_issue); + Validations_listeningConstraint = getResourceOrNull(graph, URIs.Validations_listeningConstraint); + Valve = getResourceOrNull(graph, URIs.Valve); + ValveSymbol = getResourceOrNull(graph, URIs.ValveSymbol); + Variable = getResourceOrNull(graph, URIs.Variable); + Variable_Type = getResourceOrNull(graph, URIs.Variable_Type); + Variable_Type_Inverse = getResourceOrNull(graph, URIs.Variable_Type_Inverse); + Vertical = getResourceOrNull(graph, URIs.Vertical); + WithLookupExpression = getResourceOrNull(graph, URIs.WithLookupExpression); + angle = getResourceOrNull(graph, URIs.angle); + angle_Inverse = getResourceOrNull(graph, URIs.angle_Inverse); + } + + public static SysdynResource getInstance(ReadGraph graph) { + Session session = graph.getSession(); + SysdynResource ret = session.peekService(SysdynResource.class); + if(ret == null) { + QueryControl qc = graph.getService(QueryControl.class); + ret = new SysdynResource(qc.getIndependentGraph(graph)); + session.registerService(SysdynResource.class, ret); + } + return ret; + } + + public static SysdynResource getInstance(Session session) throws DatabaseException { + SysdynResource ret = session.peekService(SysdynResource.class); + if(ret == null) { + ret = session.syncRequest(new Read() { + public SysdynResource perform(ReadGraph graph) throws DatabaseException { + QueryControl qc = graph.getService(QueryControl.class); + return new SysdynResource(qc.getIndependentGraph(graph)); + } + }); + session.registerService(SysdynResource.class, ret); + } + return ret; + } + +} + diff --git a/stable/org.simantics.sysdyn.ontology/testGraph/Cancer.pgraph.keep b/stable/org.simantics.sysdyn.ontology/testGraph/Cancer.pgraph.keep new file mode 100644 index 00000000..42efd793 --- /dev/null +++ b/stable/org.simantics.sysdyn.ontology/testGraph/Cancer.pgraph.keep @@ -0,0 +1,6820 @@ +L0 = +G2D = +STR = +DIA = +SIMU = +MOD = +SYSDYN = +PROJ = + +//###################################################################### +//# Example work model with two modules +//###################################################################### + +WM = : PROJ.Project + PROJ.HasFeature _ : PROJ.FeatureSpec + PROJ.HasGroupId "org.simantics.sysdyn.feature.group" + L0.PartOf + +TAGS = WM.Tags : L0.Library + +//WM.dependency : L0.Template +// @template %type %head %tail %angle +// %type +// @L0.tag TAGS.AdminIsVisible +// @L0.tag TAGS.AdminIsFocusable +// STR.HasConnectionType SYSDYN.SysdynConnectionType +// SYSDYN.angle %angle +// DIA.HasArrowConnector _ : DIA.Connector +// SYSDYN.HasHeadTerminal %head +// DIA.AreConnected _ : DIA.Connector +// SYSDYN.HasTailTerminal %tail +// DIA.IsPlainConnectorOf %type +// +//WM.flow : L0.Template +// @template %type %head %tail +// %type +// @L0.tag TAGS.AdminIsVisible +// @L0.tag TAGS.AdminIsFocusable +// STR.HasConnectionType SYSDYN.SysdynConnectionType +// DIA.HasArrowConnector _ : DIA.Connector +// SYSDYN.HasHeadTerminal %head +// DIA.AreConnected _ : DIA.Connector +// SYSDYN.HasTailTerminal %tail +// DIA.IsPlainConnectorOf %type +// +//WM.conf_dependency : L0.Template +// @template %type %head %tail +// %type +// @L0.tag MOD.Mapped +// SYSDYN.HasHead %head +// SYSDYN.HasTail %tail +// +//WM.conf_dependency_ref : L0.Template +// @template %type %head %tail %ref +// %type +// @L0.tag MOD.Mapped +// SYSDYN.HasHead %head +// SYSDYN.HasTail %tail +// SYSDYN.RefersTo %ref + +WM.CancerModel : SYSDYN.SysdynModel + L0.HasLabel "Cancer Model" + SIMU.HasConfiguration CMC + SYSDYN.HasStartTime 0.0 + SYSDYN.HasStopTime 24.0 + +WM.CancerModel.Experiment : SYSDYN.Experiment + L0.HasLabel "Experiment" + +CMC = WM.CancerModel.CancerModelConfiguration : SYSDYN.Configuration + L0.HasLabel "CancerModelConfiguration" + +CMC.LungCProgressIAIVRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIAIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIAIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIAIVNos')" + +CMC.LungCT1Progresses : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCNotProgressing1[Type,Stage,Gender,Age]*LungCT1ProgressesRate[Type,Stage,Age,Gender]" +CMC.LungCProgressIAIB : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgressIAIBRate[Type,Age,Gender]*LungCsIANoD[Type,Gender,Age]" +CMC.LungCT1Death : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCT1Disabling[Type,Stage,Gender,Age]*LungCT1DeathRate[Type,Stage,Age,Gender]" +CMC.LungCHealthyPopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCHealthy[Gender,Age]*LungCModelPopCorrectionFactor[Gender,Age]" +CMC.LungCsIADiagnosisRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIANos')" + +CMC.LungCProgress03IV : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgress03IVRate[Type,Age,Gender]*LungCs03[Type,Gender,Age]" +CMC.LungCsIIIBNoDAgeing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCsIIIBNoD[Type,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCsIIIBNoD[Type,Gender,Age], -1) else -LungCsIIIBNoD[Type,Gender,Age]+VECTOR_MAP(LungCsIIIBNoD[Type,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCProgressIBIVRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIBIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIBIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIBIVNos')" + +CMC.LungCOutputs02NosDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs02Diagnosis[NotSmoker,Gender!,Age!])" + +CMC.LungCProgressIIAIV : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgressIIAIVRate[Type,Age,Gender]*LungCsIIANoD[Type,Gender,Age]" +CMC.LungCTherapy1Mortality : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCFirstTreatmentRate*(LungCD[Type,Stage,Gender,Age]*LungCTherapy1Ratio[Type,Stage,Age,Gender])*LungCTherapy1MortalityRatio/100" +CMC.LungCCured1PopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCCured1[Type,Stage,Gender,Age]" +CMC.LungCProgress01IV : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgress01IVRate[Type,Age,Gender]*LungCs01[Type,Gender,Age]" +CMC.LungCs03Diagnosis : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCs03DiagnosisRate[Type,Age,Gender]*LungCs03[Type,Gender,Age]" +CMC.LungCs03PopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCs03[Type,Gender,Age]" +CMC.LungCProgressIAIIA : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgressIAIIARate[Type,Age,Gender]*LungCsIANoD[Type,Gender,Age]" +CMC.LungCDPopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCD[Type,Stage,Gender,Age]" +CMC.LungCsIIIADiagnosisRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIIIANos')" + +CMC.LungCOutputsIANsNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIANoD[NonSmall,Gender!,Age!])" + +CMC.LungCOutputTherapy1 : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCTherapy1[Type!,Stage!,Gender!,Age!])+sum(LungCTherapyCure1[Type!,Stage!,Gender!,Age!])+sum(LungCTherapy1Mortality[Type!,Stage!,Gender!,Age!])" + +CMC.LungCT2ProgressesRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Re01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Re02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Re03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Re01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Re02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Re03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Re01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Re02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Re03Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2ReIVNos')" + +CMC.LungCOutputTherapy2Cure : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCTherapyCure2[Type!,Stage!,Gender!,Age!])" + +CMC.LungCT2Progresses : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCNotProgressing2[Type,Stage,Gender,Age]*LungCT2ProgressesRate[Type,Stage,Age,Gender]" +CMC.LungCT1ProgToDisablingRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Di01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Di02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Di03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Di01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Di02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Di03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Di01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Di02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Di03Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1DiIVNos')" + +CMC.LungCProgressIIBIIIB : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgressIIBIIIBRate[Type,Age,Gender]*LungCsIIBNoD[Type,Gender,Age]" +CMC.LungCsIIIANoDAgeing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCsIIIANoD[Type,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCsIIIANoD[Type,Gender,Age], -1) else -LungCsIIIANoD[Type,Gender,Age]+VECTOR_MAP(LungCsIIIANoD[Type,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCOutputsIBNsDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIBDiagnosis[NonSmall,Gender!,Age!])" + +CMC.LungCOutputRelapse : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCT1Progresses[Type!,Stage!,Gender!,Age!])+sum(LungCT2Progresses[Type!,Stage!,Gender!,Age!])" + +CMC.LungCT1Deceased : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "0" + +CMC.LungCT1DisablingPopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCT1Disabling[Type,Stage,Gender,Age]" +CMC.LungCOutputsIAScDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIADiagnosis[Small,Gender!,Age!])" + +CMC.LungCProgressIBIV : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgressIBIVRate[Type,Age,Gender]*LungCsIBNoD[Type,Gender,Age]" +CMC.LungCsIVDiagnosis : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCsIVDiagnosisRate[Type,Age,Gender]*LungCsIVNoD[Type,Gender,Age]" +CMC.LungCOutputsIIIBScDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIIBDiagnosis[Small,Gender!,Age!])" + +CMC.LungCsIIADiagnosis : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCsIIADiagnosisRate[Type,Age,Gender]*LungCsIIANoD[Type,Gender,Age]" +CMC.LungCTherapy1Ratio : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Ra01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Ra02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Ra03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Ra01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Ra02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Ra03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Ra01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Ra02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Ra03Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1RaIVNos')" + +CMC.LungCsIBNoDPopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCsIBNoD[Type,Gender,Age]" +CMC.LungCsIANoDAgeing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCsIANoD[Type,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCsIANoD[Type,Gender,Age], -1) else -LungCsIANoD[Type,Gender,Age]+VECTOR_MAP(LungCsIANoD[Type,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCCured1Ageing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCCured1[Type,Stage,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCCured1[Type,Stage,Gender,Age], -1) else -LungCCured1[Type,Stage,Gender,Age]+VECTOR_MAP(LungCCured1[Type,Stage,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCProgress03IARate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P03IASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P03IANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P03IANos')" + +CMC.LungCT1Disabling : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCT1DisablingIniVal[Type,Stage,Age,Gender]" + +CMC.LungCCured2PopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCCured2[Type,Stage,Gender,Age]" +CMC.LungCTreated2IniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Tr01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Tr02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Tr03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Tr01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Tr02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Tr03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2TrIVNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Tr01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Tr02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Tr03Nos')" + +CMC.LungCsIIBDiagnosisRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIIBNos')" + +CMC.LungCOutputNoDSc : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCOutputs01ScNoD+LungCOutputs02ScNoD+LungCOutputs03ScNoD+LungCOutputsIAScNoD+LungCOutputsIBScNoD+LungCOutputsIIAScNoD+LungCOutputsIIBScNoD+LungCOutputsIIIAScNoD+LungCOutputsIIIBScNoD+LungCOutputsIVScNoD" + +CMC.LungCOutputsIANsDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIADiagnosis[NonSmall,Gender!,Age!])" + +CMC.LungCTherapy2Failed : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCFirstTreatmentRate*(LungCD[Type,Stage,Gender,Age]*LungCTherapy2Ratio[Type,Stage,Age,Gender])*LungCTherapy2FailRatio/100" +CMC.LungCProgressIIBIIIARate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIBIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIBIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIBIIIANos')" + +CMC.LungCProgressIBIIB : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgressIBIIBRate[Type,Age,Gender]*LungCsIBNoD[Type,Gender,Age]" +CMC.LungCsIIIBNoD : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCsIIIBNoDIniVal[Type,Age,Gender]" + +CMC.LungCDAgeing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCD[Type,Stage,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCD[Type,Stage,Gender,Age], -1) else -LungCD[Type,Stage,Gender,Age]+VECTOR_MAP(LungCD[Type,Stage,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCOutputProgressing2 : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCT2Progressing[Type!,Stage!,Gender!,Age!])" + +CMC.LungCT1ProgressingAgeing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCT1Progressing[Type,Stage,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCT1Progressing[Type,Stage,Gender,Age], -1) else -LungCT1Progressing[Type,Stage,Gender,Age]+VECTOR_MAP(LungCT1Progressing[Type,Stage,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCT1ProgToDisabling : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCT1Progressing[Type,Stage,Gender,Age]*LungCT1ProgToDisablingRate[Type,Stage,Age,Gender]" +CMC.LungCT2ProgressingPopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCT2Progressing[Type,Stage,Gender,Age]" +CMC.LungCInception : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCHealthy[Gender,Age]*LungCSmokersPercentageOfPopulation[Age,Gender]/100*LungCInceptionRate[Small,Age,Gender]" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCHealthy[Gender,Age]*LungCSmokersPercentageOfPopulation[Age,Gender]/100*LungCInceptionRate[NonSmall,Age,Gender]" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCHealthy[Gender,Age]*LungCInceptionRate[NotSmoker,Age,Gender]*LungCInceptionRateChanges[Gender]" +CMC.LungCTherapyCure2 : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCFirstTreatmentRate*(LungCD[Type,Stage,Gender,Age]*LungCTherapy2Ratio[Type,Stage,Age,Gender]*LungCTherapy2CureRatio[Type,Stage,Age,Gender])*(1-LungCTherapy2FailRatio/100)" +CMC.LungCCured1 : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCCured1IniVal[Type,Stage,Age,Gender]" + +CMC.LungCBirth : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "TotalPopulationBirth[Gender]" +CMC.LungCT2ProgressingAgeing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCT2Progressing[Type,Stage,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCT2Progressing[Type,Stage,Gender,Age], -1) else -LungCT2Progressing[Type,Stage,Gender,Age]+VECTOR_MAP(LungCT2Progressing[Type,Stage,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCTherapy1 : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCFirstTreatmentRate*(LungCD[Type,Stage,Gender,Age]*LungCTherapy1Ratio[Type,Stage,Age,Gender]*(1-LungCTherapy1CureRatio[Type,Stage,Age,Gender]))*(1-LungCTherapy1MortalityRatio/100)" +CMC.LungCOutputNoDNs : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCOutputs01NsNoD+LungCOutputs02NsNoD+LungCOutputs03NsNoD+LungCOutputsIANsNoD+LungCOutputsIBNsNoD+LungCOutputsIIANsNoD+LungCOutputsIIBNsNoD+LungCOutputsIIIANsNoD+LungCOutputsIIIBNsNoD+LungCOutputsIVNsNoD" + +CMC.LungCProgressIIAIIIA : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgressIIAIIIARate[Type,Age,Gender]*LungCsIIANoD[Type,Gender,Age]" +CMC.LungCs01PopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCs01[Type,Gender,Age]" +CMC.LungCOutputsIIBNosDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIBDiagnosis[NotSmoker,Gender!,Age!])" + +CMC.LungCModelPop : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "0.1+LungCHealthy[Gender,Age]+LungCNoDSum[Gender,Age]+sum(LungCD[Type!,Stage!,Gender,Age])+sum(LungCCured1[Type!,Stage!,Gender,Age])+sum(LungCNotProgressing1[Type!,Stage!,Gender,Age])+sum(LungCT1Progressing[Type!,Stage!,Gender,Age])+sum(LungCT1Disabling[Type!,Stage!,Gender,Age])+sum(LungCCured2[Type!,Stage!,Gender,Age])+sum(LungCNotProgressing2[Type!,Stage!,Gender,Age])+sum(LungCT2Progressing[Type!,Stage!,Gender,Age])+sum(LungCT2Disabling[Type!,Stage!,Gender,Age])" + +CMC.LungCProgressIIIAIIIBRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIIAIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIIAIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIIAIIIBNos')" + +CMC.LungCProgress0203 : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgress0203Rate[Type,Age,Gender]*LungCs02[Type,Gender,Age]" +CMC.LungCOutputsIIBNosNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIBNoD[NotSmoker,Gender!,Age!])" + +CMC.LungCsIIBDiagnosis : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCsIIBDiagnosisRate[Type,Age,Gender]*LungCsIIBNoD[Type,Gender,Age]" +CMC.LungCOutputs03ScNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs03[Small,Gender!,Age!])" + +CMC.LungCsIIIBNoDPopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCsIIIBNoD[Type,Gender,Age]" +CMC.LungCsIIANoDIniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIIANos')" + +CMC.LungCProgress02IVRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P02IVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P02IVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P02IVNos')" + +CMC.LungCOutputs01ScDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs01Diagnosis[Small,Gender!,Age!])" + +CMC.LungCT2Progressing : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCT2ProgressingIniVal[Type,Stage,Age,Gender]" + +CMC.LungCT2Death : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCT2Disabling[Type,Stage,Gender,Age]*LungCT2DeathRate[Type,Stage,Age,Gender]" +CMC.LungCOutputsIIAScDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIADiagnosis[Small,Gender!,Age!])" + +CMC.LungCsIBNoD : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCsIBNoDIniVal[Type,Age,Gender]" + +CMC.LungCT1DisablingIniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Di01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Di02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Di03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Di01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Di02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Di03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1DiIVNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Di01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Di02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Di03Nos')" + +CMC.LungCNotProgressing1 : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCTreated1IniVal[Type,Stage,Age,Gender]" + +CMC.LungCOutputsIBScDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIBDiagnosis[Small,Gender!,Age!])" + +CMC.LungCOutputProgressing1 : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCT1Progressing[Type!,Stage!,Gender!,Age!])" + +CMC.LungCProgressIIIAIV : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgressIIIAIVRate[Type,Age,Gender]*LungCsIIIANoD[Type,Gender,Age]" +CMC.LungCProgressIAIV : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgressIAIVRate[Type,Age,Gender]*LungCsIANoD[Type,Gender,Age]" +CMC.LungCsIADiagnosis : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCsIADiagnosisRate[Type,Age,Gender]*LungCsIANoD[Type,Gender,Age]" +CMC.LungCOutputsIVNsDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIVDiagnosis[NonSmall,Gender!,Age!])" + +CMC.LungCOutputsIIIBNsDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIIBDiagnosis[NonSmall,Gender!,Age!])" + +CMC.LungCProgress01IVRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P01IVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P01IVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P01IVNos')" + +CMC.LungCProgressIIAIIB : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgressIIAIIBRate[Type,Age,Gender]*LungCsIIANoD[Type,Gender,Age]" +CMC.LungCOutputNotProgressing1 : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCNotProgressing1[Type!,Stage!,Gender!,Age!])" + +CMC.LungCsIIANoDPopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCsIIANoD[Type,Gender,Age]" +CMC.LungCOutputsIIBNsNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIBNoD[NonSmall,Gender!,Age!])" + +CMC.LungCProgressIIAIIBRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIAIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIAIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIAIIBNos')" + +CMC.LungCProgress0203Rate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P0203Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P0203Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P0203Nos')" + +CMC.LungCsIIBNoDPopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCsIIBNoD[Type,Gender,Age]" +CMC.LungCSmokersPercentageOfPopulation : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_DATA('LCancer.xls', 'LungC_Risk', 'PSmokingMenT', 'PSmokingMen')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_DATA('LCancer.xls', 'LungC_Risk', 'PSmokingWomenT', 'PSmokingWomen')" + +CMC.LungCOutputsIVScDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIVDiagnosis[Small,Gender!,Age!])" + +CMC.LungCs01Ageing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCs01[Type,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCs01[Type,Gender,Age], -1) else -LungCs01[Type,Gender,Age]+VECTOR_MAP(LungCs01[Type,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCOutputsIBNosNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIBNoD[NotSmoker,Gender!,Age!])" + +CMC.LungCs02 : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCs02IniVal[Type,Age,Gender]" + +CMC.LungCCausedDeath : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCT1Death[Type!,Stage!,Gender,Age])+sum(LungCT2Death[Type!,Stage!,Gender,Age])+sum(LungCTherapy1Mortality[Type!,Stage!,Gender,Age])" + +CMC.LungCsIBDiagnosis : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCsIBNoD[Type,Gender,Age]*LungCsIBDiagnosisRate[Type,Age,Gender]" +CMC.LungCProgressIIBIV : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgressIIBIVRate[Type,Age,Gender]*LungCsIIBNoD[Type,Gender,Age]" +CMC.LungCOutputCured2 : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCCured2[Type!,Stage!,Gender!,Age!])" + +CMC.LungCsIBDiagnosisRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIBNos')" + +CMC.LungCTherapy1MortalityRatio : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Mor')" + +CMC.LungCTreated1PopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCNotProgressing1[Type,Stage,Gender,Age]" +CMC.LungCOutputTherapy2 : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCTherapy2[Type!,Stage!,Gender!,Age!])+sum(LungCTherapyCure2[Type!,Stage!,Gender!,Age!])+sum(LungCTherapy2Failed[Type!,Stage!,Gender!,Age!])" + +CMC.LungCsIIBNoDIniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIIBNos')" + +CMC.LungCs03DiagnosisRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PD03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PD03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PD03Nos')" + +CMC.LungCsIIIANoDIniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIIIANos')" + +CMC.LungCTreated1Ageing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCNotProgressing1[Type,Stage,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCNotProgressing1[Type,Stage,Gender,Age], -1) else -LungCNotProgressing1[Type,Stage,Gender,Age]+VECTOR_MAP(LungCNotProgressing1[Type,Stage,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCT2DisablingPopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCT2Disabling[Type,Stage,Gender,Age]" +CMC.LungCOutputs03ScDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs03Diagnosis[Small,Gender!,Age!])" + +CMC.LungCProgressIIIBIV : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgressIIIBIVRate[Type,Age,Gender]*LungCsIIIBNoD[Type,Gender,Age]" +CMC.LungCProgressIIIBIVRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIIBIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIIBIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIIBIVNos')" + +CMC.LungCProgressIIIAIVRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIIAIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIIAIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIIAIVNos')" + +CMC.LungCT2ProgToDisabling : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCT2Progressing[Type,Stage,Gender,Age]*LungCT2ProgToDisablingRate[Type,Stage,Age,Gender]" +CMC.LungCProgress03IVRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P03IVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P03IVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P03IVNos')" + +CMC.LungCOutputs03NosNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs03[NotSmoker,Gender!,Age!])" + +CMC.LungCOutputsIIIAScDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIIADiagnosis[Small,Gender!,Age!])" + +CMC.LungCOutputsIIBScNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIBNoD[Small,Gender!,Age!])" + +CMC.LungCOutputsIIIBNosDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIIBDiagnosis[NotSmoker,Gender!,Age!])" + +CMC.Cloud45 : SYSDYN.Cloud + +CMC.LungCOutputs03NosDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs03Diagnosis[NotSmoker,Gender!,Age!])" + +CMC.LungCOutputs03NsDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs03Diagnosis[NonSmall,Gender!,Age!])" + +CMC.LungCOutputsIBNosDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIBDiagnosis[NotSmoker,Gender!,Age!])" + +CMC.LungCOutputsIIIANsNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIIANoD[NonSmall,Gender!,Age!])" + +CMC.LungCHealthy : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCHealthyIniVal[Age,Gender]" + +CMC.LungCs01DiagnosisRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PD01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PD01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PD01Nos')" + +CMC.LungCTreated1IniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Tr01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Tr02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Tr03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Tr01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Tr02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Tr03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1TrIVNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Tr01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Tr02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Tr03Nos')" + +CMC.LungCProgressIBIIBRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIBIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIBIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIBIIBNos')" + +CMC.LungCsIIBNoDAgeing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCsIIBNoD[Type,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCsIIBNoD[Type,Gender,Age], -1) else -LungCsIIBNoD[Type,Gender,Age]+VECTOR_MAP(LungCsIIBNoD[Type,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCProgressIIIAIIIB : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCsIIIANoD[Type,Gender,Age]*LungCProgressIIIAIIIBRate[Type,Age,Gender]" +CMC.LungCOutputsIVNsNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIVNoD[NonSmall,Gender!,Age!])" + +CMC.LungCT1ProgressingIniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Pr01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Pr02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Pr03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Pr01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Pr02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Pr03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1PrIVNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Pr01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Pr02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Pr03Nos')" + +CMC.LungCs02Ageing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCs02[Type,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCs02[Type,Gender,Age], -1) else -LungCs02[Type,Gender,Age]+VECTOR_MAP(LungCs02[Type,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCOutputDisabling1 : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCT1Disabling[Type!,Stage!,Gender!,Age!])" + +CMC.LungCOutputsIIIANsDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIIADiagnosis[NonSmall,Gender!,Age!])" + +CMC.LungCsIIANoDAgeing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCsIIANoD[Type,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCsIIANoD[Type,Gender,Age], -1) else -LungCsIIANoD[Type,Gender,Age]+VECTOR_MAP(LungCsIIANoD[Type,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCOutputsIIIANosNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIIANoD[NotSmoker,Gender!,Age!])" + +CMC.LungCProgress03IA : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgress03IARate[Type,Age,Gender]*LungCs03[Type,Gender,Age]" +CMC.LungCOutputsIIIANosDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIIADiagnosis[NotSmoker,Gender!,Age!])" + +CMC.LungCTreated2PopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCNotProgressing2[Type,Stage,Gender,Age]" +CMC.LungCsIIIBDiagnosis : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCsIIIBDiagnosisRate[Type,Age,Gender]*LungCsIIIBNoD[Type,Gender,Age]" +CMC.LungCInceptionRateChanges : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_DATA('LCancer.xls', 'LungC_Risk', 'B', 'C147')" + +CMC.LungCNotProgressing2 : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCTreated2IniVal[Type,Stage,Age,Gender]" + +CMC.LungCProgressIIBIVRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIBIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIBIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIBIVNos')" + +CMC.LungCs02Diagnosis : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCs02DiagnosisRate[Type,Age,Gender]*LungCs02[Type,Gender,Age]" +CMC.LungCFirstTreatmentRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "10" + +CMC.LungCCured2 : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCCured2IniVal[Type,Stage,Age,Gender]" + +CMC.LungCOutputs02NosNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs02[NotSmoker,Gender!,Age!])" + +CMC.LungCOutputs02ScNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs02[Small,Gender!,Age!])" + +CMC.LungCProgressIIBIIIA : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgressIIBIIIARate[Type,Age,Gender]*LungCsIIBNoD[Type,Gender,Age]" +CMC.LungCs03Ageing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCs03[Type,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCs03[Type,Gender,Age], -1) else -LungCs03[Type,Gender,Age]+VECTOR_MAP(LungCs03[Type,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCOutputNsDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs01Diagnosis[NonSmall,Gender!,Age!])+sum(LungCs02Diagnosis[NonSmall,Gender!,Age!])+sum(LungCs03Diagnosis[NonSmall,Gender!,Age!])+sum(LungCsIADiagnosis[NonSmall,Gender!,Age!])+sum(LungCsIBDiagnosis[NonSmall,Gender!,Age!])+sum(LungCsIIADiagnosis[NonSmall,Gender!,Age!])+sum(LungCsIIBDiagnosis[NonSmall,Gender!,Age!])+sum(LungCsIIIADiagnosis[NonSmall,Gender!,Age!])+sum(LungCsIIIBDiagnosis[NonSmall,Gender!,Age!])+sum(LungCsIVDiagnosis[NonSmall,Gender!,Age!])" + +CMC.LungCTherapyCure1 : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCFirstTreatmentRate*(LungCD[Type,Stage,Gender,Age]*LungCTherapy1Ratio[Type,Stage,Age,Gender]*LungCTherapy1CureRatio[Type,Stage,Age,Gender])*(1-LungCTherapy1MortalityRatio/100)" +CMC.LungCT2DisablingIniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Di01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Di02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Di03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Di01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Di02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Di03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2DiIVNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Di01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Di02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Di03Nos')" + +CMC.LungCsIBNoDIniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIBNos')" + +CMC.LungCOutputModelPopExcludingHealthy : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPop[Gender,Age]-LungCHealthy[Gender,Age]" + +CMC.LungCsIIADiagnosisRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIIANos')" + +CMC.LungCProgress0102 : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgress0102Rate[Type,Age,Gender]*LungCs01[Type,Gender,Age]" +CMC.LungCsIVNoDAgeing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCsIVNoD[Type,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCsIVNoD[Type,Gender,Age], -1) else -LungCsIVNoD[Type,Gender,Age]+VECTOR_MAP(LungCsIVNoD[Type,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCModelPopCorrectionRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "0.9" + +CMC.LungCTherapy2 : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCFirstTreatmentRate*(LungCD[Type,Stage,Gender,Age]*LungCTherapy2Ratio[Type,Stage,Age,Gender]*(1-LungCTherapy2CureRatio[Type,Stage,Age,Gender]))*(1-LungCTherapy2FailRatio/100)" +CMC.LungCsIIANoD : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCsIIANoDIniVal[Type,Age,Gender]" + +CMC.LungCsIIIANoD : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCsIIIANoDIniVal[Type,Age,Gender]" + +CMC.LungCOutputsIVNosDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIVDiagnosis[NotSmoker,Gender!,Age!])" + +CMC.LungCTherapy2Ratio : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Ra01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Ra02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Ra03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Ra01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Ra02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Ra03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Ra01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Ra02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Ra03Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2RaIVNos')" + +CMC.LungCOutputs01NosNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs01[NotSmoker,Gender!,Age!])" + +CMC.LungCCured2Ageing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCCured2[Type,Stage,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCCured2[Type,Stage,Gender,Age], -1) else -LungCCured2[Type,Stage,Gender,Age]+VECTOR_MAP(LungCCured2[Type,Stage,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCs03 : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCs03IniVal[Type,Age,Gender]" + +CMC.LungCOutputs03NsNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs03[NonSmall,Gender!,Age!])" + +CMC.LungCOutputsIIANosNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIANoD[NotSmoker,Gender!,Age!])" + +CMC.LungCsIIIANoDPopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCsIIIANoD[Type,Gender,Age]" +CMC.LungCs01Diagnosis : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCs01DiagnosisRate[Type,Age,Gender]*LungCs01[Type,Gender,Age]" +CMC.LungCOutputs02NsDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs02Diagnosis[NonSmall,Gender!,Age!])" + +CMC.LungCOutputsIANosDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIADiagnosis[NotSmoker,Gender!,Age!])" + +CMC.LungCProgress02IV : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCProgress02IVRate[Type,Age,Gender]*LungCs02[Type,Gender,Age]" +CMC.LungCT1Progressing : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCT1ProgressingIniVal[Type,Stage,Age,Gender]" + +CMC.LungCOutputTherapy1Cure : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCTherapyCure1[Type!,Stage!,Gender!,Age!])" + +CMC.LungCsIANoDIniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIANos')" + +CMC.LungCOutputsIANosNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIANoD[NotSmoker,Gender!,Age!])" + +CMC.LungCOutputTherapy1MortalityInTherapy : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCTherapy1Mortality[Type!,Stage!,Gender!,Age!])" + +CMC.LungCTreated2Ageing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCNotProgressing2[Type,Stage,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCNotProgressing2[Type,Stage,Gender,Age], -1) else -LungCNotProgressing2[Type,Stage,Gender,Age]+VECTOR_MAP(LungCNotProgressing2[Type,Stage,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCs01IniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INd01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INd01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INd01Nos')" + +CMC.LungCOutputDisabling2 : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCT2Disabling[Type!,Stage!,Gender!,Age!])" + +CMC.LungCT1ProgressesRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Re01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Re02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Re03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Re01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Re02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Re03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Re01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Re02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Re03Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1ReIVNos')" + +CMC.LungCs02PopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCs02[Type,Gender,Age]" +CMC.LungCOutputsIIAScNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIANoD[Small,Gender!,Age!])" + +CMC.LungCsIVNoDPopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCsIVNoD[Type,Gender,Age]*LungCModelPopCorrectionFactor[Gender,Age]" +CMC.LungCoutputNoDNos : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCOutputs01NosNoD+LungCOutputs02NosNoD+LungCOutputs03NosNoD+LungCOutputsIANosNoD+LungCOutputsIBNosNoD+LungCOutputsIIANosNoD+LungCOutputsIIBNosNoD+LungCOutputsIIIANosNoD+LungCOutputsIIIBNosNoD+LungCOutputsIVNosNoD" + +CMC.LungCOutputsIIANosDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIADiagnosis[NotSmoker,Gender!,Age!])" + +CMC.LungCs01 : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCs01IniVal[Type,Age,Gender]" + +CMC.LungCOutputCured1 : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCCured1[Type!,Stage!,Gender!,Age!])" + +CMC.LungCTherapy1CureRatio : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Cr01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Cr02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Cr03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Cr01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Cr02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Cr03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Cr01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Cr02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Cr03Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1CrIVNos')" + +CMC.LungCsIIIBDiagnosisRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIIIBNos')" + +CMC.LungCsIVDiagnosisRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PDIVNos')" + +CMC.LungCOutputsIIBNsDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIBDiagnosis[NonSmall,Gender!,Age!])" + +CMC.LungCOutputModelPop : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCModelPop[Gender!,Age!])" + +CMC.LungCsIANoDPopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCsIANoD[Type,Gender,Age]" +CMC.LungCCured2IniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Cr01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Cr02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Cr03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Cr01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Cr02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Cr03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2CrIVNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Cr01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Cr02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Cr03Nos')" + +CMC.LungCModelPopCorrectionFactor : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionRate*(TotalPopulation[Gender,Age]/LungCModelPop[Gender,Age]-1)-(TotalPopulationDeath[Gender,Age]-LungCCausedDeath[Gender,Age])/LungCModelPop[Gender,Age]" + +CMC.LungCTherapy2FailRatio : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Fail')" + +CMC.LungCsIBNoDAgeing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age0 then -LungCsIBNoD[Type,Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCsIBNoD[Type,Gender,Age], -1) else -LungCsIBNoD[Type,Gender,Age]+VECTOR_MAP(LungCsIBNoD[Type,Gender,Age], -1)*DummyRateForUnitsConversion" +CMC.LungCOutputNosDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs01Diagnosis[NotSmoker,Gender!,Age!])+sum(LungCs02Diagnosis[NotSmoker,Gender!,Age!])+sum(LungCs03Diagnosis[NotSmoker,Gender!,Age!])+sum(LungCsIADiagnosis[NotSmoker,Gender!,Age!])+sum(LungCsIBDiagnosis[NotSmoker,Gender!,Age!])+sum(LungCsIIADiagnosis[NotSmoker,Gender!,Age!])+sum(LungCsIIBDiagnosis[NotSmoker,Gender!,Age!])+sum(LungCsIIIADiagnosis[NotSmoker,Gender!,Age!])+sum(LungCsIIIBDiagnosis[NotSmoker,Gender!,Age!])+sum(LungCsIVDiagnosis[NotSmoker,Gender!,Age!])" + +CMC.LungCOutputNotProgressing2 : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCNotProgressing2[Type!,Stage!,Gender!,Age!])" + +CMC.LungCOutputsIIIBNosNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIIBNoD[NotSmoker,Gender!,Age!])" + +CMC.LungCProgressIIBIIIBRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIBIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIBIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIBIIIBNos')" + +CMC.LungCOutputT1Mortality : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCT1Death[Type!,Stage!,Gender!,Age!])" + +CMC.LungCOutputsIIIBNsNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIIBNoD[NonSmall,Gender!,Age!])" + +CMC.LungCDIniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDia01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDia02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDia03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDia01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDia02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDia03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDiaIVNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDia01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDia02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IDia03Nos')" + +CMC.LungCOutputsIIANsNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIANoD[NonSmall,Gender!,Age!])" + +CMC.LungCProgressIIAIVRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIAIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIAIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIAIVNos')" + +CMC.LungCOutputs01ScNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs01[Small,Gender!,Age!])" + +CMC.LungCOutputNoDSum : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCNoDSum[Gender!,Age!])" + +CMC.LungCsIVNoDIniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIVNos')" + +CMC.LungCT1ProgressingPopCorr : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCModelPopCorrectionFactor[Gender,Age]*LungCT1Progressing[Type,Stage,Gender,Age]" +CMC.LungCOutputTherapy1NoCure : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCTherapy1[Type!,Stage!,Gender!,Age!])" + +CMC.LungCOutputsIVScNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIVNoD[Small,Gender!,Age!])" + +CMC.LungCProgress0102Rate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P0102Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P0102Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'P0102Nos')" + +CMC.LungCOutputDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs01Diagnosis[Type!,Gender!,Age!])+sum(LungCs02Diagnosis[Type!,Gender!,Age!])+sum(LungCs03Diagnosis[Type!,Gender!,Age!])+sum(LungCsIADiagnosis[Type!,Gender!,Age!])+sum(LungCsIBDiagnosis[Type!,Gender!,Age!])+sum(LungCsIIADiagnosis[Type!,Gender!,Age!])+sum(LungCsIIBDiagnosis[Type!,Gender!,Age!])+sum(LungCsIIIADiagnosis[Type!,Gender!,Age!])+sum(LungCsIIIBDiagnosis[Type!,Gender!,Age!])+sum(LungCsIVDiagnosis[Type!,Gender!,Age!])" + +CMC.LungCOutputHealthyAndTreated : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCHealthy[Gender!,Age!])+sum(LungCNotProgressing2[Type!,Stage!,Gender!,Age!])+sum(LungCNotProgressing1[Type!,Stage!,Gender!,Age!])+sum(LungCCured1[Type!,Stage!,Gender!,Age!])+sum(LungCCured2[Type!,Stage!,Gender!,Age!])" + +CMC.LungCOutputsIIANsDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIADiagnosis[NonSmall,Gender!,Age!])" + +CMC.LungCT2DeathRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Mo01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Mo02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Mo03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Mo01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Mo02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Mo03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Mo01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Mo02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Mo03Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2MoIVNos')" + +CMC.LungCProgressIAIBRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIAIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIAIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIAIBNos')" + +CMC.LungCT2Deceased : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "0" + +CMC.LungCs03IniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INd03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INd03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INd03Nos')" + +CMC.LungCOutputs01NsDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs01Diagnosis[NonSmall,Gender!,Age!])" + +CMC.LungCOutputs02NsNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs02[NonSmall,Gender!,Age!])" + +CMC.LungCsIIIADiagnosis : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "LungCsIIIADiagnosisRate[Type,Age,Gender]*LungCsIIIANoD[Type,Gender,Age]" +CMC.LungCTherapy2CureRatio : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Cr01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Cr02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Cr03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Cr01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Cr02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Cr03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Cr01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Cr02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Cr03Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2CrIVNos')" + +CMC.LungCHealthyIniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IHe')" + +CMC.LungCOutputMortality : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCCausedDeath[Gender!,Age!])" + +CMC.LungCs02IniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INd02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INd02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INd02Nos')" + +CMC.LungCOutputScDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs01Diagnosis[Small,Gender!,Age!])+sum(LungCs02Diagnosis[Small,Gender!,Age!])+sum(LungCs03Diagnosis[Small,Gender!,Age!])+sum(LungCsIADiagnosis[Small,Gender!,Age!])+sum(LungCsIBDiagnosis[Small,Gender!,Age!])+sum(LungCsIIADiagnosis[Small,Gender!,Age!])+sum(LungCsIIBDiagnosis[Small,Gender!,Age!])+sum(LungCsIIIADiagnosis[Small,Gender!,Age!])+sum(LungCsIIIBDiagnosis[Small,Gender!,Age!])+sum(LungCsIVDiagnosis[Small,Gender!,Age!])" + +CMC.LungCOutputs01NsNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs01[NonSmall,Gender!,Age!])" + +CMC.LungCT1DeathRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Mo01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Mo02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Mo03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Mo01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Mo02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Mo03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Mo01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Mo02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1Mo03Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT1MoIVNos')" + +CMC.LungCProgressIAIIARate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIAIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIAIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIAIIANos')" + +CMC.LungCsIIIBNoDIniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'INdIIIBNos')" + +CMC.LungCOutputs01NosDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs01Diagnosis[NotSmoker,Gender!,Age!])" + +CMC.LungCInceptionRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIncSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIncNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIncNos')" + +CMC.LungCs02DiagnosisRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PD02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PD02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PD02Nos')" + +CMC.LungCNoDSum : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs01[Type!,Gender,Age])+sum(LungCs02[Type!,Gender,Age])+sum(LungCs03[Type!,Gender,Age])+sum(LungCsIANoD[Type!,Gender,Age])+sum(LungCsIBNoD[Type!,Gender,Age])+sum(LungCsIIANoD[Type!,Gender,Age])+sum(LungCsIIBNoD[Type!,Gender,Age])+sum(LungCsIIIANoD[Type!,Gender,Age])+sum(LungCsIIIBNoD[Type!,Gender,Age])+sum(LungCsIVNoD[Type!,Gender,Age])" + +CMC.LungCOutputsIIIAScNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIIANoD[Small,Gender!,Age!])" + +CMC.LungCHealthyAgeing : SYSDYN.Valve + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "(if Age==Age0 then -LungCHealthy[Gender,Age] elseif Age==Age100 then +VECTOR_MAP(LungCHealthy[Gender,Age], -1) else -LungCHealthy[Gender,Age]+VECTOR_MAP(LungCHealthy[Gender,Age], -1))*DummyRateForUnitsConversion" +CMC.LungCsIVNoD : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCsIVNoDIniVal[Type,Age,Gender]" + +CMC.LungCOutputsIIIBScNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIIBNoD[Small,Gender!,Age!])" + +CMC.LungCOutputs02ScDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCs02Diagnosis[Small,Gender!,Age!])" + +CMC.LungCOutputsIBNsNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIBNoD[NonSmall,Gender!,Age!])" + +CMC.LungCT2ProgToDisablingRate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Di01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Di02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Di03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Di01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Di02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Di03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Di01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Di02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2Di03Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PT2DiIVNos')" + +CMC.LungCOutputsIAScNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIANoD[Small,Gender!,Age!])" + +CMC.LungCCured1IniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Cr01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Cr02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Cr03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Cr01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Cr02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Cr03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1CrIVNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Cr01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Cr02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT1Cr03Nos')" + +CMC.LungCOutputT2Mortality : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCT2Death[Type!,Stage!,Gender!,Age!])" + +CMC.LungCOutputTherapy2NoCure : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCTherapy2[Type!,Stage!,Gender!,Age!])" + +CMC.LungCOutputsIBScNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIBNoD[Small,Gender!,Age!])" + +CMC.LungCOutputsIIBScDiagnosis : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIIBDiagnosis[Small,Gender!,Age!])" + +CMC.LungCsIIBNoD : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCsIIBNoDIniVal[Type,Age,Gender]" + +CMC.LungCT2ProgressingIniVal : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIIIBSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIVSm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Pr01Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Pr02Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Pr03Sm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIIIBNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIVNs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Pr01Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Pr02Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Pr03Ns')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIIIANos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIIIBNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2PrIVNos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Pr01Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Pr02Nos')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'IT2Pr03Nos')" + +CMC.LungCOutputTherapy2Failed : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCTherapy2Failed[Type!,Stage!,Gender!,Age!])" + +CMC.LungCOutputsIVNosNoD : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(LungCsIVNoD[NotSmoker,Gender!,Age!])" + +CMC.LungCsIANoD : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCsIANoDIniVal[Type,Age,Gender]" + +CMC.LungCT2Disabling : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCT2DisablingIniVal[Type,Stage,Age,Gender]" + +CMC.LungCProgressIIAIIIARate : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIAIIIASm')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIAIIIANs')" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_CONSTANT('LCancer.xls', 'LungC_In', 'PIIAIIIANos')" + +CMC.LungCD : SYSDYN.Stock + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCDIniVal[Type,sIA,Age,Gender]" + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCDIniVal[Type,sIB,Age,Gender]" + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCDIniVal[Type,sIIA,Age,Gender]" + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCDIniVal[Type,sIIB,Age,Gender]" + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCDIniVal[Type,sIIIA,Age,Gender]" + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCDIniVal[Type,sIIIB,Age,Gender]" + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCDIniVal[Type,sIV,Age,Gender]" + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCDIniVal[Type,s03,Age,Gender]" + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCDIniVal[Type,s02,Age,Gender]" + _ : SYSDYN.StockExpression + SYSDYN.HasInitialEquation "LungCDIniVal[Type,s01,Age,Gender]" + +CMC.d127 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPop CMC.LungCD +CMC.d882 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCoutputNoDNos CMC.LungCOutputs01NosNoD +CMC.d331 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIANoDAgeing CMC.DummyRateForUnitsConversion +CMC.d737 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNosDiagnosis CMC.LungCs02Diagnosis +CMC.f580 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIVNoD CMC.LungCProgressIIIBIV +CMC.f805 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCTherapyCure1 CMC.LungCD +CMC.d84 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT1Progresses CMC.LungCNotProgressing1 +CMC.d463 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPop CMC.LungCNotProgressing2 +CMC.f517 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIVNoD CMC.LungCProgress03IV +CMC.d458 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCNoDSum CMC.LungCsIIIBNoD +CMC.d451 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCNoDSum CMC.LungCs02 +CMC.d220 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT1ProgressingPopCorr CMC.LungCModelPopCorrectionFactor +CMC.d454 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCNoDSum CMC.LungCsIBNoD +CMC.d846 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputTherapy1 CMC.LungCTherapyCure1 +CMC.d722 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNsDiagnosis CMC.LungCsIVDiagnosis +CMC.d578 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIIBIV CMC.LungCsIIIBNoD +CMC.d695 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs03NsDiagnosis CMC.LungCs03Diagnosis +CMC.d728 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputScDiagnosis CMC.LungCsIIADiagnosis +CMC.d742 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNosDiagnosis CMC.LungCsIIBDiagnosis +CMC.d378 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIBDiagnosis CMC.LungCsIBNoD +CMC.d325 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIANoDPopCorr CMC.LungCsIIANoD +CMC.f29 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT1Progressing CMC.LungCT1Progresses +CMC.d889 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCoutputNoDNos CMC.LungCOutputsIIIANosNoD +CMC.d572 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIAIV CMC.LungCsIIANoD +CMC.f540 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgressIIIBIV CMC.LungCsIIIBNoD +CMC.d58 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCInception CMC.LungCHealthy +CMC.d211 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT1Death CMC.LungCT1DeathRate +CMC.f15 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCs02 CMC.LungCProgress0102 +CMC.d861 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDNs CMC.LungCOutputs01NsNoD +CMC.f337 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIBNoD CMC.LungCsIIBNoDAgeing +CMC.d101 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTreated1Ageing CMC.DummyRateForUnitsConversion +CMC.d340 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIBNoDAgeing CMC.LungCsIIBNoD +CMC.f76 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCNotProgressing1 CMC.LungCTreated1Ageing +CMC.d62 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs01Ageing CMC.LungCs01 +CMC.d833 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCCured2Ageing CMC.DummyRateForUnitsConversion +CMC.d571 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIAIV CMC.LungCProgressIIAIVRate +CMC.f139 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCs01 CMC.LungCs01PopCorr +CMC.d129 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPopCorrectionFactor CMC.TotalPopulationDeath +CMC.d917 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapyCure2 CMC.LungCTherapy2FailRatio +CMC.d926 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputTherapy2Failed CMC.LungCTherapy2Failed +CMC.d548 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIANoD CMC.LungCsIIANoDIniVal +CMC.f495 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCD CMC.LungCs02Diagnosis +CMC.d739 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNosDiagnosis CMC.LungCsIADiagnosis +CMC.d876 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDSc CMC.LungCOutputsIBScNoD +CMC.d662 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs02ScNoD CMC.LungCs02 +CMC.d783 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIIANosDiagnosis CMC.LungCsIIIADiagnosis +CMC.d758 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs03NosNoD CMC.LungCs03 +CMC.f236 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIANoD CMC.LungCProgress03IA +CMC.d706 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIIAScDiagnosis CMC.LungCsIIIADiagnosis +CMC.f348 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIIANoD CMC.LungCsIIIANoDAgeing +CMC.f145 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIANoD CMC.LungCsIANoDPopCorr +CMC.d627 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputProgressing2 CMC.LungCT2Progressing +CMC.d715 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNsDiagnosis CMC.LungCs03Diagnosis +CMC.f23 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCNotProgressing1 CMC.LungCTherapy1 +CMC.f364 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIVNoD CMC.LungCsIVNoDAgeing +CMC.d96 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy2 CMC.LungCFirstTreatmentRate +CMC.d486 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCNotProgressing1 CMC.LungCTreated1IniVal +CMC.f509 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIVNoD CMC.LungCProgress01IV +CMC.d160 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTreated2PopCorr CMC.LungCModelPopCorrectionFactor +CMC.d569 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIBIV CMC.LungCProgressIBIVRate +CMC.d367 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIVNoDAgeing CMC.LungCsIVNoD +CMC.d716 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNsDiagnosis CMC.LungCsIADiagnosis +CMC.d391 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIBDiagnosis CMC.LungCsIIBDiagnosisRate +CMC.d778 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs03NosDiagnosis CMC.LungCs03Diagnosis +CMC.d743 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNosDiagnosis CMC.LungCsIIIADiagnosis +CMC.d720 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNsDiagnosis CMC.LungCsIIIADiagnosis +CMC.d723 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputScDiagnosis CMC.LungCs01Diagnosis +CMC.d453 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCNoDSum CMC.LungCsIANoD +CMC.d180 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT2ProgressingAgeing CMC.DummyRateForUnitsConversion +CMC.d244 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgress0203 CMC.LungCs02 +CMC.d351 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIIANoDAgeing CMC.DummyRateForUnitsConversion +CMC.f246 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCs02 CMC.LungCs02PopCorr +CMC.d488 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT1Disabling CMC.LungCT1DisablingIniVal +CMC.d835 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCCured2PopCorr CMC.LungCModelPopCorrectionFactor +CMC.d415 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIAIB CMC.LungCProgressIAIBRate +CMC.d452 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCNoDSum CMC.LungCs03 +CMC.f342 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIIANoD CMC.LungCsIIIANoDPopCorr +CMC.d862 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDNs CMC.LungCOutputs02NsNoD +CMC.f579 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIVNoD CMC.LungCProgressIIIAIV +CMC.f295 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgressIIBIIIA CMC.LungCsIIBNoD +CMC.d341 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIBNoDAgeing CMC.DummyRateForUnitsConversion +CMC.d87 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT1Progresses CMC.LungCT1ProgressesRate +CMC.d508 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs01Diagnosis CMC.LungCs01DiagnosisRate +CMC.d221 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT1ProgressingPopCorr CMC.LungCT1Progressing +CMC.d64 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgress0102 CMC.LungCProgress0102Rate +CMC.d417 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIBIIB CMC.LungCProgressIBIIBRate +CMC.f12 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCInception CMC.LungCHealthy +CMC.d881 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDSc CMC.LungCOutputsIVScNoD +CMC.d765 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIVNosNoD CMC.LungCsIVNoD +CMC.d784 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIIBNosDiagnosis CMC.LungCsIIIBDiagnosis +CMC.d507 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs01Diagnosis CMC.LungCs01 +CMC.d405 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIADiagnosis CMC.LungCsIIANoD +CMC.d573 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIBIV CMC.LungCProgressIIBIVRate +CMC.f237 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgress03IA CMC.LungCs03 +CMC.f370 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIVNoD CMC.LungCsIVNoDPopCorr +CMC.f309 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIBNoD CMC.LungCsIBNoDPopCorr +CMC.d762 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIBNosNoD CMC.LungCsIIBNoD +CMC.d734 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCInception CMC.LungCInceptionRateChanges +CMC.d875 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDSc CMC.LungCOutputsIAScNoD +CMC.d567 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgress03IV CMC.LungCs03 +CMC.d116 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCCausedDeath CMC.LungCT2Death +CMC.d144 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs01PopCorr CMC.LungCs01 +CMC.d914 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy2Failed CMC.LungCFirstTreatmentRate +CMC.d380 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIBDiagnosis CMC.LungCsIBDiagnosisRate +CMC.d100 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs01Ageing CMC.DummyRateForUnitsConversion +CMC.f824 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCCured2 CMC.LungCCured2PopCorr +CMC.d661 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs01ScNoD CMC.LungCs01 +CMC.f286 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIBNoD CMC.LungCProgressIIAIIB +CMC.d800 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCCured1PopCorr CMC.LungCCured1 +CMC.f381 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIADiagnosis CMC.LungCsIIANoD +CMC.d581 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIVNoD CMC.LungCsIVNoDIniVal +CMC.d308 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIIAIIIB CMC.LungCsIIIANoD +CMC.f392 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIIADiagnosis CMC.LungCsIIIANoD +CMC.f177 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT2Progressing CMC.LungCT2ProgressingAgeing +CMC.f496 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCs02Diagnosis CMC.LungCs02 +CMC.d605 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputDiagnosis CMC.LungCsIBDiagnosis +CMC.d373 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIVNoDPopCorr CMC.LungCModelPopCorrectionFactor +CMC.d607 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputDiagnosis CMC.LungCsIIBDiagnosis +CMC.d813 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPop CMC.LungCCured1 +CMC.f42 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT2Death CMC.LungCT2Disabling +CMC.f205 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT1Death CMC.LungCT1Disabling +CMC.d759 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIANosNoD CMC.LungCsIANoD +CMC.d644 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIANsNoD CMC.LungCsIANoD +CMC.d851 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputTherapy2Cure CMC.LungCTherapyCure2 +CMC.d927 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCCausedDeath CMC.LungCTherapy1Mortality +CMC.d694 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs02ScDiagnosis CMC.LungCs02Diagnosis +CMC.d213 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT1Death CMC.LungCT1Disabling +CMC.d51 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCBirth CMC.TotalPopulationBirth +CMC.d456 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCNoDSum CMC.LungCsIIBNoD +CMC.d568 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIAIV CMC.LungCsIANoD +CMC.d874 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDSc CMC.LungCOutputs03ScNoD +CMC.d171 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT2ProgressingPopCorr CMC.LungCT2Progressing +CMC.d916 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy2Failed CMC.LungCTherapy2FailRatio +CMC.f386 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIBDiagnosis CMC.LungCsIIBNoD +CMC.d796 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCCured1Ageing CMC.LungCCured1 +CMC.f200 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT1Disabling CMC.LungCT1ProgToDisabling +CMC.f525 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIVNoD CMC.LungCProgressIBIV +CMC.d787 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCInception CMC.LungCSmokersPercentageOfPopulation +CMC.d161 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTreated2PopCorr CMC.LungCNotProgressing2 +CMC.d919 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy2Failed CMC.LungCTherapy2Ratio +CMC.f534 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgressIIBIV CMC.LungCsIIBNoD +CMC.d744 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNosDiagnosis CMC.LungCsIIIBDiagnosis +CMC.f20 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIADiagnosis CMC.LungCsIANoD +CMC.d888 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCoutputNoDNos CMC.LungCOutputsIIBNosNoD +CMC.d557 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgress02IV CMC.LungCs02 +CMC.d718 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNsDiagnosis CMC.LungCsIIADiagnosis +CMC.d468 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPop CMC.LungCNoDSum +CMC.d700 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIBScDiagnosis CMC.LungCsIBDiagnosis +CMC.f287 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgressIIAIIB CMC.LungCsIIANoD +CMC.f475 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCTherapy2 CMC.LungCD +CMC.d868 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDNs CMC.LungCOutputsIIIANsNoD +CMC.f294 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIIANoD CMC.LungCProgressIIBIIIA +CMC.d413 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIIAIIIB CMC.LungCProgressIIIAIIIBRate +CMC.d932 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputRelapse CMC.LungCT2Progresses +CMC.d764 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIIBNosNoD CMC.LungCsIIIBNoD +CMC.f275 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIBNoD CMC.LungCProgressIAIB +CMC.d803 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCCured1PopCorr CMC.LungCModelPopCorrectionFactor +CMC.d606 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputDiagnosis CMC.LungCsIIADiagnosis +CMC.d724 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputScDiagnosis CMC.LungCs02Diagnosis +CMC.d691 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs01NsDiagnosis CMC.LungCs01Diagnosis +CMC.d666 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIAScNoD CMC.LungCsIIANoD +CMC.d432 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIVDiagnosis CMC.LungCsIVDiagnosisRate +CMC.d346 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIIANoDPopCorr CMC.LungCModelPopCorrectionFactor +CMC.f911 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCTherapy2Failed CMC.LungCD +CMC.d907 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputTherapy1 CMC.LungCTherapy1Mortality +CMC.d708 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIIBScDiagnosis CMC.LungCsIIIBDiagnosis +CMC.d650 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIVNsNoD CMC.LungCsIVNoD +CMC.d710 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIVScDiagnosis CMC.LungCsIVDiagnosis +CMC.f895 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT1Deceased CMC.LungCTherapy1Mortality +CMC.d856 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputHealthyAndTreated CMC.LungCCured1 +CMC.d69 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIANoDAgeing CMC.LungCsIANoD +CMC.d664 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIAScNoD CMC.LungCsIANoD +CMC.d545 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs03 CMC.LungCs03IniVal +CMC.f191 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIANoD CMC.LungCProgressIAIIA +CMC.f224 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT1Disabling CMC.LungCT1DisablingPopCorr +CMC.d187 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputModelPop CMC.LungCModelPop +CMC.d646 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIANsNoD CMC.LungCsIIANoD +CMC.d262 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs03PopCorr CMC.LungCs03 +CMC.d79 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTreated1Ageing CMC.LungCNotProgressing1 +CMC.d212 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT1ProgToDisabling CMC.LungCT1Progressing +CMC.d352 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIIANoDAgeing CMC.LungCsIIIANoD +CMC.d126 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPop CMC.LungCHealthy +CMC.d251 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs02PopCorr CMC.LungCs02 +CMC.f426 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCD CMC.LungCsIIIBDiagnosis +CMC.f279 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgressIBIIB CMC.LungCsIBNoD +CMC.d176 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT2DisablingPopCorr CMC.LungCT2Disabling +CMC.d256 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs02Ageing CMC.DummyRateForUnitsConversion +CMC.d810 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy1 CMC.LungCTherapy1CureRatio +CMC.d574 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIBIV CMC.LungCsIIBNoD +CMC.d170 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT2ProgressingPopCorr CMC.LungCModelPopCorrectionFactor +CMC.f33 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT2Progressing CMC.LungCT2Progresses +CMC.d920 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy2Failed CMC.LungCD +CMC.f428 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCD CMC.LungCsIVDiagnosis +CMC.d887 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCoutputNoDNos CMC.LungCOutputsIIANosNoD +CMC.d227 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT1DisablingPopCorr CMC.LungCModelPopCorrectionFactor +CMC.f26 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCNotProgressing2 CMC.LungCTherapy2 +CMC.d99 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCHealthyAgeing CMC.DummyRateForUnitsConversion +CMC.d566 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIAIV CMC.LungCProgressIAIVRate +CMC.f526 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgressIBIV CMC.LungCsIBNoD +CMC.d72 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIADiagnosis CMC.LungCsIADiagnosisRate +CMC.d869 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDNs CMC.LungCOutputsIIIANsNoD +CMC.d806 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapyCure1 CMC.LungCFirstTreatmentRate +CMC.d255 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs02Ageing CMC.LungCs02 +CMC.d500 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs02Diagnosis CMC.LungCs02DiagnosisRate +CMC.f790 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCCured1 CMC.LungCTherapyCure1 +CMC.f533 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIVNoD CMC.LungCProgressIIBIV +CMC.d918 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy2 CMC.LungCTherapy2FailRatio +CMC.d604 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputDiagnosis CMC.LungCsIADiagnosis +CMC.d556 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgress02IV CMC.LungCProgress02IVRate +CMC.d717 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNsDiagnosis CMC.LungCsIBDiagnosis +CMC.f232 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCs03 CMC.LungCProgress0203 +CMC.d462 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPop CMC.LungCNotProgressing1 +CMC.d843 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPop CMC.LungCCured2 +CMC.d815 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputCured1 CMC.LungCCured1 +CMC.d330 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIANoDAgeing CMC.LungCsIIANoD +CMC.f263 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCs03 CMC.LungCs03Ageing +CMC.f167 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT2Progressing CMC.LungCT2ProgressingPopCorr +CMC.d360 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIIBNoDPopCorr CMC.LungCModelPopCorrectionFactor +CMC.d692 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs01ScDiagnosis CMC.LungCs01Diagnosis +CMC.d610 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputDiagnosis CMC.LungCsIVDiagnosis +CMC.f514 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgress02IV CMC.LungCs02 +CMC.d931 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputRelapse CMC.LungCT1Progresses +CMC.d725 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputScDiagnosis CMC.LungCs03Diagnosis +CMC.d663 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs03ScNoD CMC.LungCs03 +CMC.f513 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIVNoD CMC.LungCProgress02IV +CMC.d854 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputTherapy1NoCure CMC.LungCTherapy1 +CMC.f797 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCCured1 CMC.LungCCured1PopCorr +CMC.f510 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgress01IV CMC.LungCs01 +CMC.d549 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIBNoD CMC.LungCsIIBNoDIniVal +CMC.d877 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDSc CMC.LungCOutputsIIAScNoD +CMC.d645 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIBNsNoD CMC.LungCsIBNoD +CMC.f322 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIANoD CMC.LungCsIIANoDPopCorr +CMC.f469 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCD CMC.LungCDAgeing +CMC.f353 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIIBNoD CMC.LungCsIIIBNoDPopCorr +CMC.d575 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIIAIV CMC.LungCProgressIIIAIVRate +CMC.f375 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIBDiagnosis CMC.LungCsIBNoD +CMC.d709 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIVNsDiagnosis CMC.LungCsIVDiagnosis +CMC.d128 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPopCorrectionFactor CMC.LungCCausedDeath +CMC.d589 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNotProgressing2 CMC.LungCNotProgressing2 +CMC.d250 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs02PopCorr CMC.LungCModelPopCorrectionFactor +CMC.f192 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgressIAIIA CMC.LungCsIANoD +CMC.d303 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIBIIB CMC.LungCsIBNoD +CMC.d614 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputTherapy2 CMC.LungCTherapy2 +CMC.d699 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIBNsDiagnosis CMC.LungCsIBDiagnosis +CMC.d501 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs02Diagnosis CMC.LungCs02 +CMC.f278 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIBNoD CMC.LungCProgressIBIIB +CMC.d490 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCNotProgressing2 CMC.LungCTreated2IniVal +CMC.f150 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCNotProgressing1 CMC.LungCTreated1PopCorr +CMC.d155 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTreated1PopCorr CMC.LungCNotProgressing1 +CMC.d130 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPopCorrectionFactor CMC.TotalPopulation +CMC.d245 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgress03IA CMC.LungCs03 +CMC.d626 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputDisabling1 CMC.LungCT1Disabling +CMC.d543 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs01 CMC.LungCs01IniVal +CMC.d583 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy2 CMC.LungCTherapy2Ratio +CMC.f257 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCs03 CMC.LungCs03PopCorr +CMC.d782 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIBNosDiagnosis CMC.LungCsIIBDiagnosis +CMC.d85 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT2Progresses CMC.LungCNotProgressing2 +CMC.d809 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapyCure1 CMC.LungCTherapy1CureRatio +CMC.f332 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIBNoD CMC.LungCsIIBNoDPopCorr +CMC.f425 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCD CMC.LungCsIIIADiagnosis +CMC.d745 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNosDiagnosis CMC.LungCsIVDiagnosis +CMC.f34 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT2Progresses CMC.LungCNotProgressing2 +CMC.d832 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapyCure2 CMC.LungCFirstTreatmentRate +CMC.d736 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNosDiagnosis CMC.LungCs01Diagnosis +CMC.d781 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIANosDiagnosis CMC.LungCsIIADiagnosis +CMC.d603 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputDiagnosis CMC.LungCs03Diagnosis +CMC.d828 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapyCure2 CMC.LungCTherapy2Ratio +CMC.d90 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT2ProgToDisabling CMC.LungCT2Progressing +CMC.d102 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTreated2Ageing CMC.DummyRateForUnitsConversion +CMC.d565 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgress03IV CMC.LungCProgress03IVRate +CMC.d620 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputT2Mortality CMC.LungCT2Death +CMC.d850 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputTherapy2NoCure CMC.LungCTherapy2 +CMC.d891 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCoutputNoDNos CMC.LungCOutputsIVNosNoD +CMC.f16 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgress0102 CMC.LungCs01 +CMC.d730 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputScDiagnosis CMC.LungCsIIIADiagnosis +CMC.d921 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCD CMC.LungCDIniVal +CMC.d55 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCHealthyAgeing CMC.LungCHealthy +CMC.f233 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgress0203 CMC.LungCs02 +CMC.d57 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCInception CMC.LungCInceptionRate +CMC.d368 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIVNoDAgeing CMC.DummyRateForUnitsConversion +CMC.f424 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCD CMC.LungCsIIADiagnosis +CMC.d872 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDSc CMC.LungCOutputs01ScNoD +CMC.d316 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIBNoDPopCorr CMC.LungCsIBNoD +CMC.d89 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT2ProgToDisabling CMC.LungCT2ProgToDisablingRate +CMC.d175 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT2DisablingPopCorr CMC.LungCModelPopCorrectionFactor +CMC.f11 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCs01 CMC.LungCInception +CMC.d492 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT2Progressing CMC.LungCT2ProgressingIniVal +CMC.d347 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIIANoDPopCorr CMC.LungCsIIIANoD +CMC.d842 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputCured2 CMC.LungCCured2 +CMC.d665 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIBScNoD CMC.LungCsIBNoD +CMC.f434 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCD CMC.LungCs03Diagnosis +CMC.d93 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT2Death CMC.LungCT2DeathRate +CMC.d899 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy1Mortality CMC.LungCFirstTreatmentRate +CMC.d865 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDNs CMC.LungCOutputsIBNsNoD +CMC.f291 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgressIIBIIIB CMC.LungCsIIBNoD +CMC.d374 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIVNoDPopCorr CMC.LungCsIVNoD +CMC.d904 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy1 CMC.LungCTherapy1MortalityRatio +CMC.f429 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIVDiagnosis CMC.LungCsIVNoD +CMC.d649 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIIBNsNoD CMC.LungCsIIIBNoD +CMC.d409 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIAIIIA CMC.LungCProgressIIAIIIARate +CMC.d642 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs02NsNoD CMC.LungCs02 +CMC.d648 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIIANsNoD CMC.LungCsIIIANoD +CMC.d886 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCoutputNoDNos CMC.LungCOutputsIBNosNoD +CMC.d585 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT2Progresses CMC.LungCT2ProgressesRate +CMC.f327 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIANoD CMC.LungCsIIANoDAgeing +CMC.d727 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputScDiagnosis CMC.LungCsIBDiagnosis +CMC.d320 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIBNoDAgeing CMC.LungCsIBNoD +CMC.d732 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputScDiagnosis CMC.LungCsIVDiagnosis +CMC.d811 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCCured1 CMC.LungCCured1IniVal +CMC.d361 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIIBNoDPopCorr CMC.LungCsIIIBNoD +CMC.d465 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPop CMC.LungCT1Disabling +CMC.d184 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputHealthyAndTreated CMC.LungCNotProgressing1 +CMC.d776 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs01NosDiagnosis CMC.LungCs01Diagnosis +CMC.d894 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputModelPopExcludingHealthy CMC.LungCHealthy +CMC.d131 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPopCorrectionFactor CMC.LungCModelPopCorrectionRate +CMC.d181 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT2ProgressingAgeing CMC.LungCT2Progressing +CMC.d385 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIADiagnosis CMC.LungCsIIADiagnosisRate +CMC.f502 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCD CMC.LungCs01Diagnosis +CMC.d307 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIBIIIA CMC.LungCsIIBNoD +CMC.d801 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCCured1Ageing CMC.DummyRateForUnitsConversion +CMC.d154 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTreated1PopCorr CMC.LungCModelPopCorrectionFactor +CMC.f830 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCTherapyCure2 CMC.LungCD +CMC.d553 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgress01IV CMC.LungCProgress01IVRate +CMC.d747 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs01NosNoD CMC.LungCs01 +CMC.d847 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputTherapy2 CMC.LungCTherapyCure2 +CMC.d704 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIBScDiagnosis CMC.LungCsIIBDiagnosis +CMC.d326 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIANoDPopCorr CMC.LungCModelPopCorrectionFactor +CMC.f47 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCBirth CMC.Cloud45 +CMC.d619 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputT1Mortality CMC.LungCT1Death +CMC.f37 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT2Disabling CMC.LungCT2ProgToDisabling +CMC.d335 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIBNoDPopCorr CMC.LungCsIIBNoD +CMC.d855 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputTherapy1Cure CMC.LungCTherapyCure1 +CMC.d195 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIAIIA CMC.LungCsIANoD +CMC.d698 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIAScDiagnosis CMC.LungCsIADiagnosis +CMC.d554 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgress01IV CMC.LungCs01 +CMC.d831 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapyCure2 CMC.LungCD +CMC.f521 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIVNoD CMC.LungCProgressIAIV +CMC.f162 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCD CMC.LungCDPopCorr +CMC.d433 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIVDiagnosis CMC.LungCsIVNoD +CMC.d780 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIBNosDiagnosis CMC.LungCsIBDiagnosis +CMC.d880 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDSc CMC.LungCOutputsIIIBScNoD +CMC.d647 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIBNsNoD CMC.LungCsIIBNoD +CMC.d74 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy2 CMC.LungCD +CMC.d440 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs03Diagnosis CMC.LungCs03 +CMC.d890 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCoutputNoDNos CMC.LungCOutputsIIIBNosNoD +CMC.d740 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNosDiagnosis CMC.LungCsIBDiagnosis +CMC.f299 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgressIIIAIIIB CMC.LungCsIIIANoD +CMC.d103 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIANoDAgeing CMC.DummyRateForUnitsConversion +CMC.d922 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT2Disabling CMC.LungCT2DisablingIniVal +CMC.f201 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT1ProgToDisabling CMC.LungCT1Progressing +CMC.d602 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputDiagnosis CMC.LungCs02Diagnosis +CMC.d871 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDNs CMC.LungCOutputsIVNsNoD +CMC.f423 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCD CMC.LungCsIIBDiagnosis +CMC.d719 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNsDiagnosis CMC.LungCsIIBDiagnosis +CMC.d902 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy1Mortality CMC.LungCTherapy1MortalityRatio +CMC.d827 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCCured2PopCorr CMC.LungCCured2 +CMC.d91 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT2Death CMC.LungCT2Disabling +CMC.d266 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs03Ageing CMC.LungCs03 +CMC.d467 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPop CMC.LungCT2Disabling +CMC.d701 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIANsDiagnosis CMC.LungCsIIADiagnosis +CMC.f474 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCTherapy1 CMC.LungCD +CMC.f820 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCCured2 CMC.LungCCured2Ageing +CMC.d867 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDNs CMC.LungCOutputsIIBNsNoD +CMC.f214 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT1Progressing CMC.LungCT1ProgressingPopCorr +CMC.f422 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCD CMC.LungCsIBDiagnosis +CMC.f817 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCCured2 CMC.LungCTherapyCure2 +CMC.d905 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy1Mortality CMC.LungCD +CMC.d97 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy1 CMC.LungCTherapy1Ratio +CMC.f41 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT2Deceased CMC.LungCT2Death +CMC.d731 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputScDiagnosis CMC.LungCsIIIBDiagnosis +CMC.d668 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIIAScNoD CMC.LungCsIIIANoD +CMC.f52 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCHealthy CMC.LungCHealthyAgeing +CMC.d302 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIAIB CMC.LungCsIANoD +CMC.d229 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCCausedDeath CMC.LungCT1Death +CMC.d866 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDNs CMC.LungCOutputsIIANsNoD +CMC.f910 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT2Progressing CMC.LungCTherapy2Failed +CMC.d693 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs02NsDiagnosis CMC.LungCs02Diagnosis +CMC.f503 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCs01Diagnosis CMC.LungCs01 +CMC.d315 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIBNoDPopCorr CMC.LungCModelPopCorrectionFactor +CMC.d402 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIIBDiagnosis CMC.LungCsIIIBNoD +CMC.d641 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs01NsNoD CMC.LungCs01 +CMC.d893 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputModelPopExcludingHealthy CMC.LungCModelPop +CMC.d576 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIIAIV CMC.LungCsIIIANoD +CMC.d761 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIANosNoD CMC.LungCsIIANoD +CMC.d838 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapyCure2 CMC.LungCTherapy2CureRatio +CMC.d222 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT1ProgressingAgeing CMC.LungCT1Progressing +CMC.d616 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputMortality CMC.LungCCausedDeath +CMC.d738 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNosDiagnosis CMC.LungCs03Diagnosis +CMC.d83 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTreated2Ageing CMC.LungCNotProgressing2 +CMC.d804 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapyCure1 CMC.LungCTherapy1Ratio +CMC.d870 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDNs CMC.LungCOutputsIIIBNsNoD +CMC.d305 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIAIIB CMC.LungCsIIANoD +CMC.f896 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCTherapy1Mortality CMC.LungCD +CMC.d544 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs02 CMC.LungCs02IniVal +CMC.f217 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT1Progressing CMC.LungCT1ProgressingAgeing +CMC.d122 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCHealthyPopCorr CMC.LungCHealthy +CMC.d777 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs02NosDiagnosis CMC.LungCs02Diagnosis +CMC.d143 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs01PopCorr CMC.LungCModelPopCorrectionFactor +CMC.d269 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs03Ageing CMC.DummyRateForUnitsConversion +CMC.d464 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPop CMC.LungCT1Progressing +CMC.d628 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputDisabling2 CMC.LungCT2Disabling +CMC.d878 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDSc CMC.LungCOutputsIIBScNoD +CMC.d363 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIIBNoDAgeing CMC.DummyRateForUnitsConversion +CMC.f46 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCHealthy CMC.LungCBirth +CMC.d630 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDSum CMC.LungCNoDSum +CMC.d183 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputHealthyAndTreated CMC.LungCHealthy +CMC.f518 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgress03IV CMC.LungCs03 +CMC.d472 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCDAgeing CMC.LungCD +CMC.d362 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIIBNoDAgeing CMC.LungCsIIIBNoD +CMC.d439 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs03Diagnosis CMC.LungCs03DiagnosisRate +CMC.f317 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIBNoD CMC.LungCsIBNoDAgeing +CMC.d608 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputDiagnosis CMC.LungCsIIIADiagnosis +CMC.d132 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPopCorrectionFactor CMC.LungCModelPop +CMC.d411 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIAIIB CMC.LungCProgressIIAIIBRate +CMC.d705 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIIANsDiagnosis CMC.LungCsIIIADiagnosis +CMC.f398 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIIBDiagnosis CMC.LungCsIIIBNoD +CMC.d836 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCCured2 CMC.LungCCured2IniVal +CMC.d546 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIANoD CMC.LungCsIANoDIniVal +CMC.d407 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIAIIA CMC.LungCProgressIAIIARate +CMC.f537 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgressIIIAIV CMC.LungCsIIIANoD +CMC.f522 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgressIAIV CMC.LungCsIANoD +CMC.d785 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIVNosDiagnosis CMC.LungCsIVDiagnosis +CMC.d587 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNotProgressing1 CMC.LungCNotProgressing1 +CMC.d609 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputDiagnosis CMC.LungCsIIIBDiagnosis +CMC.d667 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIBScNoD CMC.LungCsIIBNoD +CMC.d741 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNosDiagnosis CMC.LungCsIIADiagnosis +CMC.f298 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIIBNoD CMC.LungCProgressIIIAIIIB +CMC.d95 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy1 CMC.LungCFirstTreatmentRate +CMC.d714 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNsDiagnosis CMC.LungCs02Diagnosis +CMC.d601 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputDiagnosis CMC.LungCs01Diagnosis +CMC.d243 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgress03IA CMC.LungCProgress03IARate +CMC.d779 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIANosDiagnosis CMC.LungCsIADiagnosis +CMC.d551 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIIBNoD CMC.LungCsIIIBNoDIniVal +CMC.f529 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIVNoD CMC.LungCProgressIIAIV +CMC.d697 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIANsDiagnosis CMC.LungCsIADiagnosis +CMC.d726 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputScDiagnosis CMC.LungCsIADiagnosis +CMC.d397 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIIADiagnosis CMC.LungCsIIIANoD +CMC.d857 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputHealthyAndTreated CMC.LungCCured2 +CMC.d707 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIIBNsDiagnosis CMC.LungCsIIIBDiagnosis +CMC.d65 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgress0102 CMC.LungCs01 +CMC.d261 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCs03PopCorr CMC.LungCModelPopCorrectionFactor +CMC.d459 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCNoDSum CMC.LungCsIVNoD +CMC.d321 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIBNoDAgeing CMC.DummyRateForUnitsConversion +CMC.d823 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCCured2Ageing CMC.LungCCured2 +CMC.d903 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapyCure1 CMC.LungCTherapy1MortalityRatio +CMC.f204 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT1Deceased CMC.LungCT1Death +CMC.d165 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCDPopCorr CMC.LungCModelPopCorrectionFactor +CMC.d729 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputScDiagnosis CMC.LungCsIIBDiagnosis +CMC.f435 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCs03Diagnosis CMC.LungCs03 +CMC.d924 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputTherapy2 CMC.LungCTherapy2Failed +CMC.d885 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCoutputNoDNos CMC.LungCOutputsIANosNoD +CMC.d884 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCoutputNoDNos CMC.LungCOutputs03NosNoD +CMC.d228 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT1DisablingPopCorr CMC.LungCT1Disabling +CMC.d760 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIBNosNoD CMC.LungCsIBNoD +CMC.d863 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDNs CMC.LungCOutputs03NsNoD +CMC.d749 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs02NosNoD CMC.LungCs02 +CMC.d268 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIANoDPopCorr CMC.LungCModelPopCorrectionFactor +CMC.f172 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT2Disabling CMC.LungCT2DisablingPopCorr +CMC.f404 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgressIAIB CMC.LungCsIANoD +CMC.d223 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT1ProgressingAgeing CMC.DummyRateForUnitsConversion +CMC.d613 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputTherapy1 CMC.LungCTherapy1 +CMC.d721 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNsDiagnosis CMC.LungCsIIIBDiagnosis +CMC.f282 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIIANoD CMC.LungCProgressIIAIIIA +CMC.d669 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIIBScNoD CMC.LungCsIIIBNoD +CMC.d121 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCHealthyPopCorr CMC.LungCModelPopCorrectionFactor +CMC.d702 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIAScDiagnosis CMC.LungCsIIADiagnosis +CMC.d487 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT1Progressing CMC.LungCT1ProgressingIniVal +CMC.d873 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDSc CMC.LungCOutputs02ScNoD +CMC.d577 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIIBIV CMC.LungCProgressIIIBIVRate +CMC.d209 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCT1ProgToDisabling CMC.LungCT1ProgToDisablingRate +CMC.f117 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCHealthy CMC.LungCHealthyPopCorr +CMC.d643 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs03NsNoD CMC.LungCs03 +CMC.d455 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCNoDSum CMC.LungCsIIANoD +CMC.f80 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCNotProgressing2 CMC.LungCTreated2Ageing +CMC.d336 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIBNoDPopCorr CMC.LungCModelPopCorrectionFactor +CMC.d457 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCNoDSum CMC.LungCsIIIANoD +CMC.d696 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputs03ScDiagnosis CMC.LungCs03Diagnosis +CMC.d713 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNsDiagnosis CMC.LungCs01Diagnosis +CMC.d879 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDSc CMC.LungCOutputsIIIAScNoD +CMC.d550 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIIANoD CMC.LungCsIIIANoDIniVal +CMC.d670 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIVScNoD CMC.LungCsIVNoD +CMC.d419 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIBIIIA CMC.LungCProgressIIBIIIARate +CMC.f290 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIIBNoD CMC.LungCProgressIIBIIIB +CMC.d149 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIANoDPopCorr CMC.LungCsIANoD +CMC.d625 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputProgressing1 CMC.LungCT1Progressing +CMC.d304 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIAIIIA CMC.LungCsIIANoD +CMC.d547 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIBNoD CMC.LungCsIBNoDIniVal +CMC.d396 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIIADiagnosis CMC.LungCsIIIADiagnosisRate +CMC.f530 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgressIIAIV CMC.LungCsIIANoD +CMC.f66 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIANoD CMC.LungCsIANoDAgeing +CMC.f19 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCD CMC.LungCsIADiagnosis +CMC.d306 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIBIIIB CMC.LungCsIIBNoD +CMC.d763 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIIANosNoD CMC.LungCsIIIANoD +CMC.d70 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIADiagnosis CMC.LungCsIANoD +CMC.d839 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy2 CMC.LungCTherapy2CureRatio +CMC.f793 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCCured1 CMC.LungCCured1Ageing +CMC.d166 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCDPopCorr CMC.LungCD +CMC.f30 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT1Progresses CMC.LungCNotProgressing1 +CMC.d570 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIBIV CMC.LungCsIBNoD +CMC.d909 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputTherapy1MortalityInTherapy CMC.LungCTherapy1Mortality +CMC.d403 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIIBDiagnosis CMC.LungCsIIIBDiagnosisRate +CMC.d466 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCModelPop CMC.LungCT2Progressing +CMC.f252 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCs02 CMC.LungCs02Ageing +CMC.d883 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCoutputNoDNos CMC.LungCOutputs02NosNoD +CMC.f283 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCProgressIIAIIIA CMC.LungCsIIANoD +CMC.d134 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCHealthy CMC.LungCHealthyIniVal +CMC.d75 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy1 CMC.LungCD +CMC.f156 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCNotProgressing2 CMC.LungCTreated2PopCorr +CMC.d421 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgressIIBIIIB CMC.LungCProgressIIBIIIBRate +CMC.f59 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCs01 CMC.LungCs01Ageing +CMC.d450 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCNoDSum CMC.LungCs01 +CMC.d703 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputsIIBNsDiagnosis CMC.LungCsIIBDiagnosis +CMC.d864 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputNoDNs CMC.LungCOutputsIANsNoD +CMC.d900 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapy1Mortality CMC.LungCTherapy1Ratio +CMC.d473 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCDAgeing CMC.DummyRateForUnitsConversion +CMC.d185 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCOutputHealthyAndTreated CMC.LungCNotProgressing2 +CMC.d390 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCsIIBDiagnosis CMC.LungCsIIBNoD +CMC.f356 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCsIIIBNoD CMC.LungCsIIIBNoDAgeing +CMC.f38 : SYSDYN.Flow + @WM.conf_dependency CMC.LungCT2ProgToDisabling CMC.LungCT2Progressing +CMC.d807 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCTherapyCure1 CMC.LungCD +CMC.d242 : SYSDYN.Dependency + @WM.conf_dependency CMC.LungCProgress0203 CMC.LungCProgress0203Rate + +CMC.TotalPopulationT1 : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "delay(TotalPopulation[Gender,Age], 1)" + +CMC.TotalPopulationBirth : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "DummyRateForUnitsConversion*TotalPopulationT1[Gender,Age0]" + +CMC.TotalPopulationMen : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_DATA('LCancer.xls', 'Population_In', '7', 'C113')" + +CMC.OutputDataTotalPopulationMenSum : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(TotalPopulationMen[Age!])" + +CMC.TotalPopulationWomen : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "XLS_DATA('LCancer.xls', 'Population_In', '7', 'C9')" + +CMC.TotalPopulation : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "TotalPopulationMen[Age]" + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "TotalPopulationWomen[Age]" + +CMC.OutputDataTotalPopulationWomenSum : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "sum(TotalPopulationWomen[Age!])" + +CMC.DummyRateForUnitsConversion : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "1" + +CMC.TotalPopulationDeath : SYSDYN.Auxiliary + @L0.tag MOD.Mapped + SYSDYN.HasExpressions _ : SYSDYN.Expressions + @L0.orderedSet + _ : SYSDYN.NormalExpression + SYSDYN.HasEquation "if Age==Age99 then (TotalPopulation[Gender,Age99]+TotalPopulation[Gender,Age100]-TotalPopulationT1[Gender,Age100])/4 elseif Age==Age100 then (TotalPopulation[Gender,Age99]+TotalPopulation[Gender,Age100]-TotalPopulationT1[Gender,Age100])*3/4 else VECTOR_MAP(TotalPopulation[Gender,Age], 0)-VECTOR_MAP(TotalPopulationT1[Gender,Age], 1)*DummyRateForUnitsConversion" + +CMC.d6 : SYSDYN.Dependency + @WM.conf_dependency CMC.TotalPopulationDeath CMC.TotalPopulation +CMC.d21 : SYSDYN.Dependency + @WM.conf_dependency CMC.TotalPopulationDeath CMC.DummyRateForUnitsConversion +CMC.d9 : SYSDYN.Dependency + @WM.conf_dependency CMC.TotalPopulation CMC.TotalPopulationMen +CMC.d17 : SYSDYN.Dependency + @WM.conf_dependency CMC.OutputDataTotalPopulationMenSum CMC.TotalPopulationMen +CMC.d12 : SYSDYN.Dependency + @WM.conf_dependency CMC.TotalPopulationDeath CMC.TotalPopulationT1 +CMC.d20 : SYSDYN.Dependency + @WM.conf_dependency CMC.TotalPopulationBirth CMC.DummyRateForUnitsConversion +CMC.d14 : SYSDYN.Dependency + @WM.conf_dependency CMC.TotalPopulationT1 CMC.TotalPopulation +CMC.d18 : SYSDYN.Dependency + @WM.conf_dependency CMC.OutputDataTotalPopulationWomenSum CMC.TotalPopulationWomen +CMC.d10 : SYSDYN.Dependency + @WM.conf_dependency CMC.TotalPopulation CMC.TotalPopulationWomen +CMC.d13 : SYSDYN.Dependency + @WM.conf_dependency CMC.TotalPopulationBirth CMC.TotalPopulationT1 + +LungCancerConfigurationDiagram : SYSDYN.ConfigurationDiagram + + org.simantics.sysdyn.product.site.feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/stable/org.simantics.sysdyn.product.site.feature/Resources.rmap b/stable/org.simantics.sysdyn.product.site.feature/Resources.rmap new file mode 100644 index 00000000..78c416fe --- /dev/null +++ b/stable/org.simantics.sysdyn.product.site.feature/Resources.rmap @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.product.site.feature/buckminster.cspex b/stable/org.simantics.sysdyn.product.site.feature/buckminster.cspex new file mode 100644 index 00000000..46e472e2 --- /dev/null +++ b/stable/org.simantics.sysdyn.product.site.feature/buckminster.cspex @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.product.site.feature/buckminster.properties b/stable/org.simantics.sysdyn.product.site.feature/buckminster.properties new file mode 100644 index 00000000..f310dee4 --- /dev/null +++ b/stable/org.simantics.sysdyn.product.site.feature/buckminster.properties @@ -0,0 +1,22 @@ +#buckminster.output.root=c:/simantics-build/site +#buckminster.temp.root=c:/simantics-build/temp + +# How .qualifier in versions should be replaced +qualifier.replacement.*=generator:lastRevision +generator.lastRevision.format=r{0,number,000000} + +# Pack200 compression +#site.pack200=true +#site.retain.unpack=true + +# JAR Signing +#site.signing=true +#signing.type=local +#local.sign=true + +# Generate source bundles +cbi.include.source=false + +target.os=win32 +target.ws=win32 +target.arch=* diff --git a/stable/org.simantics.sysdyn.product.site.feature/build.properties b/stable/org.simantics.sysdyn.product.site.feature/build.properties new file mode 100644 index 00000000..82ab19c6 --- /dev/null +++ b/stable/org.simantics.sysdyn.product.site.feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/stable/org.simantics.sysdyn.product.site.feature/build/product.ant b/stable/org.simantics.sysdyn.product.site.feature/build/product.ant new file mode 100644 index 00000000..77b45fc6 --- /dev/null +++ b/stable/org.simantics.sysdyn.product.site.feature/build/product.ant @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.product.site.feature/feature.xml b/stable/org.simantics.sysdyn.product.site.feature/feature.xml new file mode 100644 index 00000000..8612af15 --- /dev/null +++ b/stable/org.simantics.sysdyn.product.site.feature/feature.xml @@ -0,0 +1,24 @@ + + + + + [Enter Feature Description here.] + + + + [Enter Copyright Description here.] + + + + [Enter License Description here.] + + + + + diff --git a/stable/org.simantics.sysdyn.product.site.feature/jenkins.buckminster.script b/stable/org.simantics.sysdyn.product.site.feature/jenkins.buckminster.script new file mode 100644 index 00000000..5fd1c714 --- /dev/null +++ b/stable/org.simantics.sysdyn.product.site.feature/jenkins.buckminster.script @@ -0,0 +1,6 @@ +importtargetdefinition -A 'd:/target/3.6.2/target-win.target' +import 'org.simantics.sysdyn.product.site/site.cquery' +build +perform -D target.os=* -D target.ws=* -D target.arch=* org.simantics.sysdyn.product.site#site.p2 +perform -D target.os=win32 -D target.ws=win32 -D target.arch=x86 -D p2.profileName=SysdynProfile -D p2.rootId=org.simantics.sysdyn.product.Sysdyn -D build.label=SimanticsSysdyn-b${BUILD_NUMBER}-r${SVN_REVISION} org.simantics.sysdyn.product.site#create.product.zip +perform -D target.os=win32 -D target.ws=win32 -D target.arch=x86_64 -D p2.profileName=SysdynProfile -D p2.rootId=org.simantics.sysdyn.product.Sysdyn -D build.label=SimanticsSysdyn-b${BUILD_NUMBER}-r${SVN_REVISION} org.simantics.sysdyn.product.site#create.product.zip diff --git a/stable/org.simantics.sysdyn.product.site.feature/site.cquery b/stable/org.simantics.sysdyn.product.site.feature/site.cquery new file mode 100644 index 00000000..f5538104 --- /dev/null +++ b/stable/org.simantics.sysdyn.product.site.feature/site.cquery @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/stable/org.simantics.sysdyn.ui.old/.classpath b/stable/org.simantics.sysdyn.ui.old/.classpath new file mode 100644 index 00000000..8a8f1668 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/stable/org.simantics.sysdyn.ui.old/.project b/stable/org.simantics.sysdyn.ui.old/.project new file mode 100644 index 00000000..2ebd5691 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/.project @@ -0,0 +1,28 @@ + + + org.simantics.sysdyn.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/stable/org.simantics.sysdyn.ui.old/.settings/org.eclipse.jdt.core.prefs b/stable/org.simantics.sysdyn.ui.old/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..6d816954 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Thu Nov 05 12:45:23 EET 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/stable/org.simantics.sysdyn.ui.old/META-INF/MANIFEST.MF b/stable/org.simantics.sysdyn.ui.old/META-INF/MANIFEST.MF new file mode 100644 index 00000000..33131cad --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: org.simantics.sysdyn.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.simantics.sysdyn.ui.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.simantics.ui;bundle-version="1.0.0", + org.simantics.diagram;bundle-version="1.0.0", + org.simantics.db;bundle-version="0.6.2", + org.simantics.db.common;bundle-version="0.6.2", + org.simantics.db.layer0;bundle-version="0.7.0", + org.simantics.g2d;bundle-version="1.0.0", + org.simantics.scenegraph;bundle-version="1.0.0", + org.simantics.layer0.utils;bundle-version="0.6.2" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 diff --git a/stable/org.simantics.sysdyn.ui.old/adapters.xml b/stable/org.simantics.sysdyn.ui.old/adapters.xml new file mode 100644 index 00000000..86c2aa36 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/adapters.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui.old/build.properties b/stable/org.simantics.sysdyn.ui.old/build.properties new file mode 100644 index 00000000..6f20375d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/stable/org.simantics.sysdyn.ui.old/plugin.xml b/stable/org.simantics.sysdyn.ui.old/plugin.xml new file mode 100644 index 00000000..cac6482e --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/plugin.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + diff --git a/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/Activator.java b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/Activator.java new file mode 100644 index 00000000..21342378 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/Activator.java @@ -0,0 +1,50 @@ +package org.simantics.sysdyn.ui; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.simantics.sysdyn.ui"; + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/SysdynResource.java b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/SysdynResource.java new file mode 100644 index 00000000..426b3220 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/SysdynResource.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2007- VTT Technical Research Centre of Finland. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui; + + +import org.simantics.db.Resource; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; + +public class SysdynResource { + + public final Resource HasX; + public final Resource HasY; + public final Resource SysdynModel; + public final Resource SysdynModelManager; + public final Resource SysdynModellingDomain; + public final Resource TestDiagram; + public final Resource Variable; + public final Resource VariableElement; + + public static class URIs { + public static final String HasX = "http://www.simantics.org/Sysdyn#HasX"; + public static final String HasY = "http://www.simantics.org/Sysdyn#HasY"; + public static final String SysdynModel = "http://www.simantics.org/Sysdyn#SysdynModel"; + public static final String SysdynModelManager = "http://www.simantics.org/Sysdyn#SysdynModelManager"; + public static final String SysdynModellingDomain = "http://www.simantics.org/Sysdyn#SysdynModellingDomain"; + public static final String TestDiagram = "http://www.simantics.org/Sysdyn#TestDiagram"; + public static final String Variable = "http://www.simantics.org/Sysdyn#Variable"; + public static final String VariableElement = "http://www.simantics.org/Sysdyn#VariableElement"; + } + + public static Resource getResourceOrNull(ReadGraph graph, String uri) { + try { + return graph.getResourceByURI(uri); + } catch(DatabaseException e) { + System.err.println(e.getMessage()); + return null; + } + } + + public SysdynResource(ReadGraph graph) { + HasX = getResourceOrNull(graph, URIs.HasX); + HasY = getResourceOrNull(graph, URIs.HasY); + SysdynModel = getResourceOrNull(graph, URIs.SysdynModel); + SysdynModelManager = getResourceOrNull(graph, URIs.SysdynModelManager); + SysdynModellingDomain = getResourceOrNull(graph, URIs.SysdynModellingDomain); + TestDiagram = getResourceOrNull(graph, URIs.TestDiagram); + Variable = getResourceOrNull(graph, URIs.Variable); + VariableElement = getResourceOrNull(graph, URIs.VariableElement); + } + + public static SysdynResource getInstance(ReadGraph graph) { + Session session = graph.getSession(); + SysdynResource ret = session.getService(SysdynResource.class); + if(ret == null) { + ret = new SysdynResource(graph); + session.registerService(SysdynResource.class, ret); + } + return ret; + } + +} + diff --git a/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/adapters/VariableClassFactory.java b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/adapters/VariableClassFactory.java new file mode 100644 index 00000000..e45047f4 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/adapters/VariableClassFactory.java @@ -0,0 +1,46 @@ +package org.simantics.sysdyn.ui.adapters; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.adapter.ElementQuerySupport; +import org.simantics.diagram.adapter.GraphElementClassFactory; +import org.simantics.diagram.adapter.GraphElementFactory; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.impl.Element; +import org.simantics.sysdyn.ui.SysdynResource; +import org.simantics.sysdyn.ui.diagram.DrawableElementClass; +import org.simantics.sysdyn.ui.elements.TestDrawable; + +public class VariableClassFactory implements GraphElementFactory, GraphElementClassFactory { + + @Override + public IElement spawn(ReadGraph g, Resource resource, + ElementQuerySupport support, IDiagram diagram) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + + ElementClass elementClass = + DrawableElementClass.createElementClass(sr.VariableElement); + IElement element = Element.spawnNew(elementClass); + + TestDrawable drawable = new TestDrawable(); + drawable.moveTo( + (Double)g.getRelatedValue(resource, sr.HasX), + (Double)g.getRelatedValue(resource, sr.HasY) + ); + element.setHint(DrawableElementClass.KEY_CONTENT, drawable); + + //diagram.addElement(element); + return element; + } + + @Override + public ElementClass create(ReadGraph g, Resource elementType, + ElementQuerySupport support) throws DatabaseException { + return DrawableElementClass.createElementClass(elementType); + } + +} diff --git a/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/adapters/VariableElementWriter.java b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/adapters/VariableElementWriter.java new file mode 100644 index 00000000..a671b6ba --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/adapters/VariableElementWriter.java @@ -0,0 +1,23 @@ +package org.simantics.sysdyn.ui.adapters; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.synchronization.graph.ElementWriter; +import org.simantics.g2d.element.IElement; + +public class VariableElementWriter implements ElementWriter { + + @Override + public void addToGraph(WriteGraph graph, IElement element, + Resource elementResource) throws DatabaseException { + System.out.println("addToGraph"); + } + + @Override + public void removeFromGraph(WriteGraph graph, Resource elementResource) + throws DatabaseException { + System.out.println("removeFromGraph"); + } + +} diff --git a/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/diagram/DiagramEditorFacade.java b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/diagram/DiagramEditorFacade.java new file mode 100644 index 00000000..daf35821 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/diagram/DiagramEditorFacade.java @@ -0,0 +1,124 @@ +package org.simantics.sysdyn.ui.diagram; + +import java.awt.Color; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.simantics.db.ReadGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.adapter.GraphToDiagramSynchronizer; +import org.simantics.diagram.adapter.IDiagramLoader; +import org.simantics.diagram.participant.SGFocusParticipant; +import org.simantics.g2d.canvas.Hints; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.canvas.impl.CanvasContext; +import org.simantics.g2d.chassis.SWTChassis; +import org.simantics.g2d.diagram.DiagramHints; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.diagram.participant.CanvasBoundsParticipant; +import org.simantics.g2d.diagram.participant.DiagramParticipant; +import org.simantics.g2d.diagram.participant.ElementInteractor; +import org.simantics.g2d.diagram.participant.ElementPainter; +import org.simantics.g2d.diagram.participant.Selection; +import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor; +import org.simantics.g2d.element.ElementClassProviders; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.impl.Element; +import org.simantics.g2d.participant.CanvasGrab; +import org.simantics.g2d.participant.KeyUtil; +import org.simantics.g2d.participant.MousePanZoomInteractor; +import org.simantics.g2d.participant.MouseUtil; +import org.simantics.g2d.participant.Notifications; +import org.simantics.g2d.participant.PanZoomRotateHandler; +import org.simantics.g2d.participant.PointerPainter; +import org.simantics.g2d.participant.RulerPainter; +import org.simantics.g2d.participant.SGTransformUtil; +import org.simantics.g2d.snap.GridSnapAdvisor; +import org.simantics.layer0.utils.ResourceArray; +import org.simantics.sysdyn.ui.elements.IDrawable; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.workbench.ResourceEditorPart; +import org.simantics.utils.datastructures.hints.IHintContext; +import org.simantics.utils.threads.AWTThread; + +public abstract class DiagramEditorFacade extends ResourceEditorPart { + + SWTChassis chassis; + IDiagram diagram; + IDiagramLoader loader; + + public DiagramEditorFacade() { + super(); + } + + @Override + public void reload(ReadGraph g) throws DatabaseException { + // TODO Auto-generated method stub + } + + @Override + public void createPartControl(Composite parent) { + chassis = new SWTChassis(parent, SWT.NONE); + chassis.syncPopulate(); + + final ICanvasContext context = new CanvasContext( + AWTThread.getThreadAccess()); + chassis.setCanvasContext(context); + + context.add(new SGTransformUtil()); + context.add(new MouseUtil()); + context.add(new KeyUtil()); + context.add(new PanZoomRotateHandler()); + context.add(new MousePanZoomInteractor()); + context.add(new RulerPainter()); + context.add(new CanvasGrab()); + context.add(new CanvasBoundsParticipant()); + context.add(new Notifications()); + context.add(new SGFocusParticipant(chassis)); + context.add(new DiagramParticipant()); + context.add(new ElementPainter()); + context.add(new PointerInteractor(true, true, true, false, true, false, null)); + context.add(new ElementInteractor()); + context.add(new Selection()); + + IHintContext h = context.getDefaultHintContext(); + h.setHint(PointerPainter.KEY_PAINT_POINTER, true); + + h.setHint(ElementPainter.KEY_SELECTION_FRAME_COLOR, Color.MAGENTA); + h.setHint(Hints.KEY_TOOL, Hints.POINTERTOOL); + + h.setHint(PanZoomRotateHandler.KEY_ZOOM_IN_LIMIT, 100000.0); + h.setHint(PanZoomRotateHandler.KEY_ZOOM_OUT_LIMIT, 10.0); + + h.setHint(DiagramHints.SNAP_ADVISOR, + new GridSnapAdvisor(10.0)); + + try { + SimanticsUI.getSession().syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + loader = new GraphToDiagramSynchronizer(graph, context, + ElementClassProviders.staticProvider(null)); + + diagram = loader.loadDiagram(graph, + getResourceInput().getResource(), + ResourceArray.EMPTY, + null); + } + + }); + h.setHint(DiagramHints.KEY_DIAGRAM, diagram); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + + @Override + public void setFocus() { + chassis.setFocus(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/diagram/DrawableElementClass.java b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/diagram/DrawableElementClass.java new file mode 100644 index 00000000..2851dccd --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/diagram/DrawableElementClass.java @@ -0,0 +1,137 @@ +package org.simantics.sysdyn.ui.diagram; + +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.Collection; + +import org.simantics.db.Resource; +import org.simantics.diagram.adapter.handler.ResourceAdapter; +import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.InternalSize; +import org.simantics.g2d.element.handler.Move; +import org.simantics.g2d.element.handler.Outline; +import org.simantics.g2d.element.handler.Pick2; +import org.simantics.g2d.element.handler.SceneGraph; +import org.simantics.g2d.element.handler.Transform; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.sysdyn.ui.elements.IDrawable; +import org.simantics.sysdyn.ui.elements.ITransformable; +import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; + +public class DrawableElementClass { + private DrawableElementClass() {} + + public static KeyOf KEY_CONTENT = new KeyOf(IDrawable.class, "CONTENT"); + public static AffineTransform IDENTITY_TRANSFORM = new AffineTransform(); + + public static WidgetHandler WIDGET_HANDLER_INSTANCE = new WidgetHandler(); + + private static class WidgetHandler implements Transform, SceneGraph, InternalSize, Move, Outline, Pick2 { + + private static final long serialVersionUID = 1722978969083481038L; + + @Override + public void setTransform(IElement e, AffineTransform at) { + IDrawable drawable = (IDrawable)e.getHint(KEY_CONTENT); + if(drawable instanceof ITransformable) { + drawable = ((ITransformable)drawable).setTransform(at); + e.setHint(KEY_CONTENT, drawable); + drawable.updateSG(); + } + } + + @Override + public AffineTransform getTransform(IElement e) { + IDrawable drawable = (IDrawable)e.getHint(KEY_CONTENT); + if(drawable instanceof ITransformable) + return ((ITransformable)drawable).getTransform(); + else + return IDENTITY_TRANSFORM; + } + + @Override + public void cleanup(IElement e) { + ((IDrawable)e.getHint(KEY_CONTENT)).cleanupSG(); + } + + @Override + public void init(IElement e, G2DParentNode parent) { + ((IDrawable)e.getHint(KEY_CONTENT)).initSG(parent); + } + + @Override + public Rectangle2D getBounds(IElement e, Rectangle2D size) { + if(size == null) + size = new Rectangle2D.Double(); + ((IDrawable)e.getHint(KEY_CONTENT)).getBounds(size); + return size; + } + + @Override + public Point2D getPosition(IElement e) { + IDrawable drawable = (IDrawable)e.getHint(KEY_CONTENT); + if(drawable instanceof ITransformable) + return ((ITransformable)drawable).getPosition(); + else + return new Point2D.Double(0.0, 0.0); + } + + @Override + public void moveTo(IElement e, double x, double y) { + IDrawable drawable = (IDrawable)e.getHint(KEY_CONTENT); + if(drawable instanceof ITransformable) { + drawable = ((ITransformable)drawable).moveTo(x, y); + e.setHint(KEY_CONTENT, drawable); + drawable.updateSG(); + } + } + + @Override + public Shape getElementShape(IElement e) { + return getBounds(e, null); + } + + @Override + public int pick(IElement e, Shape s, PickPolicy policy, + Collection result) { + if(pickTest(e, s, policy)) { + result.add(e); + return 1; + } + else + return 0; + } + + @Override + public boolean pickTest(IElement e, Shape s, PickPolicy policy) { + IDrawable drawable = (IDrawable)e.getHint(KEY_CONTENT); + switch(policy) { + case PICK_CONTAINED_OBJECTS: + return drawable.pickContained(s); + case PICK_INTERSECTING_OBJECTS: + return drawable.pickIntersecting(s); + default: + return false; + } + } + + } + + public static ElementClass createElementClass(final Resource resource) { + return ElementClass.compile( + WIDGET_HANDLER_INSTANCE, + new ResourceAdapter() { + + @Override + public Resource getResource() { + return resource; + } + + } + ); + } +} diff --git a/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/diagram/SysdynDiagramEditor.java b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/diagram/SysdynDiagramEditor.java new file mode 100644 index 00000000..614a4374 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/diagram/SysdynDiagramEditor.java @@ -0,0 +1,12 @@ +package org.simantics.sysdyn.ui.diagram; + +import org.simantics.sysdyn.ui.elements.TestDrawable; + + +public class SysdynDiagramEditor extends DiagramEditorFacade { + + public SysdynDiagramEditor() { + super(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/Drawable.java b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/Drawable.java new file mode 100644 index 00000000..90ab9cd5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/Drawable.java @@ -0,0 +1,34 @@ +package org.simantics.sysdyn.ui.elements; + +import java.awt.Shape; +import java.awt.geom.AffineTransform; + +import org.simantics.scenegraph.g2d.G2DParentNode; + +public abstract class Drawable implements IDrawable { + + public static final AffineTransform IDENTITY = new AffineTransform(); + + @Override + public void initSG(G2DParentNode parent) { + } + + @Override + public void cleanupSG() { + } + + @Override + public void updateSG() { + } + + @Override + public boolean pickContained(Shape s) { + return false; + } + + @Override + public boolean pickIntersecting(Shape s) { + return false; + } + +} diff --git a/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/IDrawable.java b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/IDrawable.java new file mode 100644 index 00000000..d48a3c90 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/IDrawable.java @@ -0,0 +1,15 @@ +package org.simantics.sysdyn.ui.elements; + +import java.awt.Shape; +import java.awt.geom.Rectangle2D; + +import org.simantics.scenegraph.g2d.G2DParentNode; + +public interface IDrawable { + void getBounds(Rectangle2D size); + void initSG(G2DParentNode parent); + void updateSG(); + void cleanupSG(); + boolean pickIntersecting(Shape s); + boolean pickContained(Shape s); +} diff --git a/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/ITransformable.java b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/ITransformable.java new file mode 100644 index 00000000..266b8b5c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/ITransformable.java @@ -0,0 +1,11 @@ +package org.simantics.sysdyn.ui.elements; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; + +public interface ITransformable extends IDrawable { + ITransformable setTransform(AffineTransform at); + AffineTransform getTransform(); + public ITransformable moveTo(double x, double y); + Point2D getPosition(); +} diff --git a/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/PositionableDrawable.java b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/PositionableDrawable.java new file mode 100644 index 00000000..58d697e3 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/PositionableDrawable.java @@ -0,0 +1,40 @@ +package org.simantics.sysdyn.ui.elements; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; + +public abstract class PositionableDrawable extends Drawable implements ITransformable, Cloneable { + protected double posX; + protected double posY; + + @Override + public Point2D getPosition() { + return new Point2D.Double(posX, posY); + } + @Override + public AffineTransform getTransform() { + return new AffineTransform(1.0, 0.0, 0.0, 1.0, posX, posY); + } + @Override + public ITransformable moveTo(double x, double y) { + try { + PositionableDrawable d = (PositionableDrawable)clone(); + d.posX = x; + d.posY = y; + return d; + } catch(CloneNotSupportedException e) { + throw new Error(e); + } + } + @Override + public ITransformable setTransform(AffineTransform at) { + try { + PositionableDrawable d = (PositionableDrawable)clone(); + d.posX = at.getTranslateX(); + d.posY = at.getTranslateY(); + return d; + } catch(CloneNotSupportedException e) { + throw new Error(e); + } + } +} diff --git a/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/TestDrawable.java b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/TestDrawable.java new file mode 100644 index 00000000..5d35c5ec --- /dev/null +++ b/stable/org.simantics.sysdyn.ui.old/src/org/simantics/sysdyn/ui/elements/TestDrawable.java @@ -0,0 +1,36 @@ +package org.simantics.sysdyn.ui.elements; + +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; + +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.nodes.ShapeNode; + + +public class TestDrawable extends PositionableDrawable { + + @Override + public void getBounds(Rectangle2D size) { + size.setFrame(-10.0, -10.0, 20.0, 20.0); + } + + ShapeNode node; + + @Override + public void initSG(G2DParentNode parent) { + node = parent.addNode(ShapeNode.class); + node.setShape(new Rectangle2D.Double(-10.0, -10.0, 20.0, 20.0)); + } + + @Override + public boolean pickContained(Shape s) { + return s.contains(-10.0, -10.0, 20.0, 20.0); + } + + @Override + public boolean pickIntersecting(Shape s) { + return s.intersects(-10.0, -10.0, 20.0, 20.0); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/.classpath b/stable/org.simantics.sysdyn.ui/.classpath new file mode 100644 index 00000000..8a8f1668 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/stable/org.simantics.sysdyn.ui/.hgignore b/stable/org.simantics.sysdyn.ui/.hgignore new file mode 100644 index 00000000..73df90f6 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/.hgignore @@ -0,0 +1,5 @@ +syntax: regexp +^bin/ + +syntax: glob +*.svn/* \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/.project b/stable/org.simantics.sysdyn.ui/.project new file mode 100644 index 00000000..2ebd5691 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/.project @@ -0,0 +1,28 @@ + + + org.simantics.sysdyn.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/stable/org.simantics.sysdyn.ui/.settings/org.eclipse.jdt.core.prefs b/stable/org.simantics.sysdyn.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..e9cf5f10 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Tue Nov 10 13:35:16 EET 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/stable/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF b/stable/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF new file mode 100644 index 00000000..2852c03b --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF @@ -0,0 +1,59 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Simantics System Dynamics UI +Bundle-SymbolicName: org.simantics.sysdyn.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Require-Bundle: org.simantics.layer0.utils;bundle-version="0.6.2", + org.simantics.scenegraph;bundle-version="0.9.0", + org.junit4;bundle-version="4.5.0";resolution:=optional, + org.simantics.ui;bundle-version="1.0.0", + org.eclipse.ui;bundle-version="3.5.0", + org.eclipse.core.runtime;bundle-version="3.5.0", + org.simantics.objmap;bundle-version="0.1.0", + org.simantics.sysdyn;bundle-version="1.0.0", + org.simantics.project;bundle-version="1.0.0", + org.eclipse.jface.text;bundle-version="3.5.0", + org.eclipse.ui.editors;bundle-version="3.5.0", + org.jfree.jcommon;bundle-version="1.0.16", + org.jfree.jchart;bundle-version="1.0.13", + org.simantics.modelica;bundle-version="1.0.0", + org.apache.log4j;bundle-version="1.2.15", + org.eclipse.ui.console;bundle-version="3.4.0", + org.simantics.browsing.ui.graph;bundle-version="1.1.0", + org.simantics.browsing.ui.swt;bundle-version="1.1.0", + org.simantics.modeling.ui;bundle-version="1.0.0", + org.eclipse.ui.cheatsheets, + org.simantics.graphviz.ui;bundle-version="1.0.0", + org.simantics.graphviz;bundle-version="1.0.0", + org.simantics.diagram;bundle-version="0.9.4", + org.simantics.modeling;bundle-version="1.0.0", + org.simantics.mapping;bundle-version="1.0.0", + org.simantics.structural.ontology;bundle-version="1.0.0", + gnu.trove2;bundle-version="2.0.4", + org.simantics.simulation;bundle-version="1.0.0", + org.simantics.message;bundle-version="0.9.0", + org.simantics.structural2;bundle-version="1.0.0", + org.simantics.layer0;bundle-version="1.0.0", + org.simantics.diagram.ontology;bundle-version="1.0.0", + org.simantics.graph;bundle-version="1.0.2", + org.simantics.graph.db;bundle-version="1.0.0", + org.simantics.structural.ui;bundle-version="1.1.1", + org.simantics.browsing.ui.model;bundle-version="1.0.0", + org.simantics.spreadsheet.ui;bundle-version="1.1.0", + org.simantics.views.swt;bundle-version="1.0.0", + org.simantics.selectionview;bundle-version="1.0.0", + org.simantics.issues;bundle-version="1.1.0", + org.simantics.issues.ui;bundle-version="1.1.0", + org.simantics.issues.common;bundle-version="1.1.0", + org.simantics.scenegraph.profile;bundle-version="1.0.0", + org.simantics.trend;bundle-version="1.0.0", + org.simantics.history;bundle-version="1.0.0", + org.simantics.utils.thread.swt;bundle-version="1.1.0", + org.simantics.jfreechart.ontology;bundle-version="0.1.0", + org.eclipse.ui.forms;bundle-version="3.5.2", + org.simantics.scenegraph.swing;bundle-version="1.0.0" +Bundle-Activator: org.simantics.sysdyn.ui.Activator +Bundle-ActivationPolicy: lazy +Export-Package: org.simantics.sysdyn.ui.browser.nodes +Bundle-Vendor: VTT Technical Reserarch Centre of Finland diff --git a/stable/org.simantics.sysdyn.ui/adapters.xml b/stable/org.simantics.sysdyn.ui/adapters.xml new file mode 100644 index 00000000..ecd9bdd0 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/adapters.xml @@ -0,0 +1,14 @@ + + + none 0 fill 1 + \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/build.properties b/stable/org.simantics.sysdyn.ui/build.properties new file mode 100644 index 00000000..8658bc35 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/build.properties @@ -0,0 +1,21 @@ +############################################################################### +# Copyright (c) 2010 Association for Decentralized Information Management in +# Industry THTH ry. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# VTT Technical Research Centre of Finland - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + adapters.xml,\ + icons/,\ + doc/,\ + cheatsheet/,\ + splash.bmp diff --git a/stable/org.simantics.sysdyn.ui/cheatsheet/tutorial.xml b/stable/org.simantics.sysdyn.ui/cheatsheet/tutorial.xml new file mode 100644 index 00000000..c8966527 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/cheatsheet/tutorial.xml @@ -0,0 +1,29 @@ + + + + + + This cheatsheet helps with basic system dynamics modeling. + + + + + + Press the ? button on the right to open the tutorial. + + + diff --git a/stable/org.simantics.sysdyn.ui/doc/manual.mediawiki b/stable/org.simantics.sysdyn.ui/doc/manual.mediawiki new file mode 100644 index 00000000..100ef978 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/doc/manual.mediawiki @@ -0,0 +1,79 @@ +Possible connections between sysdyn elements: + +{| border="1" +|   +|   +| colspan="4", align="center" | To +|- +|   +|   +| Auxiliary +| Stock +| Valve +| Cloud +|- +| rowspan="4" | From +| Auxiliary +| dependency +| - +| dependency +| - +|- +| Stock +| dependency +| - +| flow / dependency +| - +|- +| Valve +| dependency +| flow +| dependency (?) +| flow +|- +| Cloud +| - +| - +| flow +| - +|} + +Connection actions between sysdyn elements: + +{| border="1" +|   +|   +| colspan="4", align="center" | To +|- +|   +|   +| Auxiliary +| Stock +| Valve +| Cloud +|- +| rowspan="4" | From +| Auxiliary +| dependency +| - +| dependency +| - +|- +| Stock +| dependency +| valve + 2 x flow +| flow / dependency +| valve + 2 x flow +|- +| Valve +| dependency +| flow +| dependency (?) +| flow +|- +| Cloud +| - +| valve + 2 x flow +| flow +| - +|} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/icons/brick.png b/stable/org.simantics.sysdyn.ui/icons/brick.png new file mode 100644 index 00000000..7851cf34 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/brick.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/brick_link.png b/stable/org.simantics.sysdyn.ui/icons/brick_link.png new file mode 100644 index 00000000..9ebf013a Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/brick_link.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/bricks.png b/stable/org.simantics.sysdyn.ui/icons/bricks.png new file mode 100644 index 00000000..0905f933 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/bricks.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/chart_bar.png b/stable/org.simantics.sysdyn.ui/icons/chart_bar.png new file mode 100644 index 00000000..9051fbc6 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/chart_bar.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/chart_bar_blackAndWhite.png b/stable/org.simantics.sysdyn.ui/icons/chart_bar_blackAndWhite.png new file mode 100644 index 00000000..087f88c0 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/chart_bar_blackAndWhite.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/chart_bar_light.png b/stable/org.simantics.sysdyn.ui/icons/chart_bar_light.png new file mode 100644 index 00000000..6069b5c9 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/chart_bar_light.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/chart_line.png b/stable/org.simantics.sysdyn.ui/icons/chart_line.png new file mode 100644 index 00000000..85020f32 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/chart_line.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/chart_line_light.png b/stable/org.simantics.sysdyn.ui/icons/chart_line_light.png new file mode 100644 index 00000000..2a77b242 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/chart_line_light.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/chart_organisation.png b/stable/org.simantics.sysdyn.ui/icons/chart_organisation.png new file mode 100644 index 00000000..c32d25c1 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/chart_organisation.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/chart_pie.png b/stable/org.simantics.sysdyn.ui/icons/chart_pie.png new file mode 100644 index 00000000..fe00fa05 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/chart_pie.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/chart_pie_light.png b/stable/org.simantics.sysdyn.ui/icons/chart_pie_light.png new file mode 100644 index 00000000..fa553c29 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/chart_pie_light.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/close.gif b/stable/org.simantics.sysdyn.ui/icons/close.gif new file mode 100644 index 00000000..1aca259d Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/close.gif differ diff --git a/stable/org.simantics.sysdyn.ui/icons/control_fastforward.png b/stable/org.simantics.sysdyn.ui/icons/control_fastforward.png new file mode 100644 index 00000000..31f7fd3a Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/control_fastforward.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/control_fastforward_blue.png b/stable/org.simantics.sysdyn.ui/icons/control_fastforward_blue.png new file mode 100644 index 00000000..4a2f9d4e Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/control_fastforward_blue.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/control_pause.png b/stable/org.simantics.sysdyn.ui/icons/control_pause.png new file mode 100644 index 00000000..2d9ce9c4 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/control_pause.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/control_pause_blue.png b/stable/org.simantics.sysdyn.ui/icons/control_pause_blue.png new file mode 100644 index 00000000..ec61099b Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/control_pause_blue.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/control_play.png b/stable/org.simantics.sysdyn.ui/icons/control_play.png new file mode 100644 index 00000000..0846555d Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/control_play.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/control_play_blue.png b/stable/org.simantics.sysdyn.ui/icons/control_play_blue.png new file mode 100644 index 00000000..f8c8ec68 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/control_play_blue.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/control_step.png b/stable/org.simantics.sysdyn.ui/icons/control_step.png new file mode 100644 index 00000000..820b020d Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/control_step.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/control_step_blue.png b/stable/org.simantics.sysdyn.ui/icons/control_step_blue.png new file mode 100644 index 00000000..98071cc0 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/control_step_blue.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/error.svg b/stable/org.simantics.sysdyn.ui/icons/error.svg new file mode 100644 index 00000000..e4eb0ab1 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/icons/error.svg @@ -0,0 +1,151 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/stable/org.simantics.sysdyn.ui/icons/fatal.svg b/stable/org.simantics.sysdyn.ui/icons/fatal.svg new file mode 100644 index 00000000..5ee48164 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/icons/fatal.svg @@ -0,0 +1,612 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/stable/org.simantics.sysdyn.ui/icons/folder.png b/stable/org.simantics.sysdyn.ui/icons/folder.png new file mode 100644 index 00000000..784e8fa4 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/folder.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/folder_link.png b/stable/org.simantics.sysdyn.ui/icons/folder_link.png new file mode 100644 index 00000000..b9b75f6c Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/folder_link.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/maximize.gif b/stable/org.simantics.sysdyn.ui/icons/maximize.gif new file mode 100644 index 00000000..5e5999be Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/maximize.gif differ diff --git a/stable/org.simantics.sysdyn.ui/icons/minimize.gif b/stable/org.simantics.sysdyn.ui/icons/minimize.gif new file mode 100644 index 00000000..7402dc9f Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/minimize.gif differ diff --git a/stable/org.simantics.sysdyn.ui/icons/page_white_text.png b/stable/org.simantics.sysdyn.ui/icons/page_white_text.png new file mode 100644 index 00000000..813f712f Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/page_white_text.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/page_white_text_width.png b/stable/org.simantics.sysdyn.ui/icons/page_white_text_width.png new file mode 100644 index 00000000..d9cf1325 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/page_white_text_width.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/sysdyn.png b/stable/org.simantics.sysdyn.ui/icons/sysdyn.png new file mode 100644 index 00000000..35710420 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/sysdyn.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/sysdyn32.png b/stable/org.simantics.sysdyn.ui/icons/sysdyn32.png new file mode 100644 index 00000000..01398b25 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/sysdyn32.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/table.png b/stable/org.simantics.sysdyn.ui/icons/table.png new file mode 100644 index 00000000..abcd9368 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/table.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/table_multiple.png b/stable/org.simantics.sysdyn.ui/icons/table_multiple.png new file mode 100644 index 00000000..d76448e3 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/table_multiple.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/table_multiple_pinned.png b/stable/org.simantics.sysdyn.ui/icons/table_multiple_pinned.png new file mode 100644 index 00000000..5f4e487d Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/table_multiple_pinned.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/time.png b/stable/org.simantics.sysdyn.ui/icons/time.png new file mode 100644 index 00000000..911da3f1 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/time.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/timeline_marker.png b/stable/org.simantics.sysdyn.ui/icons/timeline_marker.png new file mode 100644 index 00000000..a3fbddf8 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/icons/timeline_marker.png differ diff --git a/stable/org.simantics.sysdyn.ui/icons/warning.svg b/stable/org.simantics.sysdyn.ui/icons/warning.svg new file mode 100644 index 00000000..1dd13ec6 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/icons/warning.svg @@ -0,0 +1,173 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/stable/org.simantics.sysdyn.ui/plugin.properties b/stable/org.simantics.sysdyn.ui/plugin.properties new file mode 100644 index 00000000..bbdc0c46 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/plugin.properties @@ -0,0 +1,14 @@ +############################################################################### +# Copyright (c) 2010 Association for Decentralized Information Management in +# Industry THTH ry. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# VTT Technical Research Centre of Finland - initial API and implementation +############################################################################### +about.text=Simantics System Dynamics Workbench.\n\ +\n\ +Development build \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/plugin.xml b/stable/org.simantics.sysdyn.ui/plugin.xml new file mode 100644 index 00000000..7b2f5227 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/plugin.xml @@ -0,0 +1,1875 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Variable browser for Sysdyn. + + + + + Structural model browser view for Sysdyn. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Simple System Dynamics Tutorials + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/stable/org.simantics.sysdyn.ui/plugin_customization.ini b/stable/org.simantics.sysdyn.ui/plugin_customization.ini new file mode 100644 index 00000000..92e8ed0c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/plugin_customization.ini @@ -0,0 +1,2 @@ +org.eclipse.ui/SHOW_PROGRESS_ON_STARTUP = false +org.eclipse.ui/DOCK_PERSPECTIVE_BAR=right \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/splash.bmp b/stable/org.simantics.sysdyn.ui/splash.bmp new file mode 100644 index 00000000..cb932ea1 Binary files /dev/null and b/stable/org.simantics.sysdyn.ui/splash.bmp differ diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java new file mode 100644 index 00000000..cb2d6dd3 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui; + +import java.net.URL; + +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.LocalResourceManager; +import org.eclipse.jface.resource.ResourceManager; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.simantics.utils.FileUtils; + +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.simantics.sysdyn.ui"; + + // The shared instance + private static Activator plugin; + + private static LocalResourceManager resourceManager; + + public static String FATAL_SVG_TEXT; + public static String ERROR_SVG_TEXT; + public static String WARNING_SVG_TEXT; + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + ConsoleAppender appender = + new ConsoleAppender(new SimpleLayout()); + BasicConfigurator.configure(appender); + Logger.getRootLogger().setLevel(Level.WARN); + plugin = this; + + + Bundle bundle = context.getBundle(); + + FATAL_SVG_TEXT = FileUtils.getContents(bundle.getResource("icons/fatal.svg")); + ERROR_SVG_TEXT = FileUtils.getContents(bundle.getResource("icons/error.svg")); + WARNING_SVG_TEXT = FileUtils.getContents(bundle.getResource("icons/warning.svg")); + } + + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + public static Activator getDefault() { + return plugin; + } + + public static ResourceManager initializeResourceManager(Display display) { + if (resourceManager == null) { + resourceManager = new LocalResourceManager(JFaceResources.getResources(display)); + } + return resourceManager; + } + + public static ResourceManager getResources() { + if (resourceManager == null) + throw new IllegalStateException("ResourceManager of bundle '" + PLUGIN_ID + "' is not initialized."); + return resourceManager; + } + + public static URL getDefaultResource(String name) { + Activator plugin = getDefault(); + if(plugin == null) throw new IllegalStateException("The plugin is not active."); + return plugin.getBundle().getResource(name); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ActivateExperimentAction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ActivateExperimentAction.java new file mode 100644 index 00000000..4e00ace6 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ActivateExperimentAction.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.actions; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.project.IProject; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.ui.handlers.SysdynExperimentActivator; +import org.simantics.ui.DoubleClickEvent; +import org.simantics.ui.IDoubleClickAction; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; +import org.simantics.utils.ui.ErrorLogger; +import org.simantics.utils.ui.action.PriorityAction; + +public class ActivateExperimentAction implements IDoubleClickAction { + + @Override + public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException { + ReadGraph g = e.getGraph(); + final Resource experiment = ResourceAdaptionUtils.toSingleResource(e.getResource()); + if (experiment == null) + return; + + if (g.isInstanceOf(experiment, SimulationResource.getInstance(g).Experiment)) { + final IProject project = SimanticsUI.getProject(); + if (project == null) + return; + + final IExperimentManager experimentManager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + if (experimentManager == null) { + ErrorLogger.defaultLogWarning("Experiment manager not available.", new Exception()); + return; + } + + e.add(new PriorityAction(PriorityAction.HIGH+20) { + @Override + public void run() { + SysdynExperimentActivator.scheduleActivation(SimanticsUI.getSession(), project, experimentManager, experiment); + } + }); + e.consume(); + } + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConsumeUnnecessaryEntersAction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConsumeUnnecessaryEntersAction.java new file mode 100644 index 00000000..e984ef15 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConsumeUnnecessaryEntersAction.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.actions; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.operation.Layer0X; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.DoubleClickEvent; +import org.simantics.ui.IDoubleClickAction; +import org.simantics.ui.utils.ResourceAdaptionUtils; +import org.simantics.utils.ui.action.PriorityAction; + +public class ConsumeUnnecessaryEntersAction implements IDoubleClickAction { + + @Override + public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException { + ReadGraph g = e.getGraph(); + Layer0 l0 = Layer0.getInstance(g); + Layer0X L0X = Layer0X.getInstance(g); + final Resource resource = ResourceAdaptionUtils.toSingleResource(e.getResource()); + if(resource == null) + return; + SysdynResource sr = SysdynResource.getInstance(g); + + if(g.isInstanceOf(resource, sr.SysdynModel) || g.isInstanceOf(resource, sr.Variable)) { + consume(e); + } else if(g.hasStatement(resource, L0X.Represents)){ + Resource represents = g.getSingleObject(resource, L0X.Represents); + if (g.isInstanceOf(represents, sr.Variable)) { + consume(e); + } + } + } + + private void consume(DoubleClickEvent e) { + e.add(new PriorityAction(PriorityAction.HIGH) { + @Override + public void run() { + + } + }); + e.consume(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ShowInstantiatedModuleAction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ShowInstantiatedModuleAction.java new file mode 100644 index 00000000..9816a242 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ShowInstantiatedModuleAction.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.actions; + +import java.util.Set; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.PartInitException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.BrowserSelection; +import org.simantics.sysdyn.ui.browser.nodes.ModuleNode; +import org.simantics.sysdyn.ui.editor.SysdynEditorInput; +import org.simantics.ui.DoubleClickEvent; +import org.simantics.ui.IDoubleClickAction; +import org.simantics.ui.workbench.ResourceEditorInput2; +import org.simantics.utils.ui.ISelectionUtils; +import org.simantics.utils.ui.action.PriorityAction; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +public class ShowInstantiatedModuleAction implements IDoubleClickAction { + + private static final String EDITOR_ID = "org.simantics.sysdyn.ui.diagramViewer"; + + @Override + public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException { + + ReadGraph g = e.getGraph(); + + if(e.getResource() instanceof IStructuredSelection) { + Set bss = ISelectionUtils.filterSetSelection(e.getResource(), BrowserSelection.class); + + if(!bss.isEmpty()) { + Layer0 l0 = Layer0.getInstance(g); + for(BrowserSelection bs : bss) { + Resource configuration = (Resource)bs.getAdapter(Resource.class); + Resource instanceOf = g.getSingleObject(configuration, l0.InstanceOf); + + SysdynResource sr = SysdynResource.getInstance(g); + StructuralResource2 sr2 = StructuralResource2.getInstance(g); + if(g.isInheritedFrom(instanceOf, sr.Module)) { + configuration = g.getSingleObject(instanceOf, sr2.IsDefinedBy); + Variable variable = (Variable) bs.getAdapter(Variable.class); + String rvi = Variables.getRVI(g, variable).substring(1); + Resource model = Variables.getModel(g, variable); + addShowModuleAction(e, getResourceEditorInput(g, model, configuration, rvi)); + } + } + } else { + ModuleNode moduleNode = ISelectionUtils.filterSingleSelection(e.getResource(), ModuleNode.class); + if(moduleNode != null) { + Layer0 l0 = Layer0.getInstance(g); + StructuralResource2 sr2 = StructuralResource2.getInstance(g); + Resource model; + String rvi; + if(moduleNode.getVariable() != null) { + model = Variables.getModel(g, moduleNode.getVariable()); + Variable var = moduleNode.getVariable(); + rvi = Variables.getRVI(g, var).substring(1); + } else { + rvi = (String)g.getRelatedValue(moduleNode.data, Layer0.getInstance(g).HasName); + model = g.getSingleObject(moduleNode.data, l0.PartOf); + } + + Resource instanceOf = g.getSingleObject(moduleNode.data, l0.InstanceOf); + Resource conf = g.getSingleObject(instanceOf, sr2.IsDefinedBy); + + addShowModuleAction(e, getResourceEditorInput(g, model, conf, rvi)); + } + } + } + } + + private ResourceEditorInput2 getResourceEditorInput(ReadGraph g, Resource model, Resource configuration, String rvi) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + SysdynResource sr = SysdynResource.getInstance(g); + + String modelURI; + if(model != null) { + modelURI = g.getURI(model); + } else { + Resource parent = configuration; + do { + parent = g.getPossibleObject(parent, l0.PartOf); + } while (parent != null && !g.isInstanceOf(parent, sr.SysdynModel)); + modelURI = g.getURI(parent); + rvi = null; + } + + Resource diagram = g.getSingleObject(configuration, ModelingResources.getInstance(g).CompositeToDiagram); + return new SysdynEditorInput(EDITOR_ID, diagram, modelURI, rvi == null ? "" : "/" + rvi); + } + + private void addShowModuleAction(DoubleClickEvent e, final ResourceEditorInput2 editorInput) { + e.add(new PriorityAction(PriorityAction.HIGH) { + @Override + public void run() { + try { + WorkbenchUtils.openEditor(EDITOR_ID, editorInput); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + }); + e.consume(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/BrowserSelection.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/BrowserSelection.java new file mode 100644 index 00000000..cfd31c81 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/BrowserSelection.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.viewers.ISelection; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.db.Resource; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.sysdyn.ui.browser.nodes.VariableNode; + +public class BrowserSelection implements IAdaptable, ISelection { + private Resource resource; + private Object originalInput; + private Variable variable; + + public BrowserSelection(Object originalInput, VariableNode vn) { + this.originalInput = originalInput; + this.resource = vn.data; + Variable variable = vn.getVariable(); + if(variable != null) { + this.variable = variable; + } + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if (adapter == Resource.class) + return resource; + if (adapter == Variable.class) + return variable; + if (NodeContext.class.equals(adapter)) + return originalInput; + if (originalInput instanceof IAdaptable) { + IAdaptable input = (IAdaptable)originalInput; + return input.getAdapter(adapter); + } + return null; + } + + @Override + public boolean isEmpty() { + if(originalInput == null) + return true; + return false; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynBrowser.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynBrowser.java new file mode 100644 index 00000000..15d9a7f1 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynBrowser.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.swt.widgets.Composite; +import org.simantics.browsing.ui.GraphExplorer; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.platform.GraphExplorerView; +import org.simantics.browsing.ui.swt.AdaptableHintContext; +import org.simantics.browsing.ui.swt.ContextMenuInitializer; +import org.simantics.browsing.ui.swt.DefaultSelectionDataResolver; +import org.simantics.browsing.ui.swt.GraphExplorerFactory; +import org.simantics.browsing.ui.swt.IContextMenuInitializer; +import org.simantics.db.layer0.SelectionHints; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.browser.nodes.VariableNode; +import org.simantics.sysdyn.ui.properties.SysdynPropertyPage; +import org.simantics.ui.workbench.IPropertyPage; +import org.simantics.utils.datastructures.BinaryFunction; +import org.simantics.utils.datastructures.hints.IHintContext; + + +public class SysdynBrowser extends GraphExplorerView { + +// private static final Set browseContexts = Collections.singleton("http://www.simantics.org/Sysdyn-1.1/Browser"); + private static final Set browseContexts = new HashSet(Arrays.asList("http://www.simantics.org/Sysdyn-1.1/Browser", "http://www.simantics.org/Operating-1.1/Browser", "http://www.simantics.org/Image-1.0/Browser")); + + private BinaryFunction selectionTransformation = new BinaryFunction() { + + @Override + public Object[] call(GraphExplorer explorer, Object[] objects) { + Object[] result = new Object[objects.length]; + for (int i = 0; i < objects.length; i++) { + + NodeContext ctx = (NodeContext)objects[i]; + @SuppressWarnings("unchecked") + VariableNode vn = (VariableNode) ctx.getAdapter(VariableNode.class); + IHintContext context; + if(vn != null && vn.getVariable() != null) { + context = new AdaptableHintContext(SelectionHints.KEY_MAIN, SelectionHints.KEY_SELECTION_PROPERTY); + context.setHint(SelectionHints.KEY_MAIN, new BrowserSelection(objects[i], vn)); + context.setHint(SelectionHints.KEY_SELECTION_PROPERTY, vn.getVariable()); + } else { + context = new AdaptableHintContext(SelectionHints.KEY_MAIN); + context.setHint(SelectionHints.KEY_MAIN, objects[i]); + } + result[i] = context; + } + return result; + } + + }; + + protected GraphExplorer createExplorerControl(Composite parent) { + return GraphExplorerFactory.getInstance() + .selectionDataResolver(new DefaultSelectionDataResolver()) + .selectionTransformation(selectionTransformation) + .create(parent, getStyle()); + } + + @Override + protected IContextMenuInitializer getContextMenuInitializer() { + return new ContextMenuInitializer("#SysdynBrowserPopup"); + } + + @Override + protected Set getBrowseContexts() { + return browseContexts; + } + + @Override + protected void createControls(Composite parent) { + // Make sure the resource manager of this plug-in is initialized + // properly before using it in this browser. + Activator.initializeResourceManager(parent.getDisplay()); + + super.createControls(parent); + //IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager(); + //toolBar.add(new HomeAction()); + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if (adapter == IPropertyPage.class) + return new SysdynPropertyPage(getSite(), Collections.singleton(SysdynResource.URIs.Browser)); + return super.getAdapter(adapter); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynModelBrowser.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynModelBrowser.java new file mode 100644 index 00000000..bf28f106 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynModelBrowser.java @@ -0,0 +1,28 @@ +package org.simantics.sysdyn.ui.browser; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.simantics.structural.ui.modelBrowser.ModelBrowser; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.SysdynPropertyPage; +import org.simantics.ui.workbench.IPropertyPage; + +public class SysdynModelBrowser extends ModelBrowser { + + final private Set browseContexts = new HashSet(Arrays.asList(SysdynResource.URIs.ProjectBrowseContext, "http://www.simantics.org/Operating-1.1/Browser", "http://www.simantics.org/Image-1.0/Browser")); + + @Override + protected IPropertyPage getPropertyPage() { + return new SysdynPropertyPage(getSite(), Collections.singleton(SysdynResource.URIs.ModelBrowser)); + } + + @Override + protected Set getBrowseContexts() { + return browseContexts; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynOperationBrowser.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynOperationBrowser.java new file mode 100644 index 00000000..85ca518e --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynOperationBrowser.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser; + +import java.util.Collections; +import java.util.Set; + +import org.simantics.browsing.ui.platform.GraphExplorerView; +import org.simantics.sysdyn.SysdynResource; + +public class SysdynOperationBrowser extends GraphExplorerView { + + final private Set browseContexts = Collections.singleton(SysdynResource.URIs.SysdynOperationBrowser); + + @Override + protected Set getBrowseContexts() { + return browseContexts; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewEnumerationAction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewEnumerationAction.java new file mode 100644 index 00000000..4ac2459d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewEnumerationAction.java @@ -0,0 +1,67 @@ +package org.simantics.sysdyn.ui.browser.actions; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; + +public class NewEnumerationAction implements ActionFactory{ + + @Override + public Runnable create(Object target) { + if(!(target instanceof Resource)) + return null; + final Resource resource = (Resource)target; + + return new Runnable() { + @Override + public void run() { + + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + Layer0 l0 = Layer0.getInstance(g); + + Resource configuration = null; + if(g.isInstanceOf(resource, sr.Configuration)) { + configuration = resource; + } else if(g.isInheritedFrom(resource, sr.ModuleSymbol)) { + Resource module = g.getPossibleObject(resource,ModelingResources.getInstance(g).SymbolToComponentType); + configuration = g.getPossibleObject(module, StructuralResource2.getInstance(g).IsDefinedBy); + } else { + Resource instanceOf = g.getSingleObject(resource, l0.InstanceOf); + if(g.isInheritedFrom(instanceOf, sr.Module)) { + configuration = g.getPossibleObject(instanceOf, StructuralResource2.getInstance(g).IsDefinedBy); + } else { + return; + } + } + + Resource enumerationIndexes = OrderedSetUtils.create(g, sr.EnumerationIndexes); + + String name = NameUtils.findFreshName(g, "Enum", configuration, l0.ConsistsOf, "%s%d"); + + GraphUtils.create2(g, + sr.Enumeration, + l0.HasName, name, + sr.HasEnumerationIndexes, enumerationIndexes, + l0.PartOf, configuration); + } + }); + } + }; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewFunctionAction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewFunctionAction.java new file mode 100644 index 00000000..e52c0e9a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewFunctionAction.java @@ -0,0 +1,59 @@ +package org.simantics.sysdyn.ui.browser.actions; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.ui.SimanticsUI; + +public class NewFunctionAction implements ActionFactory{ + + @Override + public Runnable create(Object target) { + if(!(target instanceof Resource)) + return null; + final Resource resource = (Resource)target; + + return new Runnable() { + @Override + public void run() { + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + SysdynResource sr = SysdynResource.getInstance(g); + + Resource library = null; + if(g.isInstanceOf(resource, sr.SysdynModel) || g.isInstanceOf(resource, l0.Library)) + library = resource; + else if (g.isInstanceOf(resource, sr.SysdynModelicaFunction)) + library = g.getPossibleObject(resource, l0.PartOf); + + if(library == null) + return; + + + String name = NameUtils.findFreshName(g, "Function", library, l0.ConsistsOf, "%s%d"); + + GraphUtils.create2(g, sr.SysdynModelicaFunction, + l0.HasName, name, + l0.HasDescription, "", + sr.HasModelicaFunctionCode, "", + l0.PartOf, library); + + FunctionUtils.updateFunctionFileForLibrary(g, library); + } + }); + + } + }; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewFunctionLibraryAction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewFunctionLibraryAction.java new file mode 100644 index 00000000..1064e019 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewFunctionLibraryAction.java @@ -0,0 +1,86 @@ +package org.simantics.sysdyn.ui.browser.actions; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.ui.SimanticsUI; + +public class NewFunctionLibraryAction implements ActionFactory{ + + @Override + public Runnable create(Object target) { + if(!(target instanceof Resource)) + return null; + final Resource resource = (Resource)target; + + return new Runnable() { + @Override + public void run() { + createLibrary(resource, false); + } + }; + } + + /** + * Create a new Library to the selected root or to SharedOntologies + * + * @param libraryLocation Resource of the model or other + * library where the new library will be added. + * @param shared is the library a shared library + */ + protected static void createLibrary(final Resource libraryLocation, final boolean shared) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + SysdynResource sr = SysdynResource.getInstance(g); + + if(!(g.isInstanceOf(libraryLocation, sr.SysdynModel) || + g.isInstanceOf(libraryLocation, sr.SysdynModelicaFunctionLibrary) || + g.isInstanceOf(libraryLocation, sr.SharedFunctionOntology))) + return; + + Resource root = libraryLocation; + + String name = "FunctionLibrary"; + Resource libraryType = sr.SysdynModelicaFunctionLibrary; + + if(shared) { + + try { + root = g.getResource("http://SharedOntologies"); + } catch (ResourceNotFoundException e) { + root = g.getResource("http:/"); + root = GraphUtils.create2(g, l0.Library, + l0.HasName, "SharedOntologies", + l0.PartOf, root); + } + + name = "Shared" + name; + libraryType = sr.SharedFunctionOntology; + } + + name = NameUtils.findFreshName(g, name, root, l0.ConsistsOf, "%s%d"); + + Resource functionLibrary = GraphUtils.create2(g, libraryType, + l0.HasName, name, + l0.HasDescription, "", + l0.PartOf, root); + + if(shared) + g.claim(libraryLocation, l0.IsLinkedTo, functionLibrary); + + FunctionUtils.updateFunctionFileForLibrary(g, functionLibrary); + } + }); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewModuleTypeAction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewModuleTypeAction.java new file mode 100644 index 00000000..0670d0d4 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewModuleTypeAction.java @@ -0,0 +1,109 @@ +package org.simantics.sysdyn.ui.browser.actions; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.db.layer0.adapter.Template; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.operation.Layer0X; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.ArrayMap; + +public class NewModuleTypeAction implements ActionFactory{ + + @Override + public Runnable create(Object target) { + if(!(target instanceof Resource)) + return null; + final Resource model = (Resource)target; + + return new Runnable() { + @Override + public void run() { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + // Same as in SysdynProject.java. Should use the same code, not copy. + SysdynResource sr = SysdynResource.getInstance(g); + Layer0 l0 = Layer0.getInstance(g); + Layer0X L0X = Layer0X.getInstance(g); + ModelingResources mr = ModelingResources.getInstance(g); + StructuralResource2 sr2 = StructuralResource2.getInstance(g); + DiagramResource dr = DiagramResource.getInstance(g); + + String name = NameUtils.findFreshName(g, "ModuleType", model, l0.ConsistsOf, "%s%d"); + + Resource moduleType = g.newResource(); + g.claimLiteral(moduleType, l0.HasName, name); + g.claim(moduleType, l0.Inherits, sr.Module); + g.claim(moduleType, l0.PartOf, model); + + Resource configuration = GraphUtils.create2(g, + sr.Configuration, + l0.HasName, name + "Configuration", + l0.PartOf, moduleType); + + g.claim(moduleType, sr2.IsDefinedBy , configuration); + + Resource diagram = g.newResource(); + g.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(g, + ArrayMap + .keys("", "diagram", "name") + .values(configuration, diagram, "Diagrammi") + ); + + + // Remove default mapping and add sysdyn mapping + for(Resource trigger : g.getObjects(diagram, L0X.HasTrigger)) { + if(g.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) { + g.deny(diagram, L0X.HasTrigger, trigger); + } + } + Resource mapping = g.newResource(); + g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); + g.claim(diagram, L0X.HasTrigger, mapping); + + Resource moduleSymbol = g.newResource(); + g.claimLiteral(moduleSymbol, l0.HasName, name + " Symbol"); + g.claimLiteral(moduleSymbol, l0.HasLabel, name + " Symbol"); + g.claim(moduleSymbol, l0.Inherits, sr.ModuleSymbol); + g.claim(moduleSymbol, mr.SymbolToComponentType, moduleType); + g.claim(moduleSymbol, l0.PartOf, moduleType); + + Resource terminal = g.newResource(); + g.claim(terminal, l0.InstanceOf, sr.SysdynTerminal); + Resource connectionVariable = g.newResource(); + g.claim(connectionVariable, l0.InstanceOf, sr2.ConnectionVariable); + g.claim(connectionVariable, sr2.Binds, sr.IsHeadOfTerminal); + g.claim(connectionVariable, sr2.IsParameterOf, moduleSymbol); + g.claim(terminal, dr.HasConnectionVariable, connectionVariable); + + + Resource terminal2 = g.newResource(); + g.claim(terminal2, l0.InstanceOf, sr.SysdynTerminal); + Resource connectionVariable2 = g.newResource(); + g.claim(connectionVariable2, l0.InstanceOf, sr2.ConnectionVariable); + g.claim(connectionVariable2, sr2.Binds, sr.IsTailOfTerminal); + g.claim(connectionVariable2, sr2.IsParameterOf, moduleSymbol); + g.claim(terminal2, dr.HasConnectionVariable, connectionVariable2); + + g.claim(moduleSymbol, sr2.IsDefinedBy, OrderedSetUtils.create(g, sr2.Composite, terminal, terminal2)); + + + } + }); + } + }; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewSharedFunctionLibraryAction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewSharedFunctionLibraryAction.java new file mode 100644 index 00000000..c5bdeba4 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/NewSharedFunctionLibraryAction.java @@ -0,0 +1,22 @@ +package org.simantics.sysdyn.ui.browser.actions; + +import org.simantics.db.Resource; + +public class NewSharedFunctionLibraryAction extends NewFunctionLibraryAction { + + + @Override + public Runnable create(Object target) { + if(!(target instanceof Resource)) + return null; + final Resource resource = (Resource)target; + + return new Runnable() { + @Override + public void run() { + createLibrary(resource, true); + } + }; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/OpenWorkbookAction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/OpenWorkbookAction.java new file mode 100644 index 00000000..f233f3a4 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/OpenWorkbookAction.java @@ -0,0 +1,82 @@ +package org.simantics.sysdyn.ui.browser.actions; + +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.db.layer0.util.Simantics; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ui.diagramEditor.OpenSheetAdapter; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.spreadsheet.resource.SpreadsheetResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.workbench.ResourceEditorInput2; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +public class OpenWorkbookAction implements ActionFactory{ + + @Override + public Runnable create(Object target) { + + if(!(target instanceof Resource)) + return null; + + final Resource resource = (Resource)target; + + return new Runnable() { + + @Override + public void run() { + + try { + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); + + Resource book = graph.syncRequest(new PossibleObjectWithType(resource, L0.ConsistsOf, sr.Book)); + final Resource sheet = graph.syncRequest(new PossibleObjectWithType(book, L0.ConsistsOf, sr.Spreadsheet)); + + SimulationResource SIMU = SimulationResource.getInstance(graph); + Variable variable = graph.adapt(sheet, Variable.class); + Resource model = Variables.getModel(graph, variable); + final String modelURI = graph.getURI(model); + final String RVI = Variables.getRVI(graph, variable); + + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + + private static final String EDITOR_ID = "org.simantics.spreadsheet.ui.editor2"; + + @Override + public void run() { + try { + System.out.println("Activating sheet: model=" + modelURI + " rvi=" + RVI); + WorkbenchUtils.openEditor(EDITOR_ID, new ResourceEditorInput2(EDITOR_ID, sheet, modelURI, RVI)); + } catch (PartInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + }; + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/ModuleContentChildRule.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/ModuleContentChildRule.java new file mode 100644 index 00000000..3bb27557 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/ModuleContentChildRule.java @@ -0,0 +1,56 @@ +package org.simantics.sysdyn.ui.browser.childrules; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.model.children.ChildRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; + +public class ModuleContentChildRule implements ChildRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public Collection getChildren(ReadGraph graph, Object parent) throws DatabaseException { + ArrayList children = new ArrayList(); + + if(!(parent instanceof Resource)) { + return children; + } + + Layer0 l0 = Layer0.getInstance(graph); + StructuralResource2 str = StructuralResource2.getInstance(graph); + + Resource symbol = (Resource)parent; + + Resource component = graph.getPossibleObject(symbol,ModelingResources.getInstance(graph).SymbolToComponentType); + + if(component == null) + return children; + + Resource configuration = graph.getSingleObject(component, str.IsDefinedBy); + + if(configuration == null) + return children; + + children.addAll(graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, str.Component))); + + return children; + } + + @Override + public Collection getParents(ReadGraph graph, Object child) + throws DatabaseException { + return new ArrayList(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/ModuleTypeChildRule.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/ModuleTypeChildRule.java new file mode 100644 index 00000000..7afcb1b9 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/childrules/ModuleTypeChildRule.java @@ -0,0 +1,57 @@ +package org.simantics.sysdyn.ui.browser.childrules; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.model.children.ChildRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; + + +public class ModuleTypeChildRule implements ChildRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public Collection getChildren(ReadGraph graph, Object parent) + throws DatabaseException { + + ArrayList children = new ArrayList(); + + if(!(parent instanceof Resource)) { + return children; + } + + Layer0 l0 = Layer0.getInstance(graph); + StructuralResource2 st = StructuralResource2.getInstance(graph); + + Resource model = (Resource)parent; + if(!graph.isInstanceOf(model, SysdynResource.getInstance(graph).SysdynModel)) + return children; + + for(Resource r : graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, st.ComponentType))) { + if(graph.isInheritedFrom(r, SysdynResource.getInstance(graph).Module)) { + Resource symbol = graph.getPossibleObject(r,ModelingResources.getInstance(graph).ComponentTypeToSymbol); + children.add(symbol); + } + } + + return children; + } + + @Override + public Collection getParents(ReadGraph graph, Object child) + throws DatabaseException { + return new ArrayList(); + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java new file mode 100644 index 00000000..5ff989ea --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.swt.ImagerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.browser.nodes.BookNode; +import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode; +import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode; +import org.simantics.sysdyn.ui.browser.nodes.ExperimentsFolder; +import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode; +import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder; +import org.simantics.sysdyn.ui.browser.nodes.InputNode; +import org.simantics.sysdyn.ui.browser.nodes.ModelNode; +import org.simantics.sysdyn.ui.browser.nodes.ModuleNode; +import org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode; +import org.simantics.sysdyn.ui.browser.nodes.ModulesNode; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder; +import org.simantics.sysdyn.ui.browser.nodes.SheetNode; +import org.simantics.sysdyn.ui.browser.nodes.VariableNode; + +public class AbstractNodeImager extends ImagerContributor> { + + @Override + public ImageDescriptor getDescriptor(ReadGraph graph, AbstractNode node) throws DatabaseException { + + String image = null; + if (node instanceof SharedFunctionsFolder) + image = "icons/folder_link.png"; + else if (node instanceof ExperimentsFolder || + node instanceof ModulesNode || + node instanceof FunctionsFolder || + node instanceof FunctionLibraryNode || + node instanceof SharedFunctionLibraryNode) + image = "icons/folder.png"; + else if (node instanceof ModuleTypeNode || node instanceof ModuleNode || node instanceof ConfigurationNode) + image = "icons/bricks.png"; + else if (node instanceof ExperimentNode) { + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.isInstanceOf(node.data, sr.PlaybackExperiment)) + image = "icons/timeline_marker.png"; + else + image = "icons/time.png"; + } else if (node instanceof InputNode) + image = "icons/brick_link.png"; + else if (node instanceof ModelNode) + image = "icons/chart_organisation.png"; + else if (node instanceof VariableNode) + image = "icons/brick.png"; + else if (node instanceof BookNode) + image = "icons/table_multiple.png"; + else if (node instanceof SheetNode) + image = "icons/table.png"; + + if (image != null) + return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource(image)); + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeLabeler.java new file mode 100644 index 00000000..6fd403f2 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeLabeler.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; + +public class AbstractNodeLabeler extends LabelerContributor> { + + @Override + public String getLabel(ReadGraph graph, AbstractNode node) throws DatabaseException { + if (!graph.hasStatement(node.data)) + return ""; + return graph.adapt(node.data, String.class); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Book.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Book.java new file mode 100644 index 00000000..8bd950fc --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Book.java @@ -0,0 +1,29 @@ +package org.simantics.sysdyn.ui.browser.contributions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.spreadsheet.resource.SpreadsheetResource; +import org.simantics.sysdyn.ui.browser.nodes.BookNode; +import org.simantics.sysdyn.ui.browser.nodes.SheetNode; + +public class Book extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, BookNode book) throws DatabaseException { + ArrayList> result = new ArrayList>(); + Layer0 l0 = Layer0.getInstance(graph); + for(Resource r : graph.syncRequest(new ObjectsWithType(book.data, l0.ConsistsOf, SpreadsheetResource.getInstance(graph).Spreadsheet))) { + result.add(new SheetNode(r)); + } + return result; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/BookLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/BookLabeler.java new file mode 100644 index 00000000..e0f950d5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/BookLabeler.java @@ -0,0 +1,15 @@ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.BookNode; + +public class BookLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, BookNode input) throws DatabaseException { + return "SpreadSheets"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ChartImager.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ChartImager.java new file mode 100644 index 00000000..10948a1c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ChartImager.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.swt.ImagerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.browser.nodes.AbstractChartNode; +import org.simantics.sysdyn.ui.browser.nodes.BarChartNode; +import org.simantics.sysdyn.ui.browser.nodes.LineChartNode; +import org.simantics.sysdyn.ui.browser.nodes.PieChartNode; + +/** + * Provides image for {@link LineChartNode} in model browser + * @author Teemu Lempinen + * + */ +public class ChartImager extends ImagerContributor> { + + @Override + public ImageDescriptor getDescriptor(ReadGraph graph, AbstractChartNode input) throws DatabaseException { + if(input instanceof BarChartNode) + return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar.png")); + else if(input instanceof PieChartNode) + return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_pie.png")); + else + return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_line.png")); + + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ChartLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ChartLabeler.java new file mode 100644 index 00000000..1301ab5f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ChartLabeler.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.ui.browser.nodes.AbstractChartNode; +import org.simantics.sysdyn.ui.browser.nodes.LineChartNode; + +/** + * Provides label for {@link LineChartNode} in model browser + * @author Teemu Lempinen + * + */ +public class ChartLabeler extends LabelerContributor> { + + @Override + public String getLabel(ReadGraph graph, AbstractChartNode chart) throws DatabaseException { + String name = graph.getPossibleRelatedValue(chart.data, Layer0.getInstance(graph).HasLabel); + return name == null ? "Chart (no label)" : name; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Charts.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Charts.java new file mode 100644 index 00000000..90707af4 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Charts.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.browser.nodes.BarChartNode; +import org.simantics.sysdyn.ui.browser.nodes.LineChartNode; +import org.simantics.sysdyn.ui.browser.nodes.ChartsFolder; +import org.simantics.sysdyn.ui.browser.nodes.PieChartNode; + +/** + * Class for creating chart nodes for model browser + * @author Teemu Lempinen + * + */ +public class Charts extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, ChartsFolder folder) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + ArrayList> result = new ArrayList>(); + for(Resource chart : graph.syncRequest( + new ObjectsWithType(folder.data, + l0.ConsistsOf, + jfree.Chart))) { + Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.Plot)); + if(plot != null) { + if(graph.isInstanceOf(plot, jfree.XYPlot)) { + result.add(new LineChartNode(chart)); + } else if(graph.isInstanceOf(plot, jfree.CategoryPlot)) { + result.add(new BarChartNode(chart)); + } else if(graph.isInstanceOf(plot, jfree.PiePlot)) { + result.add(new PieChartNode(chart)); + } + } + } + return result; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ChartsImager.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ChartsImager.java new file mode 100644 index 00000000..e51b8e74 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ChartsImager.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.swt.ImagerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.browser.nodes.ChartsFolder; + +/** + * Provides image for {@link ChartsFolder} in model browser + * @author Teemu Lempinen + * + */ +public class ChartsImager extends ImagerContributor { + + @Override + public ImageDescriptor getDescriptor(ReadGraph graph, ChartsFolder chartNode) throws DatabaseException { + return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/folder.png")); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ChartsLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ChartsLabeler.java new file mode 100644 index 00000000..fe718b2c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ChartsLabeler.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.ChartsFolder; + +/** + * Provides label for {@link ChartsFolder} in model browser + * @author Teemu Lempinen + * + */ +public class ChartsLabeler extends LabelerContributor { + + @Override + public String getLabel(ReadGraph graph, ChartsFolder input) throws DatabaseException { + return "Charts"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Configuration.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Configuration.java new file mode 100644 index 00000000..c874e042 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Configuration.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ui.modelBrowser2.model.SheetsNode; +import org.simantics.spreadsheet.resource.SpreadsheetResource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.BookNode; +import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode; +import org.simantics.sysdyn.ui.browser.nodes.EnumerationNode; +import org.simantics.sysdyn.ui.browser.nodes.InputNode; +import org.simantics.sysdyn.ui.browser.nodes.ModuleNode; +import org.simantics.sysdyn.ui.browser.nodes.VariableNode; + +public class Configuration extends ViewpointContributor> { + + @Override + public Collection getContribution(ReadGraph graph, ConfigurationNode configuration) throws DatabaseException { + ArrayList result = new ArrayList(); + Variable variable = configuration.getVariable(); + + if (variable == null) { + return result; + } + + SysdynResource sr = SysdynResource.getInstance(graph); + ArrayList variables = new ArrayList(); + ArrayList inputs = new ArrayList(); + ArrayList modules = new ArrayList(); + ArrayList enumerations = new ArrayList(); + + for(Variable child : variable.browseChildren(graph)) { + Resource represents = (Resource)child.getPropertyValue(graph, Variables.REPRESENTS); + if(graph.isInstanceOf(represents, sr.IndependentVariable)) { + variables.add(child); + } else if (graph.isInstanceOf(represents, sr.Input)) { + inputs.add(child); + } else if (graph.isInstanceOf(represents, sr.Module)) { + modules.add(child); + } else if (graph.isInstanceOf(represents, sr.Enumeration)) { + enumerations.add(child); + } + } + + for (Variable v : variables) { + Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS); + result.add(new VariableNode(v, represents)); + } + for (Variable v : inputs) { + Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS); + result.add(new InputNode(v, represents)); + } + for (Variable v : modules) { + Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS); + result.add(new ModuleNode(v, represents)); + } + for (Variable v : enumerations) { + Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS); + result.add(new EnumerationNode(v, represents)); + } + + for(Resource r : graph.syncRequest(new ObjectsWithType( + configuration.data, + Layer0.getInstance(graph).ConsistsOf, + SpreadsheetResource.getInstance(graph).Book))) { + result.add(new BookNode(r)); + } + + return result; + } + + @Override + public String getViewpointId() { + return "Standard"; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ConfigurationLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ConfigurationLabeler.java new file mode 100644 index 00000000..f706d15d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ConfigurationLabeler.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode; + +public class ConfigurationLabeler extends LabelerContributor>{ + + @Override + public String getLabel(ReadGraph graph, ConfigurationNode conf) throws DatabaseException { + return "Configuration"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Experiment.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Experiment.java new file mode 100644 index 00000000..9e7aff06 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Experiment.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.ui.browser.nodes.ExperimentsFolder; + +public class Experiment extends ViewpointContributor { + + @SuppressWarnings("unchecked") + @Override + public Collection getContribution(ReadGraph graph, ExperimentsFolder experimentsFolder) throws DatabaseException { + ArrayList> result = new ArrayList>(); + Layer0 l0 = Layer0.getInstance(graph); + for(Resource r : graph.syncRequest(new ObjectsWithType(experimentsFolder.data, l0.ConsistsOf, SimulationResource.getInstance(graph).Experiment))) { + try { + result.add(graph.adapt(r, AbstractNode.class)); + } catch(DatabaseException e) { + e.printStackTrace(); + } + } + return result; + } + + @Override + public String getViewpointId() { + return "Standard"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabelDecorator.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabelDecorator.java new file mode 100644 index 00000000..d86672d5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabelDecorator.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.eclipse.jface.resource.FontDescriptor; +import org.eclipse.swt.SWT; +import org.simantics.browsing.ui.content.LabelDecorator; +import org.simantics.browsing.ui.graph.contributor.labeler.LabelDecoratorContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode; + +public class ExperimentLabelDecorator extends LabelDecoratorContributor { + + @Override + public LabelDecorator getDecorator(ReadGraph graph, ExperimentNode experimentNode) throws DatabaseException { + if (graph.hasStatement(experimentNode.data, SimulationResource.getInstance(graph).IsActive)) { + return new LabelDecorator.Stub() { + @Override + public String decorateLabel(String label, String column, int itemIndex) { + return label + " [ACTIVE]"; + } + + @SuppressWarnings("unchecked") + @Override + public F decorateFont(F font, String column, int itemIndex) { + return (F) ((FontDescriptor) font).withStyle(SWT.BOLD); + } + }; + } + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabeler.java new file mode 100644 index 00000000..865638d5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabeler.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode; + +public class ExperimentLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, ExperimentNode experiment) throws DatabaseException { + String name = graph.getPossibleRelatedValue(experiment.data, Layer0.getInstance(graph).HasLabel); + return name == null ? "Experiment (no name)" : name; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentsLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentsLabeler.java new file mode 100644 index 00000000..ca413c73 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentsLabeler.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.ExperimentsFolder; + +public class ExperimentsLabeler extends LabelerContributor { + + @Override + public String getLabel(ReadGraph graph, ExperimentsFolder experiments) throws DatabaseException { + return "Experiments"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionLibraries.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionLibraries.java new file mode 100644 index 00000000..87151394 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionLibraries.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode; +import org.simantics.sysdyn.ui.browser.nodes.FunctionNode; +import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder; + +public class FunctionLibraries extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, FunctionsFolder functionsFolder) + throws DatabaseException { + + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + + ArrayList> result = new ArrayList>(); + + // Find model functions + for(Resource function : graph.syncRequest(new ObjectsWithType(functionsFolder.data, l0.ConsistsOf, sr.SysdynModelicaFunction))) { + result.add(new FunctionNode(function)); + } + + // Find model function libraries + for(Resource functionLibrary : graph.syncRequest(new ObjectsWithType(functionsFolder.data, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) { + result.add(new FunctionLibraryNode(functionLibrary)); + } + + Resource sysdyn = graph.getPossibleResource("http://www.simantics.org/Sysdyn-1.1"); + if(sysdyn != null) { + for(Resource library : graph.syncRequest(new ObjectsWithType(sysdyn, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) { + result.add(new FunctionLibraryNode(library)); + } + } + + + result.add(new SharedFunctionsFolder(functionsFolder.data)); + + return result; + + } + + @Override + public String getViewpointId() { + return "Standard"; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionLibraryLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionLibraryLabeler.java new file mode 100644 index 00000000..1ac513f1 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionLibraryLabeler.java @@ -0,0 +1,20 @@ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode; + +public class FunctionLibraryLabeler extends LabelerContributor>{ + + @Override + public String getLabel(ReadGraph graph, FunctionLibraryNode input) + throws DatabaseException { + String name = NameUtils.getSafeName(graph, input.data); + return name; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionsLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionsLabeler.java new file mode 100644 index 00000000..35d2bec1 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionsLabeler.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder; + +public class FunctionsLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, FunctionsFolder input) throws DatabaseException { + return "Functions"; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/InputLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/InputLabeler.java new file mode 100644 index 00000000..7d34ce2c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/InputLabeler.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.operation.Layer0X; +import org.simantics.sysdyn.ui.browser.nodes.InputNode; + +public class InputLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, InputNode var) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + Layer0X L0X = Layer0X.getInstance(graph); + Resource varres = var.data; + StringBuilder sb = new StringBuilder(); + for(Resource r : graph.getObjects(varres, l0.HasName)) + sb.append(graph.getValue(r)); + if(graph.isInstanceOf(varres, L0X.Realization)) { + varres = graph.getPossibleObject(varres, L0X.Represents); + if(varres == null) return sb.toString(); + } + sb.append(" : "); + for(Resource t : graph.getObjects(varres, l0.InstanceOf)) + for(Resource r : graph.getObjects(t, l0.HasName)) + sb.append(graph.getValue(r)); + return sb.toString(); + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/LibraryFunctions.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/LibraryFunctions.java new file mode 100644 index 00000000..c37ea465 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/LibraryFunctions.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode; +import org.simantics.sysdyn.ui.browser.nodes.FunctionNode; + +public class LibraryFunctions extends ViewpointContributor> { + + @Override + public Collection getContribution(ReadGraph graph, + FunctionLibraryNode library) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + ArrayList> result = new ArrayList>(); + for(Resource function : graph.syncRequest(new ObjectsWithType(library.data, l0.ConsistsOf, SysdynResource.getInstance(graph).SysdynModelicaFunction))) { + result.add(new FunctionNode(function)); + } + for(Resource functionLibrary : graph.syncRequest(new ObjectsWithType(library.data, l0.ConsistsOf, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary))) { + result.add(new FunctionLibraryNode(functionLibrary)); + } + return result; + + } + + @Override + public String getViewpointId() { + return "Standard"; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Model.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Model.java new file mode 100644 index 00000000..01c21fb1 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Model.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.primitiverequest.PossibleObject; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.operation.Layer0X; +import org.simantics.sysdyn.ui.browser.nodes.ChartsFolder; +import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode; +import org.simantics.sysdyn.ui.browser.nodes.ExperimentsFolder; +import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder; +import org.simantics.sysdyn.ui.browser.nodes.ModelNode; +import org.simantics.sysdyn.ui.browser.nodes.ModulesNode; + +/** + * Provides children for a model in model browser + * @author Teemu Lempinen + * + */ +public class Model extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, ModelNode model) + throws DatabaseException { + ArrayList> result = new ArrayList>(); + + Layer0X L0X = Layer0X.getInstance(graph); + Resource baseRealization = graph.syncRequest(new PossibleObject(model.data, L0X.HasBaseRealization)); + if (baseRealization != null) { + try { + String URI = graph.getURI(baseRealization); + Variable variable = Variables.getVariable(graph, URI); + result.add(new ConfigurationNode(variable, baseRealization)); + } catch (DatabaseException e) { + } + } + result.add(new ExperimentsFolder(model.data)); + result.add(new ModulesNode(model.data)); + result.add(new FunctionsFolder(model.data)); + result.add(new ChartsFolder(model.data)); + return result; + } + + @Override + public String getViewpointId() { + return "Standard"; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModelLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModelLabeler.java new file mode 100644 index 00000000..16798d8c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModelLabeler.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.ui.browser.nodes.ModelNode; + +public class ModelLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, ModelNode model) throws DatabaseException { + String label = graph.getPossibleRelatedValue(model.data, Layer0.getInstance(graph).HasLabel); + return label == null ? "Model (no name)" : label; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleLabeler.java new file mode 100644 index 00000000..6c268098 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleLabeler.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.operation.Layer0X; +import org.simantics.sysdyn.ui.browser.nodes.ModuleNode; + +public class ModuleLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, ModuleNode module) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + Layer0X L0X = Layer0X.getInstance(graph); + Resource resource = module.data; + StringBuilder sb = new StringBuilder(); + for(Resource r : graph.getObjects(resource, l0.HasName)) + sb.append(graph.getValue(r)); + if(graph.isInstanceOf(resource, L0X.Realization)) { + resource = graph.getPossibleObject(resource, L0X.Represents); + if(resource == null) return sb.toString(); + } + sb.append(" : "); + for(Resource t : graph.getObjects(resource, l0.InstanceOf)) + for(Resource r : graph.getObjects(t, l0.HasName)) + sb.append(graph.getValue(r)); + return sb.toString(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleType.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleType.java new file mode 100644 index 00000000..ed5a9ead --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleType.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.EnumerationNode; +import org.simantics.sysdyn.ui.browser.nodes.InputNode; +import org.simantics.sysdyn.ui.browser.nodes.ModuleNode; +import org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode; +import org.simantics.sysdyn.ui.browser.nodes.VariableNode; + +public class ModuleType extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, ModuleTypeNode module) throws DatabaseException { + ArrayList> result = new ArrayList>(); + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 str = StructuralResource2.getInstance(graph); + + ModelingResources mr = ModelingResources.getInstance(graph); + Resource instance = graph.getPossibleObject(module.data, mr.SymbolToComponentType); + + if(instance == null) return result; + Resource conf = graph.getSingleObject(instance, str.IsDefinedBy); + for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.IndependentVariable))) { + result.add(new VariableNode(r)); + } + for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Input))) { + result.add(new InputNode(r)); + } + for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Module))) { + result.add(new ModuleNode(r)); + } + for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Enumeration))) { + result.add(new EnumerationNode(r)); + } + return result; + } + + @Override + public String getViewpointId() { + return "Standard"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleTypeLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleTypeLabeler.java new file mode 100644 index 00000000..32654013 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleTypeLabeler.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode; + +public class ModuleTypeLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, ModuleTypeNode moduleType) throws DatabaseException { + ModelingResources mr = ModelingResources.getInstance(graph); + Resource typeResource = graph.getPossibleObject(moduleType.data, mr.SymbolToComponentType); + String label = null; + if(typeResource != null) + label = graph.getPossibleRelatedValue(typeResource, Layer0.getInstance(graph).HasName); + return label == null ? "ModuleType (no name)" : label; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Modules.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Modules.java new file mode 100644 index 00000000..41bf4e96 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Modules.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode; +import org.simantics.sysdyn.ui.browser.nodes.ModulesNode; + +public class Modules extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, ModulesNode model) + throws DatabaseException { + + ArrayList> result = new ArrayList>(); + Layer0 l0 = Layer0.getInstance(graph); + StructuralResource2 st = StructuralResource2.getInstance(graph); + for(Resource r : graph.syncRequest(new ObjectsWithType(model.data, l0.ConsistsOf, st.ComponentType))) { + if(graph.isInheritedFrom(r, SysdynResource.getInstance(graph).Module)) { + Resource symbol = graph.getPossibleObject(r,ModelingResources.getInstance(graph).ComponentTypeToSymbol); + result.add(new ModuleTypeNode(symbol)); + } + } + return result; + + } + + @Override + public String getViewpointId() { + return "Standard"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModulesLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModulesLabeler.java new file mode 100644 index 00000000..47010533 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModulesLabeler.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.ModulesNode; + +public class ModulesLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, ModulesNode input) throws DatabaseException { + return "Modules"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/OperatingInterfacesLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/OperatingInterfacesLabeler.java new file mode 100644 index 00000000..8c7a8c6c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/OperatingInterfacesLabeler.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.OperatingInterfacesFolder; + +public class OperatingInterfacesLabeler extends LabelerContributor { + + @Override + public String getLabel(ReadGraph graph, OperatingInterfacesFolder input) throws DatabaseException { + return "Operating interfaces"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Project.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Project.java new file mode 100644 index 00000000..5506660f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Project.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; + +public class Project extends ViewpointContributor { + + @SuppressWarnings("unchecked") + @Override + public Collection getContribution(ReadGraph graph, Resource project) + throws DatabaseException { + + ArrayList> result = new ArrayList>(); + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + for(Resource r : graph.syncRequest(new ObjectsWithType(project, l0.ConsistsOf, sr.SysdynModel))) { + try { + result.add(graph.adapt(r, AbstractNode.class)); + } catch(DatabaseException e) { + e.printStackTrace(); + } + } + return result; + + } + + @Override + public String getViewpointId() { + return "Standard"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionLibraries.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionLibraries.java new file mode 100644 index 00000000..7d5c736a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionLibraries.java @@ -0,0 +1,36 @@ +package org.simantics.sysdyn.ui.browser.contributions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder; + +public class SharedFunctionLibraries extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, + SharedFunctionsFolder sharedFunctionsFolder) throws DatabaseException { + + ArrayList> result = new ArrayList>(); + + + for(Resource sharedLibrary : graph.syncRequest(new ObjectsWithType( + sharedFunctionsFolder.data, + Layer0.getInstance(graph).IsLinkedTo, + SysdynResource.getInstance(graph).SharedFunctionOntology))) + { + result.add(new SharedFunctionLibraryNode(sharedLibrary)); + } + + return result; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionsLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionsLabeler.java new file mode 100644 index 00000000..c1c8c0a8 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SharedFunctionsLabeler.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder; + +public class SharedFunctionsLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, SharedFunctionsFolder input) throws DatabaseException { + return "Shared Functions"; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SheetLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SheetLabeler.java new file mode 100644 index 00000000..ff4bd59f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SheetLabeler.java @@ -0,0 +1,15 @@ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.ui.browser.nodes.SheetNode; + +public class SheetLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, SheetNode sheet) throws DatabaseException { + return graph.getPossibleRelatedValue(sheet.data, Layer0.getInstance(graph).HasName); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResult.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResult.java new file mode 100644 index 00000000..c95383a5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResult.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode; + +public class SimulationResult extends ViewpointContributor { + + @SuppressWarnings("unchecked") + @Override + public Collection getContribution(ReadGraph graph, ExperimentNode experiment) throws DatabaseException { + ArrayList> result = new ArrayList>(); + SysdynResource sr = SysdynResource.getInstance(graph); + for(final Resource r : graph.syncRequest(new ObjectsWithType(experiment.data, sr.HasResult, sr.Result))) { + String resultPath = (String)graph.getPossibleRelatedValue(r, sr.HasResultFile); + File file = new File(resultPath); + if(file.exists()) { + try { + result.add(graph.adapt(r, AbstractNode.class)); + } catch(DatabaseException e) { + e.printStackTrace(); + } + } else { + graph.asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + graph.deny(r, l0.PartOf); + graph.deny(r, graph.getInverse(SysdynResource.getInstance(graph).HasResult)); + + } + }); + } + } + return result; + } + + @Override + public String getViewpointId() { + return "Standard"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultDecorator.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultDecorator.java new file mode 100644 index 00000000..c35120a3 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultDecorator.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.eclipse.jface.resource.FontDescriptor; +import org.eclipse.swt.SWT; +import org.simantics.browsing.ui.content.LabelDecorator; +import org.simantics.browsing.ui.graph.contributor.labeler.LabelDecoratorContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode; + +public class SimulationResultDecorator extends LabelDecoratorContributor{ + + @Override + public LabelDecorator getDecorator(ReadGraph graph, SimulationResultNode result) throws DatabaseException { + if (graph.hasStatement(result.data, SysdynResource.getInstance(graph).ShowResult)) { + return new LabelDecorator.Stub() { + + @SuppressWarnings("unchecked") + @Override + public F decorateFont(F font, String column, int itemIndex) { + return (F) ((FontDescriptor) font).withStyle(SWT.BOLD); + } + }; + } + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java new file mode 100644 index 00000000..70e418d8 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.swt.ImagerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode; + +public class SimulationResultImager extends ImagerContributor{ + + @Override + public ImageDescriptor getDescriptor(ReadGraph graph, SimulationResultNode result) throws DatabaseException { + if(graph.hasStatement(result.data, SysdynResource.getInstance(graph).ShowResult)) + return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar.png")); + else + return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar_blackAndWhite.png")); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultLabeler.java new file mode 100644 index 00000000..917adb9c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultLabeler.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode; + +public class SimulationResultLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, SimulationResultNode result) throws DatabaseException { + String name = graph.getPossibleRelatedValue(result.data, Layer0.getInstance(graph).HasLabel); + return name == null ? "Experiment (no name)" : name; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SysdynProject.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SysdynProject.java new file mode 100644 index 00000000..91c46b6a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SysdynProject.java @@ -0,0 +1,39 @@ +package org.simantics.sysdyn.ui.browser.contributions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.structural.ui.modelBrowser.nodes.AbstractNode; +import org.simantics.sysdyn.SysdynResource; + +public class SysdynProject extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, Resource project) + throws DatabaseException { + + ArrayList result = new ArrayList(); + Layer0 L0 = Layer0.getInstance(graph); + for(Resource r : graph.syncRequest(new ObjectsWithType(project, L0.ConsistsOf, SysdynResource.getInstance(graph).SysdynModel))) { + try { + result.add(graph.adapt(r, AbstractNode.class)); + } catch(DatabaseException e) { + e.printStackTrace(); + } + } + return result; + + } + + @Override + public String getViewpointId() { + return "Standard"; + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/VariableLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/VariableLabeler.java new file mode 100644 index 00000000..6302ad0d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/VariableLabeler.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.operation.Layer0X; +import org.simantics.sysdyn.ui.browser.nodes.VariableNode; + +public class VariableLabeler extends LabelerContributor>{ + + @Override + public String getLabel(ReadGraph graph, VariableNode var) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + Layer0X L0X = Layer0X.getInstance(graph); + Resource varres = var.data; + StringBuilder sb = new StringBuilder(); + for(Resource r : graph.getObjects(varres, l0.HasName)) + sb.append(graph.getValue(r)); + if(graph.isInstanceOf(varres, L0X.Realization)) { + varres = graph.getPossibleObject(varres, L0X.Represents); + if(varres == null) return sb.toString(); + } + sb.append(" : "); + for(Resource t : graph.getObjects(varres, l0.InstanceOf)) + for(Resource r : graph.getObjects(t, l0.HasName)) + sb.append(graph.getValue(r)); + return sb.toString(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/labelrules/ModuleTypeLabelRule.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/labelrules/ModuleTypeLabelRule.java new file mode 100644 index 00000000..90d72345 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/labelrules/ModuleTypeLabelRule.java @@ -0,0 +1,32 @@ +package org.simantics.sysdyn.ui.browser.labelrules; + +import java.util.Collections; +import java.util.Map; + +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.model.labels.LabelRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.modeling.ModelingResources; + +public class ModuleTypeLabelRule implements LabelRule { + public static final ModuleTypeLabelRule INSTANCE = new ModuleTypeLabelRule(); + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public Map getLabel(ReadGraph graph, Object content) throws DatabaseException { + Resource symbol = (Resource)content; + Resource component = graph.getSingleObject(symbol, ModelingResources.getInstance(graph).SymbolToComponentType); + + return Collections.singletonMap(ColumnKeys.SINGLE, + NameUtils.getSafeName(graph, component) + ); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/AbstractChartNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/AbstractChartNode.java new file mode 100644 index 00000000..61eb1850 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/AbstractChartNode.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import java.util.Iterator; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.DeleteException; +import org.simantics.browsing.ui.common.node.IDeletableNode; +import org.simantics.browsing.ui.common.node.IDropTargetNode; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.CancelTransactionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ExceptionUtils; + +public abstract class AbstractChartNode extends AbstractNode implements IDropTargetNode, IDeletableNode { + + public AbstractChartNode(Resource data) { + super(data); + } + + + /** + * Add variable to this chart, if the dropped element(s) can be adapted to a {@link Variable} + */ + @Override + public void drop(Object data) { + IStructuredSelection selection = (IStructuredSelection)data; + Iterator iterator = selection.iterator(); + while(iterator.hasNext()) { + Object o = iterator.next(); + if(o instanceof IAdaptable) { + Variable v = (Variable) ((IAdaptable)o).getAdapter(Variable.class); + if(v != null) { + addVariableToChart(v); + } + } + } + } + + + /** + * Adds a variable to this chart and map it to the first rangeAxis + * @param variable + */ + protected abstract void addVariableToChart(final Variable variable); + + @Override + public void delete() throws DeleteException { + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + RemoverUtil.remove(graph, data); + } + }); + } catch (DatabaseException e) { + ExceptionUtils.logAndShowError(e); + } + + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/BarChartNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/BarChartNode.java new file mode 100644 index 00000000..91fe6d6c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/BarChartNode.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.request.SingleObjectWithType; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.trend.chart.ChartUtils; +import org.simantics.ui.SimanticsUI; + +/** + * Bar chart node + * @author Teemu Lempinen + * + */ +public class BarChartNode extends AbstractChartNode { + + public BarChartNode(Resource data) { + super(data); + } + + + /** + * Adds a variable to this chart + * @param variable + */ + @Override + protected void addVariableToChart(final Variable variable) { + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + Resource plot = graph.syncRequest(new SingleObjectWithType(data, l0.ConsistsOf, jfree.Plot)); + if(plot == null) + return; + + Resource dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.Dataset)); + + if(dataset == null) + return; + + // Create the series and attach it to the dataset + String rvi = Variables.getRVI(graph, variable); + ChartUtils.createSeries(graph, dataset, rvi); + } + }); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/BookNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/BookNode.java new file mode 100644 index 00000000..02f5bc51 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/BookNode.java @@ -0,0 +1,11 @@ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.db.Resource; + +public class BookNode extends AbstractNode { + + public BookNode(Resource data) { + super(data); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ChartsFolder.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ChartsFolder.java new file mode 100644 index 00000000..d75b01ba --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ChartsFolder.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.db.Resource; + +/** + * Folder containing all sysdyn charts + * @author Teemu Lempinen + * + */ +public class ChartsFolder extends AbstractNode { + + public ChartsFolder(Resource resource) { + super(resource); + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if(clazz == adapter) // There is no resource for this node.. + return null; + return super.getAdapter(adapter); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ConfigurationNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ConfigurationNode.java new file mode 100644 index 00000000..4b614428 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ConfigurationNode.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.IDeletable; +import org.simantics.db.Resource; +import org.simantics.db.layer0.variable.Variable; + +public class ConfigurationNode extends VariableNode implements IDeletable { + + public ConfigurationNode(Resource resource) { + super(resource); + } + + public ConfigurationNode(Variable variable, Resource represents) { + super(variable, represents); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java new file mode 100644 index 00000000..77113d48 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/EnumerationNode.java @@ -0,0 +1,55 @@ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.DeleteException; +import org.simantics.browsing.ui.common.node.IDeletableNode; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.CancelTransactionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ExceptionUtils; + +public class EnumerationNode extends VariableNode implements IDeletableNode { + + public EnumerationNode(Resource resource) { + super(resource); + } + + public EnumerationNode(Variable variable, Resource represents) { + super(variable, represents); + } + + @Override + public void delete() throws DeleteException { + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + SysdynResource sr = SysdynResource.getInstance(graph); + for(Resource redeclaration : graph.getObjects(data, sr.ReplacedEnumeration_Inverse)) { + graph.deny(redeclaration, sr.HasRedeclaration_Inverse); + } + + for(Resource redeclaration : graph.getObjects(data, sr.ReplacingEnumeration_Inverse)) { + graph.deny(redeclaration, sr.HasRedeclaration_Inverse); + } + + for(Resource list : OrderedSetUtils.getOwnerLists(graph, data, sr.ArrayIndexes)) { + OrderedSetUtils.remove(graph, list, data); + } + + RemoverUtil.remove(graph, data); + + } + }); + } catch (DatabaseException e) { + ExceptionUtils.logAndShowError(e); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java new file mode 100644 index 00000000..9bc33413 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentNode.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.DeleteException; +import org.simantics.browsing.ui.common.node.IDeletableNode; +import org.simantics.browsing.ui.common.node.IDoubleClickableNode; +import org.simantics.browsing.ui.common.node.IModifiableNode; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.CancelTransactionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.project.IProject; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.handlers.SysdynExperimentActivator; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ErrorLogger; +import org.simantics.utils.ui.ExceptionUtils; + +public class ExperimentNode extends AbstractNode implements IDoubleClickableNode, IDeletableNode, IModifiableNode{ + + public ExperimentNode(Resource resource) { + super(resource); + } + + @Override + public boolean handleDoubleClick() { + if (data == null) + return false; + IProject project = SimanticsUI.getProject(); + IExperimentManager experimentManager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + if (experimentManager == null) { + ErrorLogger.defaultLogWarning("Experiment manager not available.", new Exception()); + return false; + } + SysdynExperimentActivator.scheduleActivation(SimanticsUI.getSession(), project, experimentManager, data); + return true; + } + + @Override + public Modifier getModifier(String columnId) { + LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data) { + @Override + public String isValid(String label) { + if (label.isEmpty()) + return "Empty label not allowed"; + return null; + } + }; + return modifier; + } + + @Override + public void delete() throws DeleteException { + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + Collection results = graph.getObjects(data, SysdynResource.getInstance(graph).HasResult); + if(results != null) + for(Resource result : results) + SimulationResultNode.unlinkResult(graph, result); + RemoverUtil.remove(graph, data); + } + }); + } catch (DatabaseException e) { + ExceptionUtils.logAndShowError(e); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentsFolder.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentsFolder.java new file mode 100644 index 00000000..76be910d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ExperimentsFolder.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.db.Resource; + +public class ExperimentsFolder extends AbstractNode { + + public ExperimentsFolder(Resource resource) { + super(resource); + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if(clazz == adapter) // There is no resource for this node.. + return null; + return super.getAdapter(adapter); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionLibraryNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionLibraryNode.java new file mode 100644 index 00000000..becb2cd1 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionLibraryNode.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.DeleteException; +import org.simantics.browsing.ui.common.node.IDeletableNode; +import org.simantics.browsing.ui.common.node.IDropTargetNode; +import org.simantics.browsing.ui.common.node.IModifiableNode; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; + +public class FunctionLibraryNode extends AbstractNode implements IDeletableNode, IModifiableNode, IDropTargetNode { + + + public FunctionLibraryNode(Resource resource) { + super(resource); + } + + @Override + public Modifier getModifier(String columnId) { + try { + Resource hasName = Layer0.getInstance(SimanticsUI.getSession()).HasName; + LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data, hasName) { + @Override + public String isValid(String label) { + if (label.isEmpty()) + return "Empty label not allowed"; + if (label.contains(" ")) + return "Spaces are not allowed"; + return null; + } + }; + return modifier; + } catch (DatabaseException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void delete() throws DeleteException { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + RemoverUtil.remove(graph, data); + } + }); + } + + @Override + public void drop(Object data) { + final Resource[] resources = ResourceAdaptionUtils.toResources(data); + final Resource library = this.data; + if(resources.length > 0) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + for(Resource tobeMoved : resources) { + if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) || + graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) { + Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf); + graph.deny(tobeMoved, l0.PartOf); + graph.claim(tobeMoved, l0.PartOf, library); + FunctionUtils.updateFunctionFileForLibrary(graph, oldLib); + FunctionUtils.updateFunctionFileForLibrary(graph, library); + } + } + } + }); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionNode.java new file mode 100644 index 00000000..710d221c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionNode.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.DeleteException; +import org.simantics.browsing.ui.common.node.IDeletableNode; +import org.simantics.browsing.ui.common.node.IDropTargetNode; +import org.simantics.browsing.ui.common.node.IModifiableNode; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; + +public class FunctionNode extends VariableNode implements IDeletableNode, IModifiableNode, IDropTargetNode { + + public FunctionNode(final Resource resource) { + super(resource); + } + + @Override + public Modifier getModifier(String columnId) { + try { + Resource hasName = Layer0.getInstance(SimanticsUI.getSession()).HasName; + LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data, hasName) { + @Override + public String isValid(String label) { + if (label.isEmpty()) + return "Empty label not allowed"; + if (label.contains(" ")) + return "Spaces are not allowed"; + return null; + } + }; + return modifier; + } catch (DatabaseException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void delete() throws DeleteException { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + RemoverUtil.remove(graph, data); + } + }); + } + + @Override + public void drop(Object data) { + final Resource[] resources = ResourceAdaptionUtils.toResources(data); + final Resource thisFunction = this.data; + + if(resources.length > 0) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource library = null; + for(Resource tobeMoved : resources) { + if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) || + graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) { + if(library == null) { + library = graph.getSingleObject(thisFunction, l0.PartOf); + } + Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf); + graph.deny(tobeMoved, l0.PartOf); + graph.claim(tobeMoved, l0.PartOf, library); + FunctionUtils.updateFunctionFileForLibrary(graph, oldLib); + FunctionUtils.updateFunctionFileForLibrary(graph, library); + } + } + } + }); + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionsFolder.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionsFolder.java new file mode 100644 index 00000000..bbba4a0b --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/FunctionsFolder.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.IDropTargetNode; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; + +public class FunctionsFolder extends AbstractNode implements IDropTargetNode{ + + public FunctionsFolder(Resource resource) { + super(resource); + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if(clazz == adapter) // There is no resource for this node.. + return null; + return super.getAdapter(adapter); + } + + @Override + public void drop(Object data) { + final Resource[] resources = ResourceAdaptionUtils.toResources(data); + final Resource library = this.data; + if(resources.length > 0) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + for(Resource tobeMoved : resources) { + if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) || + graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) { + Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf); + graph.deny(tobeMoved, l0.PartOf); + graph.claim(tobeMoved, l0.PartOf, library); + FunctionUtils.updateFunctionFileForLibrary(graph, oldLib); + FunctionUtils.updateFunctionFileForLibrary(graph, library); + } + } + } + }); + } + } + + + + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/InputNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/InputNode.java new file mode 100644 index 00000000..ca731e92 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/InputNode.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.db.Resource; +import org.simantics.db.layer0.variable.Variable; + +public class InputNode extends VariableNode { + + public InputNode(Resource resource) { + super(resource); + } + + public InputNode(Variable variable, Resource represents) { + super(variable, represents); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/LineChartNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/LineChartNode.java new file mode 100644 index 00000000..1aa188f6 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/LineChartNode.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.SingleObjectWithType; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.trend.chart.ChartUtils; +import org.simantics.ui.SimanticsUI; + +/** + * Node representing a line chart + * @author Teemu Lempinen + * + */ +public class LineChartNode extends AbstractChartNode { + + public LineChartNode(Resource data) { + super(data); + } + + /** + * Adds a variable to this chart and map it to the first rangeAxis + * @param variable + */ + @Override + protected void addVariableToChart(final Variable variable) { + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + Resource plot = graph.syncRequest(new SingleObjectWithType(data, l0.ConsistsOf, jfree.Plot)); + if(plot == null) + return; + + Resource rangeAxis = null; + Resource dataset = null; + Resource rangeAxisList = graph.getPossibleObject(plot, jfree.Plot_rangeAxisList); + if(rangeAxisList == null || ListUtils.toList(graph, rangeAxisList).isEmpty()) { + // No range axis -> Create a new one + rangeAxis = ChartUtils.createNumberRangeAxis(graph, plot); + Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis); + dataset = ChartUtils.createXYDataset(graph, plot, domainAxis, rangeAxis); + } else { + rangeAxis = ListUtils.toList(graph, rangeAxisList).get(0); + dataset = graph.getPossibleObject(rangeAxis, jfree.Dataset_mapToRangeAxis_Inverse); + } + + // Create the series and attach it to the dataset + String rvi = Variables.getRVI(graph, variable); + ChartUtils.createSeries(graph, dataset, rvi); + } + }); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java new file mode 100644 index 00000000..0c77fa90 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModelNode.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.DeleteException; +import org.simantics.browsing.ui.common.node.IDeletableNode; +import org.simantics.browsing.ui.common.node.IDoubleClickableNode; +import org.simantics.browsing.ui.common.node.IModifiableNode; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.CancelTransactionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.db.request.Write; +import org.simantics.layer0.Layer0; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ExceptionUtils; + +public class ModelNode extends AbstractNode implements IDoubleClickableNode, IDeletableNode, IModifiableNode { + + Listener configurationNameSynchronizer; + private boolean disposed = false; + + public ModelNode(Resource resource) { + super(resource); + + // Not the best solution for name sync + configurationNameSynchronizer = new Listener() { + + @Override + public void execute(final String result) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SimulationResource sim = SimulationResource.getInstance(graph); + Resource configuration = graph.getPossibleObject(data, sim.HasConfiguration); + graph.claimLiteral(configuration, l0.HasLabel, result); + } + }); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return disposed; + } + }; + + SimanticsUI.getSession().asyncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + return graph.getRelatedValue(data, Layer0.getInstance(graph).HasLabel); + } + + }, configurationNameSynchronizer); + } + + @Override + public Modifier getModifier(String columnId) { + LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data) { + @Override + public String isValid(String label) { + if (label.isEmpty()) + return "Empty label not allowed"; + if (label.contains(" ")) + return "Spaces are not allowed"; + return null; + } + + @Override + protected Write getWriteRequest(final String label) { + return new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + g.claimLiteral(data, l0.HasLabel, label); + String safeName = NameUtils.findFreshName(g, label, g.getSingleObject(data, l0.PartOf), l0.ConsistsOf, "%s%d"); + g.claimLiteral(data, l0.HasName, safeName); + } + }; + } + }; + return modifier; + } + + @Override + public void delete() throws DeleteException { + disposed = true; + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + Layer0 l0 = Layer0.getInstance(graph); + + for(Resource r : graph.getObjects(data, l0.ConsistsOf)) + if(graph.isInstanceOf(r, SysdynResource.getInstance(graph).Result)) + SimulationResultNode.deleteResultFiles(graph, r); + + RemoverUtil.remove(graph, data); + } + }); + } catch (DatabaseException e) { + ExceptionUtils.logAndShowError(e); + } + + } + + @Override + public boolean handleDoubleClick() { + return true; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleNode.java new file mode 100644 index 00000000..0f2dc7c5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleNode.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.PasteHandler; +import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.layer0.Layer0; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.ui.SimanticsUI; + +public class ModuleNode extends ConfigurationNode { + + Resource configuration; + + public ModuleNode(Resource resource) { + super(resource); + + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource type = graph.getPossibleObject(data, Layer0.getInstance(graph).InstanceOf); + configuration = graph.getPossibleObject(type, StructuralResource2.getInstance(graph).IsDefinedBy); + } + }); + } + + public ModuleNode(Variable variable, Resource represents) { + super(variable, represents); + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource type = graph.getPossibleObject(data, Layer0.getInstance(graph).InstanceOf); + configuration = graph.getPossibleObject(type, StructuralResource2.getInstance(graph).IsDefinedBy); + } + }); + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if(PasteHandler.class == adapter && configuration != null) + return new DefaultPasteHandler(configuration); + return super.getAdapter(adapter); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java new file mode 100644 index 00000000..ec6e58f7 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleTypeNode.java @@ -0,0 +1,206 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import java.util.Collection; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.DeleteException; +import org.simantics.browsing.ui.common.node.IDeletableNode; +import org.simantics.browsing.ui.common.node.IModifiableNode; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.layer0.adapter.PasteHandler; +import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.issues.ontology.IssueResource; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.ui.SimanticsUI; + +public class ModuleTypeNode extends AbstractNode implements IDeletableNode, IModifiableNode { + + + Listener configurationNameSynchronizer; + private boolean disposed = false; + private Resource configuration; + + public ModuleTypeNode(Resource resource) { + super(resource); + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + ModelingResources mr = ModelingResources.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + Resource type = graph.getPossibleObject(data, mr.SymbolToComponentType); + configuration = graph.getPossibleObject(type, sr2.IsDefinedBy); + } + }); + + // Not the best solution for name sync + configurationNameSynchronizer = new Listener() { + + @Override + public void execute(final String result) { + if(result == null) + return; + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if(configuration != null) + graph.claimLiteral(configuration, Layer0.getInstance(graph).HasLabel, result); + } + }); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return disposed; + } + }; + + SimanticsUI.getSession().asyncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + Resource type = graph.getPossibleObject(data, mr.SymbolToComponentType); + return (String) (type != null ? graph.getRelatedValue(type, l0.HasName) : null); + } + + }, configurationNameSynchronizer); + + } + + @Override + public Modifier getModifier(String columnId) { + Modifier modifier = null; + try { + modifier = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Modifier perform(ReadGraph graph) throws ManyObjectsForFunctionalRelationException, ServiceException { + ModelingResources mr = ModelingResources.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource type = graph.getPossibleObject(data, mr.SymbolToComponentType); + + LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), type, l0.HasName) { + @Override + public String isValid(String label) { + if (label.isEmpty()) + return "Empty name not allowed"; + return null; + } + }; + + + return modifier; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + return modifier; + } + + @Override + public void delete() throws DeleteException { + disposed = true; + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException{ + Layer0 l0 = Layer0.getInstance(graph); + StructuralResource2 st = StructuralResource2.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + + Resource type = graph.getPossibleObject(data, mr.SymbolToComponentType); + Resource model = graph.getSingleObject(type, l0.PartOf); + Resource modelConfiguration = graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration); + if (!graph.syncRequest(new ObjectsWithType(modelConfiguration, l0.ConsistsOf, type)).isEmpty()) { + throw new ModuleDeleteException("The module is used at the model configuration"); + } + Collection moduleTypes = graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, st.ComponentType)); + for(Resource r : moduleTypes) { + Resource configuration = graph.getSingleObject(r, st.IsDefinedBy); + if(!graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, type)).isEmpty()) { + throw new ModuleDeleteException("The module is used at another module: " + graph.getRelatedValue(r, l0.HasName)); + } + } + + IssueResource ISSUE = IssueResource.getInstance(graph); + // Remove issues + for(Resource issueSource : graph.syncRequest(new ObjectsWithType(type, l0.ConsistsOf, ISSUE.DependencyIssueSource))) { + for(Resource issue : graph.syncRequest(new ObjectsWithType(issueSource, ISSUE.IssueSource_Manages, ISSUE.Issue))) { + RemoverUtil.remove(graph, issue); + } + } + RemoverUtil.remove(graph, type); + } + }); + } catch (ModuleDeleteException e) { + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + MessageDialog dialog = new MessageDialog(shell, "Unable to delete", null, e.message, SWT.ERROR, + new String[] { "OK" }, 0); + dialog.create(); + dialog.open(); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + private class ModuleDeleteException extends DatabaseException { + private static final long serialVersionUID = 4076002781765246919L; + String message; + + public ModuleDeleteException(String message) { + this.message = message; + } + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if(PasteHandler.class == adapter && configuration != null) + return new DefaultPasteHandler(configuration); + return super.getAdapter(adapter); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModulesNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModulesNode.java new file mode 100644 index 00000000..faf9faed --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModulesNode.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.db.Resource; + +public class ModulesNode extends AbstractNode { + + public ModulesNode(Resource resource) { + super(resource); + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if(clazz == adapter) // There is no resource for this node.. + return null; + return super.getAdapter(adapter); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/OperatingInterfacesFolder.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/OperatingInterfacesFolder.java new file mode 100644 index 00000000..ce152952 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/OperatingInterfacesFolder.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.db.Resource; + +public class OperatingInterfacesFolder extends AbstractNode { + + public OperatingInterfacesFolder(Resource resource) { + super(resource); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/PieChartNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/PieChartNode.java new file mode 100644 index 00000000..82f2750c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/PieChartNode.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.request.SingleObjectWithType; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.trend.chart.ChartUtils; +import org.simantics.ui.SimanticsUI; + +/** + * Node for pie charts + * @author Teemu Lempinen + * + */ +public class PieChartNode extends AbstractChartNode { + + public PieChartNode(Resource data) { + super(data); + } + + /** + * Adds a variable to this chart + * @param variable + */ + @Override + protected void addVariableToChart(final Variable variable) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + Resource plot = graph.syncRequest(new SingleObjectWithType(data, l0.ConsistsOf, jfree.Plot)); + if(plot == null) + return; + + Resource dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.Dataset)); + + if(dataset == null) + return; + + // Create the series and attach it to the dataset + String rvi = Variables.getRVI(graph, variable); + Resource series = ChartUtils.createSeries(graph, dataset, rvi); + graph.claimLiteral(series, jfree.Series_exploded, false); + } + }); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionLibraryNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionLibraryNode.java new file mode 100644 index 00000000..7d764691 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionLibraryNode.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.DeleteException; +import org.simantics.browsing.ui.common.node.IDropTargetNode; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; + +public class SharedFunctionLibraryNode extends FunctionLibraryNode implements IDropTargetNode { + + public SharedFunctionLibraryNode(Resource resource) { + super(resource); + } + + @Override + public void delete() throws DeleteException { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + + graph.deny(data, l0.PartOf); + graph.deny(data, l0.IsLinkedTo_Inverse); + + // TODO: remove file + } + }); + } + + @Override + public void drop(Object data) { + final Resource[] resources = ResourceAdaptionUtils.toResources(data); + final Resource library = this.data; + if(resources.length > 0) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + for(Resource tobeMoved : resources) { + if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) || + graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) { + Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf); + graph.deny(tobeMoved, l0.PartOf); + graph.claim(tobeMoved, l0.PartOf, library); + FunctionUtils.updateFunctionFileForLibrary(graph, oldLib); + FunctionUtils.updateFunctionFileForLibrary(graph, library); + } + } + + } + }); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionsFolder.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionsFolder.java new file mode 100644 index 00000000..0531fd92 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SharedFunctionsFolder.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.db.Resource; + +public class SharedFunctionsFolder extends AbstractNode { + + public SharedFunctionsFolder(Resource data) { + super(data); + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if(clazz == adapter) // There is no resource for this node.. + return null; + return super.getAdapter(adapter); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SheetNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SheetNode.java new file mode 100644 index 00000000..8df2d43d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SheetNode.java @@ -0,0 +1,81 @@ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.IDoubleClickableNode; +import org.simantics.browsing.ui.common.node.IModifiableNode; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.workbench.ResourceEditorInput2; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +public class SheetNode extends AbstractNode implements IModifiableNode, IDoubleClickableNode { + + public SheetNode(Resource data) { + super(data); + } + + @Override + public Modifier getModifier(String columnId) { + + Session session = SimanticsUI.getSession(); + LabelModifier modifier = new LabelModifier(session, data, session.getService(Layer0.class).HasName) { + @Override + public String isValid(String label) { + if (label.isEmpty()) + return "Empty label not allowed"; + return null; + } + }; + return modifier; + } + + @Override + public boolean handleDoubleClick() { + + try { + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + + Variable variable = graph.adapt(data, Variable.class); + Resource model = Variables.getModel(graph, variable); + final String modelURI = graph.getURI(model); + final String RVI = Variables.getRVI(graph, variable); + + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + + private static final String EDITOR_ID = "org.simantics.spreadsheet.ui.editor2"; + + @Override + public void run() { + try { + System.out.println("Activating sheet: model=" + modelURI + " rvi=" + RVI); + WorkbenchUtils.openEditor(EDITOR_ID, new ResourceEditorInput2(EDITOR_ID, data, modelURI, RVI)); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + }); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + + return true; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java new file mode 100644 index 00000000..d21f18b1 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import java.io.File; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.DeleteException; +import org.simantics.browsing.ui.common.node.IDeletableNode; +import org.simantics.browsing.ui.common.node.IDoubleClickableNode; +import org.simantics.browsing.ui.common.node.IModifiableNode; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.CancelTransactionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.handlers.ToggleResultActivation; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ExceptionUtils; + +public class SimulationResultNode extends AbstractNode implements IDoubleClickableNode, IDeletableNode, IModifiableNode { + + public SimulationResultNode(Resource resource) { + super(resource); + } + + + @Override + public Modifier getModifier(String columnId) { + LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data) { + @Override + public String isValid(String label) { + if (label.isEmpty()) + return "Empty label not allowed"; + return null; + } + }; + return modifier; + } + + + @Override + public void delete() throws DeleteException { + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + unlinkResult(graph, data); + } + }); + } catch (DatabaseException e) { + ExceptionUtils.logAndShowError(e); + } + + } + + + public static void unlinkResult(WriteGraph graph, Resource result) throws DatabaseException { + deleteResultFiles(graph, result); + RemoverUtil.remove(graph, result); + } + + public static void deleteResultFiles(WriteGraph graph, Resource result) throws DatabaseException { + String path; + path = graph.getPossibleRelatedValue(result, SysdynResource.getInstance(graph).HasResultFile); + if(path != null) { + File file = new File(path); + file.delete(); + File parent = file.getParentFile(); + if(parent.listFiles() != null && parent.listFiles().length == 0) + parent.delete(); + } + } + + + @Override + public boolean handleDoubleClick() { + Resource[] resources = {data}; + ToggleResultActivation.toggleActivation(resources); + return true; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SymbolNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SymbolNode.java new file mode 100644 index 00000000..43456151 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SymbolNode.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.IDeletable; +import org.simantics.db.Resource; + +public class SymbolNode extends AbstractNode implements IDeletable { + + public SymbolNode(Resource resource) { + super(resource); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/VariableNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/VariableNode.java new file mode 100644 index 00000000..cada925b --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/VariableNode.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.db.Resource; +import org.simantics.db.layer0.variable.Variable; + +public class VariableNode extends AbstractNode { + + Variable variable; + + public VariableNode(Resource resource) { + super(resource); + } + + public VariableNode(Variable variable, Resource represents) { + super(represents); + this.variable = variable; + } + + public Variable getVariable() { + return variable; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/CreateDependencyGraph.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/CreateDependencyGraph.java new file mode 100644 index 00000000..b48de97d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/CreateDependencyGraph.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.dependencies; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.graphviz.Edge; +import org.simantics.graphviz.Graph; +import org.simantics.graphviz.IGraph; +import org.simantics.graphviz.Node; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.sysdyn.SysdynResource; + +public class CreateDependencyGraph implements Read { + + Resource root; + HashMap nodes; + boolean isInverted; + int levels; + + public CreateDependencyGraph(Resource root, int levels, boolean isInverted) { + this.root = root; + this.isInverted = isInverted; + this.levels = levels; + } + + @Override + public Graph perform(ReadGraph g) throws DatabaseException { + + nodes = new HashMap(); + Graph graph = new Graph(); + graph.setRankdir("LR"); + ModelingResources mr = ModelingResources.getInstance(g); + Resource element = g.getPossibleObject(root, mr.ElementToComponent); + if (element != null) { + root = element; + } + SysdynResource sr = SysdynResource.getInstance(g); + if (g.isInstanceOf(root, sr.IndependentVariable) || g.isInstanceOf(root, sr.Input)) { + setRoot(g, graph, root); + Collection resources = new ArrayList(); + resources.add(root); + for (int i = 0; i < levels && !resources.isEmpty(); i++) { + Collection newResources = new ArrayList(); + for(Resource r : resources) { + newResources.addAll(setDependencies(g, graph, r)); + } + resources = new ArrayList(newResources); + } + } + return graph; + } + + private void setRoot(ReadGraph g, IGraph graph, Resource root) throws DatabaseException { + Node n; + n = new Node(graph, getName(g, root)); + setShape(g, root, n); + n.set("style", "filled"); + n.setFillColor("#d3d3d3"); + nodes.put(root, n); + } + + + private Collection getDependants(ReadGraph g, IGraph graph, Resource r, Resource toDependency, Resource fromDependency, Resource connectionType) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + + Collection dependencies = g.syncRequest(new ObjectsWithType(r, toDependency, connectionType)); + + Collection dependants = new ArrayList(); + Node n; + for(Resource d : dependencies) { + Resource dependant = g.getPossibleObject(d, fromDependency); + if(dependant == null) + continue; + if(g.isInstanceOf(dependant, sr.Cloud)) { + break; + } + if( !nodes.containsKey(dependant)) { + n= new Node(graph, getName(g, dependant)); + setShape(g, dependant, n); + nodes.put(dependant, n); + dependants.add(dependant); + } + + if(isInverted) { + new Edge(graph, nodes.get(r), nodes.get(dependant)); + } else { + new Edge(graph, nodes.get(dependant), nodes.get(r)); + } + } + return dependants; + } + private Collection setDependencies(ReadGraph g, IGraph graph, Resource r) throws DatabaseException{ + SysdynResource sr = SysdynResource.getInstance(g); + + // stop here if element is a module + if (g.isInstanceOf(r, sr.Module)) + return Collections.emptyList(); + + Collection dependants; + if(isInverted) + dependants = getDependants(g, graph, r, sr.IsTailOf, sr.HasHead, sr.Dependency); + else { + dependants = getDependants(g, graph, r, sr.IsHeadOf, sr.HasTail, sr.Dependency); + if (g.isInstanceOf(r, sr.Stock)) { + dependants.addAll(getDependants(g, graph, r, sr.IsTailOf, sr.HasHead, sr.Flow)); + dependants.addAll(getDependants(g, graph, r, sr.IsHeadOf, sr.HasTail, sr.Flow)); + } + } + + return dependants; + } + + private void setShape(ReadGraph g, Resource r, Node n) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + if(g.isInstanceOf(r, sr.Stock)) + n.setShape("rectangle"); + else if(g.isInstanceOf(r, sr.Module)) { + n.setShape("rectangle"); + n.setStyle("rounded"); + } + else + n.setShape("ellipse"); + } + + private String getName(ReadGraph g, Resource r) throws DatabaseException { + return (String)g.getRelatedValue(r, Layer0.getInstance(g).HasName); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/DependencyView.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/DependencyView.java new file mode 100644 index 00000000..d783c03c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/DependencyView.java @@ -0,0 +1,202 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.dependencies; + +import java.util.Set; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.part.ViewPart; +import org.simantics.db.Resource; +import org.simantics.db.procedure.Listener; +import org.simantics.graphviz.Graph; +import org.simantics.graphviz.ui.GraphvizComponent; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ISelectionUtils; + +public class DependencyView extends ViewPart { + + private GraphvizComponent component; + private boolean disposed, isInverted = false; + private Button bButton, fButton; + private Resource currentSelection; + private int levels = 3; + private ISelectionListener selectionListener; + private Composite baseComposite; + + static int MAXLEVELS = 4; + static int MINLEVELS = 1; + + @Override + public void createPartControl(Composite parent) { + disposed = false; + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(parent); + baseComposite = new Composite(parent, + SWT.NO_BACKGROUND | SWT.EMBEDDED); + GridLayoutFactory.fillDefaults().applyTo(baseComposite); + GridDataFactory.fillDefaults().grab(true, true).applyTo(baseComposite); + + component = new GraphvizComponent(baseComposite, SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, true).applyTo(component); + + Composite composite = new Composite(parent, SWT.NULL); + RowLayout layout = new RowLayout(); + layout.center = true; + composite.setLayout(layout); + + Label label = new Label(composite, SWT.NULL); + label.setText("Direction: "); + + bButton = new Button(composite, SWT.RADIO); + bButton.setText("Backward"); + bButton.setSelection(true); + bButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + if(bButton.getSelection()) + isInverted = false; + else + isInverted = true; + if(currentSelection != null) { + readGraph(currentSelection); + } + } + }); + + fButton = new Button(composite, SWT.RADIO); + fButton.setText("Forward"); + + label = new Label(composite, SWT.NULL); + label.setText("Steps: "); + + Spinner spinner = new Spinner(composite, SWT.BORDER); + spinner.setMaximum(MAXLEVELS); + spinner.setMinimum(MINLEVELS); + spinner.setTextLimit(1); + spinner.setSelection(levels); + + spinner.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + Spinner s = (Spinner)e.widget; + int lvls = Integer.parseInt(s.getText()); + if(lvls > MAXLEVELS) + levels = MAXLEVELS; + else if (lvls < MINLEVELS) + levels = MINLEVELS; + levels = lvls; + if(currentSelection != null) { + readGraph(currentSelection); + } + + } + }); + + drawSelection(getSite().getWorkbenchWindow().getSelectionService().getSelection()); + + selectionListener = new ISelectionListener() { + + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + drawSelection(selection); + } + }; + getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener); + } + + private void drawSelection(ISelection selection) { + if(selection == null || selection.isEmpty()) + return; + if(selection instanceof IStructuredSelection) { + Object[] els = ((IStructuredSelection) selection).toArray(); + if(els.length == 1) { + Set ress = ISelectionUtils.filterSetSelection(selection, Resource.class); + if(ress.isEmpty()) return; + Resource r = (ress.toArray(Resource.NONE))[0]; + if(r != null && !r.equals(currentSelection)) { + currentSelection = r; + readGraph(currentSelection); + } + } + } + } + + private void readGraph(Resource resource) { + SimanticsUI.getSession().asyncRequest(new CreateDependencyGraph( + resource, levels, isInverted), + new Listener() { + + @Override + public void exception(Throwable e) { + e.printStackTrace(); + } + + @Override + public void execute(final Graph graph) { + Job job = new Job("Layout composite graph") { + + @Override + protected IStatus run(IProgressMonitor monitor) { + if(!isDisposed()) { + component.setGraph(graph, "dot"); + component.fit(); + } + return Status.OK_STATUS; + } + }; + job.schedule(); + } + + @Override + public boolean isDisposed() { + return disposed; + } + }); + } + + + @Override + public void setFocus() { + if(baseComposite != null && !baseComposite.isDisposed()) { + baseComposite.setFocus(); + component.setFocus(); + } + } + + + + + @Override + public void dispose() { + super.dispose(); + getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(selectionListener); + disposed = true; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramToCompositeMapping3.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramToCompositeMapping3.java new file mode 100644 index 00000000..240874fe --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramToCompositeMapping3.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.editor; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.utils.binaryPredicates.InversePredicate; +import org.simantics.layer0.utils.binaryPredicates.OrderedSetElementsPredicate; +import org.simantics.mapping.constraint.instructions.IInstruction; +import org.simantics.mapping.constraint.instructions.TypedBracketInstruction.CreationInstruction; +import org.simantics.mapping.rule.instructions.IRuleInstruction; +import org.simantics.sysdyn.SysdynResource; + +public class DiagramToCompositeMapping3 extends org.simantics.modeling.mapping.DiagramToCompositeMapping3 { + + private SysdynResource sdr; + + public DiagramToCompositeMapping3(ReadGraph g, Resource mapping) + throws DatabaseException { + super(g, mapping); + } + + @Override + protected void setup(ReadGraph graph) { + sdr = SysdynResource.getInstance(graph); + } + + @Override + protected Resource getConfigurationConnectionType() { + return sdr.DependencyConnection; + } + + @Override + public CreationInstruction componentCreationInstruction(int component, int componentType, int configuration) { + return new SysdynCreationInstruction(project, configurationRoot, component, componentType, configuration); + } + + @Override + protected IRuleInstruction additiveRule() { + return + + if_(bf(OrderedSetElementsPredicate.INSTANCE, Diagram, Element), + query( + if_(and(bf(L0.InstanceOf, Element, ElementType), + bf(MOD.SymbolToComponentType, ElementType, ComponentType) + ), + // If element type of the element has a corresponding component type + createComponentRule(), + + if_(and(b(DIA.Connection, Element), bf(L0.InstanceOf, Element, ElementType), bf(MOD.DiagramConnectionTypeToConnectionType, ElementType, ComponentType)), + createNormalConnectionRule(), + + if_(b(DIA.Flag, Element), + createFlagRule() + ) + ) + ) + ) + ); + } + + @Override + protected IRuleInstruction destructiveRule() { + return + if_(and(bf(L0.ConsistsOf, Configuration, Component), + b(mapped, Component) // handle only mapped components + ), + query( + if_(and(bf(MOD.ComponentToElement, Component, Element), + bf(new InversePredicate(OrderedSetElementsPredicate.INSTANCE), Element, Diagram) + ), + // If component has a corresponding element in the diagram + if_(and(statement_bff(Component, ConnectionRelation, Connection, STR.IsConnectedTo), + b(mapped, Connection) + ), + // If component has a mapped connection + unless( + bf(MOD.ConnectionToDiagramConnection, Connection, DiagramConnectionRelation), + // If the configuration connection does not have a correspondence in the diagram remove it + and(deny(exists(Connection))) + ) + ), + + unless( + bf(MOD.ConnectionToDiagramConnection, Component, Element), + // If the configuration connection does not have a correspondence in the diagram remove it + and(deny(exists(Component))) + ) + + ) + ) + ); + } + + @Override + protected IInstruction claimBasicConnection() { + return and(exists( + bf(MOD.DiagramConnectionToConnection, Element, Connection), + Connection + ), + bb(L0.InstanceOf, Connection, ComponentType), + bb(L0.PartOf, Connection, Configuration), + b(mapped, Connection) + + ); + } + +// @Override +// protected IInstruction claimBasicConnection() { +// return and(exists( +// bf(MOD.DiagramConnectionToConnection, Element, Connection), +// Connection +// ), +// bb(L0.InstanceOf, Connection, ComponentType), +// b(mapped, Connection), +// bb(L0.PartOf, Connection, Configuration) +// ); +// } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java new file mode 100644 index 00000000..34dd82e5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java @@ -0,0 +1,226 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.editor; + +import java.awt.dnd.DnDConstants; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Set; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchPartSite; +import org.simantics.browsing.ui.swt.AdaptableHintContext; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.layer0.SelectionHints; +import org.simantics.diagram.handler.CopyPasteHandler; +import org.simantics.diagram.handler.DeleteHandler; +import org.simantics.diagram.synchronization.IModifiableSynchronizationContext; +import org.simantics.diagram.synchronization.SynchronizationHints; +import org.simantics.diagram.ui.DiagramModelHints; +import org.simantics.diagram.ui.WorkbenchSelectionProvider; +import org.simantics.g2d.canvas.Hints; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.canvas.impl.CanvasContext; +import org.simantics.g2d.connection.IConnectionAdvisor; +import org.simantics.g2d.diagram.DiagramHints; +import org.simantics.g2d.diagram.participant.ElementPainter; +import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementClasses; +import org.simantics.g2d.element.ElementHints; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.IElementClassProvider; +import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.g2d.participant.GridPainter; +import org.simantics.g2d.participant.RulerPainter; +import org.simantics.modeling.mapping.ElementCopyAdvisor; +import org.simantics.modeling.mapping.MappedElementCopyAdvisor; +import org.simantics.modeling.ui.diagramEditor.handlers.LinkBrowsingHandler; +import org.simantics.structural2.modelingRules.IModelingRules; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.editor.participant.CreateVariablesShortcutParticipant; +import org.simantics.sysdyn.ui.editor.participant.SysdynComponentCopyAdvisor; +import org.simantics.sysdyn.ui.editor.participant.SysdynElementClassProviders; +import org.simantics.sysdyn.ui.editor.participant.SysdynPopulateElementDropParticipant; +import org.simantics.sysdyn.ui.elements2.CloudFactory; +import org.simantics.sysdyn.ui.elements2.SysdynElementClasses; +import org.simantics.sysdyn.ui.elements2.SysdynElementFactory; +import org.simantics.sysdyn.ui.elements2.connections.ConnectionClasses; +import org.simantics.sysdyn.ui.elements2.connections.RouteFlowEdgeClass; +import org.simantics.sysdyn.ui.elements2.connections.SysdynConnectionClass; +import org.simantics.sysdyn.ui.properties.SysdynPropertyPage; +import org.simantics.sysdyn.ui.trend.chart.element.PopulateChartDropParticipant; +import org.simantics.ui.workbench.IPropertyPage; +import org.simantics.utils.datastructures.hints.HintContext; +import org.simantics.utils.datastructures.hints.IHintContext; +import org.simantics.utils.threads.AWTThread; +import org.simantics.utils.threads.ThreadUtils; + +/** + * @author Tuukka Lehtonen + */ +public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.DiagramViewer { + + protected String getPopupId() { + return "#SysdynDiagramPopup"; + } + + @Override + public void createPartControl(Composite parent) { + super.createPartControl(parent); + + + ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() { + + @Override + public void run() { + if (isDisposed()) { + return; + } else { + ElementPainter ep = canvasContext.getSingleItem(ElementPainter.class); + for(IElement e : sourceDiagram.getElements()) { + if(e.getElementClass().getId().contains("Connection")){ + ep.update(e); + } + } + //scheduleZoomToFit(); + } + } + }); + } + + @Override + protected Set getPropertyPageContexts() { + return Collections.singleton(SysdynResource.URIs.Browser); + } + + @Override + protected IPropertyPage createPropertyPage(IWorkbenchPartSite site, Set contexts) { + return new SysdynPropertyPage(site, contexts); + } + + @Override + protected IElementClassProvider createElementClassProvider(ReadGraph graph) { + SysdynResource sr = SysdynResource.getInstance(graph); + ElementClass dependencyClass = SysdynConnectionClass.CLASS.newClassWith(new StaticObjectAdapter(sr.DependencyConnection)); + ElementClass flowClass = RouteFlowEdgeClass.FLOW_CLASS.newClassWith(new StaticObjectAdapter(sr.FlowConnection)); + return SysdynElementClassProviders.mappedProvider( + ElementClasses.CONNECTION, dependencyClass, + ElementClasses.FLAG, CloudFactory.createElementClass(sr.CloudSymbol, SysdynElementFactory.createTerminals(graph, sr.CloudSymbol)), + ConnectionClasses.FLOW, flowClass, + ConnectionClasses.DEPENDENCY, dependencyClass, + SysdynElementClasses.VALVE, CloudFactory.createElementClass(sr.ValveSymbol, SysdynElementFactory.createTerminals(graph, sr.ValveSymbol)) + ); + + + } + + @Override + public ICanvasContext createViewerCanvas() { + ICanvasContext ctx = super.createViewerCanvas(); + // GRID and RULER have to be set here. They cause deadlocks in Show Module if set in onCreated() + IHintContext h = ctx.getDefaultHintContext(); + h.setHint(GridPainter.KEY_GRID_ENABLED, Boolean.FALSE); + h.setHint(RulerPainter.KEY_RULER_ENABLED, Boolean.FALSE); + h.setHint(Hints.KEY_DISPLAY_MARGINS, Boolean.FALSE); + h.setHint(Hints.KEY_DISPLAY_PAGE, Boolean.FALSE); + return ctx; + } + + @Override + protected void onCreated() { + sourceDiagram.setHint(DiagramHints.KEY_ALLOW_ROUTE_POINTS, Boolean.FALSE); + sourceDiagram.setHint(SynchronizationHints.COPY_ADVISOR, new MappedElementCopyAdvisor(new ElementCopyAdvisor(), new SysdynComponentCopyAdvisor())); + } + + @Override + protected void addKeyBindingParticipants(CanvasContext ctx) { + ctx.add(new DeleteHandler(getEditorSite().getActionBars().getStatusLineManager())); + ctx.add(new CopyPasteHandler(getEditorSite().getActionBars().getStatusLineManager()).setWorkbenchSite(getEditorSite())); + ctx.add(new CreateVariablesShortcutParticipant(synchronizer)); + } + + @Override + protected void initializeSynchronizationContext(ReadGraph graph, IModifiableSynchronizationContext context) { + super.initializeSynchronizationContext(graph, context); + + // Make sure SysdynResource is available. + SysdynResource.getInstance(graph); + } + + @Override + protected void addStructureParticipants(ICanvasContext ctx) { + + ctx.add(new WorkbenchSelectionProvider(swt, getSite()) { + + @Override + protected ISelection constructAdaptableSelection(Iterable selection) { + ArrayList objects = new ArrayList(); + Resource runtime = sourceDiagram.getHint(DiagramModelHints.KEY_DIAGRAM_RUNTIME_RESOURCE); + for (Object o : selection) { + if (o instanceof IElement) { + IElement e = (IElement) o; + Object object = e.getHint(ElementHints.KEY_OBJECT); + if (object != null && runtime != null) { + IHintContext context = new AdaptableHintContext(SelectionHints.KEY_MAIN); + context.setHint(SelectionHints.KEY_MAIN, object); + if (runtime != null) + context.setHint(SelectionHints.KEY_VARIABLE_RESOURCE, runtime); + objects.add(context); + } + } else { + System.out.println(" unrecognized selection: " + o.getClass() + ": " + o); + } + } + if(objects.isEmpty() && runtime != null) { + HintContext context = new HintContext(); + context.setHint(SelectionHints.KEY_VARIABLE_RESOURCE, runtime); + objects.add(context); + } + return new StructuredSelection(objects); + } + + }); + // Add visual browsing capabilities for structural models + + // Remove double click handler, because it is not working properly + // ctx.add(new StructuralBrowsingHandler(getSite(), sessionContext, getResourceInput2())); + ctx.add(new LinkBrowsingHandler(getSite(), this, sessionContext)); + + } + + protected void addDropParticipants(ICanvasContext ctx) { + ctx.getDefaultHintContext().setHint(Hints.KEY_ALLOWED_DRAG_ACTIONS, DnDConstants.ACTION_COPY); + + ctx.add(new SysdynPopulateElementDropParticipant(synchronizer)); + ctx.add(new PopulateChartDropParticipant(synchronizer)); + } + + @Override + protected void addOtherParticipants(CanvasContext ctx) { + } + + @Override + protected PointerInteractor getPointerInteractor() { + return new org.simantics.sysdyn.ui.editor.participant.PointerInteractor(true, true, true, false, true, false, synchronizer.getElementClassProvider()); + } + + @Override + protected IConnectionAdvisor getConnectionAdvisor(IModelingRules modelingRules, Session session) { + return new SysdynConnectionAdvisor(modelingRules, sessionContext.getSession()); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromConfigurationAdapter.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromConfigurationAdapter.java new file mode 100644 index 00000000..433a3b36 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromConfigurationAdapter.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.editor; + +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.ResourceArray; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ComponentUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.modeling.ui.Activator; +import org.simantics.operation.Layer0X; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.structural2.StructuralVariables; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.workbench.ResourceEditorInput2; +import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +public class OpenDiagramFromConfigurationAdapter extends AbstractResourceEditorAdapter { + + private static final String EDITOR_ID = "org.simantics.sysdyn.ui.diagramViewer"; + + public OpenDiagramFromConfigurationAdapter() { + super("Diagram Editor", Activator.COMPOSITE_ICON); + } + + protected String getEditorId() { + return EDITOR_ID; + } + + @Override + public boolean canHandle(ReadGraph g, Resource r) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + if(g.isInheritedFrom(r, sr.ModuleSymbol)) { + ModelingResources mr = ModelingResources.getInstance(g); + StructuralResource2 sr2 = StructuralResource2.getInstance(g); + Resource componentType = g.getSingleObject(r, mr.SymbolToComponentType); + r = g.getSingleObject(componentType, sr2.IsDefinedBy); + } + Layer0X L0X = Layer0X.getInstance(g); + Resource represents = g.getPossibleObject(r, L0X.Represents); + if(represents != null){ + if(g.isInstanceOf(represents, sr.Configuration)) { + r = represents; + } + } + return ComponentUtils.compositeHasDiagram(g, r) /*|| ComponentUtils.componentHasDiagram(g, r)*/; + } + + @Override + public void openEditor(final Resource r) throws Exception { + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph g) throws DatabaseException { + Resource cr = r; + Layer0X L0X = Layer0X.getInstance(g); + if(g.isInheritedFrom(r, SysdynResource.getInstance(g).ModuleSymbol)) { + ModelingResources mr = ModelingResources.getInstance(g); + StructuralResource2 sr2 = StructuralResource2.getInstance(g); + Resource componentType = g.getSingleObject(r, mr.SymbolToComponentType); + Resource configuration = g.getSingleObject(componentType, sr2.IsDefinedBy); + cr = configuration; + } else { + Resource represents = g.getPossibleObject(r, L0X.Represents); + if(represents != null && g.isInstanceOf(represents, SysdynResource.getInstance(g).Configuration)){ + cr = represents; + } else { + cr = r; + } + } + + + final Resource diagram = ComponentUtils.getPossibleCompositeDiagram(g, cr); + if(diagram == null) return; + final ResourceArray compositePath = StructuralVariables.getCompositeArray(g, cr); + final ResourceArray variablePath = compositePath.removeFromBeginning(1); + + Resource model = StructuralVariables.getModel(g, compositePath.head()); + if(model == null) return; + final String modelURI = g.getURI(model); + + final String rvi = StructuralVariables.getRVI(g, variablePath); + if(rvi == null) return; + + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + try { + String editorId = getEditorId(); +// System.out.println("Activating diagram: model=" + modelURI + " rvi='" + rvi + "'"); + WorkbenchUtils.openEditor(editorId, new ResourceEditorInput2(editorId, diagram, modelURI, rvi)); + } catch (PartInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }); + + } + + }); + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynConnectionAdvisor.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynConnectionAdvisor.java new file mode 100644 index 00000000..e21d6abb --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynConnectionAdvisor.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.editor; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.simantics.db.ReadGraph; +import org.simantics.db.RequestProcessor; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.diagram.content.ConnectionUtil; +import org.simantics.diagram.content.ResourceTerminal; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.g2d.connection.IConnectionAdvisor; +import org.simantics.g2d.diagram.handler.Topology.Terminal; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.structural2.modelingRules.CPIgnore; +import org.simantics.structural2.modelingRules.ConnectionJudgement; +import org.simantics.structural2.modelingRules.ConnectionJudgementType; +import org.simantics.structural2.modelingRules.IConnectionPoint; +import org.simantics.structural2.modelingRules.IModelingRules; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.elements2.CloudFactory.CloudSceneGraph; + +public class SysdynConnectionAdvisor implements IConnectionAdvisor { + + IModelingRules modelingRules; + RequestProcessor processor; + + public SysdynConnectionAdvisor(IModelingRules modelingRules, + RequestProcessor processor) { + this.modelingRules = modelingRules; + this.processor = processor; + } + + IConnectionPoint getConnectionPoint(ReadGraph g, IElement element, Terminal term) throws DatabaseException { + Object obj = null; + if (element != null) + obj = ElementUtils.getObject(element); + + if (obj instanceof Resource) { + Resource elementResource = (Resource) obj; + return ConnectionUtil.toConnectionPoint(g, elementResource, term); + } + + // FIXME: this currently allows connections to begin from flags + // but is rather hackish. + if(element.getElementClass().containsClass(CloudSceneGraph.class)) { + return CPIgnore.NULL_INSTANCE; + } + + return null; + } + + @Override + public Object canBeConnected(Object backend, + final IElement element1, final Terminal term1, + final IElement element2, final Terminal term2) { + try { + if(backend == null) + backend = processor; + return ((RequestProcessor)backend).syncRequest(new Read() { + + @Override + public Object perform(ReadGraph g) throws DatabaseException { + if(element1 != null && term1 != null && element2 != null && term2 != null) { + StaticObjectAdapter soa = element1.getElementClass().getSingleItem(StaticObjectAdapter.class); + Resource startElementResource = soa.adapt(Resource.class); + soa = element2.getElementClass().getSingleItem(StaticObjectAdapter.class); + Resource endElementResource = soa.adapt(Resource.class); + + DiagramResource dr = DiagramResource.getInstance(g); + StructuralResource2 str2 = StructuralResource2.getInstance(g); + Resource terminal2 = ((ResourceTerminal) term2).getResource(); + SysdynResource sr = SysdynResource.getInstance(g); + + Resource connectionVariable = g.getPossibleObject(terminal2, dr.HasConnectionVariable); + if(!g.hasStatement(connectionVariable, str2.Binds, sr.IsHeadOfTerminal)) { + return null; + } + + if(g.isInstanceOf(endElementResource, sr.InputSymbol)) { + if(g.isInheritedFrom(startElementResource, sr.ModuleSymbol)) return null; + if(g.getObjects(endElementResource, sr.IsHeadOfTerminal).size() > 0) return null; + } + + } + + ArrayList cps = new ArrayList(); + cps.add(getConnectionPoint(g, element1, term1)); + if(element2 != null) + cps.add(getConnectionPoint(g, element2, term2)); + ConnectionJudgement judgement = + modelingRules.judgeConnection(g, cps); + + if(judgement.type == ConnectionJudgementType.LEGAL) + return judgement; + else + return null; + } + + }); + } catch(DatabaseException e) { + e.printStackTrace(); + return null; + } + } + + @Override + public boolean canBeginConnection(Object backend, + final IElement element, final Terminal term) { + try { + if(backend == null) + backend = processor; + return ((RequestProcessor)backend).syncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph g) throws DatabaseException { + return modelingRules.judgeConnection(g, + Arrays.asList(getConnectionPoint(g, element, term))) + .type != ConnectionJudgementType.ILLEGAL; + } + + }); + } catch(DatabaseException e) { + e.printStackTrace(); + return false; + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynCreationInstruction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynCreationInstruction.java new file mode 100644 index 00000000..f465a16e --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynCreationInstruction.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.editor; + +import gnu.trove.TIntIntHashMap; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.URIStringUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.mapping.constraint.instructions.TypedBracketInstruction.CreationInstruction; +import org.simantics.modeling.services.ComponentNamingUtil; +import org.simantics.modeling.services.NamingException; +import org.simantics.operation.Layer0X; +import org.simantics.project.IProject; + +public class SysdynCreationInstruction extends CreationInstruction { + + IProject project; + Resource configurationRoot; + int lComponentType; + int lConfiguration; + + public SysdynCreationInstruction(IProject project, Resource configurationRoot, int variableId, int componentType, + int configuration) { + super(variableId); + this.project = project; + this.configurationRoot = configurationRoot; + lComponentType = componentType; + lConfiguration = configuration; + } + + @Override + public Resource create(WriteGraph g, Object[] bindings) throws DatabaseException { + Resource componentType = (Resource) bindings[lComponentType]; + Resource configuration = (Resource) bindings[lConfiguration]; + + Layer0 l0 = Layer0.getInstance(g); + Layer0X L0X = Layer0X.getInstance(g); + + try { + String proposition = URIStringUtils.escape(ComponentNamingUtil.findFreshInstanceName(g, project, configurationRoot, configuration, componentType)); + Resource result = GraphUtils.create(g, + l0.HasName, proposition + ); + g.claim(result, L0X.Represents, result); + return result; + } catch (NamingException e1) { + throw new DatabaseException(e1); + } + } + + @Override + public void mapVariables(TIntIntHashMap map) { + super.mapVariables(map); + lComponentType = map.get(lComponentType); + lConfiguration = map.get(lConfiguration); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorInput.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorInput.java new file mode 100644 index 00000000..67b642d2 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorInput.java @@ -0,0 +1,419 @@ +package org.simantics.sysdyn.ui.editor; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.IPersistableElement; +import org.simantics.db.ReadGraph; +import org.simantics.db.RequestProcessor; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.ResourceArray; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.AdaptionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.service.SerialisationSupport; +import org.simantics.layer0.Layer0; +import org.simantics.operation.Layer0X; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.icons.ImageDescriptorProvider; +import org.simantics.ui.workbench.ResourceEditorInput2; +import org.simantics.ui.workbench.ResourceEditorInputFactory2; +import org.simantics.ui.workbench.TitleRequest; +import org.simantics.ui.workbench.ToolTipRequest; +import org.simantics.utils.ObjectUtils; +import org.simantics.utils.datastructures.cache.ProvisionException; +import org.simantics.utils.ui.ErrorLogger; +import org.simantics.utils.ui.workbench.StringMemento; + +/** + * TEMPORARY fix to support sysdyn + * + * @author tlteemu + * + */ +public class SysdynEditorInput extends ResourceEditorInput2 { + + private final static boolean DEBUG_UPDATE = false; + + private static final String NO_NAME = "(no name)"; + + private final String editorID; + + private final String modelURI; + + private final String rvi; + + private String randomAccessResourceId; + + private transient Resource resource; + + /** + * Gotten from the editor that needs to initialize this input. Currently + * needed for two things: {@link #exists()} and {@link #saveState(IMemento)}. + */ + private transient Session session; + + private transient boolean exists; + + private transient String name; + + private transient String tooltip; + + private transient ImageDescriptor imageDesc; + + /** Persistent memento for external data */ + private final StringMemento persistentStore = new StringMemento(); + + /** + * @param editorID + * @param r + */ + public SysdynEditorInput(String editorID, Resource r, String modelURI, String rvi) { + super(editorID, r, modelURI, rvi); + if (editorID == null) + throw new IllegalArgumentException("null editor id"); + if (r == null) + throw new IllegalArgumentException("null resource"); + + this.editorID = editorID; + this.randomAccessResourceId = ""; + this.resource = r; + this.modelURI = modelURI; + this.rvi = rvi; + this.session = SimanticsUI.getSession(); + + ensureRandomAccessId(); + setNonExistant(); + } + + /** + * @param editorID + * @param randomAccessResourceId + */ + public SysdynEditorInput(String editorID, String randomAccessResourceId, String modelURI, String rvi) { + super(editorID, randomAccessResourceId, modelURI, rvi); + if (editorID == null) + throw new IllegalArgumentException("null editor id"); + if (randomAccessResourceId == null) + throw new IllegalArgumentException("null resource id"); + + this.editorID = editorID; + this.randomAccessResourceId = randomAccessResourceId; + this.resource = null; + this.modelURI = modelURI; + this.rvi = rvi; + this.session = SimanticsUI.getSession(); + + setNonExistant(); + } + + void ensureRandomAccessId() { + if (resource == null) + throw new IllegalStateException("resource is null, input is disposed"); + // Make sure that the resource has a random access id + try { + SerialisationSupport support = session.getService(SerialisationSupport.class); + randomAccessResourceId = String.valueOf(support.getRandomAccessId(resource)); + } catch (DatabaseException e) { + throw new RuntimeException(e); + } + } + + @Override + public void init(IAdaptable adapter) throws DatabaseException { + if (resource == null && randomAccessResourceId != null) { + getSession().syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + try { + long id = Long.parseLong(randomAccessResourceId); + resource = g.getService(SerialisationSupport.class).getResource(id); + update(g); + } catch (NumberFormatException e) { + setNonExistant(); + } catch (DatabaseException e) { + setNonExistant(); + } + } + }); + } else { + if (resource != null) { + updateCaches(getSession(), true); + } + } + } + + @Override + public void dispose() { + //System.out.println("dispose resource editor input: " + name); + // NOTE: this has to be done since Eclipse will cache these IEditorInput + // instances within EditorHistoryItem's that are stored in an EditorHistory + // instance. They are held by strong reference which means that the session + // cannot be collected if it is not nulled here. + session = null; + resource = null; + } + + /** + * @return a graph instance if it exists and has not yet been disposed, + * null otherwise + */ + public Session getSession() { + // TODO: also throw an exception if the session is disposed + if (session == null) + throw new IllegalStateException("session is disposed"); + return session; + } + + @Override + public boolean exists() { + return exists; + } + + @Override + public boolean exists(ReadGraph graph) throws DatabaseException { + try { + assertExists(graph); + return true; + } catch (ResourceNotFoundException e) { + } catch (Nonexistant e) { + } + return false; + } + + @Override + public Resource getResource() { + return resource; + } + + @Override + @Deprecated + public ResourceArray getResourceArray() { + return new ResourceArray(resource); + } + + @Override + public String getModelURI() { + return modelURI; + } + + @Override + public String getRVI() { + return rvi; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getImageDescriptor() + */ + @Override + public ImageDescriptor getImageDescriptor() { + return imageDesc; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getName() + */ + @Override + public String getName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getToolTipText() + */ + @Override + public String getToolTipText() { + return tooltip; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getPersistable() + */ + @Override + public IPersistableElement getPersistable() { + // Don't allow persistability when it's not possible. + if (!isPersistable()) + return null; + return this; + } + + protected boolean isPersistable() { + if (session == null) + return false; + LifecycleSupport lc = session.peekService(LifecycleSupport.class); + if (lc == null) + return false; + if (lc.isClosed()) + return false; + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPersistableElement#getFactoryId() + */ + @Override + public String getFactoryId() { + return ResourceEditorInputFactory2.getFactoryId(); + } + + /** + * Saves the state of the given resource editor input into the given memento. + * + * @param memento the storage area for element state + * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento) + */ + @Override + public void saveState(IMemento memento) { +// List ids = randomAccessResourceId; + if (randomAccessResourceId == null) { + // Must create a new random access ID. + ensureRandomAccessId(); + } + IMemento child = memento.createChild(ResourceEditorInputFactory2.TAG_RESOURCE_ID); + child.putTextData(randomAccessResourceId); + memento.putString(ResourceEditorInputFactory2.TAG_EDITOR_ID, editorID); + memento.putString(ResourceEditorInputFactory2.TAG_MODEL_URI, modelURI); + memento.putString(ResourceEditorInputFactory2.TAG_RVI, rvi); + memento.putString(ResourceEditorInputFactory2.TAG_EXTERNAL_MEMENTO_ID, persistentStore.toString()); + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + //System.out.println("[ResourceEditorInput] getAdapter: " + adapter.getName()); + return null; + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + editorID.hashCode(); + result = prime * result + ObjectUtils.hashCode(modelURI); + result = prime * result + ObjectUtils.hashCode(rvi); + result = prime * result + ObjectUtils.hashCode(randomAccessResourceId); + return result; + } + + private void updateCaches(RequestProcessor processor, boolean sync) throws DatabaseException { + ReadRequest req = new ReadRequest() { + @Override + public void run(ReadGraph g) throws DatabaseException { + update(g); + } + }; + if (sync) { + processor.syncRequest(req); + } else { + processor.asyncRequest(req); + } + } + + static class Nonexistant extends DatabaseException { + private static final long serialVersionUID = -7964385375237203651L; + + @Override + public synchronized Throwable fillInStackTrace() { + return this; + } + } + + /* (non-Javadoc) + * @see org.simantics.ui.workbench.IResourceEditorInput#update(org.simantics.db.Graph) + */ + @Override + public void update(ReadGraph g) throws DatabaseException { + Resource r = getResource(); + if (r == null) + return; + + if (DEBUG_UPDATE) + System.out.println("update(" + this + ")"); + + try { + assertExists(g); + + name = g.syncRequest(new TitleRequest(editorID, this)); + if (name == null) + name = NO_NAME; + + tooltip = g.syncRequest(new ToolTipRequest(editorID, this)); + if (tooltip == null) + tooltip = NO_NAME; + + try { + ImageDescriptorProvider idp = g.adapt(r, ImageDescriptorProvider.class); + imageDesc = idp.get(); + } catch (AdaptionException e) { + imageDesc = ImageDescriptor.getMissingImageDescriptor(); + } catch (ProvisionException e) { + imageDesc = ImageDescriptor.getMissingImageDescriptor(); + ErrorLogger.defaultLogError(e); + } + + if (DEBUG_UPDATE) + System.out.println("update(" + this + ") finished"); + } catch (DatabaseException e) { + if (DEBUG_UPDATE) + e.printStackTrace(); + setNonExistant(); + } + } + + private void assertExists(ReadGraph g) throws DatabaseException { + Resource r = getResource(); + if (r == null) + throw new Nonexistant(); + + // 1. Check resource existence + boolean exists = g.hasStatement(r); + if (!exists) + throw new Nonexistant(); + + Layer0 L0 = Layer0.getInstance(g); + // 2. Validate modelURI + if (getModelURI() != null) { + Layer0X L0X = Layer0X.getInstance(g); + + // 3. Validate RVI + Resource model = g.getResource(modelURI); + Resource baseRealization = g.getPossibleObject(model, L0X.HasBaseRealization); + Variable modelVariable = Variables.getVariable(g, g.getURI(baseRealization)); + modelVariable.browse(g, getRVI()); + } + + // Touch the diagram title calculation within this existence + // checking request. + g.syncRequest(new TitleRequest(editorID, this)); + } + + private void setNonExistant() { + if (DEBUG_UPDATE) + System.out.println("setNonExistant(" + this + " @ " + System.identityHashCode(this) + ")"); + + exists = false; + tooltip = name = NO_NAME; + imageDesc = ImageDescriptor.getMissingImageDescriptor(); + } + + public IMemento getPersistentStore() { + return persistentStore; + } + + @Override + public String toString() { + return getClass().getSimpleName() + " [name=" + getName() + ", resource=" + resource + "]"; + } + + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java new file mode 100644 index 00000000..261d04db --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.editor; + +import org.eclipse.ui.IEditorInput; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.modeling.ui.features.EditorNamingService2; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.ui.workbench.IResourceEditorInput2; + +/** + * SysdynEditorNamingService provides names for diagram viewers. + * If the viewer shows an instantiated module, the service provides a name of type: "instanceName : instanceOf". + * Otherwise works as standard EditorNamingService2. + * + * @author TLTEEMU + * + */ +public class SysdynEditorNamingService extends EditorNamingService2 { + + @Override + public String getName(ReadGraph g, String editorId, IEditorInput in) throws DatabaseException { + if(in instanceof IResourceEditorInput2) { + IResourceEditorInput2 input = (IResourceEditorInput2) in; + + if(!input.getRVI().isEmpty()) { + Resource model = g.getPossibleResource(input.getModelURI()); + if(model != null) { + Resource configuration = g.getPossibleObject(model, SimulationResource.getInstance(g).HasConfiguration); + String configurationName = NameUtils.getSafeName(g, configuration); + String uri = input.getModelURI() + "/" + configurationName + input.getRVI(); + Variable v = Variables.getPossibleVariable(g, uri); + if(v != null) { + String name = input.getRVI(); + if(name.contains("/")) + name = name.substring(name.lastIndexOf("/") + 1); + + String instanceOf = super.getName(g, editorId, in); + return name + " : " + instanceOf; + } + } + + } + } + return super.getName(g, editorId, in); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/CreateVariablesShortcutParticipant.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/CreateVariablesShortcutParticipant.java new file mode 100644 index 00000000..03d91fe0 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/CreateVariablesShortcutParticipant.java @@ -0,0 +1,294 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.editor.participant; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.util.Set; + +import org.simantics.db.Resource; +import org.simantics.db.common.request.Queries; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.adapter.GraphToDiagramSynchronizer; +import org.simantics.diagram.elements.TextNode; +import org.simantics.diagram.query.DiagramRequests; +import org.simantics.g2d.canvas.SGDesignation; +import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency; +import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit; +import org.simantics.g2d.diagram.DiagramHints; +import org.simantics.g2d.diagram.DiagramMutator; +import org.simantics.g2d.diagram.DiagramUtils; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant; +import org.simantics.g2d.diagram.participant.ElementPainter; +import org.simantics.g2d.diagram.participant.Selection; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.participant.MouseUtil; +import org.simantics.g2d.participant.MouseUtil.MouseInfo; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.events.KeyEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent; +import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler; +import org.simantics.scenegraph.g2d.events.KeyEvent.KeyPressedEvent; +import org.simantics.scenegraph.g2d.events.KeyEvent.KeyReleasedEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent; +import org.simantics.scenegraph.g2d.nodes.ShapeNode; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.elements2.AuxiliaryFactory; +import org.simantics.sysdyn.ui.elements2.CloudFactory; +import org.simantics.sysdyn.ui.elements2.InputFactory; +import org.simantics.sysdyn.ui.elements2.StockFactory; +import org.simantics.sysdyn.ui.elements2.ValveFactory; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.Callback; +import org.simantics.utils.ui.ExceptionUtils; + +public class CreateVariablesShortcutParticipant extends AbstractDiagramParticipant { + + private GraphToDiagramSynchronizer synchronizer; + + private VariableInformation variableInformation; + + @Dependency + MouseUtil mouseUtil; + + @Dependency + Selection selection; + + @Dependency + ElementPainter diagramPainter; + + ShapeNode node; + G2DParentNode parent; + + @SGInit(designation = SGDesignation.CANVAS) + public void init(G2DParentNode parent) { + this.parent = parent; + } + + public void removeSG() { + node.remove(); + node = null; + setDirty(); + } + + void updateSG() { + + if (node == null) { + node = variableInformation.node; + } + + MouseInfo mi = mouseUtil.getMouseInfo(0); + if (mi == null) + return; + + Point2D newPos = mi.canvasPosition; + double x = newPos.getX(); + double y = newPos.getY(); + + AffineTransform origAt = node.getTransform(); + double oldX = origAt.getTranslateX(); + double oldY = origAt.getTranslateY(); + AffineTransform move = new AffineTransform(); + move.setToTranslation(x - oldX, y - oldY); + AffineTransform at2 = new AffineTransform(origAt); + at2.preConcatenate(move); + node.setTransform(at2); + setDirty(); + } + + public CreateVariablesShortcutParticipant(GraphToDiagramSynchronizer synchronizer) { + this.synchronizer = synchronizer; + } + + @EventHandler(priority = -10) + public boolean handleKeyboardEvent(KeyEvent ke) { + + KeyPressedEvent kpe; + if (ke instanceof KeyPressedEvent) { + + kpe = (KeyPressedEvent) ke; + + if (kpe.stateMask != java.awt.event.KeyEvent.SHIFT_DOWN_MASK || isEditing()) + return false; + + if (kpe.keyCode == java.awt.event.KeyEvent.VK_A) { + variableInformation = new VariableInformation( + java.awt.event.KeyEvent.VK_A, + SysdynResource.URIs.AuxiliarySymbol, + (ShapeNode)AuxiliaryFactory.AUX_STATIC_IMAGE.init(parent) + ); + } else if (kpe.keyCode == java.awt.event.KeyEvent.VK_S) { + variableInformation = new VariableInformation( + java.awt.event.KeyEvent.VK_S, + SysdynResource.URIs.StockSymbol, + (ShapeNode)StockFactory.STOCK_IMAGE.init(parent) + ); + } else if (kpe.keyCode == java.awt.event.KeyEvent.VK_C) { + variableInformation = new VariableInformation( + java.awt.event.KeyEvent.VK_C, + SysdynResource.URIs.CloudSymbol, + (ShapeNode)CloudFactory.CLOUD_IMAGE.init(parent) + ); + } else if (kpe.keyCode == java.awt.event.KeyEvent.VK_V) { + variableInformation = new VariableInformation( + java.awt.event.KeyEvent.VK_V, + SysdynResource.URIs.ValveSymbol, + (ShapeNode)ValveFactory.VALVE_STATIC_IMAGE.init(parent) + ); + } else if (kpe.keyCode == java.awt.event.KeyEvent.VK_I) { + variableInformation = new VariableInformation( + java.awt.event.KeyEvent.VK_I, + SysdynResource.URIs.InputSymbol, + (ShapeNode)InputFactory.INPUT_IMAGE.init(parent) + ); + } + + if (variableInformation != null) { + updateSG(); + return true; + } + } + + KeyReleasedEvent kre; + if (ke instanceof KeyReleasedEvent) { + kre = (KeyReleasedEvent) ke; + + if (variableInformation != null + && (kre.keyCode == variableInformation.shortcutKey || kre.keyCode == java.awt.event.KeyEvent.VK_SHIFT)) { + if (node != null) { + variableInformation = null; + removeSG(); + return true; + } + } + } + + return false; + + } + + @EventHandler(priority = -10) + public boolean handleMouse(MouseMovedEvent e) { + + if (variableInformation != null ) { + updateSG(); + } else { + if (node != null) { + removeSG(); + } + } + return false; + } + + + @EventHandler(priority = 100) + public boolean handleMouseEvent(MouseEvent me) { + + + MouseEvent.MouseClickEvent mce; + if (me instanceof MouseEvent.MouseClickEvent) { + mce = (MouseEvent.MouseClickEvent) me; + } else { + return false; + } + + if (! + ( + mce.button == MouseEvent.LEFT_BUTTON && + variableInformation != null && + mce.stateMask == MouseEvent.SHIFT_MASK + )) + { + return false; + } + + + final IDiagram d = getHint(DiagramHints.KEY_DIAGRAM); + if (d == null) + return false; + + DiagramUtils.mutateDiagram(d, new Callback() { + @Override + public void run(DiagramMutator m) { + + Resource r; + try { + r = SimanticsUI + .getSession() + .syncRequest( + Queries + .resource(variableInformation.symbolURI)); + ElementClass ec = SimanticsUI.getSession().syncRequest( + DiagramRequests.getElementClass(r, diagram)); + + IElement element = m.newElement(ec); + + // MouseUtil mutil = new MouseUtil(); + MouseInfo minfo = mouseUtil.getMouseInfo(0); + + //at least when using breakpoints this is possible + if(minfo == null) + return; + + Point2D p = minfo.canvasPosition; + //FIXME - Arto element doesn't know its size at first. Hopefully temp fix. + p.setLocation(p.getX()-5.46, p.getY()+1); + + ElementUtils.setPos(element, p); + + } catch (DatabaseException e) { + ExceptionUtils.logAndShowError(e); + } + + } + }); + + synchronizer.getCanvasContext().getContentContext().setDirty(); + + return true; + } + + private class VariableInformation { + public String symbolURI; + public ShapeNode node; + public int shortcutKey; + + public VariableInformation(int shortcutKey, String symbolURI, ShapeNode node) { + this.symbolURI = symbolURI; + this.node = node; + this.shortcutKey = shortcutKey; + } + } + + private boolean isEditing() { + int selectionId = 0; + Set ss = selection.getSelection(selectionId); + if (ss.isEmpty()) { + return false; + } + for (IElement e : ss) { + for(Object o : e.getHints().values()) { + if (o instanceof TextNode) { + TextNode tn = (TextNode) o; + if(tn.isEditMode()) + return true; + } + } + } + return false; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/PointerInteractor.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/PointerInteractor.java new file mode 100644 index 00000000..3cc4e29f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/PointerInteractor.java @@ -0,0 +1,148 @@ +package org.simantics.sysdyn.ui.editor.participant; +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ + +import java.awt.Shape; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.List; + +import org.simantics.diagram.participant.ConnectTool2; +import org.simantics.g2d.canvas.Hints; +import org.simantics.g2d.canvas.IToolMode; +import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency; +import org.simantics.g2d.canvas.impl.DependencyReflection.Reference; +import org.simantics.g2d.connection.IConnectionAdvisor; +import org.simantics.g2d.diagram.DiagramHints; +import org.simantics.g2d.diagram.handler.PickContext; +import org.simantics.g2d.diagram.participant.Selection; +import org.simantics.g2d.diagram.participant.TerminalPainter; +import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil; +import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo; +import org.simantics.g2d.element.ElementClasses; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.IElementClassProvider; +import org.simantics.g2d.participant.KeyUtil; +import org.simantics.g2d.participant.MouseUtil; +import org.simantics.g2d.participant.TransformUtil; +import org.simantics.g2d.utils.GeometryUtils; +import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler; +import org.simantics.scenegraph.g2d.events.MouseEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent; +import org.simantics.sysdyn.ui.editor.participant.SysdynElementClassProviders.ISysdynElementClassProvider; +import org.simantics.sysdyn.ui.editor.routing.DependencyRouter; +import org.simantics.sysdyn.ui.editor.routing.FlowRouter; +import org.simantics.sysdyn.ui.elements2.AuxiliaryFactory; +import org.simantics.sysdyn.ui.elements2.CloudFactory; +import org.simantics.sysdyn.ui.elements2.InputFactory; +import org.simantics.sysdyn.ui.elements2.ModuleFactory; +import org.simantics.sysdyn.ui.elements2.connections.ConnectionClasses; + +/** + * Pointer tool does the following operations with mouse: + * - Selections + * - Scale + * - Rotate + * - Translate + * - Draws connections + * + * + * Pointer tool is active only when KEY_TOOLMODE is PointerToolMode + * + * TODO Pick rectangle not a point + * + * @author Toni Kalajainen + */ +public class PointerInteractor extends org.simantics.diagram.participant.PointerInteractor2 { + + @Dependency Selection selection; + @Dependency KeyUtil keys; + @Dependency TransformUtil util; + @Dependency PickContext pickContext; + @Dependency MouseUtil mice; + @Reference TerminalPainter terminalPainter; + + public PointerInteractor(boolean clickSelect, boolean boxSelect, boolean dragElement, boolean dndDragElement, boolean connect, boolean doubleClickEdit, IElementClassProvider newConnectionClassProvider) { + super(clickSelect, boxSelect, dragElement, dndDragElement, connect, doubleClickEdit, newConnectionClassProvider); + } + + @EventHandler(priority = TOOL_PRIORITY) + public boolean handlePress(MouseButtonPressedEvent me) { + if (!connects()) return false; + + IToolMode mode = getHint(Hints.KEY_TOOL); + + if (mode != Hints.POINTERTOOL && mode != Hints.CONNECTTOOL) return false; + assertDependencies(); + Point2D curCanvasPos = util.controlToCanvas(me.controlPosition, null); + + // Pick Terminal + TerminalInfo ti = pickTerminal(me.controlPosition); + + if((me.stateMask & MouseEvent.ALT_MASK) == 0) return false; + + if(elementClassProvider != null) { + ConnectTool2 bsi = null; + if (ti != null) { + + IElement terminalElement = ti.e; + + if( me.button == MouseEvent.LEFT_BUTTON) { + if(terminalElement.getElementClass().getId().equals(CloudFactory.class.getSimpleName())) return false; + diagram.setHint(DiagramHints.ROUTE_ALGORITHM, new DependencyRouter()); + diagram.setHint(DiagramHints.KEY_USE_CONNECTION_FLAGS, false); + ISysdynElementClassProvider secp = (ISysdynElementClassProvider)elementClassProvider; + secp.put(ElementClasses.CONNECTION, elementClassProvider.get(ConnectionClasses.DEPENDENCY)); + + } else if (me.button == MouseEvent.RIGHT_BUTTON) { + String id = terminalElement.getElementClass().getId(); + if(id.equals(AuxiliaryFactory.class.getSimpleName()) + || id.equals(InputFactory.class.getSimpleName()) + || id.equals(ModuleFactory.class.getSimpleName())) return false; + diagram.setHint(DiagramHints.ROUTE_ALGORITHM, new FlowRouter(false)); + diagram.setHint(DiagramHints.KEY_USE_CONNECTION_FLAGS, true); + ISysdynElementClassProvider secp = (ISysdynElementClassProvider)elementClassProvider; + secp.put(ElementClasses.CONNECTION, elementClassProvider.get(ConnectionClasses.FLOW)); + + } + + IConnectionAdvisor advisor = diagram.getHint(DiagramHints.CONNECTION_ADVISOR); + if (advisor == null || (advisor != null && advisor.canBeginConnection(null, ti.e, ti.t))) { + bsi = new SysdynConnectTool(ti, me.mouseId, curCanvasPos); + } + } + else if (me.button == MouseEvent.RIGHT_BUTTON) { + // Start connection out of thin air, without a terminal. + diagram.setHint(DiagramHints.ROUTE_ALGORITHM, new FlowRouter(false)); + diagram.setHint(DiagramHints.KEY_USE_CONNECTION_FLAGS, true); + ISysdynElementClassProvider secp = (ISysdynElementClassProvider)elementClassProvider; + secp.put(ElementClasses.CONNECTION, elementClassProvider.get(ConnectionClasses.FLOW)); + bsi = new SysdynConnectTool(null, me.mouseId, curCanvasPos); + } + + if (bsi != null) { + getContext().add(bsi); + return true; + } + + } + return false; + } + + public List pickTerminals(Point2D controlPos) + { + Rectangle2D controlPickRect = new Rectangle2D.Double(controlPos.getX()-PointerInteractor.PICK_DIST, controlPos.getY()-PointerInteractor.PICK_DIST, PointerInteractor.PICK_DIST*2+1, PointerInteractor.PICK_DIST*2+1); + Shape canvasPickRect = GeometryUtils.transformShape(controlPickRect, util.getInverseTransform()); + List ti = TerminalUtil.pickTerminals(diagram, canvasPickRect, false, true); + return ti; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java new file mode 100644 index 00000000..a689a252 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.editor.participant; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleTypedParent; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.synchronization.ISynchronizationContext; +import org.simantics.diagram.synchronization.graph.CopyAdvisorUtil; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ComponentUtils; +import org.simantics.modeling.mapping.ComponentCopyAdvisor; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.utils.datastructures.BinaryFunction; + +public class SysdynComponentCopyAdvisor extends ComponentCopyAdvisor{ + + @Override + public Object copy(ISynchronizationContext context, WriteGraph graph, Resource source, Resource sourceContainer, Resource targetContainer) throws DatabaseException { + + BinaryFunction tester = new BinaryFunction() { + + @Override + public Boolean call(ReadGraph graph, Statement statement) { + /* + SysdynResource sr = SysdynResource.getInstance(graph); + try { + if(graph.isInstanceOf(statement.getSubject(), sr.IndependentVariable)) { + if(statement.getPredicate().equals(sr.HasExpressions) || + statement.getPredicate().equals(sr.HasArrayIndexes) ) + return false; + } + } catch (ServiceException e) { + e.printStackTrace(); + } + */ + return false; + } + + }; + + Resource copy; + + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + SimulationResource SIMU = SimulationResource.getInstance(graph); + Resource model = graph.syncRequest(new PossibleTypedParent(targetContainer, SIMU.Model)); + if(graph.isInstanceOf(source, sr2.Connection)) { + copy = CopyAdvisorUtil.copy(graph, source, tester); + } else { + copy = CopyAdvisorUtil.copy4(graph, source, model); + } + + + renameComponent(context, graph, source, copy, sourceContainer, targetContainer); + return copy; + } + + + public static String renameComponent(ISynchronizationContext context, WriteGraph graph, Resource source, + Resource copy, Resource sourceContainer, Resource targetContainer) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + String copyName = NameUtils.getSafeName(graph, copy); + Resource configurationRoot = ComponentUtils.getCompositeConfigurationRoot(graph, targetContainer); + String name = NameUtils.findFreshName(graph, copyName, configurationRoot, l0.ConsistsOf, "%s%d"); + graph.claimLiteral(copy, l0.HasName, name, Bindings.STRING); + return name; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java new file mode 100644 index 00000000..036d5bb6 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java @@ -0,0 +1,415 @@ +package org.simantics.sysdyn.ui.editor.participant; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.geom.AffineTransform; +import java.awt.geom.Path2D; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Deque; +import java.util.Iterator; +import java.util.List; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.diagram.participant.ConnectTool2; +import org.simantics.diagram.participant.ConnectionBuilder; +import org.simantics.diagram.participant.ControlPoint; +import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit; +import org.simantics.g2d.connection.IConnectionAdvisor; +import org.simantics.g2d.diagram.DiagramHints; +import org.simantics.g2d.diagram.handler.Topology.Terminal; +import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil; +import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementClasses; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.EdgeVisuals.EdgeEnd; +import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.g2d.element.impl.Element; +import org.simantics.g2d.elementclass.BranchPointClass; +import org.simantics.g2d.elementclass.FlagClass; +import org.simantics.g2d.routing.Constants; +import org.simantics.g2d.routing.IConnection; +import org.simantics.g2d.routing.IRouter2; +import org.simantics.g2d.routing.TrivialRouter2; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent; +import org.simantics.scenegraph.g2d.nodes.ShapeNode; +import org.simantics.scenegraph.g2d.snap.ISnapAdvisor; +import org.simantics.structural2.modelingRules.ConnectionJudgement; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.editor.routing.FlowRouter; +import org.simantics.sysdyn.ui.elements2.CloudFactory; +import org.simantics.sysdyn.ui.elements2.ValveFactory.ValveSceneGraph; +import org.simantics.sysdyn.ui.elements2.connections.ConnectionClasses; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.Callback; +import org.simantics.utils.ui.ExceptionUtils; + +public class SysdynConnectTool extends ConnectTool2 { + + public SysdynConnectTool(TerminalInfo startTerminal, int mouseId, + Point2D startCanvasPos) { + super(startTerminal, mouseId, startCanvasPos); + } + + + @SGInit + public void initSG(G2DParentNode parent) { + ghostNode = parent.addNode(G2DParentNode.class); + ghostNode.setZIndex(PAINT_PRIORITY); + + ShapeNode pathNode = ghostNode.getOrCreateNode("path", ShapeNode.class); + pathNode.setColor(Color.BLACK); + pathNode.setStroke(new BasicStroke(1f)); + pathNode.setScaleStroke(true); + pathNode.setZIndex(0); + + G2DParentNode points = ghostNode.getOrCreateNode("points", G2DParentNode.class); + points.setZIndex(1); + + updateSG(); + } + + + protected TerminalInfo createFlag(EdgeEnd connectionEnd) { + ElementClass flagClass = elementClassProvider.get(ElementClasses.FLAG); + IElement e = Element.spawnNew(flagClass); + + e.setHint(FlagClass.KEY_FLAG_TYPE, endToFlagType(connectionEnd)); + e.setHint(FlagClass.KEY_FLAG_MODE, FlagClass.Mode.Internal); + + TerminalInfo ti = new TerminalInfo(); + ti.e = e; + + // start: this part changed to support overlapping terminals + ArrayList terminals = new ArrayList(); + ElementUtils.getTerminals(e, terminals, false); + ti.t = terminals.get(0); + // end + + ti.posElem = TerminalUtil.getTerminalPosOnElement(e, ti.t); + ti.posDia = TerminalUtil.getTerminalPosOnDiagram(e, ti.t); + + return ti; + } + + static class Segment { + public final ControlPoint begin; + public final ControlPoint end; + public Path2D path; + + public Segment(ControlPoint begin, ControlPoint end) { + this.begin = begin; + this.end = end; + } + + @Override + public String toString() { + return "Segment[begin=" + begin + ", end=" + end + ", path=" + path + "]"; + } + } + + private List toSegments(Deque points) { + if (points.isEmpty()) + return Collections.emptyList(); + + List segments = new ArrayList(); + + Iterator it = points.iterator(); + ControlPoint prev = it.next(); + while (it.hasNext()) { + ControlPoint next = it.next(); + segments.add(new Segment(prev, next)); + prev = next; + } + + return segments; + } + + public interface SysdynConnection extends IConnection { } + + protected void updateSG() { + if (controlPoints.isEmpty()) + return; + + // Route connection segments separately + IRouter2 router = ElementUtils.getHintOrDefault(diagram, DiagramHints.ROUTE_ALGORITHM, TrivialRouter2.INSTANCE); + final List segments = toSegments(controlPoints); + //System.out.println("controlpoints: " + controlPoints); + //System.out.println("segments: " + segments); + router.route(new SysdynConnection() { + @Override + public Collection getSegments() { + return segments; + } + + @Override + public Connector getBegin(Object seg) { + return getConnector(((Segment) seg).begin); + } + + @Override + public Connector getEnd(Object seg) { + return getConnector(((Segment) seg).end); + } + + private Connector getConnector(ControlPoint cp) { + Connector c = new Connector(); + c.x = cp.getPosition().getX(); + c.y = cp.getPosition().getY(); + + c.allowedDirections = Constants.EAST_FLAG | Constants.WEST_FLAG + | Constants.NORTH_FLAG | Constants.SOUTH_FLAG; + + TerminalInfo ti = cp.getAttachedTerminal(); + if (ti != null && (ti != startFlag && ti != endFlag)) { + if(ti.e.getElementClass().containsClass(ValveSceneGraph.class)) { + Rectangle2D bounds = ElementUtils.getElementBoundsOnDiagram(ti.e).getBounds2D(); + c.parentObstacle = new Rectangle2D.Double( + bounds.getCenterX() - FlowRouter.OFFSET, + bounds.getCenterY() - FlowRouter.OFFSET, + FlowRouter.OFFSET * 2, + FlowRouter.OFFSET * 2); + } else { + c.parentObstacle = ElementUtils.getElementBoundsOnDiagram(ti.e).getBounds2D(); + } + } else if (ti != null && ti == startFlag) { + c.parentObstacle = org.simantics.scenegraph.utils.GeometryUtils.transformRectangle(AffineTransform.getTranslateInstance(c.x, c.y), + ElementUtils.getElementBoundsOnDiagram(ti.e).getBounds2D()); + } else if (isEndingInFlag() && ti.e != null) { + c.parentObstacle = org.simantics.scenegraph.utils.GeometryUtils.transformRectangle(AffineTransform.getTranslateInstance(c.x, c.y), + CloudFactory.CLOUD_IMAGE.getBounds()); + } else { + c.parentObstacle = org.simantics.scenegraph.utils.GeometryUtils.transformRectangle(AffineTransform.getTranslateInstance(c.x, c.y), + BranchPointClass.DEFAULT_IMAGE2.getBounds()); + } + + return c; + } + + @Override + public void setPath(Object seg, Path2D path) { + ((Segment) seg).path = (Path2D) path.clone(); + } + +// private int toAllowedDirections(BranchPoint.Direction direction) { +// switch (direction) { +// case Any: +// return 0xf; +// case Horizontal: +// return Constants.EAST_FLAG | Constants.WEST_FLAG; +// case Vertical: +// return Constants.NORTH_FLAG | Constants.SOUTH_FLAG; +// default: +// throw new IllegalArgumentException("unrecognized direction: " + direction); +// } +// } + }); + + // Combine the routed paths + Path2D path = new Path2D.Double(); + for (Segment seg : segments) { + //System.out.println("SEG: " + seg); + if (seg.path != null) + path.append(seg.path.getPathIterator(null), true); + } + + // Create scene graph to visualize the connection. + ShapeNode pathNode = ghostNode.getOrCreateNode("path", ShapeNode.class); + pathNode.setShape(path); + + /* + * Removed Points + */ + + setDirty(); + } + + + @Override + protected Object canConnect(final IConnectionAdvisor advisor, final IElement endElement, final Terminal endTerminal) { + final IElement se = startTerminal != null ? startTerminal.e : startFlag.e; + final Terminal st = startTerminal != null ? startTerminal.t : null; + + if(se.equals(endElement)) return null; + if(Boolean.FALSE.equals(diagram.getHint(DiagramHints.KEY_USE_CONNECTION_FLAGS)) && endElement == null) { + return null; + } + + if(endElement == null && endTerminal == null) + return advisor.canBeConnected(null, se, st, endElement, endTerminal); + + try { + return SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Object perform(ReadGraph g) throws DatabaseException { + + // Checking if connection type can be connected to the intended endElement + SysdynResource sr = SysdynResource.getInstance(g); + StaticObjectAdapter soa = endElement.getElementClass().getSingleItem(StaticObjectAdapter.class); + Resource end = soa.adapt(Resource.class); + ElementClass dependency = elementClassProvider.get(ConnectionClasses.DEPENDENCY); + ElementClass flow = elementClassProvider.get(ConnectionClasses.FLOW); + ElementClass currentConnection = elementClassProvider.get(ElementClasses.CONNECTION); + if(currentConnection.equals(dependency)) { + if(end.equals(sr.CloudSymbol)) return null; + soa = se.getElementClass().getSingleItem(StaticObjectAdapter.class); + Resource start = soa.adapt(Resource.class); + if(g.isInheritedFrom(start, sr.ModuleSymbol) && !end.equals(sr.InputSymbol)) return null; + if(end.equals(sr.StockSymbol)) return null; + } else if (currentConnection.equals(flow)) { + if(!(end.equals(sr.StockSymbol) || end.equals(sr.ValveSymbol) || end.equals(sr.CloudSymbol))) return null; + } else { + return null; + } + + + if (advisor == null) + return Boolean.TRUE; + return advisor.canBeConnected(g, se, st, endElement, endTerminal); + } + + }); + } catch(DatabaseException e) { + e.printStackTrace(); + return null; + } + + } + + protected boolean processMouseMove(MouseMovedEvent me) { + mouseHasMoved = true; + + Point2D mouseControlPos = me.controlPosition; + Point2D mouseCanvasPos = util.controlToCanvas(mouseControlPos, new Point2D.Double()); + + ISnapAdvisor snapAdvisor = getHint(DiagramHints.SNAP_ADVISOR); + if (snapAdvisor != null) + snapAdvisor.snap(mouseCanvasPos); + + // Record last snapped canvas position of mouse. + this.lastMouseCanvasPos.setLocation(mouseCanvasPos); + + if (isEndingInFlag()) { + endFlagNode.setTransform(AffineTransform.getTranslateInstance(mouseCanvasPos.getX(), mouseCanvasPos.getY())); + } + + List tiList = ((org.simantics.sysdyn.ui.editor.participant.PointerInteractor)pi).pickTerminals(me.controlPosition); + TerminalInfo ti = null; + + IConnectionAdvisor advisor = diagram.getHint(DiagramHints.CONNECTION_ADVISOR); + for(TerminalInfo info : tiList) { + if(advisor == null || info.e == null || info.t == null) + continue; + Object canConnect = canConnect(advisor, info.e, info.t); + if (canConnect != null) { + ti = info; + break; + } + } + + if (ti != null && !isStartTerminal(ti.e, ti.t)) { + Object canConnect = canConnect(ti.e, ti.t); + if (canConnect != null) { + connectionJudgment = (ConnectionJudgement) canConnect; + + if (!isEndingInFlag() || !TerminalUtil.isSameTerminal(ti, endTerminal)) { + controlPoints.getLast() + .setPosition(ti.posDia) + .setAttachedToTerminal(ti); + + endTerminal = ti; + } + + // Make sure that we are ending with a flag if ALT is pressed + // and no end terminal is defined. + endWithoutTerminal(lastMouseCanvasPos, shouldEndWithFlag(me)); + + updateSG(); + return false; + } + } + + connectionJudgment = null; + if (isEndTerminalDefined()) { + // CASE: Mouse was previously on top of a valid terminal to end + // the connection. Now the mouse has been moved where there is + // no longer a terminal to connect to. + // + // => Disconnect the last edge segment from the previous + // terminal, mark endElement/endTerminal non-existent + // and connect the disconnected edge to a new branch point. + + controlPoints.getLast() + .setPosition(mouseCanvasPos) + .setDirection(calculateCurrentBranchPointDirection()) + .setAttachedToTerminal(null); + + endTerminal = null; + } else { + // CASE: Mouse was not previously on top of a valid ending + // element terminal. + // + // => Move and re-orient last branch point. + + controlPoints.getLast() + .setPosition(mouseCanvasPos) + .setDirection(calculateCurrentBranchPointDirection()); + } + + // Make sure that we are ending with a flag if ALT is pressed and no end + // terminal is defined. + endWithoutTerminal(lastMouseCanvasPos, shouldEndWithFlag(me)); + + updateSG(); + + return false; + } + + Point2D mousePosition; + + protected boolean processMouseButtonPress(MouseButtonPressedEvent e) { + MouseButtonEvent me = e; + mousePosition = me.controlPosition; + return super.processMouseButtonPress(e); + } + + @Override + protected void createConnection() { + + if(this.connectionJudgment == null) return; + + final ConnectionJudgement judgment = this.connectionJudgment; + // ConnectionBuilder changed to SysdynconnectionBuilder to support overlapping terminals and valve creation + final ConnectionBuilder builder = new SysdynConnectionBuilder(this.diagram); + final Deque controlPoints = this.controlPoints; + final TerminalInfo startTerminal = this.startTerminal; + final TerminalInfo endTerminal = this.endTerminal; + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + builder.create(graph, judgment, controlPoints, startTerminal, endTerminal); + } + }, new Callback() { + @Override + public void run(DatabaseException parameter) { + if (parameter != null) + ExceptionUtils.logAndShowError(parameter); + } + }); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectionBuilder.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectionBuilder.java new file mode 100644 index 00000000..5d48050f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectionBuilder.java @@ -0,0 +1,235 @@ +package org.simantics.sysdyn.ui.editor.participant; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.Deque; +import java.util.Iterator; +import java.util.List; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.content.ConnectionUtil; +import org.simantics.diagram.participant.ConnectionBuilder; +import org.simantics.diagram.participant.ControlPoint; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.diagram.ui.DiagramModelHints; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.diagram.handler.Topology.Terminal; +import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil; +import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementClasses; +import org.simantics.g2d.element.ElementHints; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.EdgeVisuals.EdgeEnd; +import org.simantics.g2d.element.impl.Element; +import org.simantics.g2d.elementclass.FlagClass; +import org.simantics.layer0.Layer0; +import org.simantics.structural2.modelingRules.ConnectionJudgement; +import org.simantics.structural2.modelingRules.IModelingRules; +import org.simantics.sysdyn.ui.elements2.SysdynElementClasses; +import org.simantics.sysdyn.ui.elements2.ValveFactory; +import org.simantics.sysdyn.ui.elements2.connections.ConnectionClasses; +import org.simantics.utils.datastructures.Pair; + +public class SysdynConnectionBuilder extends ConnectionBuilder{ + + public SysdynConnectionBuilder(IDiagram diagram) { + super(diagram); + } + + /** + * @param graph + * @param judgment + * @param controlPoints + * @param startTerminal + * @param endTerminal + * @throws DatabaseException + */ + public void create(WriteGraph graph, ConnectionJudgement judgment, Deque controlPoints, + TerminalInfo startTerminal, TerminalInfo endTerminal) throws DatabaseException { + // If needs a valve, we will create two separate connections + if(needsValve(startTerminal, endTerminal)) { + createValveAndConnections(graph, judgment, controlPoints, startTerminal, endTerminal); + } + // If no need for valve, just call createConnection with false on createValve parameter + else { + createConnection(graph, judgment, controlPoints, startTerminal, endTerminal, false); + } + } + /** + * @param graph + * @param judgment + * @param controlPoints + * @param startTerminal + * @param endTerminal + * @throws DatabaseException + */ + public TerminalInfo createConnection(WriteGraph graph, ConnectionJudgement judgment, Deque controlPoints, + TerminalInfo startTerminal, TerminalInfo endTerminal, boolean createValve) throws DatabaseException { + TerminalInfo newValve = null; + + this.cu = new ConnectionUtil(graph); + + // 1. Get diagram connection to construct. + Resource connection = getOrCreateConnection(graph, startTerminal, endTerminal); + + // 2. Add branch points + List> bps = createBranchPoints(graph, connection, controlPoints); + + // 3. Create edges between branch points. + Resource firstBranchPoint = null; + Resource lastBranchPoint = null; + if (!bps.isEmpty()) { + Iterator> it = bps.iterator(); + Pair prev = it.next(); + firstBranchPoint = prev.second; + while (it.hasNext()) { + Pair next = it.next(); + cu.connect(prev.second, next.second); + prev = next; + } + lastBranchPoint = prev.second; + } + + // 4. Connect start/end terminals if those exist. + // If first/lastBranchPoint != null, connect to those. + // Otherwise connect the start/end terminals together. + Resource startConnector = null; + Resource endConnector = null; + IElement startFlag = null; + IElement endFlag = null; + + if (startTerminal != null) { + startConnector = createConnectorForNode(graph, connection, startTerminal, EdgeEnd.Begin, judgment); + } else if (createFlags) { + startFlag = createFlag(graph, connection, EdgeEnd.Begin, controlPoints.getFirst(), FlagClass.Type.In, ""); + ArrayList terminals = new ArrayList(); + ElementUtils.getTerminals(startFlag, terminals, false); + Terminal st = terminals.get(1); + startConnector = createConnectorForNode(graph, connection, (Resource) ElementUtils.getObject(startFlag), + st, EdgeEnd.Begin, judgment); + } + + if (endTerminal != null) { + endConnector = createConnectorForNode(graph, connection, endTerminal, EdgeEnd.End, judgment); + } else if (createFlags) { + if(createValve) + endFlag = createValveElement(graph, connection, EdgeEnd.End, controlPoints.getLast()); + else + endFlag = createFlag(graph, connection, EdgeEnd.End, controlPoints.getLast(), FlagClass.Type.Out, ""); + ArrayList terminals = new ArrayList(); + ElementUtils.getTerminals(endFlag, terminals, false); + Terminal et = terminals.get(0); + endConnector = createConnectorForNode(graph, connection, (Resource) ElementUtils.getObject(endFlag), + et, EdgeEnd.End, judgment); + + if(createValve) { + newValve = new TerminalInfo(); + newValve.e = endFlag; + newValve.t = terminals.get(1); + newValve.posElem = TerminalUtil.getTerminalPosOnElement(endFlag, newValve.t); + newValve.posDia = TerminalUtil.getTerminalPosOnDiagram(endFlag, newValve.t); + } + } + + if (firstBranchPoint == null || lastBranchPoint == null) { + cu.connect(startConnector, endConnector); + } else { + cu.connect(startConnector, firstBranchPoint); + cu.connect(lastBranchPoint, endConnector); + } + + // 5. Finally, set connection type according to modelling rules + IModelingRules modelingRules = diagram.getHint(DiagramModelHints.KEY_MODELING_RULES); + if (judgment.connectionType != null && modelingRules != null) { + modelingRules.setConnectionType(graph, connection, judgment.connectionType); + } + + this.cu = null; + return newValve; + } + + + /** + * @param graph + * @param connection + * @param end + * @param cp + * @param type + * @return an element describing the new created flag resource + * @throws DatabaseException + */ + public IElement createValveElement(WriteGraph graph, Resource connection, EdgeEnd end, ControlPoint cp) throws DatabaseException { + ElementClass valveClass = elementClassProvider.get(SysdynElementClasses.VALVE); + IElement valveElement = Element.spawnNew(valveClass); + Resource valveClassResource = ElementUtils.checkedAdapt(valveClass, Resource.class); + + Layer0 L0 = Layer0.getInstance(graph); + G2DResource G2D = G2DResource.getInstance(graph); + DiagramResource DIA = DiagramResource.getInstance(graph); + + Resource valve = graph.newResource(); + graph.claim(valve, L0.InstanceOf, null, valveClassResource); + valveElement.setHint(ElementHints.KEY_OBJECT, valve); + + OrderedSetUtils.add(graph, diagramResource, valve); + + AffineTransform at = AffineTransform.getTranslateInstance(cp.getPosition().getX(), cp.getPosition().getY()); + valveElement.setHint(ElementHints.KEY_TRANSFORM, at); + double[] matrix = new double[6]; + at.getMatrix(matrix); + graph.claimLiteral(valve, DIA.HasTransform, G2D.Transform, matrix); + + // Put the element on all the currently active layers if possible. + if (layerManager != null) { + layerManager.removeFromAllLayers(graph, valve); + layerManager.putElementOnVisibleLayers(diagram, graph, valve); + } + + return valveElement; + } + + private boolean needsValve(TerminalInfo startTerminal, TerminalInfo endTerminal) { + if (!elementClassProvider.get(ElementClasses.CONNECTION) + .equals(elementClassProvider.get(ConnectionClasses.FLOW))) + return false; + if(startTerminal != null && startTerminal.e != null && startTerminal.e.getElementClass().getId().equals(ValveFactory.class.getSimpleName())) { + return false; + } else if(endTerminal != null && endTerminal.e != null && endTerminal.e.getElementClass().getId().equals(ValveFactory.class.getSimpleName())) { + return false; + } + return true; + } + + private void createValveAndConnections(WriteGraph graph, ConnectionJudgement judgment, Deque controlPoints, + TerminalInfo startTerminal, TerminalInfo endTerminal) throws DatabaseException { + + ControlPoint cpfirst = controlPoints.getFirst(); + ControlPoint cplast = controlPoints.getLast(); + + // Set the position in the middle of the route + double startX = cpfirst.getPosition().getX(); + double startY = cpfirst.getPosition().getY(); + double x = cplast.getPosition().getX(); + double y = cplast.getPosition().getY(); + Point2D pos = new Point2D.Double(startX - (startX - x) / 2, startY - (startY - y) / 2); + + // Replace the last control point with the control point in the middle + controlPoints.getLast().setPosition(pos); + + // Create a connection to a new valve and get the new valve + TerminalInfo newValve = createConnection(graph, judgment, controlPoints, startTerminal, null, true); + + // Replace the last control point with the original control point + controlPoints.getLast().setPosition(x, y); + + // Create a connection starting from the new valve + createConnection(graph, judgment, controlPoints, newValve, endTerminal, false); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynElementClassProviders.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynElementClassProviders.java new file mode 100644 index 00000000..93c5675c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynElementClassProviders.java @@ -0,0 +1,69 @@ +package org.simantics.sysdyn.ui.editor.participant; + +import java.util.HashMap; +import java.util.Map; + +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementClassProviders; +import org.simantics.g2d.element.IElementClassProvider; + +public class SysdynElementClassProviders extends ElementClassProviders { + + /** + * Create an element class provider that based on the specified map. The + * provider will directly access the map with the received keys. The + * argument map will be copied. + * + * @param map the map to use for element class provision + * @return null if there is no provider for the specified key + */ + public static IElementClassProvider mappedProvider(Map map) { + // Copy the map as a safety measure + final Map copy = new HashMap(map); + return new ISysdynElementClassProvider() { + @Override + public ElementClass get(Object key) { + return copy.get(key); + } + + @Override + public void put(Object key, ElementClass value) { + copy.put(key, value); + } + + }; + } + + /** + * Does the same as {@link #mappedProvider(Map)}, the map is simply provided + * differently. The specified array must contain + * [key, ElementClass, key, ElementClass, ...]. + * + * @param map the map to use for element class provision + * @return null if there is no provider for the specified key + */ + public static IElementClassProvider mappedProvider(Object... keyClassPairs) { + if (keyClassPairs.length % 2 != 0) + throw new IllegalArgumentException(); + Map map = new HashMap(); + int n = keyClassPairs.length / 2; + for (int i = 0; i < n; ++i) { + Object key = keyClassPairs[i * 2]; + Object elementClass = keyClassPairs[i*2+1]; + if (!(elementClass instanceof ElementClass)) + throw new IllegalArgumentException("not an ElementClass instance: " + elementClass); + map.put(key, (ElementClass) elementClass); + } + return mappedProvider(map); + } + + + public interface ISysdynElementClassProvider extends IElementClassProvider { + + /** + * Update a value in an IElementClassProvider + */ + void put(Object key, ElementClass value); + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynPopulateElementDropParticipant.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynPopulateElementDropParticipant.java new file mode 100644 index 00000000..f15307c9 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynPopulateElementDropParticipant.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.editor.participant; + +import java.awt.dnd.DropTargetDragEvent; +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.diagram.adapter.GraphToDiagramSynchronizer; +import org.simantics.diagram.ui.DiagramModelHints; +import org.simantics.g2d.dnd.ElementClassDragItem; +import org.simantics.g2d.dnd.IDnDContext; +import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.modeling.ModelingResources; +import org.simantics.modeling.ui.diagramEditor.PopulateElementDropParticipant; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; + +public class SysdynPopulateElementDropParticipant extends PopulateElementDropParticipant { + + public SysdynPopulateElementDropParticipant(GraphToDiagramSynchronizer synchronizer) { + super(synchronizer); + } + + @Override + public void dragEnter(DropTargetDragEvent dtde, IDnDContext dp) { + super.dragEnter(dtde, dp); + + // Check that user is not trying to populate a module to itself. + // This doesn't prevent infinite recursion if there is one module between two exactly the same modules. + // e.g. WorkModule -> WokrforceModule -> WorkModule creates an infinite recursion + final Collection items = dp.getItemsByClass(ElementClassDragItem.class); + if(!items.isEmpty()) { + Collection unvalidModules = null; + try { + unvalidModules = synchronizer.getSession().syncRequest(new Read>() { + + @Override + public Collection perform(ReadGraph graph) + throws DatabaseException { + Collection unvalidModules = new ArrayList(); + for(ElementClassDragItem item : items) { + StaticObjectAdapter soa = item.getElementClass().getSingleItem(StaticObjectAdapter.class); + Resource type = soa.adapt(Resource.class); + + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.isInheritedFrom(type, sr.ModuleSymbol)) { + Resource module = graph.getSingleObject(type, ModelingResources.getInstance(graph).SymbolToComponentType); + Resource configuration = graph.getSingleObject(module, StructuralResource2.getInstance(graph).IsDefinedBy); + Resource dia = graph.getSingleObject(configuration, ModelingResources.getInstance(graph).CompositeToDiagram); + Resource editorDia = diagram.getHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE); + if(dia.equals(editorDia)) + unvalidModules.add(item); + } + } + return unvalidModules; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + if(!unvalidModules.isEmpty()) { + for(ElementClassDragItem item : unvalidModules) { + dp.remove(item); + } + } + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/DependencyRouter.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/DependencyRouter.java new file mode 100644 index 00000000..e7d42fc5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/DependencyRouter.java @@ -0,0 +1,152 @@ +package org.simantics.sysdyn.ui.editor.routing; + +import java.awt.geom.Arc2D; +import java.awt.geom.Path2D; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +import org.simantics.g2d.routing.IConnection; +import org.simantics.g2d.routing.IConnection.Connector; +import org.simantics.g2d.routing.IRouter2; +import org.simantics.sysdyn.ui.elements2.connections.Arcs; +import org.simantics.utils.datastructures.Pair; + +public class DependencyRouter implements IRouter2 { + + @Override + public void route(IConnection connection) { + if(connection.getSegments().isEmpty()) + return; + Object seg = connection.getSegments().iterator().next(); + Connector begin = connection.getBegin(seg); + Connector end = connection.getEnd(seg); + + Pair shapes = new Pair(new Arc2D.Double(), new Path2D.Double()); + createArrowShape(shapes, + begin.parentObstacle, + end.parentObstacle, + 0.1); + + Path2D path = new Path2D.Double(); + path.append(shapes.first, false); + path.append(shapes.second, false); + connection.setPath(seg, path); + } + + + /* + * Total length of the arrow is ARROW_LENGTH1 + ARROW_LENGTH2 + */ + public static double ARROW_LENGTH1 = 0.2; + public static double ARROW_LENGTH2 = 1.0; + public static double ARROW_WIDTH = 0.5; + + + private static Path2D createArrow(Path2D shape, double x, double y, double dx, double dy) { + if(shape == null) + shape = new Path2D.Double(); + else + shape.reset(); + + shape.moveTo(x+ARROW_LENGTH1*dx, y+ARROW_LENGTH1*dy); + x -= ARROW_LENGTH2*dx; + y -= ARROW_LENGTH2*dy; + shape.lineTo(x-ARROW_WIDTH*dy, y+ARROW_WIDTH*dx); + shape.lineTo(x+ARROW_WIDTH*dy, y-ARROW_WIDTH*dx); + shape.closePath(); + return shape; + } + + public static Arc2D createArc(Arc2D arc, Rectangle2D tail, Rectangle2D head, double angle) { + double x0 = tail.getCenterX(); + double y0 = tail.getCenterY(); + double x1 = head.getCenterX(); + double y1 = head.getCenterY(); + +// System.out.println("createArrowShape " + x0 + " " + y0 + " " + x1 + " " + y1); + + double offset = + Math.abs(angle) < 1.0e-6 + ? 1e3 * Math.signum(angle) + : Math.tan(Math.PI*0.5-angle)*0.5; + + double cx = 0.5*(x0+x1) + offset * (y1-y0); + double cy = 0.5*(y0+y1) + offset * (x0-x1); + double dx0 = x0 - cx; + double dy0 = y0 - cy; + double dx1 = x1 - cx; + double dy1 = y1 - cy; + + double r = Math.sqrt(dx0*dx0 + dy0*dy0); + +// Rectangle2D bounds = new Rectangle2D.Double(); +// tail.getBounds(bounds); + double angle0 = Arcs.nextIntersectingAngle(cx, cy, r, + Math.atan2(-dy0, dx0), tail, angle < 0.0); +// head.getBounds(bounds); + double angle1 = Arcs.nextIntersectingAngle(cx, cy, r, + Math.atan2(-dy1, dx1), head, angle > 0.0); + double extent = angle1-angle0; + //double arcAngle = angle0; + if(angle < 0.0) { + double temp = angle0; + angle0 = angle1; + angle1 = temp; + extent = -extent; + } + if(extent < 0) + extent += Math.PI*2.0; + else if(extent >= 360.0) + extent -= Math.PI*2.0; + if(arc == null) + arc = new Arc2D.Double(); + arc.setArc(cx-r, cy-r, 2*r, 2*r, + Math.toDegrees(angle0), + Math.toDegrees(extent), + Arc2D.OPEN); +// + return arc; + } + + public static Point2D computeCenter(Rectangle2D tail, Rectangle2D head, double angle) { + + double x0 = tail.getCenterX(); + double y0 = tail.getCenterY(); + double x1 = head.getCenterX(); + double y1 = head.getCenterY(); + +// System.out.println("createArrowShape " + x0 + " " + y0 + " " + x1 + " " + y1); + + double offset = + Math.abs(angle) < 1.0e-6 + ? 1e3 * Math.signum(angle) + : Math.tan(Math.PI*0.5-angle)*0.5; + + double cx = 0.5*(x0+x1) + offset * (y1-y0); + double cy = 0.5*(y0+y1) + offset * (x0-x1); + + return new Point2D.Double(cx, cy); + + } + + public static Pair createArrowShape(Pair shapes, Rectangle2D tail, Rectangle2D head, double angle) { + if(shapes == null || shapes.first == null || shapes.second == null) { + shapes = new Pair(new Arc2D.Double(), new Path2D.Double()); + } + + createArc(shapes.first, tail, head, angle); + + double angle0 = Math.toRadians(shapes.first.getAngleStart()); + double angle1 = Math.toRadians(shapes.first.getAngleStart() + shapes.first.getAngleExtent()); + double x = Math.cos(angle > 0.0 ? angle1 : angle0); + double y = -Math.sin(angle > 0.0 ? angle1 : angle0); + double r = shapes.first.getHeight() / 2; + + createArrow(shapes.second, shapes.first.getCenterX() + r*x, shapes.first.getCenterY() + r*y, + angle < 0.0 ? -y : y, + angle > 0.0 ? -x : x); + + return shapes; + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/FlowRouter.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/FlowRouter.java new file mode 100644 index 00000000..7d33be3d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/FlowRouter.java @@ -0,0 +1,139 @@ +package org.simantics.sysdyn.ui.editor.routing; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Path2D; +import java.awt.geom.PathIterator; +import java.awt.geom.Rectangle2D; +import java.util.Collection; + +import org.simantics.g2d.routing.Constants; +import org.simantics.g2d.routing.IConnection; +import org.simantics.g2d.routing.IConnection.Connector; +import org.simantics.g2d.routing.IRouter2; +import org.simantics.sysdyn.ui.elements2.connections.Flows; + +public class FlowRouter implements IRouter2{ + + SysdynLocalRouter localRouter; + + public static final float OFFSET = 1.0f; + + public FlowRouter() { + this(false); + } + + public FlowRouter(boolean roundCorners) { + this.localRouter = new SysdynLocalRouter(); + } + + private Path2D route(double beginX, double beginY, int sDir, Rectangle2D beginObstacle, + double endX, double endY, int tDir, Rectangle2D endObstacle) { + localRouter.sx = beginX; + localRouter.sy = beginY; + if(beginObstacle == null) { + localRouter.aMinX = beginX; + localRouter.aMinY = beginY; + localRouter.aMaxX = beginX; + localRouter.aMaxY = beginY; + } + else { + localRouter.aMinX = beginObstacle.getMinX(); + localRouter.aMinY = beginObstacle.getMinY(); + localRouter.aMaxX = beginObstacle.getMaxX(); + localRouter.aMaxY = beginObstacle.getMaxY(); + } + localRouter.sourceDirection = sDir; + + localRouter.tx = endX; + localRouter.ty = endY; + if(endObstacle == null) { + localRouter.bMinX = endX; + localRouter.bMinY = endY; + localRouter.bMaxX = endX; + localRouter.bMaxY = endY; + } + else { + localRouter.bMinX = endObstacle.getMinX(); + localRouter.bMinY = endObstacle.getMinY(); + localRouter.bMaxX = endObstacle.getMaxX(); + localRouter.bMaxY = endObstacle.getMaxY(); + } + localRouter.targetDirection = tDir; + + // adjust flows to start and stop within the obstacle + if(sDir == Constants.EAST || sDir == Constants.WEST) { + localRouter.aMinY = localRouter.aMinY + OFFSET; + localRouter.aMaxY = localRouter.aMaxY - OFFSET; + } + if(tDir == Constants.EAST || tDir == Constants.WEST) { + localRouter.bMinY = localRouter.bMinY + OFFSET; + localRouter.bMaxY = localRouter.bMaxY - OFFSET; + } + if(sDir == Constants.SOUTH || sDir == Constants.NORTH) { + localRouter.aMinX = localRouter.aMinX + OFFSET; + localRouter.aMaxX = localRouter.aMaxX - OFFSET; + } + if(tDir == Constants.SOUTH || tDir == Constants.NORTH) { + localRouter.bMinX = localRouter.bMinX + OFFSET; + localRouter.bMaxX = localRouter.bMaxX - OFFSET; + } + + localRouter.route(); + + Path2D completePath = new Path2D.Double(); + + completePath = Flows.createOffsetPath(localRouter.path, OFFSET); + completePath.append(Flows.createOffsetPath(localRouter.path, -OFFSET), false); + + return completePath; + } + + @Override + public void route(IConnection connection) { + Collection segments = connection.getSegments(); + if(segments.size() == 1) + for(Object seg : segments) { + Connector begin = connection.getBegin(seg); + Connector end = connection.getEnd(seg); + + double bestLength = Double.POSITIVE_INFINITY; + Path2D bestPath = null; + + for(int sDir : Constants.POSSIBLE_DIRECTIONS[begin.allowedDirections]) + for(int tDir : Constants.POSSIBLE_DIRECTIONS[end.allowedDirections]) { + Path2D path = route(begin.x, begin.y, sDir, begin.parentObstacle, + end.x, end.y, tDir, end.parentObstacle); + + double length = pathCost(path); + if(length < bestLength) { + bestLength = length; + bestPath = path; + } + } + + if(bestPath != null) + connection.setPath(seg, bestPath); + } + } + + + final static AffineTransform IDENTITY = new AffineTransform(); + + static double pathCost(Path2D path) { + double length = 0.0; + PathIterator it = path.getPathIterator(IDENTITY); + double[] temp = new double[6]; + double x=0.0, y=0.0; + double bendCount = 0.0; + while(!it.isDone()) { + bendCount += 1.0; + if(it.currentSegment(temp) != PathIterator.SEG_MOVETO) + length += Math.abs(x - temp[0] + y - temp[1]); + x = temp[0]; + y = temp[1]; + it.next(); + } + return bendCount - 1.0 / length; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/SysdynLocalRouter.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/SysdynLocalRouter.java new file mode 100644 index 00000000..253e6a17 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/SysdynLocalRouter.java @@ -0,0 +1,477 @@ +package org.simantics.sysdyn.ui.editor.routing; + +import java.awt.geom.Path2D; +import java.util.ArrayList; + +import org.simantics.g2d.routing.Constants; + +public class SysdynLocalRouter { + + static final double OFFSET = 1.0; + + double aMinX; + double aMinY; + double aMaxX; + double aMaxY; + + double bMinX; + double bMinY; + double bMaxX; + double bMaxY; + + double sx; + double sy; + + double tx; + double ty; + + int sourceDirection; + int targetDirection; + + ArrayList points; + Path2D path; + + public SysdynLocalRouter() { + } + + /** + * Case where both source and target connection directions are to east. + */ + void routeEast() { + if (bMinX >= aMaxX || tx >= 0 && !(bMaxY < aMinY || aMaxY < bMinY)) { + if (ty != 0.0) { + /* ______ ______ + * | | | | + * | |----\ | | + * | | \--->| | + * |______| |______| + */ + double mx = 0.5 * (aMaxX + bMinX); + point(mx, 0.0); + point(mx, ty); + } else + ; // Just a straight line + } else { + double x0 = bMinX; + double x1 = aMaxX; + double my; + /* ______ + * | | + * | | + * /->| | + * | |______| + * | + * \-------------\ + * ______ | + * | | | + * | |-/ + * | | + * |______| + * + * If the elements are separated in Y-direction, + * route between the elements (this is always the shortest path). + */ + if (bMaxY < aMinY) + my = 0.5 * (aMinY + bMaxY); + else if (aMaxY < bMinY) + my = 0.5 * (aMaxY + bMinY); + else { + /* + * /------------------------\ + * | ______ ______ | + * | | | | | | + * | | | | |--+ + * +->| | | | | + * | |______| |______| | + * | | + * \------------------------/ + * + * or + * + * /-----------\ + * | ______ | + * | | | | + * | | | | + * /--+->| | | + * | ___|______| | + * | | | | + * | | |-+---/ + * | | | | + * | |______| | + * | | + * \----------/ + * + * We may choose either lower or upper path. + */ + double upperX0 = bMinX; + double upperX1 = aMaxX; + double lowerX0 = bMinX; + double lowerX1 = aMaxX; + double upperY = Math.min(aMinY, bMinY); + double lowerY = Math.max(aMaxY, bMaxY); + + if (aMinX < bMinX) { + if (ty < 0.5 * (aMinY + aMaxY)) + lowerX0 = aMinX; + else + upperX0 = aMinX; + } + + if (bMaxX > aMaxX) { + if (ty < 0.5 * (aMinY + aMaxY)) + upperX1 = bMaxX; + else + lowerX1 = bMaxX; + } + + double upperLength = upperX1 - upperY + (upperX1 - upperX0) + + (ty - upperY) + (tx - upperX0); + double lowerLength = lowerX1 + lowerY + (lowerX1 - lowerX0) + + (lowerY - ty) + (tx - lowerX0); + + if (upperLength < lowerLength) { + x0 = upperX0; + x1 = upperX1; + my = upperY; + } else { + x0 = lowerX0; + x1 = lowerX1; + my = lowerY; + } + } + point(x1, 0.0); + point(x1, my); + point(x0, my); + point(x0, ty); + } + } + + void routeWest() { + if (tx >= 0.0) { + double fx = Math.max(aMaxX, bMaxX); + double mx = 0.5 * (aMaxX + bMinX); + if (bMinY >= 0.0 || bMaxY <= 0.0 || mx < 0.0) { + /* ______ + * | | + * | | + * | |<-\ + * ______ |______| | + * | | | + * | |-------------------/ + * | | + * |______| + */ + point(fx, 0.0); + } + else { + /* /-------------\ + * | ______ | + * | | | | + * ______ | | | | + * | | | | |<-+ + * | |----+ |______| | + * | | | | + * |______| \-------------/ + * + * We may choose either upper or lower path + * by the path length. + */ + double my = Math.abs(bMinY) + Math.abs(ty - bMinY) < Math + .abs(bMaxY) + Math.abs(ty - bMaxY) ? bMinY : bMaxY; + point(mx, 0.0); + point(mx, my); + point(fx, my); + } + point(fx, ty); + } else { + double fx = Math.max(aMaxX, bMaxX); + double mx = 0.5 * (aMinX + bMaxX); + point(fx, 0.0); + if (ty <= aMinY || ty >= aMaxY + || (tx >= mx && ty >= aMinY && ty <= aMaxY)) { + /* ______ + * | | + * | | + * | |--\ + * ______ |______| | + * | | | + * | |<------------------/ + * | | + * |______| + */ + point(fx, ty); + } + else { + /* /-------------\ + * | ______ | + * | | | | + * ______ | | | | + * | | | | |--+ + * | |<---+ |______| | + * | | | | + * |______| \-------------/ + * + * We may choose either upper or lower path + * by the path length. + */ + double my = Math.abs(aMinY) + Math.abs(ty - aMinY) < Math + .abs(aMaxY) + Math.abs(ty - aMaxY) ? aMinY : aMaxY; + point(fx, my); + point(mx, my); + point(mx, ty); + } + } + } + + void routeSouth() { + if (tx > 0.0 && (bMinY >= 0.0 || (ty > 0.0 && bMinX <= aMaxX))) + point(tx, 0.0); + else if (bMinX > aMaxX) { + double mx = 0.5 * (aMaxX + bMinX); + point(mx, 0.0); + point(mx, bMinY); + point(tx, bMinY); + } else { + double fx = aMaxX; + double my = 0.5 * (aMaxY + bMinY); + if (my < aMaxY && (tx < aMinX || ty < aMinY)) { + my = Math.min(aMinY, bMinY); + if (bMaxX > aMaxX) + fx = bMaxX; + } + point(fx, 0.0); + point(fx, my); + point(tx, my); + } + } + + double xx, xy, yx, yy; + + void point(double x, double y) { + lineTo(x * xx + y * yx + sx, x * xy + y * yy + sy); + } + + /* + * should draw only horizontal or vertical lines. Determine the offset and + * draw both lines. + */ + void lineTo(double x, double y) { + double cx = path.getCurrentPoint().getX(); + double cy = path.getCurrentPoint().getY(); + + if (Math.abs(cx - x) < 1e-5) { + // Vertical line + if(points.size() % 2 == 0) { + points.add(points.get(points.size()-2)); + } + points.add(y); + } else if (Math.abs(cy - y) < 1e-5) { + // Horizontal line + if(points.size() % 2 != 0) { + points.add(cy); + } + points.add(x); + } + path.lineTo(x, y); + } + void rotate() { + double temp; + + temp = tx; + tx = ty; + ty = -temp; + + temp = aMinX; + aMinX = aMinY; + aMinY = -aMaxX; + aMaxX = aMaxY; + aMaxY = -temp; + + temp = bMinX; + bMinX = bMinY; + bMinY = -bMaxX; + bMaxX = bMaxY; + bMaxY = -temp; + + temp = xx; + xx = -xy; + xy = temp; + + temp = yx; + yx = -yy; + yy = temp; + + --targetDirection; + if (targetDirection < 0) + targetDirection += 4; + --sourceDirection; + } + + void flip() { + double temp; + + ty = -ty; + + temp = aMinY; + aMinY = -aMaxY; + aMaxY = -temp; + + temp = bMinY; + bMinY = -bMaxY; + bMaxY = -temp; + + yx = -yx; + yy = -yy; + + targetDirection = (targetDirection + 2) % 4; + } + + /* + * Puts source terminal to origo and rotates the situation so that the + * connection leaves to east. Finally, the case where target direction is to + * south is eliminated by optionally flipping the situation. + */ + void canonicalize() { + aMinX -= sx; + aMinY -= sy; + aMaxX -= sx; + aMaxY -= sy; + bMinX -= sx; + bMinY -= sy; + bMaxX -= sx; + bMaxY -= sy; + tx -= sx; + ty -= sy; + xx = yy = 1.0; + xy = yx = 0.0; + while (sourceDirection > 0) + rotate(); + + if (targetDirection == Constants.SOUTH) + flip(); + } + + public void route() { + /* + * Three cases: 1. Obstacles share X-axis at some point 2. Obstacles + * share Y-Axis at some point 3. Obstacles don't share axis => Have to + * make corners. + */ +// if ( +// aMinX > bMinX && aMinX < bMaxX || +// aMaxX > bMinX && aMaxX < bMaxX || +// aMinX < bMinX && aMaxX > bMaxX) { +// // Obstacles share x-axis => no corner +// double minX = aMinX > bMinX ? aMinX : bMinX; +// double maxX = aMaxX < bMaxX ? aMaxX : bMaxX; +// double middle = minX + (maxX - minX) / 2; +// sx = middle; +// tx = middle; +// if (sy > ty) { +// sy = aMinY; +// ty = bMaxY; +// } else { +// sy = aMaxY; +// ty = bMinY; +// } +// } else if ( +// aMinY > bMinY && aMinY < bMaxY || +// aMaxY > bMinY && aMaxY < bMaxY || +// aMinY < bMinY && aMaxY > bMaxY) { +// // Obstacles share y-axis => no corner +// double minY = aMinY > bMinY ? aMinY : bMinY; +// double maxY = aMaxY < bMaxY ? aMaxY : bMaxY; +// double middle = minY + (maxY - minY) / 2; +// sy = middle; +// ty = middle; +// if (sx > tx) { +// sx = aMinX; +// tx = bMaxX; +// } else { +// sx = aMaxX; +// tx = bMinX; +// } +// } else { + sx = aMinX + (aMaxX - aMinX) / 2; + sy = aMinY + (aMaxY - aMinY) / 2; + tx = bMinX + (bMaxX - bMinX) / 2; + ty = bMinY + (bMaxY - bMinY) / 2; + // Move starting point to the edge of the start element + switch (sourceDirection) { + case Constants.WEST: + sx = aMinX; + break; + case Constants.EAST: + sx = aMaxX; + break; + case Constants.NORTH: + sy = aMinY; + break; + case Constants.SOUTH: + sy = aMaxY; + break; + } + + // Move target point to the edge of the ending element + switch (targetDirection) { + case Constants.EAST: + tx = bMaxX; + break; + case Constants.WEST: + tx = bMinX; + break; + case Constants.NORTH: + ty = bMinY; + break; + case Constants.SOUTH: + ty = bMaxY; + break; + } +// } + + path = new Path2D.Double(); + points = new ArrayList(); + + path.moveTo(sx, sy); + points.add(sx); + points.add(sy); + + // Vertical and horizontal cases + if ((Math.abs(sx - tx) < 1e-5 && isVertical()) + || (Math.abs(sy - ty) < 1e-5 && isHorizontal())) { + lineTo(tx, ty); + return; + } + + + canonicalize(); + switch (targetDirection) { + case Constants.EAST: + routeWest(); + break; + case Constants.WEST: + routeEast(); + break; + case Constants.NORTH: + routeSouth(); + break; + } + + point(tx, ty); + + } + + private boolean isVertical() { + return + (sourceDirection == Constants.SOUTH && targetDirection == Constants.SOUTH) + || + (sourceDirection == Constants.NORTH && targetDirection == Constants.NORTH); + } + + private boolean isHorizontal() { + return + (sourceDirection == Constants.EAST && targetDirection == Constants.EAST) + || + (sourceDirection == Constants.WEST && targetDirection == Constants.WEST); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/AuxiliaryFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/AuxiliaryFactory.java new file mode 100644 index 00000000..73c4f62d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/AuxiliaryFactory.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.BasicStroke; +import java.awt.geom.Ellipse2D; +import java.util.Collection; + +import org.simantics.db.Resource; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.handler.impl.BoundsOutline; +import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.ObjectTerminal; +import org.simantics.g2d.element.handler.impl.OutlinePick; +import org.simantics.g2d.element.handler.impl.SimpleElementLayers; +import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.g2d.element.handler.impl.StaticSymbolImageInitializer; +import org.simantics.g2d.element.handler.impl.StaticSymbolImpl; +import org.simantics.g2d.element.handler.impl.TextColorImpl; +import org.simantics.g2d.element.handler.impl.TextFontImpl; +import org.simantics.g2d.element.handler.impl.TextImpl; +import org.simantics.g2d.image.Image; +import org.simantics.g2d.image.impl.ShapeImage; + +/** + * @author Tuukka Lehtonen + */ +public class AuxiliaryFactory extends SysdynElementFactory { + + public static final Image AUX_STATIC_IMAGE = new ShapeImage(new Ellipse2D.Double(-5, -2, 10, 4), null, new BasicStroke(1), true); + + @Override + protected ElementClass compileElementClass(Resource elementType, Collection terminals) { + return ElementClass.compile( + SimpleElementLayers.INSTANCE, + OutlinePick.INSTANCE, + TextImpl.INSTANCE, + TextColorImpl.BLACK, + TextFontImpl.DEFAULT, + DefaultTransform.INSTANCE, + new StaticObjectAdapter(elementType), + new StaticSymbolImpl(AUX_STATIC_IMAGE), + StaticSymbolImageInitializer.INSTANCE, + HoverTextElementHandler.INSTANCE, + BoundsOutline.INSTANCE, + new WholeElementTerminals(terminals) + ).setId(AuxiliaryFactory.class.getSimpleName()); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/BorderSceneGraph.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/BorderSceneGraph.java new file mode 100644 index 00000000..948d830d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/BorderSceneGraph.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.geom.AffineTransform; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.SceneGraphNodeKey; +import org.simantics.g2d.element.handler.SceneGraph; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.utils.datastructures.Callback; +import org.simantics.utils.datastructures.hints.IHintContext.Key; + +public class BorderSceneGraph implements SceneGraph, Callback { + + public static final BorderSceneGraph INSTANCE = new BorderSceneGraph(); + + private static final long serialVersionUID = 5544256245734478634L; + + private static final Key BORDER_NODE = new SceneGraphNodeKey(RectangleNode.class, "BORDER_NODE"); + + @Override + public void init(IElement e, G2DParentNode parent) { + RectangleNode node = ElementUtils.getOrCreateNode(e, parent, BORDER_NODE, "border", RectangleNode.class, this); + + // Calculate borders from text node bounds. + node.init(ElementUtils.getElementBounds(e)); + AffineTransform transform = ElementUtils.getTransform(e); + if(transform != null) + node.setTransform(transform); + } + + @Override + public void run(RectangleNode node) { + node.setZIndex(-10); + } + + @Override + public void cleanup(IElement e) { + ElementUtils.removePossibleNode(e, BORDER_NODE); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java new file mode 100644 index 00000000..f0b9dbcc --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java @@ -0,0 +1,181 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.Path2D; +import java.awt.geom.Rectangle2D; +import java.util.Collection; + +import org.simantics.db.Resource; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementHints; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.SceneGraphNodeKey; +import org.simantics.g2d.element.handler.HandleMouseEvent; +import org.simantics.g2d.element.handler.InternalSize; +import org.simantics.g2d.element.handler.SceneGraph; +import org.simantics.g2d.element.handler.impl.BoundsOutline; +import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.HoverImpl; +import org.simantics.g2d.element.handler.impl.ObjectTerminal; +import org.simantics.g2d.element.handler.impl.OutlinePick; +import org.simantics.g2d.element.handler.impl.SimpleElementLayers; +import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.g2d.element.handler.impl.StaticSymbolImageInitializer; +import org.simantics.g2d.element.handler.impl.StaticSymbolImpl; +import org.simantics.g2d.element.handler.impl.TextColorImpl; +import org.simantics.g2d.element.handler.impl.TextFontImpl; +import org.simantics.g2d.element.handler.impl.TextImpl; +import org.simantics.g2d.image.Image; +import org.simantics.g2d.image.impl.ShapeImage; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.events.MouseEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseEnterEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseExitEvent; +import org.simantics.scenegraph.g2d.nodes.ShapeNode; +import org.simantics.utils.datastructures.hints.IHintListener; +import org.simantics.utils.datastructures.hints.IHintObservable; +import org.simantics.utils.datastructures.hints.IHintContext.Key; + +public class CloudFactory extends SysdynElementFactory { + + public static final double CLOUD_SIZE_X = 5.0; + public static final double CLOUD_SIZE_Y = 3.0; + public static final double CLOUD_CURVES = 7; + + private static final BasicStroke STROKE = new BasicStroke(1f); + public static final Image CLOUD_IMAGE = new ShapeImage(getCloudShape(), null, STROKE, true); + + static Shape getCloudShape() { + Path2D path = new Path2D.Double(); + double ox = CLOUD_SIZE_X; + double oy = 0.0; + double posX = 0; + double posY = 0; + path.moveTo(posX + ox, posY + oy); + for (int i = 1; i < CLOUD_CURVES + 1; ++i) { + double angle = (Math.PI * 2.0 / CLOUD_CURVES) * i; + double x = Math.cos(angle) * CLOUD_SIZE_X; + double y = Math.sin(angle) * CLOUD_SIZE_Y; + path.curveTo( + posX + (2*ox + x)*0.5, posY + (2*oy + y)*0.5, + posX + (ox + 2*x)*0.5, posY + (oy + 2*y)*0.5, + posX + x, posY + y); + ox = x; + oy = y; + } + return path; + } + + public static ElementClass createElementClass(Resource elementType, Collection terminals) { + return ElementClass.compile( + SimpleElementLayers.INSTANCE, + OutlinePick.INSTANCE, + TextImpl.INSTANCE, + TextColorImpl.BLACK, + TextFontImpl.DEFAULT, + DefaultTransform.INSTANCE, + new StaticObjectAdapter(elementType), + new StaticSymbolImpl(CLOUD_IMAGE), + StaticSymbolImageInitializer.INSTANCE, + CloudSceneGraph.INSTANCE, + HoverImpl.INSTANCE, + BoundsOutline.INSTANCE, + new WholeElementTerminals(terminals) + ).setId(CloudFactory.class.getSimpleName()); + } + + @Override + protected ElementClass compileElementClass(Resource elementType, Collection terminals) { + return createElementClass(elementType, terminals); + } + + public static class CloudSceneGraph implements SceneGraph, InternalSize, HandleMouseEvent { + + private static final long serialVersionUID = 5544256245734478634L; + + public static final CloudSceneGraph INSTANCE = new CloudSceneGraph(); + + private static final Key NODE = new SceneGraphNodeKey(ShapeNode.class, "CLOUD_NODE"); + + private IHintListener hoverHintListener; + + @Override + public void init(IElement e, G2DParentNode parent) { + + HoverShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "cloud", HoverShapeNode.class); + + AffineTransform at = ElementUtils.getTransform(e); + + node.setStroke(STROKE); + node.setScaleStroke(true); + node.setColor(Color.BLACK); + node.setShape(getCloudShape()); + + if(at != null) + node.setTransform(at); + + hoverHintListener = new IHintListener() { + + @Override + public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { + + } + + @Override + public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { + IElement e = (IElement)sender; + HoverShapeNode shape = (HoverShapeNode) e.getHint(NODE); + if(shape == null) { + return; + } + shape.setHover(ElementUtils.isHovering(e)); + } + }; + e.addHintListener(hoverHintListener); + } + + @Override + public void cleanup(IElement e) { + e.removeHintListener(hoverHintListener); + ElementUtils.removePossibleNode(e, NODE); + } + + @Override + public Rectangle2D getBounds(IElement e, Rectangle2D size) { + if (size == null) + size = new Rectangle2D.Double(); + size.setFrame(getCloudShape().getBounds2D()); + return size; + } + + @Override + public boolean handleMouseEvent(IElement e, ICanvasContext ctx, MouseEvent me) { + if (me instanceof MouseEnterEvent) { + e.setHint(ElementHints.KEY_HOVER, true); + return false; + } else if (me instanceof MouseExitEvent) { + e.setHint(ElementHints.KEY_HOVER, false); + return false; + } + return false; + } + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ComponentNameSynchronizer.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ComponentNameSynchronizer.java new file mode 100644 index 00000000..7e08e26d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ComponentNameSynchronizer.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.synchronization.IModificationQueue; +import org.simantics.diagram.synchronization.ISynchronizationContext; +import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints; +import org.simantics.diagram.synchronization.graph.RelatedPropertyModification; +import org.simantics.diagram.synchronization.graph.ResourceSynchronizer; +import org.simantics.g2d.element.ElementHints; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintObservable; + +/** + * @author Tuukka Lehtonen + */ +public class ComponentNameSynchronizer extends ResourceSynchronizer { + + public static final ComponentNameSynchronizer INSTANCE = new ComponentNameSynchronizer(); + + private static final Key[] SYNCHRONIZED_HINTS = { + ElementHints.KEY_TEXT + }; + + @Override + public Key[] getSynchronizedHints() { + return SYNCHRONIZED_HINTS; + } + + @Override + public boolean hintChanged(ISynchronizationContext context, IModificationQueue queue, Resource object, IHintObservable sender, Key key, Object oldValue, Object newValue) { + if (ElementHints.KEY_TEXT.equals(key)) { + Session session = context.get(GraphSynchronizationHints.SESSION); + Layer0 l0; + try { + l0 = Layer0.getInstance(session); + ModelingResources mr = session.getService(ModelingResources.class); + return queue.offer(new RelatedPropertyModification(object, mr.ElementToComponent, l0.HasName, l0.String, newValue, Bindings.STRING), null); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + return false; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ConfigurationDiagramClassAdapter.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ConfigurationDiagramClassAdapter.java new file mode 100644 index 00000000..b102a163 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ConfigurationDiagramClassAdapter.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.adaption.ResourceAdapter; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.diagram.adapter.DiagramClassAdapter; +import org.simantics.g2d.diagram.DiagramClass; +import org.simantics.g2d.diagram.DiagramHints; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.diagram.handler.LifeCycle; +import org.simantics.g2d.routing.RouterFactory; + +/** + * @author Tuukka Lehtonen + */ +public class ConfigurationDiagramClassAdapter implements ResourceAdapter { + + @Override + public void adapt(AsyncReadGraph g, Resource source, Resource r, AsyncProcedure procedure) { + procedure.execute(g, DiagramClassAdapter.INSTANCE.newClassWith( + Initializer.INSTANCE + )); + } + + static class Initializer extends LifeCycle.Stub { + public static final Initializer INSTANCE = new Initializer(); + + @Override + public void onDiagramCreated(IDiagram diagram) { + diagram.setHint(DiagramHints.ROUTE_ALGORITHM, RouterFactory.create(false, false)); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverShapeNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverShapeNode.java new file mode 100644 index 00000000..f93a15de --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverShapeNode.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.AlphaComposite; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Composite; +import java.awt.Graphics2D; +import java.awt.Shape; +import java.awt.Stroke; + +import org.simantics.scenegraph.ISelectionPainterNode; +import org.simantics.scenegraph.g2d.nodes.ShapeNode; +import org.simantics.scenegraph.utils.NodeUtil; + +public class HoverShapeNode extends ShapeNode implements ISelectionPainterNode { + + private static final long serialVersionUID = -4580969977763722602L; + + transient public boolean hover = false; + + @Override + protected void renderShape(Graphics2D g2d, Shape s) { + boolean fill = Boolean.TRUE.equals(dynamicFill) ? true : this.fill; + if (fill) + g2d.fill(s); + + Color oldColor = g2d.getColor(); + BasicStroke oldStroke = (BasicStroke)g2d.getStroke(); + Composite oldComposite = g2d.getComposite(); + + boolean selected = NodeUtil.isSelected(this, 1); + if (selected) { + float lineWidth = oldStroke.getLineWidth() * 5; + g2d.setStroke(new BasicStroke(lineWidth < 1.0f ? lineWidth : 1.0f)); + g2d.setComposite(AlphaComposite.SrcAtop.derive(0.5f)); + g2d.setColor(Color.RED); + g2d.draw(s); + g2d.setColor(oldColor); + } + + if(!selected && hover) { + g2d.setColor(Color.LIGHT_GRAY); + float lineWidth = oldStroke.getLineWidth() * 5; + g2d.setStroke(new BasicStroke(lineWidth < 1.0f ? lineWidth : 1.0f)); + g2d.draw(s); + + } + + g2d.setColor(oldColor); + g2d.setStroke(oldStroke); + g2d.setComposite(oldComposite); + + Stroke stroke = dynamicStroke != null ? dynamicStroke : this.stroke; + if (stroke != null) + g2d.draw(s); + + } + + public void setHover(boolean hover) { + this.hover = hover; + repaint(); + } + + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementHandler.java new file mode 100644 index 00000000..9063b203 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementHandler.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.Font; +import java.awt.font.FontRenderContext; +import java.awt.font.TextLayout; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; + +import org.simantics.g2d.element.ElementHints; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.InternalSize; +import org.simantics.g2d.utils.Alignment; + +public class HoverTextElementHandler extends HoverTextElementNoBounds implements InternalSize { + + private static final long serialVersionUID = 8800738238681432901L; + + public static final HoverTextElementHandler INSTANCE = new HoverTextElementHandler(); + + public HoverTextElementHandler() { + super(); + } + + public HoverTextElementHandler(double originX, double originY, Alignment horizontalAlignment) { + super(originX, originY, horizontalAlignment); + } + + public HoverTextElementHandler(double originX, double originY, Alignment horizontalAlignment, double borderWidth) { + super(originX, originY, horizontalAlignment, borderWidth); + } + + public HoverTextElementHandler(double originX, double originY, Alignment horizontalAlignment, double borderWidth, + double paddingX, double paddingY, boolean editable) { + super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable); + } + + @Override + public Rectangle2D getBounds(IElement e, Rectangle2D size) { + HoverTextNode node = (HoverTextNode) e.getHint(SG_NODE); + if (size == null) + size = new Rectangle2D.Double(); + if (node != null) + size.setRect(node.getBoundsInLocal()); + else { + String text = e.getHint(ElementHints.KEY_TEXT); + Font font = e.getHint(ElementHints.KEY_FONT); + if(text == null || font == null) + size.setFrame(0, 0, 0, 0); + else { + FontRenderContext FRC = new FontRenderContext(new AffineTransform(), true, true); + TextLayout tl = new TextLayout(text, font, FRC); + Rectangle2D bounds = tl.getLogicalHighlightShape(0, text.length()).getBounds2D(); + size.setFrame( + bounds.getX() * SCALE - paddingX, + bounds.getY() * SCALE -paddingY, + bounds.getWidth()* SCALE + paddingX + paddingX, + bounds.getHeight()* SCALE + paddingY + paddingY); + } + } + return size; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java new file mode 100644 index 00000000..7e2f3545 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java @@ -0,0 +1,207 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.Color; +import java.awt.Font; +import java.awt.geom.AffineTransform; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.elements.ITextListener; +import org.simantics.diagram.elements.TextElementNoBounds; +import org.simantics.diagram.elements.TextNode; +import org.simantics.g2d.diagram.DiagramUtils; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementHints; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.utils.Alignment; +import org.simantics.modeling.ModelingResources; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.sysdyn.ui.utils.VariableNameUtils; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.Callback; +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintListener; +import org.simantics.utils.datastructures.hints.IHintObservable; + +/** + * ElementHandler for text elements + * In-line editing supported. + * + * @author Marko Luukkainen + */ +public class HoverTextElementNoBounds extends TextElementNoBounds { + + private static final long serialVersionUID = -148784588840819612L; + + public static final HoverTextElementNoBounds INSTANCE = new HoverTextElementNoBounds(); + + private IHintListener hoverHintListener; + + public HoverTextElementNoBounds() { + super(0, 0, Alignment.LEADING, 0); + } + + public HoverTextElementNoBounds(double originX, double originY, Alignment horizontalAlignment) { + super(originX, originY, horizontalAlignment, 0); + } + + public HoverTextElementNoBounds(double originX, double originY, Alignment horizontalAlignment, double borderWidth) { + super(originX, originY, horizontalAlignment, borderWidth); + } + + public HoverTextElementNoBounds(double originX, double originY, Alignment horizontalAlignment, double borderWidth, double paddingX, double paddingY, boolean editable) { + super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable); + } + + protected HoverTextNode getTextNode(IElement e, G2DParentNode parent) { + return ElementUtils.getOrCreateNode(e, parent, SG_NODE, "text", HoverTextNode.class, getCallback(e, parent, HoverTextNode.class)); + } + + protected Callback getCallback(final IElement e, G2DParentNode parent, Class nodeClass) { + return new Callback() { + @Override + public void run(T node) { + node.setTextListener(new ITextListener() { + + String textBeforeEdit; + Resource component; + + @Override + public void textChanged() { + TextNode node = (TextNode) e.getHint(SG_NODE); + if(!VariableNameUtils.isValid(component, node.getText(), false)) { + node.setColor(Color.RED); + } else { + node.setColor(Color.BLACK); + } + + + } + + @Override + public void textEditingStarted() { + TextNode node = (TextNode) e.getHint(SG_NODE); + textBeforeEdit = node.getText(); + + if(component != null) return; + + Object o = e.getHint(ElementHints.KEY_OBJECT); + if(o != null && o instanceof Resource) { + final Resource element = (Resource)o; + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + component = graph.getPossibleObject(element, ModelingResources.getInstance(graph).ElementToComponent); + } + }); + } + } + + @Override + public void textEditingCancelled() { + TextNode node = (TextNode) e.getHint(SG_NODE); + if (node != null) { + if(VariableNameUtils.isValid(component, node.getText(), false)) + node.setColor(Color.BLACK); + endEdit(node); + } + } + + @Override + public void textEditingEnded() { + TextNode node = (TextNode) e.getHint(SG_NODE); + if (node == null) + return; + String text = node.getText(); + if(!VariableNameUtils.isValid(component, text, false)) { + text = textBeforeEdit; + node.setText(text); + if(VariableNameUtils.isValid(component, text, false)) + node.setColor(Color.BLACK); + } else { + Object o = e.getHint(ElementHints.KEY_OBJECT); + final String textAfterEdit = text; + if(o != null && o instanceof Resource) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + VariableNameUtils.renameInEquations(graph, component, textBeforeEdit, textAfterEdit); + } + }); + } + } + ElementUtils.setText(e, text); + IDiagram diagram = ElementUtils.getDiagram(e); + DiagramUtils.synchronizeHintsToBackend(diagram, e); + endEdit(node); + } + }); + } + }; + } + + public static double SCALE = 0.235; + + @Override + public void init(final IElement e, G2DParentNode parent) { + HoverTextNode node = getTextNode(e, parent); + + //Font font = new Font("Tahoma", 0, 12); + Font font = ElementUtils.getTextFont(e); + Color color = ElementUtils.getTextColor(e); + Color fillColor = ElementUtils.getFillColor(e); + Color borderColor = ElementUtils.getBorderColor(e, Color.BLACK); + String text = ElementUtils.getText(e); + AffineTransform at = ElementUtils.getTransform(e); + Alignment hAlign = ElementUtils.getHintOrDefault(e, ElementHints.KEY_HORIZONTAL_ALIGN, horizontalAlignment); + node.init(text, font, color, originX, originY, SCALE); + node.setBackgroundColor(fillColor); + node.setBorderColor(borderColor); + node.setHorizontalAlignment((byte) hAlign.ordinal()); + node.setPadding(paddingX, paddingY); + node.setBorderWidth((float) borderWidth); + node.setEditable(editable); + if(at != null) + node.setTransform(at); + + this.hoverHintListener = new IHintListener() { + @Override + public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { + + } + + @Override + public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { + if(key == ElementHints.KEY_HOVER) { + IElement e = (IElement)sender; + TextNode name = (TextNode) e.getHint(SG_NODE); + if(name != null) + name.setHover(Boolean.TRUE.equals(e.getHint(ElementHints.KEY_HOVER))); + } + } + }; + e.addHintListener(hoverHintListener); + } + + @Override + public void cleanup(IElement e) { + if(hoverHintListener != null) + e.removeHintListener(hoverHintListener); + ElementUtils.removePossibleNode(e, SG_NODE); + } +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextNode.java new file mode 100644 index 00000000..b01d5136 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextNode.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; + +import org.simantics.diagram.elements.TextNode; +import org.simantics.scenegraph.ISelectionPainterNode; +import org.simantics.scenegraph.utils.NodeUtil; + +public class HoverTextNode extends TextNode implements ISelectionPainterNode { + + private static final long serialVersionUID = 3539499125943249895L; + + protected static transient ThreadLocal tempBounds = new ThreadLocal() { + @Override + protected Rectangle2D initialValue() { + return new Rectangle2D.Double(); + } + }; + + @Override + public void render(Graphics2D g) { + if (text == null || font == null || color == null) + return; + + AffineTransform ot = g.getTransform(); + g.transform(transform); + + boolean selected = NodeUtil.isSelected(this, 1); + if (!selected && hover){ + BasicStroke oldStroke = (BasicStroke)g.getStroke(); + Color oldColor = g.getColor(); + g.setColor(Color.LIGHT_GRAY); + g.setStroke(new BasicStroke((float)(2.0f))); + g.scale(scale, scale); + g.translate(x, y); + g.draw(expandBoundsUnscaled(alignBounds(getTextBounds()))); + g.translate(-x, -y); + g.scale(scaleRecip, scaleRecip); + g.setColor(oldColor); + g.setStroke(oldStroke); + + } + + super.render(g, false); + g.setTransform(ot); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/Input.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/Input.java new file mode 100644 index 00000000..d8e37fb3 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/Input.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.ElementHandler; + +public class Input implements ElementHandler { + + private static final long serialVersionUID = -1526125969376635502L; + + public static final Input INSTANCE = new Input(); + + public String getInputReference(IElement e) { + return e.getHint(SysdynElementHints.KEY_INPUT_REFERENCE); + } + + + public void setInputReference(IElement e, String inputReference) { + if (inputReference != null) + e.setHint(SysdynElementHints.KEY_INPUT_REFERENCE, inputReference); + else + e.removeHint(SysdynElementHints.KEY_INPUT_REFERENCE); + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java new file mode 100644 index 00000000..f3151bd9 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java @@ -0,0 +1,243 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Font; +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.Path2D; +import java.awt.geom.Rectangle2D; +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.MissingVariableException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.diagram.elements.TextNode; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.diagram.ui.DiagramModelHints; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.SceneGraphNodeKey; +import org.simantics.g2d.element.handler.InternalSize; +import org.simantics.g2d.element.handler.impl.BoundsOutline; +import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.HoverImpl; +import org.simantics.g2d.element.handler.impl.ObjectTerminal; +import org.simantics.g2d.element.handler.impl.OutlinePick; +import org.simantics.g2d.element.handler.impl.SimpleElementLayers; +import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.g2d.element.handler.impl.StaticSymbolImageInitializer; +import org.simantics.g2d.element.handler.impl.StaticSymbolImpl; +import org.simantics.g2d.element.handler.impl.TextColorImpl; +import org.simantics.g2d.element.handler.impl.TextFontImpl; +import org.simantics.g2d.element.handler.impl.TextImpl; +import org.simantics.g2d.image.Image; +import org.simantics.g2d.image.impl.ShapeImage; +import org.simantics.g2d.utils.Alignment; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.adapter.ChildVariable; +import org.simantics.sysdyn.adapter.ConfigurationVariable; +import org.simantics.sysdyn.adapter.RunVariable; +import org.simantics.utils.datastructures.hints.IHintContext.Key; + +public class InputFactory extends SysdynElementFactory { + + private static final BasicStroke STROKE = new BasicStroke(1f); + public static final Image INPUT_IMAGE = new ShapeImage(getInputShape(), null, STROKE, true); + + static Shape getInputShape() { + Path2D path = new Path2D.Double(); + path.moveTo(-6, -1); + path.lineTo(-1, -1); + path.lineTo(-1, -2.5); + path.lineTo(1.5, 0); + path.curveTo(1.5, -2.5, 6.5, -2.5, 6.5, 0); + path.curveTo(6.5, 2.5, 1.5, 2.5, 1.5, 0); + path.lineTo(-1, 2.5); + path.lineTo(-1, 1); + path.lineTo(-6, 1); + path.closePath(); + return path; + } + + @Override + protected ElementClass compileElementClass(Resource elementType, Collection terminals) { + return ElementClass.compile( + SimpleElementLayers.INSTANCE, + OutlinePick.INSTANCE, + TextImpl.INSTANCE, + TextColorImpl.BLACK, + TextFontImpl.DEFAULT, + DefaultTransform.INSTANCE, + new StaticObjectAdapter(elementType), + new StaticSymbolImpl(INPUT_IMAGE), + StaticSymbolImageInitializer.INSTANCE, + Input.INSTANCE, + new InputSceneGraph(0, 0, Alignment.LEADING), + BoundsOutline.INSTANCE, + HoverImpl.INSTANCE, + new WholeElementTerminals(terminals) + ).setId(InputFactory.class.getSimpleName()); + } + + @Override + public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException { + super.load(graph, canvas, diagram, element, e); + Layer0 l0 = Layer0.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + Resource component = null; + Resource dependency = null; + Resource refersTo = null; + Resource module = null; + String moduleName = ""; + String referenceName = ""; + component = graph.getPossibleObject(element, mr.ElementToComponent); + if(component != null) + dependency = graph.getPossibleObject(component, sr.IsHeadOf); + if(dependency != null) { + refersTo = graph.getPossibleObject(dependency, sr.RefersTo); + if(refersTo != null) { + referenceName = (String) graph.getPossibleRelatedValue(refersTo, l0.HasName); + module = graph.getPossibleObject(dependency, sr.HasTail); + moduleName = (String) graph.getPossibleRelatedValue(module, l0.HasName); + } + } else { + Resource runtime = diagram.getHint((DiagramModelHints.KEY_DIAGRAM_RUNTIME_RESOURCE)); + DiagramResource dr = DiagramResource.getInstance(graph); + String variable = (String)graph.getPossibleRelatedValue(runtime, dr.RuntimeDiagram_HasVariable); + if(variable == null) + return; + + + try { + Variable v = Variables.getVariable(graph, variable); + if(v instanceof ChildVariable) { + module = ((ChildVariable)v).getRepresents(graph); + } + if(module != null) + for(Resource dep : graph.getObjects(module, sr.IsHeadOf)) { + Resource reference = graph.getPossibleObject(dep, sr.RefersTo); + if(reference!= null && reference.equals(component)) { + refersTo = graph.getSingleObject(dep, sr.HasTail); + referenceName = (String) graph.getPossibleRelatedValue(refersTo, l0.HasName); + Variable parent = null; + if(v instanceof ChildVariable) + parent = ((ChildVariable)v).getParent(graph); + if(parent != null && !(parent instanceof RunVariable) && !(parent instanceof ConfigurationVariable)) { + String parentURI = parent.getURI(graph); + Resource p = graph.getPossibleResource(parentURI); + if(p != null) + moduleName = (String) graph.getPossibleRelatedValue(p, l0.HasName); + } + break; + } + } + } catch (MissingVariableException mve) { + // DO nothing. + } + } + + String inputReference = null; + if (moduleName != null && refersTo != null) { + inputReference = moduleName + "." + referenceName; + } + if (inputReference == null) { + inputReference = ""; + } + + SysdynElementUtils.setInputReference(e, inputReference); + + Font font = ElementUtils.getTextFont(e); + font = font.deriveFont(font.getStyle() + Font.ITALIC); + ElementUtils.setTextFont(e, font); + ElementUtils.setHover(e, false); + } + + + public static class InputSceneGraph extends HoverTextElementNoBounds implements InternalSize { + + private static final long serialVersionUID = -3713275157729126409L; + public static final Key INPUT_SG_NODE = new SceneGraphNodeKey(TextNode.class, "INPUT_SG_NODE"); + + private final double originX; + private final Alignment horizontalAlignment; + + public InputSceneGraph(double originX, double originY, Alignment horizontalAlignment) { + super(originX, originY, horizontalAlignment, 0.0, 2.0, 2.0, true); + this.originX = originX; + this.horizontalAlignment = horizontalAlignment; + } + + @Override + public void init(final IElement e, G2DParentNode parent) { + super.init(e, parent); + TextNode node = ElementUtils.getOrCreateNode(e, parent, INPUT_SG_NODE, "input", TextNode.class); + Font font = ElementUtils.getTextFont(e); + font = font.deriveFont((float) 10.0); + font = font.deriveFont(Font.ITALIC); + Color color = new Color(150, 150, 150); + Color fillColor = ElementUtils.getFillColor(e); + Color borderColor = ElementUtils.getBorderColor(e, Color.BLACK); + String text = SysdynElementUtils.getInputReference(e); + double scale = 0.235; + AffineTransform at = ElementUtils.getTransform(e); + node.init(text, font, color, originX, originY, scale); + node.setBackgroundColor(fillColor); + node.setBorderColor(borderColor); + node.setHorizontalAlignment((byte) horizontalAlignment.ordinal()); + node.setBorderWidth((float) 0); + node.setEditable(false); + node.setShowSelection(false); + + if(at != null) { + node.setTransform(at); + // Use affinetransform to move the name of the valve below the valve symbol + AffineTransform at2 = (AffineTransform) at.clone(); + at2.translate(0, font.getSize2D() * scale); + node.setTransform(at2); + } + } + + @Override + public Rectangle2D getBounds(IElement e, Rectangle2D size) { + TextNode name = (TextNode) e.getHint(SG_NODE); + TextNode reference = (TextNode) e.getHint(INPUT_SG_NODE); + if (size == null) + size = new Rectangle2D.Double(); + if (name != null) + size.setRect(name.getBoundsInLocal()); + + if(reference != null) { + /* Only the main text box as bounds + if (reference.getBoundsInLocal().getWidth() > size.getWidth()) + size.setRect(size.getX(), size.getY(), reference.getBoundsInLocal().getWidth(), size.getHeight()); + */ + } + else + size.setFrame(0, 0, 0, 0); + return size; + } + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleFactory.java new file mode 100644 index 00000000..678f63e8 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleFactory.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.BasicStroke; +import java.awt.Font; +import java.awt.geom.Rectangle2D; +import java.util.Collection; + +import org.simantics.db.Resource; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.InternalSize; +import org.simantics.g2d.element.handler.impl.BoundsOutline; +import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.ObjectTerminal; +import org.simantics.g2d.element.handler.impl.OutlinePick; +import org.simantics.g2d.element.handler.impl.SimpleElementLayers; +import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.g2d.element.handler.impl.StaticSymbolImageInitializer; +import org.simantics.g2d.element.handler.impl.StaticSymbolImpl; +import org.simantics.g2d.element.handler.impl.TextColorImpl; +import org.simantics.g2d.element.handler.impl.TextFontImpl; +import org.simantics.g2d.element.handler.impl.TextImpl; +import org.simantics.g2d.image.Image; +import org.simantics.g2d.image.impl.ShapeImage; +import org.simantics.g2d.utils.Alignment; +import org.simantics.scenegraph.g2d.G2DParentNode; + +public class ModuleFactory extends SysdynElementFactory { + + private static final BasicStroke STROKE = new BasicStroke(2.0f); + private static final Image DEFAULT_IMAGE = new ShapeImage(new Rectangle2D.Double(-5, -2.5, 10, 5), null, STROKE, true); + + @Override + protected ElementClass compileElementClass(Resource elementType, Collection terminals) { + return ElementClass.compile( + SimpleElementLayers.INSTANCE, + OutlinePick.INSTANCE, + TextImpl.INSTANCE, + TextColorImpl.BLACK, + new TextFontImpl(new Font("arial", Font.PLAIN, 25)), + DefaultTransform.INSTANCE, + new StaticObjectAdapter(elementType), + new StaticSymbolImpl(DEFAULT_IMAGE), + StaticSymbolImageInitializer.INSTANCE, + new ModuleSceneGraph(0, 0, Alignment.LEADING, 1f , 4, 4, true), + BoundsOutline.INSTANCE, + new WholeElementTerminals(terminals) + ).setId(ModuleFactory.class.getSimpleName()); + } + + + public static class ModuleSceneGraph extends HoverTextElementHandler implements InternalSize { + + private static final long serialVersionUID = 2367230056477661273L; + + public ModuleSceneGraph(double originX, double originY, Alignment horizontalAlignment, double borderWidth, + double paddingX, double paddingY, boolean editable) { + super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable); + } + + protected HoverTextNode getTextNode(IElement e, G2DParentNode parent) { + return ElementUtils.getOrCreateNode(e, parent, SG_NODE, "text", ModuleNode.class, getCallback(e, parent, ModuleNode.class)); + } + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleNode.java new file mode 100644 index 00000000..a4eee590 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleNode.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.AlphaComposite; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Composite; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Path2D; +import java.awt.geom.Rectangle2D; + +import org.simantics.scenegraph.utils.GeometryUtils; +import org.simantics.scenegraph.utils.NodeUtil; + +public class ModuleNode extends HoverTextNode { + + private static final long serialVersionUID = 8535695797227320496L; + private static double CORNER_LENGTH = 2.0; + private static double CORNER_PADDING = 0.8; + + + @Override + public void render(Graphics2D g) { + super.render(g); + + AffineTransform ot = g.getTransform(); + BasicStroke oldStroke = (BasicStroke)g.getStroke(); + Color oldColor = g.getColor(); + + + g.transform(transform); + + Rectangle2D bounds = expandBounds( alignBounds( getTightUnalignedBoundsInLocal( tempBounds.get() ) ) ); + + Path2D path = new Path2D.Double(); + // LEFT TOP + path.moveTo(bounds.getMinX() + CORNER_LENGTH, bounds.getMinY() - CORNER_PADDING); + path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMinY() - CORNER_PADDING); + path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMinY() + CORNER_LENGTH); + + // LEFT BOTTOM + path.moveTo(bounds.getMinX() + CORNER_LENGTH, bounds.getMaxY() + CORNER_PADDING); + path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMaxY() + CORNER_PADDING); + path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMaxY() - CORNER_LENGTH); + + // RIGHT TOP + path.moveTo(bounds.getMaxX() - CORNER_LENGTH, bounds.getMinY() - CORNER_PADDING); + path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMinY() - CORNER_PADDING); + path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMinY() + CORNER_LENGTH); + + // RIGHT BOTTOM + path.moveTo(bounds.getMaxX() - CORNER_LENGTH, bounds.getMaxY() + CORNER_PADDING); + path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMaxY() + CORNER_PADDING); + path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMaxY() - CORNER_LENGTH); + + g.translate(x, y); + g.setStroke(new BasicStroke((float) (scale*borderWidth))); + g.setColor(Color.GRAY); + g.draw(path); + + + boolean selected = NodeUtil.isSelected(this, 1); + if (selected && showsSelection()) { + Composite oc = g.getComposite(); + g.setComposite(AlphaComposite.SrcAtop.derive(0.5f)); + + g.setColor(Color.RED); + float bw = borderWidth; + double s = GeometryUtils.getScale(g.getTransform()); + if (bw <= 0f) { + bw = (float) (1f / s); + } else { + bw *= 3f * scale; + } + g.setStroke(new BasicStroke(bw)); + g.draw(path); + //g.draw(GeometryUtils.expandRectangle(r, 1.0)); + + g.setComposite(oc); + } + + g.setColor(oldColor); + g.setStroke(oldStroke); + g.translate(-x, -y); + + g.setTransform(ot); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/Orientation.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/Orientation.java new file mode 100644 index 00000000..77733071 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/Orientation.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.ElementHandler; + +public class Orientation implements ElementHandler { + + private static final long serialVersionUID = 958120463924210936L; + + public static final Orientation INSTANCE = new Orientation(); + + public String getOrientation(IElement e) { + return e.getHint(SysdynElementHints.KEY_ORIENTATION); + } + + + public void setOrientation(IElement e, String orientation) { + if (orientation != null) + e.setHint(SysdynElementHints.KEY_ORIENTATION, orientation); + else + e.removeHint(SysdynElementHints.KEY_ORIENTATION); + } +} + diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/RectangleNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/RectangleNode.java new file mode 100644 index 00000000..8aa983d6 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/RectangleNode.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import org.simantics.scenegraph.g2d.G2DNode; + +public class RectangleNode extends G2DNode { + + private static final long serialVersionUID = 654692698101485672L; + + protected Rectangle2D bounds = null; + + @SyncField("bounds") + public void init(Rectangle2D bounds) { + this.bounds = bounds; + } + + @Override + public void render(Graphics2D g) { + if(bounds == null) return; + AffineTransform ot = g.getTransform(); + + g.transform(transform); + g.setColor(Color.BLACK); + double scale = g.getTransform().getScaleX(); + g.setStroke(new BasicStroke( (float)(1.0 / scale) )); + + g.draw(bounds); + g.setTransform(ot); + } + + @Override + public Rectangle2D getBoundsInLocal() { + return bounds; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/StockFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/StockFactory.java new file mode 100644 index 00000000..c7e277a7 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/StockFactory.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.BasicStroke; +import java.awt.geom.Rectangle2D; +import java.util.Collection; + +import org.simantics.db.Resource; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.handler.impl.BoundsOutline; +import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.ObjectTerminal; +import org.simantics.g2d.element.handler.impl.OutlinePick; +import org.simantics.g2d.element.handler.impl.SimpleElementLayers; +import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.g2d.element.handler.impl.StaticSymbolImageInitializer; +import org.simantics.g2d.element.handler.impl.StaticSymbolImpl; +import org.simantics.g2d.element.handler.impl.TextColorImpl; +import org.simantics.g2d.element.handler.impl.TextFontImpl; +import org.simantics.g2d.element.handler.impl.TextImpl; +import org.simantics.g2d.image.Image; +import org.simantics.g2d.image.impl.ShapeImage; +import org.simantics.g2d.utils.Alignment; + +public class StockFactory extends SysdynElementFactory { + + private static final BasicStroke STROKE = new BasicStroke(1f); + public static final Image STOCK_IMAGE = new ShapeImage(new Rectangle2D.Double(-5, -2.5, 10, 5), null, STROKE, true); + + @Override + protected ElementClass compileElementClass(Resource elementType, Collection terminals) { + return ElementClass.compile( + SimpleElementLayers.INSTANCE, + OutlinePick.INSTANCE, + TextImpl.INSTANCE, + TextColorImpl.BLACK, + TextFontImpl.DEFAULT, + DefaultTransform.INSTANCE, + new StaticObjectAdapter(elementType), + new StaticSymbolImpl(STOCK_IMAGE), + StaticSymbolImageInitializer.INSTANCE, + new HoverTextElementHandler(0, 0, Alignment.LEADING, 1f), + BoundsOutline.INSTANCE, + new WholeElementTerminals(terminals) + ).setId(StockFactory.class.getSimpleName()); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementClasses.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementClasses.java new file mode 100644 index 00000000..6dc0364f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementClasses.java @@ -0,0 +1,8 @@ +package org.simantics.sysdyn.ui.elements2; + +public class SysdynElementClasses { + + public static final Object VALVE = new Object() { + public String toString() { return "VALVE"; } + }; +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementFactory.java new file mode 100644 index 00000000..784c6bac --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementFactory.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.Font; +import java.awt.geom.AffineTransform; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.exception.ServiceException; +import org.simantics.diagram.G2DUtils; +import org.simantics.diagram.adapter.SyncElementFactory; +import org.simantics.diagram.content.ResourceTerminal; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.diagram.synchronization.CompositeHintSynchronizer; +import org.simantics.diagram.synchronization.IHintSynchronizer; +import org.simantics.diagram.synchronization.SynchronizationHints; +import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; +import org.simantics.diagram.synchronization.graph.TransformSynchronizer; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementHints; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.impl.ObjectTerminal; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; + +/** + * An ElementFactory that gathers common functionality for system dynamics symbols. + * Just implement {@link #compileElementClass(Resource, Collection)} to add a symbol. + * + * @author Tuukka Lehtonen + */ +public abstract class SysdynElementFactory extends SyncElementFactory { + + public static final IHintSynchronizer SYNCHRONIZER = new CompositeHintSynchronizer( + ComponentNameSynchronizer.INSTANCE, + TransformSynchronizer.INSTANCE); + + @Override + public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + G2DResource g2d = G2DResource.getInstance(graph); + DiagramResource dr = DiagramResource.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + + Resource component = graph.getPossibleObject(element, mr.ElementToComponent); + String text = null; + if (component != null) { + text = (String) graph.getPossibleRelatedValue(component, l0.HasName); + } + if (text == null) + text = "[empty]"; + + ElementUtils.setText(e, text); + + if (graph.isInstanceOf(element, dr.FontProvider)) { + Resource fontResource = graph.getPossibleObject(element, g2d.HasFont); + if (fontResource != null) + ElementUtils.setTextFont(e, G2DUtils.getFont(graph, fontResource)); + } + if (graph.isInstanceOf(element, dr.ColorProvider)) { + Resource colorResource = graph.getPossibleObject(element, g2d.HasColor); + if (colorResource != null) + ElementUtils.setTextColor(e, G2DUtils.getColor(graph, colorResource)); + } + + if (component != null && graph.hasStatement(component, SysdynResource.getInstance(graph).IsOutput)) { + Font font = ElementUtils.getTextFont(e); + font = font.deriveFont(Font.BOLD); + ElementUtils.setTextFont(e, font); + } + + AffineTransform at = DiagramGraphUtil.getAffineTransform(graph, element); + ElementUtils.setTransform(e, at); + + // This synchronizes only text and transformation (not font and color) + e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, SYNCHRONIZER); + + e.setHint(ElementHints.KEY_HOVER, false); + } + + @Override + public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType) + throws DatabaseException { + return compileElementClass(elementType, createTerminals(graph, elementType)); + } + + public static Collection createTerminals(ReadGraph graph, Resource elementType) { + + try { + StructuralResource2 sr = StructuralResource2.getInstance(graph); + DiagramResource dr = DiagramResource.getInstance(graph); + + Resource definedByList = graph.getPossibleObject(elementType, sr.IsDefinedBy); + Collection definedBy = Collections.emptyList(); + if (definedByList != null) + definedBy = OrderedSetUtils.toList(graph, definedByList); + Collection terminals = new ArrayList(definedBy.size()); + for (Resource r : definedBy) { + if (graph.isInstanceOf(r, dr.Terminal)) { + terminals.add(new ResourceTerminal(r)); + } + } + return terminals; + } catch (ManyObjectsForFunctionalRelationException e) { + e.printStackTrace(); + } catch (ServiceException e) { + e.printStackTrace(); + } catch (DatabaseException e) { + e.printStackTrace(); + } + return null; + } + + /** + * @param elementType the type of the loaded element + * @param terminals the terminals of the element type being loaded + * @return an {@link ElementClass} representing the loaded element type + */ + protected abstract ElementClass compileElementClass(Resource elementType, Collection terminals); + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementHints.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementHints.java new file mode 100644 index 00000000..8873c23f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementHints.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; + +public class SysdynElementHints { + + public static final Key KEY_INPUT_REFERENCE = new KeyOf(String.class, "INPUT_REFERENCE"); + public static final Key KEY_ORIENTATION = new KeyOf(String.class, "ORIENTATION"); + public static final Key KEY_LOCATION = new KeyOf(String.class, "LOCATION"); + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementUtils.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementUtils.java new file mode 100644 index 00000000..1a80e682 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementUtils.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import org.simantics.g2d.element.IElement; + +public class SysdynElementUtils { + + + public static void setInputReference(IElement e, String inputReference) + { + Input i = e.getElementClass().getSingleItem(Input.class); + if(i != null) + i.setInputReference(e, inputReference); + } + + public static String getInputReference(IElement e) + { + Input i = e.getElementClass().getSingleItem(Input.class); + if(i != null) + return i.getInputReference(e); + else + return null; + } + + public static void setOrientation(IElement e, String orientation) + { + Orientation o = e.getElementClass().getSingleItem(Orientation.class); + if(o != null) + o.setOrientation(e, orientation); + } + + public static String getOrientation(IElement e) + { + Orientation o = e.getElementClass().getSingleItem(Orientation.class); + if(o != null) + return o.getOrientation(e); + else + return null; + } + + public static void setValveTextLocation(IElement e, String location) + { + ValveTextLocation v = e.getElementClass().getSingleItem(ValveTextLocation.class); + if(v != null) + v.setTextLocation(e, location); + } + + public static String getValveTextLocation(IElement e) + { + ValveTextLocation v = e.getElementClass().getSingleItem(ValveTextLocation.class); + if(v != null) + return v.getTextLocation(e); + else + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java new file mode 100644 index 00000000..28314a22 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java @@ -0,0 +1,245 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.geom.AffineTransform; +import java.awt.geom.Path2D; +import java.awt.geom.Rectangle2D; +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.elements.TextNode; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementHints; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.SceneGraphNodeKey; +import org.simantics.g2d.element.handler.HandleMouseEvent; +import org.simantics.g2d.element.handler.InternalSize; +import org.simantics.g2d.element.handler.impl.BoundsOutline; +import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.HoverImpl; +import org.simantics.g2d.element.handler.impl.ObjectTerminal; +import org.simantics.g2d.element.handler.impl.OutlinePick; +import org.simantics.g2d.element.handler.impl.SimpleElementLayers; +import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.g2d.element.handler.impl.StaticSymbolImageInitializer; +import org.simantics.g2d.element.handler.impl.StaticSymbolImpl; +import org.simantics.g2d.element.handler.impl.TextColorImpl; +import org.simantics.g2d.element.handler.impl.TextFontImpl; +import org.simantics.g2d.element.handler.impl.TextImpl; +import org.simantics.g2d.image.Image; +import org.simantics.g2d.image.impl.ShapeImage; +import org.simantics.g2d.utils.Alignment; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.nodes.ShapeNode; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; +import org.simantics.utils.datastructures.hints.IHintListener; +import org.simantics.utils.datastructures.hints.IHintObservable; + + +public class ValveFactory extends SysdynElementFactory { + + public static final Key KEY_ROTATED = new KeyOf(Boolean.class, "ROTATED"); + + public static final double VALVE_SIZE = 2.5; + + private static final BasicStroke STROKE = new BasicStroke(1f); + public static final Image VALVE_STATIC_IMAGE = new ShapeImage(createShape(VALVE_SIZE, false), null, STROKE, true); + + /* (non-Javadoc) + * @see org.simantics.sysdyn.ui.elements2.SysdynElementFactory#compileElementClass(org.simantics.db.Resource, java.util.Collection) + */ + @Override + protected ElementClass compileElementClass(Resource elementType, Collection terminals) { + return ElementClass.compile( + SimpleElementLayers.INSTANCE, + OutlinePick.INSTANCE, + TextImpl.INSTANCE, + TextColorImpl.BLACK, + TextFontImpl.DEFAULT, + DefaultTransform.INSTANCE, + new StaticObjectAdapter(elementType), + new StaticSymbolImpl(VALVE_STATIC_IMAGE), + StaticSymbolImageInitializer.INSTANCE, + HoverImpl.INSTANCE, + ValveSceneGraph.INSTANCE, + BoundsOutline.INSTANCE, + Orientation.INSTANCE, + ValveTextLocation.INSTANCE, + new WholeElementTerminals(terminals) + ).setId(ValveFactory.class.getSimpleName()); + } + + @Override + public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException { + super.load(graph, canvas, diagram, element, e); + + SysdynResource sr = SysdynResource.getInstance(graph); + + Resource orientation = graph.getPossibleObject(element, sr.HasValveOrientation); + + String orientationText; + if(orientation != null && sr.Vertical.equals(orientation)) { + orientationText = "Vertical"; + } else { + orientationText = "Horizontal"; + } + SysdynElementUtils.setOrientation(e, orientationText); + + Resource location = graph.getPossibleObject(element, sr.HasTextLocation); + String locationText; + if(location == null || sr.Bottom.equals(location)) { + locationText = "Bottom"; + } else if(sr.Top.equals(location)) { + locationText = "Top"; + } else if(sr.Left.equals(location)) { + locationText = "Left"; + } else { + locationText = "Right"; + } + SysdynElementUtils.setValveTextLocation(e, locationText); + + } + + /** + * @param valveSize + * @param rotated true for vertical valve, false + * for horizontal + * @return + */ + private static Path2D createShape(double valveSize, boolean rotated) { + Path2D path = new Path2D.Double(); + path.moveTo(-valveSize, -valveSize); + if(rotated) { + path.lineTo(-valveSize, +valveSize); + path.lineTo(+valveSize, -valveSize); + } else { + path.lineTo(+valveSize, -valveSize); + path.lineTo(-valveSize, +valveSize); + } + path.lineTo(+valveSize, +valveSize); + path.closePath(); + return path; + } + + public static class ValveSceneGraph extends HoverTextElementNoBounds implements InternalSize, HandleMouseEvent { + + private static final long serialVersionUID = 5544256245734478634L; + + public static final ValveSceneGraph INSTANCE = new ValveSceneGraph(); + + private static final Key NODE = new SceneGraphNodeKey(ShapeNode.class, "VALVE_NODE"); + + private IHintListener hoverHintListener; + + public ValveSceneGraph() { +// super(0, VALVE_SIZE + 3.0, Alignment.CENTER); // Move with affine transformation in init() + super(0, 0, Alignment.CENTER); + } + @Override + public void init(IElement e, G2DParentNode parent) { + super.init(e, parent); + AffineTransform at = ElementUtils.getTransform(e); + final HoverShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "valve", HoverShapeNode.class); + + // Calculate borders from text node bounds. + node.setStroke(STROKE); + node.setScaleStroke(true); + node.setColor(Color.BLACK); + boolean rotated = false; + String orientation = SysdynElementUtils.getOrientation(e); + if(orientation != null && orientation.equals("Vertical")) + rotated = true; + node.setShape(createShape(VALVE_SIZE, Boolean.TRUE.equals(rotated))); + Boolean hover = e.getHint(ElementHints.KEY_HOVER); + node.setHover(hover != null ? hover : false); + + if(at != null) { + node.setTransform(at); + + TextNode name = (TextNode) e.getHint(SG_NODE); + if(name != null) { + + AffineTransform at2 = (AffineTransform) at.clone(); + Alignment alignment = null; + + String location = e.getHint(SysdynElementHints.KEY_LOCATION); + if(location != null) { + if(location.equals("Bottom")) { + at2.translate(0, VALVE_SIZE + 3.0); + } else if(location.equals("Top")) { + at2.translate(0, -VALVE_SIZE - 1); + } else if(location.equals("Left")) { + at2.translate(0, 0); + alignment = Alignment.TRAILING; + } else { + at2.translate(VALVE_SIZE + 1, 0); + alignment = Alignment.LEADING; + } + } + + name.setTransform(at2); + if(alignment != null) + name.setHorizontalAlignment((byte) alignment.ordinal()); + } + } + + hoverHintListener = new IHintListener() { + + @Override + public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { + + } + + @Override + public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { + IElement e = (IElement)sender; + HoverShapeNode shape = (HoverShapeNode) e.getHint(NODE); + if(shape == null) { + return; + } + boolean hover = ElementUtils.isHovering(e); + shape.setHover(hover); + } + }; + e.addHintListener(hoverHintListener); + } + + @Override + public void cleanup(IElement e) { + e.removeHintListener(hoverHintListener); + ElementUtils.removePossibleNode(e, NODE); + } + + @Override + public Rectangle2D getBounds(IElement e, Rectangle2D size) { + if (size == null) + size = new Rectangle2D.Double(); + size.setFrame(createShape(VALVE_SIZE, Boolean.TRUE.equals(e.getHint(KEY_ROTATED))).getBounds2D()); + double paddingX = 2.0; + double paddingY = 2.0; + size.setRect(size.getX() - paddingX, size.getY() -paddingY, size.getWidth() + paddingX + paddingX, size.getHeight() + paddingY + paddingY); + return size; + } + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveTextLocation.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveTextLocation.java new file mode 100644 index 00000000..8361eec8 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveTextLocation.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.ElementHandler; + +public class ValveTextLocation implements ElementHandler { + + private static final long serialVersionUID = 7123851901569461658L; + + public static final ValveTextLocation INSTANCE = new ValveTextLocation(); + + public String getTextLocation(IElement e) { + return e.getHint(SysdynElementHints.KEY_LOCATION); + } + + + public void setTextLocation(IElement e, String location) { + if (location != null) + e.setHint(SysdynElementHints.KEY_LOCATION, location); + else + e.removeHint(SysdynElementHints.KEY_LOCATION); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/WholeElementTerminals.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/WholeElementTerminals.java new file mode 100644 index 00000000..ed736449 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/WholeElementTerminals.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.Shape; +import java.util.Collection; + +import org.simantics.g2d.diagram.handler.Topology.Terminal; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.impl.ObjectTerminal; +import org.simantics.g2d.element.handler.impl.Terminals; + +/** + * @author Tuukka Lehtonen + */ +public class WholeElementTerminals extends Terminals { + + private static final long serialVersionUID = -8209833430671135001L; + + public WholeElementTerminals(Collection ts) { + super(ts); + } + + @Override + public Shape getTerminalShape(IElement node, Terminal t) { + // For each terminal, return the shape of the element. + return ElementUtils.getElementShapeOrBounds(node); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/Arcs.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/Arcs.java new file mode 100644 index 00000000..4994125f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/Arcs.java @@ -0,0 +1,211 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +import java.awt.geom.Rectangle2D; + +public class Arcs { + + public static final double PI2 = Math.PI*2.0; + + /** + * Returns angle + 2PI * n such that the + * result is between -PI and PI. + */ + public static double normalizeAngle(double angle) { + return Math.IEEEremainder(angle, PI2); + } + + /** + * Returns true, if three normalized angles are clockwise oriented. + */ + public static boolean areClockwiseOrdered(double angle1, double angle2, double angle3) { + //System.out.println(angle1 + " " + angle2 + " " + angle3); + return angle1 < angle2 + ? (angle2 < angle3 || angle3 < angle1) + : (angle2 < angle3 && angle3 < angle1) + ; + } + + /** + * Returns an angle in radians between straight line from (x0,y0) to (x2,y2) + * and an arc from (x0,y0) to (x2,y2) thru (x1,y1). The angle + * is measured at (x0,y0) and is between -PI and PI. + */ + public static double angleOfArc( + double x0, double y0, + double x1, double y1, + double x2, double y2) { + double dx0 = x1-x0; + double dy0 = y1-y0; + double dx1 = x1-x2; + double dy1 = y1-y2; + double dx = x2-x0; + double dy = y2-y0; + // Length of cross product (p1-p0)x(p2-p0) + double dd = dx0*dy - dy0*dx; + + if(Math.abs(dd) < 1e-6) // Points are (almost) collinear + return 0.0; + else { + // (p1-p0)*(p1-p2) / dd + double offset = (dx0*dx1 + dy0*dy1) / dd; + double angle = Math.PI*0.5 - Math.atan(offset); + if(dd > 0.0) + angle = angle-Math.PI; + return angle; + + } + } + + private static double updateBestNextAngle(double curAngle, double bestAngle, double newAngle) { + if(newAngle < curAngle) + newAngle += PI2; + if(newAngle < bestAngle) + return newAngle; + return bestAngle; + } + + private static double updateBestPrevAngle(double curAngle, double bestAngle, double newAngle) { + if(newAngle > curAngle) + newAngle -= PI2; + if(newAngle > bestAngle) + return newAngle; + return bestAngle; + } + + public static double nextIntersectingAngle(double cx, double cy, double r, + double curAngle, Rectangle2D rect, boolean dir) { + if(!dir) { + double bestAngle = curAngle + PI2; + { + double dx = rect.getMinX() - cx; + if(Math.abs(dx) < r) { + double angle = normalizeAngle(Math.acos(dx / r)); + bestAngle = updateBestNextAngle(curAngle, bestAngle, angle); + bestAngle = updateBestNextAngle(curAngle, bestAngle, -angle); + } + } + { + double dx = rect.getMaxX() - cx; + if(Math.abs(dx) < r) { + double angle = normalizeAngle(Math.acos(dx / r)); + bestAngle = updateBestNextAngle(curAngle, bestAngle, angle); + bestAngle = updateBestNextAngle(curAngle, bestAngle, -angle); + } + } + { + double dy = cy - rect.getMinY(); + if(Math.abs(dy) < r) { + double angle = Math.asin(dy / r); + bestAngle = updateBestNextAngle(curAngle, bestAngle, angle); + bestAngle = updateBestNextAngle(curAngle, bestAngle, + normalizeAngle(Math.PI-angle)); + } + } + { + double dy = cy - rect.getMaxY(); + if(Math.abs(dy) < r) { + double angle = Math.asin(dy / r); + bestAngle = updateBestNextAngle(curAngle, bestAngle, angle); + bestAngle = updateBestNextAngle(curAngle, bestAngle, + normalizeAngle(Math.PI-angle)); + } + } + return normalizeAngle(bestAngle); + } + else { + double bestAngle = curAngle - PI2; + { + double dx = rect.getMinX() - cx; + if(Math.abs(dx) < r) { + double angle = normalizeAngle(Math.acos(dx / r)); + bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle); + bestAngle = updateBestPrevAngle(curAngle, bestAngle, -angle); + } + } + { + double dx = rect.getMaxX() - cx; + if(Math.abs(dx) < r) { + double angle = normalizeAngle(Math.acos(dx / r)); + bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle); + bestAngle = updateBestPrevAngle(curAngle, bestAngle, -angle); + } + } + { + double dy = cy - rect.getMinY(); + if(Math.abs(dy) < r) { + double angle = Math.asin(dy / r); + bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle); + bestAngle = updateBestPrevAngle(curAngle, bestAngle, + normalizeAngle(Math.PI-angle)); + } + } + { + double dy = cy - rect.getMaxY(); + if(Math.abs(dy) < r) { + double angle = Math.asin(dy / r); + bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle); + bestAngle = updateBestPrevAngle(curAngle, bestAngle, + normalizeAngle(Math.PI-angle)); + } + } + return normalizeAngle(bestAngle); + } + } + + public static boolean hitTest(Rectangle2D beginBounds, Rectangle2D endBounds, double angle, double x, double y, double tolerance) { + + boolean clockWise = angle > 0; + + double x0 = beginBounds.getCenterX(); + double y0 = beginBounds.getCenterY(); + double x1 = endBounds.getCenterX(); + double y1 = endBounds.getCenterY(); + + double offset = + Math.abs(angle) < 1.0e-6 + ? 1e3 * Math.signum(angle) + : Math.tan(Math.PI*0.5-angle)*0.5; + double cx = 0.5*(x0+x1) + offset * (y1-y0); + double cy = 0.5*(y0+y1) + offset * (x0-x1); + double dx0 = x0 - cx; + double dy0 = y0 - cy; + double dx1 = x1 - cx; + double dy1 = y1 - cy; + double r = Math.sqrt(dx0*dx0 + dy0*dy0); + double angle0 = Arcs.nextIntersectingAngle(cx, cy, r, + Math.atan2(-dy0, dx0), beginBounds, angle < 0.0); + double angle1 = Arcs.nextIntersectingAngle(cx, cy, r, + Math.atan2(-dy1, dx1), endBounds, angle > 0.0); + + double dx = x-cx; + double dy = y-cy; + double dist = dx*dx + dy*dy; + +// System.out.println("HitTest: x0=" + x0 + " y0=" + y0 + " y=" + y + " x=" + x + " dist=" + dist + " r2=" + r*r); + + if(dist < (r+tolerance)*(r+tolerance) && + dist > (r-tolerance)*(r-tolerance)) { + double ang = Arcs.normalizeAngle(Math.atan2(-dy, dx)); +// System.out.println("test " + angle0 + " " + ang + " " + angle1); + if(Arcs.areClockwiseOrdered(angle0, ang, angle1) == clockWise) { +// System.out.println("hit"); + return true; + } + } + + return false; + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/ConnectionClasses.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/ConnectionClasses.java new file mode 100644 index 00000000..503bfa2f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/ConnectionClasses.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +public class ConnectionClasses { + + public static final Object CONNECTION = new Object() { + public String toString() { return "CONNECTION"; } + }; + + public static final Object FLAG = new Object() { + public String toString() { return "FLAG"; } + }; + + public static final Object FLOW = new Object() { + public String toString() { return "FLOW"; } + }; + + public static final Object DEPENDENCY = new Object() { + public String toString() { return "DEPENDENCY"; } + }; +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyConnectionFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyConnectionFactory.java new file mode 100644 index 00000000..e7bb25f4 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyConnectionFactory.java @@ -0,0 +1,219 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +import java.util.HashMap; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.concurrent.atomic.AtomicInteger; + +import org.simantics.databoard.Bindings; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncMultiProcedure; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.diagram.adapter.ElementFactoryAdapter; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.DiagramHints; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.editor.routing.DependencyRouter; +import org.simantics.utils.datastructures.Pair; + +/** + * An element class for single connection entity elements. A connection entity + * consists of connection edge segments and branch points as its children. + * + * @author Tuukka Lehtonen + */ +public class DependencyConnectionFactory extends ElementFactoryAdapter { + + public static final ElementClass CLASS = SysdynConnectionClass.CLASS; + + @Override + public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, final AsyncProcedure procedure) { + DiagramResource dr = graph.getService(DiagramResource.class); + graph.forSingleType(elementType, dr.Connection, new AsyncProcedure() { + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + procedure.exception(graph, throwable); + } + @Override + public void execute(AsyncReadGraph graph, Resource connectionType) { + procedure.execute(graph, SysdynConnectionClass.CLASS.newClassWith(false, new StaticObjectAdapter(connectionType))); + } + }); + } + + @Override + public void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, final Resource elementResource, + final IElement element, final AsyncProcedure procedure) { + + final AtomicInteger ready = new AtomicInteger(1); + final ConcurrentSkipListMap> properties = new ConcurrentSkipListMap>(); + + element.setHint(DiagramHints.ROUTE_ALGORITHM, new DependencyRouter()); + + graph.forEachPredicate(elementResource, new AsyncMultiProcedure() { + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public void execute(AsyncReadGraph graph, final Resource property) { + + ready.incrementAndGet(); + Layer0 l0; + ModelingResources mr; + try { + l0 = Layer0.getInstance(graph.getSession()); + mr = ModelingResources.getInstance(graph.getSession()); + } catch (DatabaseException e) { + e.printStackTrace(); + return; + } + graph.forIsSubrelationOf(property, l0.HasProperty, new AsyncProcedure() { + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public void execute(AsyncReadGraph graph, final Boolean isProperty) { + + if(isProperty) { + + graph.forPossibleRelatedValue(elementResource, property, new AsyncProcedure() { + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public void execute(AsyncReadGraph graph, final Object value) { + + Layer0 l0; + try { + l0 = Layer0.getInstance(graph.getSession()); + } catch (DatabaseException e) { + e.printStackTrace(); + return; + } + + graph.forPossibleRelatedValue(property, l0.HasName, Bindings.STRING, new AsyncProcedure() { + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public void execute(AsyncReadGraph graph, String name) { + + properties.put(name, Pair.make(property, value)); +// System.out.println("load properties " + name + " => " + value); + if(ready.decrementAndGet() == 0) { + element.setHint(DiagramHints.PROPERTIES, new HashMap>(properties)); + procedure.execute(graph, element); + } + + } + + }); + + } + + }); + + + } else { + + if(ready.decrementAndGet() == 0) { + element.setHint(DiagramHints.PROPERTIES, new HashMap>(properties)); + procedure.execute(graph, element); + } + + } + + } + + }); + + +// graph.forPossibleObject(elementResource, mr.DiagramConnectionToConnection, new AsyncProcedure() { +// +// @Override +// public void execute(AsyncReadGraph graph, Resource result) { +// SysdynResource sr; +// try { +// sr = SysdynResource.getInstance(graph.getSession()); +// } catch (DatabaseException e) { +// e.printStackTrace(); +// return; +// } +// graph.forPossibleRelatedValue(result, sr.Polarity, Bindings.STRING, new AsyncProcedure() { +// +// @Override +// public void exception(AsyncReadGraph graph, Throwable throwable) { +// throwable.printStackTrace(); +// } +// +// @Override +// public void execute(AsyncReadGraph graph, String name) { +// +// properties.put("polarity", Pair.make(property, (Object)name)); +//// System.out.println("load properties " + name + " => " + value); +// if(ready.decrementAndGet() == 0) { +// element.setHint(DiagramHints.PROPERTIES, new HashMap>(properties)); +// procedure.execute(graph, element); +// } +// +// } +// +// }); +// +// } +// +// @Override +// public void exception(AsyncReadGraph graph, Throwable throwable) { +// throwable.printStackTrace(); +// } +// +// }); + + } + + @Override + public void finished(AsyncReadGraph graph) { + + if(ready.decrementAndGet() == 0) { + element.setHint(DiagramHints.PROPERTIES, new HashMap(properties)); + procedure.execute(graph, element); + } + + } + + }); + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyEdgeClass.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyEdgeClass.java new file mode 100644 index 00000000..45d4e7ae --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyEdgeClass.java @@ -0,0 +1,250 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Font; +import java.awt.Shape; +import java.awt.Stroke; +import java.awt.geom.Path2D; +import java.awt.geom.Rectangle2D; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.HashMap; +import java.util.Map; + +import org.simantics.db.Resource; +import org.simantics.g2d.diagram.DiagramHints; +import org.simantics.g2d.diagram.DiagramMutator; +import org.simantics.g2d.diagram.DiagramUtils; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy; +import org.simantics.g2d.diagram.handler.Topology; +import org.simantics.g2d.diagram.handler.Topology.Connection; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementHints; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.SceneGraphNodeKey; +import org.simantics.g2d.element.handler.EdgeVisuals; +import org.simantics.g2d.element.handler.EdgeVisuals.EdgeEnd; +import org.simantics.g2d.element.handler.Pick; +import org.simantics.g2d.element.handler.SceneGraph; +import org.simantics.g2d.element.handler.TerminalLayout; +import org.simantics.g2d.element.handler.Transform; +import org.simantics.g2d.element.handler.impl.ConfigurableEdgeVisuals; +import org.simantics.g2d.element.handler.impl.ConnectionSelectionOutline; +import org.simantics.g2d.element.handler.impl.FillColorImpl; +import org.simantics.g2d.element.handler.impl.ParentImpl; +import org.simantics.g2d.element.handler.impl.SimpleElementLayers; +import org.simantics.g2d.element.handler.impl.TextColorImpl; +import org.simantics.g2d.element.handler.impl.TextFontImpl; +import org.simantics.g2d.element.handler.impl.TextImpl; +import org.simantics.g2d.elementclass.connection.EdgeClass.EdgeHandler; +import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform; +import org.simantics.g2d.utils.Alignment; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.utils.NodeUtil; +import org.simantics.sysdyn.ui.editor.routing.DependencyRouter; +import org.simantics.utils.datastructures.Callback; +import org.simantics.utils.datastructures.Pair; +import org.simantics.utils.datastructures.hints.IHintContext.Key; + +public class DependencyEdgeClass { + + public static class NodePick implements Pick { + + private static final long serialVersionUID = 1L; + + @Override + public boolean pickTest(IElement e, Shape s, PickPolicy policy) { + Rectangle2D pickRect = null; + if (s instanceof Rectangle2D) + pickRect = (Rectangle2D) s; + else + // FIXME: suboptimal, but works. + pickRect = s.getBounds2D(); + + DependencyNode node = e.getHint(SysdynEdgeSceneGraph.KEY_SG_NODE); + if(node == null) { + System.out.println("pickTest no node!"); + return false; + } + return Arcs.hitTest(node.getBeginBounds(), node.getEndBounds(), node.getAngle(), pickRect.getCenterX(), pickRect.getCenterY(), 3.0); + + } + + } + + // TODO scale, rotate, move, transform + public static final ElementClass CLASS = + ElementClass.compile( + SysdynEdgeSceneGraph.INSTANCE, + EdgeHandler.INSTANCE, + ConfigurableEdgeVisuals.DEFAULT, + FillColorImpl.BLACK, + FixedTransform.INSTANCE, + TextImpl.INSTANCE, + TextColorImpl.BLACK, + TextFontImpl.DEFAULT, + new NodePick(), + ConnectionSelectionOutline.INSTANCE, + SimpleElementLayers.INSTANCE, + ParentImpl.INSTANCE + ).setId("EdgeClass.STRAIGHT"); + + public static class SysdynEdgeSceneGraph implements SceneGraph { + + private static final long serialVersionUID = 2914383071126238996L; + + public static final SysdynEdgeSceneGraph INSTANCE = new SysdynEdgeSceneGraph(); + + public static final Stroke ARROW_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); + + public static final Key KEY_SG_NODE = new SceneGraphNodeKey(DependencyNode.class, "EDGE_NODE"); + + @Override + public void init(IElement e, G2DParentNode parent) { + DependencyNode node = ElementUtils.getOrCreateNode(e, parent, KEY_SG_NODE, "edge_" + e.hashCode(), DependencyNode.class); + + Font font = ElementUtils.getTextFont(e); + Color color = ElementUtils.getTextColor(e); + + HashMap properties = e.getHint(DiagramHints.PROPERTIES); + Pair polarityPair = (Pair)properties.get("Polarity"); + Pair polarityLocationPair = (Pair)properties.get("PolarityLocation"); + + String location; + if(polarityLocationPair == null) + location = DependencyNode.INSIDE; + else + location = (String) polarityLocationPair.second; + + if(polarityPair != null) + node.init((String) polarityPair.second, location, font, color, 0, 0, 0.235); + + update(e); + } + + @Override + public void cleanup(IElement e) { + ElementUtils.removePossibleNode(e, KEY_SG_NODE); + } + + public void update(final IElement e) { + + DependencyNode node = e.getHint(KEY_SG_NODE); + if(node == null) return; + final IDiagram diagram = ElementUtils.peekDiagram(e); + + node.setFieldListener(new PropertyChangeListener() { + + @Override + public void propertyChange(final PropertyChangeEvent event) { + + String field = event.getPropertyName(); + Map> properties = e.getHint(DiagramHints.PROPERTIES); + if(properties == null) return; + final Pair property = properties.get(field); + if(property == null) return; + + DiagramUtils.mutateDiagram(diagram, new Callback() { + + @Override + public void run(DiagramMutator mutator) { + mutator.modifyProperty(e, property.first, event.getNewValue()); + } + + }); + + } + + }); + + + + Shape beginTerminalShape = null; + Shape endTerminalShape = null; + if (diagram != null) { + Topology topology = diagram.getDiagramClass().getAtMostOneItemOfClass(Topology.class); + if (topology != null) { + Connection beginConnection = topology.getConnection(e, EdgeEnd.Begin); + Connection endConnection = topology.getConnection(e, EdgeEnd.End); + beginTerminalShape = getCanvasTerminalShape(beginConnection); + endTerminalShape = getCanvasTerminalShape(endConnection); + } + } + + if(beginTerminalShape == null || endTerminalShape == null) return; + + EdgeVisuals vh = e.getElementClass().getSingleItem(EdgeVisuals.class); + Stroke stroke = vh.getStroke(e); + Font font = ElementUtils.getTextFont(e); + Color color = ElementUtils.getTextColor(e); +// Color fillColor = ElementUtils.getFillColor(e); + Color borderColor = ElementUtils.getBorderColor(e, Color.BLACK); +// String text = ElementUtils.getText(e); + Alignment hAlign = ElementUtils.getHintOrDefault(e, ElementHints.KEY_HORIZONTAL_ALIGN, Alignment.CENTER); + node.setBackgroundColor(null); + node.setBorderColor(borderColor); + node.setHorizontalAlignment((byte) hAlign.ordinal()); + node.setPadding(0, 0); + node.setBorderWidth((float) 0); + node.setEditable(false); + node.setFont(font); + + node.setBeginBounds(beginTerminalShape.getBounds2D()); + node.setEndBounds(endTerminalShape.getBounds2D()); + node.setStroke(stroke); + node.setColor(color); + node.setShapes(DependencyRouter.createArrowShape(node.getShapes(), node.getBeginBounds(), node.getEndBounds(), node.getAngle())); + + Map> properties = e.getHint(DiagramHints.PROPERTIES); + if(properties != null) { + for(Map.Entry> entry : properties.entrySet()) { + NodeUtil.setPropertyIfSupported(entry.getKey(), entry.getValue().second, node); +// node.setProperty(entry.getKey(), entry.getValue().second); +// System.out.println("setProperty " + entry.getKey() + " => " + entry.getValue().second); + } + } + EdgeHandler eh = e.getElementClass().getAtMostOneItemOfClass(EdgeHandler.class); + Path2D path = eh.getPath(e); + if(path == null) + path = new Path2D.Double(); + else + path.reset(); + path.append(node.getShapes().first, false); + eh.setPath(e, path); + + } + + private static Shape getCanvasTerminalShape(Connection connection) { + if (connection != null && connection.node != null && connection.terminal != null) { + TerminalLayout layout = connection.node.getElementClass().getAtMostOneItemOfClass(TerminalLayout.class); + if (layout != null) { + //return layout.getTerminalShape(connection.node, connection.terminal); + Shape shp = layout.getTerminalShape(connection.node, connection.terminal); + Transform tr = connection.node.getElementClass().getAtMostOneItemOfClass(Transform.class); + if (tr == null) + return shp; + + return tr.getTransform(connection.node).createTransformedShape(shp); + + } + } + return null; + } + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyEdgeFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyEdgeFactory.java new file mode 100644 index 00000000..998bbc42 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyEdgeFactory.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.diagram.adapter.ElementFactoryAdapter; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementClass; + +/** + * An element class factory for sysdyn dependency connection edge segments. + * + * @author Tuukka Lehtonen + */ +public class DependencyEdgeFactory extends ElementFactoryAdapter { + + private static final ElementClass CLASS = DependencyEdgeClass.CLASS; + + @Override + public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, + AsyncProcedure procedure) { + procedure.execute(graph, CLASS); + } + + @Override + public void getClass(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, + AsyncProcedure procedure) { + throw new UnsupportedOperationException(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyNode.java new file mode 100644 index 00000000..529ca158 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyNode.java @@ -0,0 +1,285 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.Stroke; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.geom.Arc2D; +import java.awt.geom.Path2D; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import org.simantics.diagram.elements.TextNode; +import org.simantics.scenegraph.ISelectionPainterNode; +import org.simantics.scenegraph.g2d.events.ISGMouseEvent; +import org.simantics.scenegraph.utils.NodeUtil; +import org.simantics.sysdyn.ui.editor.routing.DependencyRouter; +import org.simantics.utils.datastructures.Pair; + +public class DependencyNode extends TextNode implements ISelectionPainterNode, MouseListener, MouseMotionListener { + + public static final String INSIDE = "Inside"; + public static final String OUTSIDE = "Outside"; + + private static final long serialVersionUID = 1294351381209071074L; + + private static final BasicStroke STROKE = new BasicStroke(1.0f); + + private Color color; + private Stroke stroke; + private Rectangle2D beginBounds; + private Rectangle2D endBounds; + private double angle = 0.1; + private String side; + private transient Pair shapes = new Pair(new Arc2D.Double(), new Path2D.Double()); + + transient public boolean hover = false; + + private transient PropertyChangeListener fieldListener = null; + + @Override + public void init() { + super.init(); + NodeUtil.getEventDelegator(this).addMouseListener(this); + NodeUtil.getEventDelegator(this).addMouseMotionListener(this); + } + + + public void init(String text, String side, Font font, Color color, double x, double y, double scale) { + super.init(text, font, color, x, y, scale); + this.side = side; + } + + @Override + public void cleanup() { + NodeUtil.getEventDelegator(this).removeMouseListener(this); + NodeUtil.getEventDelegator(this).removeMouseMotionListener(this); + super.cleanup(); + } + + public void setFieldListener(PropertyChangeListener listener) { + this.fieldListener = listener; + } + + @ServerSide + public void commitProperty(String field, Object value) { + if(fieldListener != null) { + fieldListener.propertyChange(new PropertyChangeEvent(this, field, null, value)); + } + } + + @PropertySetter("color") + @SyncField("color") + public void setColor(Color color) { + this.color = color; + } + + @PropertySetter("stroke") + @SyncField("stroke") + public void setStroke(Stroke stroke) { + this.stroke = stroke; + } + + @PropertySetter("beginBounds") + @SyncField("beginBounds") + public void setBeginBounds(Rectangle2D beginBounds) { + this.beginBounds = beginBounds; + } + + @PropertySetter("endBounds") + @SyncField("endBounds") + public void setEndBounds(Rectangle2D endBounds) { + this.endBounds = endBounds; + } + + @PropertySetter("angle") + @SyncField("angle") + public void setAngle(Double angle) { + this.angle = angle.doubleValue(); + if(this.beginBounds != null && this.endBounds != null) + this.shapes = DependencyRouter.createArrowShape(this.shapes, this.beginBounds, this.endBounds, this.angle); + } + + @PropertySetter("shapes") + @SyncField("shapes") + public void setShapes(Pair shapes) { + this.shapes = shapes; + } + + public Color getColor() { + return color; + } + + public Stroke getStroke() { + return stroke; + } + + public Rectangle2D getBeginBounds() { + return beginBounds; + } + + public Rectangle2D getEndBounds() { + return endBounds; + } + + public double getAngle() { + return angle; + } + + public Pair getShapes() { + return shapes; + } + + + + @Override + public void render(Graphics2D g) { + if(beginBounds == null || endBounds == null) return; + + // Removed to let the global control handle rendering quality issues. + //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + + boolean selected = NodeUtil.isSelected(this, 2); + if(selected) { + g.setColor(Color.PINK); + g.setStroke(STROKE); + g.draw(shapes.first); + g.fill(shapes.second); + if(color != null) g.setColor(color); + g.setStroke(stroke); + g.draw(shapes.first); + g.fill(shapes.second); + } else if (hover){ + g.setColor(Color.LIGHT_GRAY); + g.setStroke(STROKE); + g.draw(shapes.first); + g.fill(shapes.second); + if(color != null) g.setColor(color); + g.setStroke(stroke); + g.draw(shapes.first); + g.fill(shapes.second); + } else { + if(color != null) g.setColor(color); + if(stroke != null) g.setStroke(stroke); + g.draw(shapes.first); + g.fill(shapes.second); + } + + + double angleRad = angle > 0 ? + Math.toRadians(shapes.first.getAngleStart() + shapes.first.getAngleExtent()) : + Math.toRadians(shapes.first.getAngleStart()); + Point2D point = angle > 0 ? shapes.first.getEndPoint() : shapes.first.getStartPoint(); + + int angle1 = 225; + int angle2 = -75; + if(OUTSIDE.equals(side)) { + angle1 *= -1; + angle2 *= -1; + } + double a = Math.toRadians(angle < 0 ? angle1 : angle2); + double s = Math.sin(a) * 2; + double c = Math.cos(a) * 3; + + g.translate(point.getX(), point.getY()); + g.rotate(-angleRad); + g.translate(s, c); + g.rotate(angleRad); + super.render(g); + g.rotate(-angleRad); + g.translate(-s, -c); + g.rotate(angleRad); + g.translate(-point.getX(), -point.getY()); + + } + + boolean pressHit = false; + + private boolean hitTest(MouseEvent event, double tolerance) { + if(event instanceof ISGMouseEvent) { + if(beginBounds == null || endBounds == null) return false; + + return Arcs.hitTest(beginBounds, endBounds, angle, ((ISGMouseEvent)event).getDoubleX(), ((ISGMouseEvent)event).getDoubleY(), tolerance); + } else { + return false; + } + } + + @Override + public Rectangle2D getBoundsInLocal() { + return null; + } + + @Override + public void mouseDragged(MouseEvent e) { + if(pressHit && e instanceof ISGMouseEvent) { + setAngle(Arcs.angleOfArc( + beginBounds.getCenterX(), beginBounds.getCenterY(), + ((ISGMouseEvent)e).getDoubleX(), ((ISGMouseEvent)e).getDoubleY(), + endBounds.getCenterX(), endBounds.getCenterY())); + } + } + + @Override + public void mouseMoved(MouseEvent e) { + boolean hit = hitTest(e, 3.0); + if(hit != hover) { + hover = hit; + repaint(); + } + } + + @Override + public void mouseClicked(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mousePressed(MouseEvent e) { + boolean hit = hitTest(e, 3.0); + pressHit = hit; + if(hit) { + commitProperty("angle", angle); + } + + } + + @Override + public void mouseReleased(MouseEvent e) { + boolean hit = hitTest(e, 3.0); + if(hit) { + commitProperty("angle", angle); + } + } + + @Override + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowArrowLineStyle.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowArrowLineStyle.java new file mode 100644 index 00000000..ca2f0921 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowArrowLineStyle.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Path2D; +import java.awt.geom.Rectangle2D; +import java.io.Serializable; +import java.util.StringTokenizer; + +import org.simantics.diagram.connection.rendering.arrows.ILineEndStyle; + + +/** + * Copied from ArrowLLineEndStyle + */ +public class FlowArrowLineStyle implements ILineEndStyle, Serializable { + + private static final long serialVersionUID = 5348566089660986479L; + + public static enum ArrowType { None, Stroke, Fill } + + public static final double length = 8.0; + public static final double width = 4.0; + public static final double space = 0.0; + + protected ArrowType type; + protected Path2D path; + protected double lineEndLength; + + protected Rectangle2D bounds = new Rectangle2D.Double(); + + public FlowArrowLineStyle(String desc, Rectangle2D bounds) { + this.type = ArrowType.None; + this.lineEndLength = 0.0; + + double l = length; + double w = width; + double s = space; + this.bounds = bounds; + + StringTokenizer tokenizer = new StringTokenizer(desc); + if (tokenizer.hasMoreTokens()) { + String type = tokenizer.nextToken(); + this.type = parseType(type); + + if (tokenizer.hasMoreTokens()) { + String ls = tokenizer.nextToken(); + l = parseSize(ls, length); + + if (tokenizer.hasMoreTokens()) { + String ws = tokenizer.nextToken(); + w = parseSize(ws, width); + + if (tokenizer.hasMoreTokens()) { + String ss = tokenizer.nextToken(); + s = parseSize(ss, space); + } + } + } + if (this.type != ArrowType.None) { + this.path = arrow(l, w, s); + lineEndLength = l+s; + } + } + } + + @Override + public void render(Graphics2D g, double x, double y, int dir) { + if (type == ArrowType.None || path == null) + return; + // Calculate coordinates to the border of the terminal + switch(dir) { + case 0: + x = bounds.getMinX(); + break; + case 1: + y = bounds.getMinY(); + break; + case 2: + x = bounds.getMaxX(); + break; + case 3: + y = bounds.getMaxY(); + break; + default: + return; + } + AffineTransform old = g.getTransform(); + g.translate(x, y); + g.rotate(dir*Math.PI*0.5); + g.setColor(Color.BLACK); + + switch (type) { + case Fill: + g.fill(path); + break; + case Stroke: + g.draw(path); + break; + } + + g.setTransform(old); + } + + @Override + public double getLineEndLength(int direction) { + switch(direction) { + case 0: + lineEndLength = bounds.getWidth() / 2.0; + break; + case 1: + lineEndLength = bounds.getHeight() / 2.0; + break; + case 2: + lineEndLength = bounds.getWidth() / 2.0; + break; + case 3: + lineEndLength = bounds.getHeight() / 2.0; + break; + } + return lineEndLength; + } + + private static Path2D arrow(double length, double width, double space) { + Path2D.Double path = new Path2D.Double(); + path.moveTo(-space, 0); + path.lineTo(-length-space, -width); + path.lineTo(-length-space, +width); + path.closePath(); + return path; + } + + private double parseSize(String size, double defaultValue) { + try { + return Double.parseDouble(size); + } catch (NumberFormatException e) { + return defaultValue; + } + } + + private ArrowType parseType(String type) { + String lower = type.toLowerCase(); + if ("none".equals(lower)) + return ArrowType.None; + if ("stroke".equals(lower)) + return ArrowType.Stroke; + if ("fill".equals(lower)) + return ArrowType.Fill; + throw new IllegalArgumentException("unrecognized arrow type: " + type); + } + + @Override + public String toString() { + return getClass().getSimpleName() + "[" + type + ", " + path + "]"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowConnectionFactoryOld.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowConnectionFactoryOld.java new file mode 100644 index 00000000..40d3e080 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowConnectionFactoryOld.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.diagram.adapter.ElementFactoryAdapter; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.DiagramHints; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.g2d.elementclass.connection.ConnectionClass; +import org.simantics.sysdyn.ui.editor.routing.FlowRouter; + +/** + * An element class for single connection entity elements. A connection entity + * consists of connection edge segments and branch points as its children. + * + * @author Tuukka Lehtonen + */ +public class FlowConnectionFactoryOld extends ElementFactoryAdapter { + + public static final ElementClass CLASS = SysdynConnectionClass.CLASS; + + @Override + public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, final AsyncProcedure procedure) { + DiagramResource dr = graph.getService(DiagramResource.class); + graph.forSingleType(elementType, dr.Connection, new AsyncProcedure() { + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + procedure.exception(graph, throwable); + } + @Override + public void execute(AsyncReadGraph graph, Resource connectionType) { + procedure.execute(graph, ConnectionClass.CLASS.newClassWith(false, new StaticObjectAdapter(connectionType))); + } + }); + } + + @Override + public void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, + final IElement element, final AsyncProcedure procedure) { + element.setHint(DiagramHints.ROUTE_ALGORITHM, new FlowRouter(false)); + procedure.execute(graph, element); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowConnectionStyle.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowConnectionStyle.java new file mode 100644 index 00000000..90da81ed --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowConnectionStyle.java @@ -0,0 +1,54 @@ +package org.simantics.sysdyn.ui.elements2.connections; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Stroke; +import java.awt.geom.Path2D; + +import org.simantics.diagram.connection.rendering.BasicConnectionStyle; + +public class FlowConnectionStyle extends BasicConnectionStyle { + + private static final long serialVersionUID = 2777194644079591357L; + + Color lineColor; + Stroke lineStroke; + + public FlowConnectionStyle(Color lineColor, Stroke lineStroke) { + super(lineColor, Color.BLACK, 0.5, lineStroke, lineStroke, 0.8); + this.lineColor = lineColor; + this.lineStroke = lineStroke; + } + + @Override + public void drawBranchPoint(Graphics2D g, double x, double y) { + } + + @Override + public void drawLine(Graphics2D g, double x1, double y1, double x2, double y2, boolean isTransient) { + System.out.println("DrawLine"); + } + + @Override + public void drawPath(Graphics2D g, Path2D path, boolean isTransient) { + if (lineColor != null) + g.setColor(lineColor); + if (lineStroke != null) + g.setStroke(lineStroke); + + Path2D p1 = Flows.createOffsetPath(path, 1); + Path2D p2 = Flows.createOffsetPath(path, -1); + p1.append(p2, false); + g.draw(p1); + } + + @Override + public void drawDegeneratedLine(Graphics2D g, double x, double y, boolean isHorizontal, boolean isTransient) { + } + + @Override + public double getDegeneratedLineLength() { + return 0; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeClassOld.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeClassOld.java new file mode 100644 index 00000000..c04f747a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeClassOld.java @@ -0,0 +1,413 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +import java.awt.Color; +import java.awt.Stroke; +import java.awt.geom.AffineTransform; +import java.awt.geom.GeneralPath; +import java.awt.geom.Path2D; +import java.awt.geom.PathIterator; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.simantics.g2d.diagram.DiagramHints; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.diagram.handler.Topology; +import org.simantics.g2d.diagram.handler.Topology.Connection; +import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.BendsHandler; +import org.simantics.g2d.element.handler.EdgeVisuals; +import org.simantics.g2d.element.handler.EdgeVisuals.ArrowType; +import org.simantics.g2d.element.handler.EdgeVisuals.EdgeEnd; +import org.simantics.g2d.element.handler.impl.ConfigurableEdgeVisuals; +import org.simantics.g2d.element.handler.impl.ConnectionSelectionOutline; +import org.simantics.g2d.element.handler.impl.FillColorImpl; +import org.simantics.g2d.element.handler.impl.ParentImpl; +import org.simantics.g2d.element.handler.impl.ShapePick; +import org.simantics.g2d.element.handler.impl.SimpleElementLayers; +import org.simantics.g2d.elementclass.BranchPoint; +import org.simantics.g2d.elementclass.connection.EdgeClass.EdgeHandler; +import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform; +import org.simantics.g2d.elementclass.connection.EdgeSceneGraph; +import org.simantics.g2d.routing.Constants; +import org.simantics.g2d.routing.IRouter2; +import org.simantics.g2d.utils.PathUtils; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.nodes.EdgeNode; +import org.simantics.sysdyn.ui.editor.participant.SysdynConnectTool.SysdynConnection; +import org.simantics.sysdyn.ui.editor.routing.FlowRouter; +import org.simantics.sysdyn.ui.elements2.ValveFactory.ValveSceneGraph; + +public class FlowEdgeClassOld { + + // TODO scale, rotate, move, transform + public static final ElementClass CLASS = ElementClass.compile( + FlowEdgeSceneGraph.INSTANCE, EdgeHandler.INSTANCE, + ConfigurableEdgeVisuals.DEFAULT, FillColorImpl.BLACK, + FixedTransform.INSTANCE, ShapePick.INSTANCE, + ConnectionSelectionOutline.INSTANCE, SimpleElementLayers.INSTANCE, + ParentImpl.INSTANCE).setId("FlowEdgeClass"); + + public static class FlowEdgeSceneGraph extends EdgeSceneGraph { + + private static final long serialVersionUID = -8737581995034992604L; + + public static final EdgeSceneGraph INSTANCE = new FlowEdgeSceneGraph(); + + @Override + public void init(IElement e, G2DParentNode parent) { + ElementUtils.getOrCreateNode(e, parent, KEY_SG_NODE, + "edge_" + e.hashCode(), FlowEdgeNodeOld.class); + final IDiagram diagram = ElementUtils.peekDiagram(e); + + boolean toValve = false; + if (diagram != null) { + Topology topology = diagram.getDiagramClass() + .getAtMostOneItemOfClass(Topology.class); + if (topology != null) { + Connection endConnection = topology.getConnection(e, + EdgeEnd.End); + toValve = endConnection.node.getElementClass() + .containsClass(ValveSceneGraph.class); + } + } + + ConfigurableEdgeVisuals cev = e.getElementClass() + .getAtMostOneItemOfClass(ConfigurableEdgeVisuals.class); + if (cev != null) { + if (toValve) + cev.setArrowType(e, EdgeEnd.End, ArrowType.None); + else { + cev.setArrowType(e, EdgeEnd.End, ArrowType.Fill); + cev.setArrowSize(e, EdgeEnd.End, 2); + } + } + + updateRoute(e); + update(e); + + } + + private static Path2D trimLineToArrows(Path2D line, + ArrowType endArrowType, double endArrowSize) { + Path2D result = new Path2D.Double(); + PathIterator pi = line.getPathIterator(null); + + double lineTo[] = new double[2]; + double prevLine[] = new double[2]; + double dummy[] = new double[2]; + + while (!pi.isDone()) { + int type = pi.currentSegment(lineTo); + pi.next(); + int nextType = pi.currentSegment(dummy); + + if (type == PathIterator.SEG_LINETO + && nextType == PathIterator.SEG_MOVETO) { + // this is the end of one line + if (endArrowType == ArrowType.Fill) { + double dx = (lineTo[0] - prevLine[0]); + double dy = (lineTo[1] - prevLine[1]); + double x2 = dx * dx; + double y2 = dy * dy; + double len = Math.sqrt(x2 + y2); + if (len > endArrowSize) { + double scale = endArrowSize / len; + lineTo[0] -= dx * scale; + lineTo[1] -= dy * scale; + } + } + } + + if (type == 0) { + result.moveTo(lineTo[0], lineTo[1]); + } else if (type == 1) { + result.lineTo(lineTo[0], lineTo[1]); + } else { + throw new UnsupportedOperationException( + "invalid path segment type: " + type); + } + prevLine[0] = lineTo[0]; + prevLine[1] = lineTo[1]; + + } + + result.setWindingRule(line.getWindingRule()); + return result; + } + + private void updateRoute(final IElement e) { + + final List segments = new ArrayList(); + segments.add(e); + + IRouter2 router = ElementUtils.getHintOrDefault(e, + DiagramHints.ROUTE_ALGORITHM, new FlowRouter()); + + router.route(new SysdynConnection() { + + IDiagram diagram = ElementUtils.peekDiagram(e); + + final Topology topology = diagram.getDiagramClass() + .getSingleItem(Topology.class); + + @Override + public Connector getBegin(Object seg) { + IElement e = (IElement) seg; + Connection begin = topology.getConnection(e, EdgeEnd.Begin); + return getConnector(begin); + } + + @Override + public Connector getEnd(Object seg) { + IElement e = (IElement) seg; + Connection end = topology.getConnection(e, EdgeEnd.End); + return getConnector(end); + } + + private Connector getConnector(Connection connection) { + Connector c = new Connector(); + c.allowedDirections = Constants.EAST_FLAG | Constants.WEST_FLAG + | Constants.NORTH_FLAG | Constants.SOUTH_FLAG; + + AffineTransform at = TerminalUtil.getTerminalPosOnDiagram( + connection.node, connection.terminal); + c.x = at.getTranslateX(); + c.y = at.getTranslateY(); + + if (connection.node.getElementClass().containsClass( + ValveSceneGraph.class)) { + Rectangle2D bounds = ElementUtils + .getElementBoundsOnDiagram(connection.node) + .getBounds2D(); + c.parentObstacle = new Rectangle2D.Double(bounds + .getCenterX() - FlowRouter.OFFSET, bounds + .getCenterY() - FlowRouter.OFFSET, + FlowRouter.OFFSET * 2, FlowRouter.OFFSET * 2); + c.allowedDirections = Constants.EAST_FLAG | Constants.WEST_FLAG; + } else { + c.parentObstacle = ElementUtils + .getElementBoundsOnDiagram(connection.node) + .getBounds2D(); + + } + + return c; + } + + private int toAllowedDirections(BranchPoint.Direction direction) { + switch (direction) { + case Any: + return 0xf; + case Horizontal: + return Constants.EAST_FLAG | Constants.WEST_FLAG; + case Vertical: + return Constants.NORTH_FLAG | Constants.SOUTH_FLAG; + default: + throw new IllegalArgumentException( + "unrecognized direction: " + direction); + } + } + + @Override + public Collection getSegments() { + return segments; + } + + @Override + public void setPath(Object seg, Path2D path) { + IElement e = (IElement) seg; + BendsHandler bends = e.getElementClass() + .getAtMostOneItemOfClass(BendsHandler.class); + AffineTransform elementTransform = ElementUtils + .getInvTransform(e); + path = (Path2D) path.clone(); + path.transform(elementTransform); + bends.setPath(e, path); + } + }); + + } + + public void update(final IElement e) { + EdgeNode node = e.getHint(KEY_SG_NODE); + if (node == null) + return; + + EdgeVisuals vh = e.getElementClass().getSingleItem( + EdgeVisuals.class); + ArrowType at1 = vh.getArrowType(e, EdgeEnd.Begin); + ArrowType at2 = vh.getArrowType(e, EdgeEnd.End); + Stroke stroke = vh.getStroke(e); + // StrokeType strokeType = vh.getStrokeType(e); + double as1 = vh.getArrowSize(e, EdgeEnd.Begin); + double as2 = vh.getArrowSize(e, EdgeEnd.End); + + Color c = ElementUtils.getFillColor(e, Color.BLACK); + + // Get terminal shape for clipping the painted edge to its bounds. + IDiagram diagram = ElementUtils.peekDiagram(e); + if (diagram != null) { + Topology topology = diagram.getDiagramClass() + .getAtMostOneItemOfClass(Topology.class); + if (topology != null) { + Connection beginConnection = topology.getConnection(e, + EdgeEnd.Begin); + Connection endConnection = topology.getConnection(e, + EdgeEnd.End); + int beginBranchDegree = getBranchPointDegree( + beginConnection, topology); + int endBranchDegree = getBranchPointDegree(endConnection, + topology); + if (beginBranchDegree > 0 && beginBranchDegree < 3) { + at1 = ArrowType.None; + } + if (endBranchDegree > 0 && endBranchDegree < 3) { + at2 = ArrowType.None; + } + } + } + + // Read bends + BendsHandler bh = e.getElementClass().getSingleItem( + BendsHandler.class); + Path2D line = bh.getPath(e); + + boolean drawArrows = at1 != ArrowType.None || at2 != ArrowType.None; + // line = clipLineEnds(line, beginTerminalShape, endTerminalShape); + + Point2D first = new Point2D.Double(); + Point2D dir1 = new Point2D.Double(); + Point2D last = new Point2D.Double(); + Point2D dir2 = new Point2D.Double(); + PathIterator pi = line.getPathIterator(null); + drawArrows &= getPathArrows(pi, first, dir1, last, dir2); + + if (drawArrows) { + line = trimLineToArrows(line, at2, as2); + } + + EdgeNode.ArrowType pat1 = convert(at1); + EdgeNode.ArrowType pat2 = convert(at2); + + node.init(new GeneralPath(line), stroke, c, dir1, dir2, first, + last, as1, as2, pat1, pat2, null, null); + } + + private boolean getPathArrows(PathIterator pi, Point2D begin, + Point2D beginDirection, Point2D end, Point2D endDirection) { + + Iterator i = PathUtils.toLineIterator(pi); + + double first1[] = null, last1[] = null; + double first2[] = null, last2[] = null; + + // double current[] = new double[2]; + + double[] previous = null; + + while (i.hasNext()) { + double[] current = i.next(); + + // Start of the first path + if (first1 == null) { + first1 = current; + last1 = current; + } + + // Command was moveTo => start of the second path + else if (previous != null + && (previous[2] != current[0] || previous[3] != current[1])) { + first2 = current; + last2 = current; + } + + // first2 == null => still in the first line + else if (first2 == null) { + last1 = current; + } + + // second path + else if (!i.hasNext()) { + last2 = current; + } + + previous = current; + } + + if (first1 == null || last1 == null || first2 == null + || last2 == null) + return false; + + double[] first = { mean(first1[0], first2[0]), + mean(first1[1], first2[1]), mean(first1[2], first2[2]), + mean(first1[3], first2[3]) }; + double[] last = { mean(last1[0], last2[0]), + mean(last1[1], last2[1]), mean(last1[2], last2[2]), + mean(last1[3], last2[3]) }; + + begin.setLocation(PathUtils.getLinePos(first, 0)); + beginDirection.setLocation(PathUtils.getLineTangent(first, 0)); + end.setLocation(PathUtils.getLinePos(last, 1)); + Point2D endTangent = PathUtils.getLineTangent(last, 1); + endDirection.setLocation(-endTangent.getX(), -endTangent.getY()); + + return true; + } + + private double mean(double c1, double c2) { + return c1 + (c2 - c1) / 2; + } + + private static EdgeNode.ArrowType convert(ArrowType at) { + switch (at) { + case None: + return EdgeNode.ArrowType.None; + case Stroke: + return EdgeNode.ArrowType.Stroke; + case Fill: + return EdgeNode.ArrowType.Fill; + default: + throw new IllegalArgumentException("unsupported arrow type: " + + at); + } + } + + private final Collection connectionsTemp = new ArrayList(); + + private int getBranchPointDegree(Connection connection, + Topology topology) { + if (connection != null && connection.node != null) { + if (connection.node.getElementClass().containsClass( + BranchPoint.class)) { + connectionsTemp.clear(); + topology.getConnections(connection.node, + connection.terminal, connectionsTemp); + int degree = connectionsTemp.size(); + connectionsTemp.clear(); + return degree; + } + } + return -1; + } + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeFactoryOld.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeFactoryOld.java new file mode 100644 index 00000000..ae6eee98 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeFactoryOld.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.diagram.adapter.ElementFactoryAdapter; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementClass; + +/** + * An element class factory for sysdyn flow connection edge segments. + * + * @author Tuukka Lehtonen + */ +public class FlowEdgeFactoryOld extends ElementFactoryAdapter { + + private static final ElementClass CLASS = FlowEdgeClassOld.CLASS; + + @Override + public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, + AsyncProcedure procedure) { + procedure.execute(graph, CLASS); + } + + @Override + public void getClass(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, + AsyncProcedure procedure) { + throw new UnsupportedOperationException(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeNodeOld.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeNodeOld.java new file mode 100644 index 00000000..81143035 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeNodeOld.java @@ -0,0 +1,78 @@ +package org.simantics.sysdyn.ui.elements2.connections; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Stroke; +import java.awt.geom.AffineTransform; +import java.awt.geom.GeneralPath; + +import org.simantics.scenegraph.ISelectionPainterNode; +import org.simantics.scenegraph.g2d.nodes.EdgeNode; +import org.simantics.scenegraph.utils.NodeUtil; + +public class FlowEdgeNodeOld extends EdgeNode implements ISelectionPainterNode { + + private static final long serialVersionUID = -6774653631527343539L; + + private static final BasicStroke SELECTION_STROKE = new BasicStroke(1.0f); + + @Override + public void render(Graphics2D g) { + if(color != null) g.setColor(color); + if(stroke == null || shape == null) return; + + if(alphaComposite != null) { + g.setComposite(alphaComposite); + } + + Stroke effectiveStroke = stroke; + if(dynamicStroke != null) { + effectiveStroke = dynamicStroke; + } + + Color effectiveColor = color; + if(dynamicColor != null) { + effectiveColor = dynamicColor; + } + + g.setStroke(effectiveStroke); + + // Draw line + boolean selected = NodeUtil.isSelected(this, 2); + if(selected) { + g.setColor(Color.PINK); + g.setStroke(SELECTION_STROKE); + g.draw(shape); + } + g.setColor(effectiveColor); + g.setStroke(effectiveStroke); + g.draw(shape); + + // Draw the ending arrow if necessary + if(last_at == ArrowType.Fill) { + AffineTransform at = g.getTransform(); + + g.setStroke(ARROW_STROKE); + + double theta = Math.atan2(lastdir.getY(), lastdir.getX()) - Math.PI/2; + g.translate(last.getX(), last.getY()); + g.rotate(theta); + g.scale(lastsize, lastsize); + g.fill(FLOW_ARROW); + g.setTransform(at); + } + + } + + public transient final static GeneralPath FLOW_ARROW; + + static { + FLOW_ARROW = new GeneralPath(); + FLOW_ARROW.moveTo(-1f, 1.6f); + FLOW_ARROW.lineTo( 0f, 0f); + FLOW_ARROW.lineTo( 1f, 1.6f); + FLOW_ARROW.closePath(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowNodeOld.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowNodeOld.java new file mode 100644 index 00000000..4f69a765 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowNodeOld.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Stroke; +import java.awt.geom.Path2D; +import java.awt.geom.Rectangle2D; + +import org.simantics.scenegraph.ISelectionPainterNode; +import org.simantics.scenegraph.g2d.G2DNode; +import org.simantics.scenegraph.utils.NodeUtil; + +public class FlowNodeOld extends G2DNode implements ISelectionPainterNode { + + private static final long serialVersionUID = 328942356917631237L; + + private static final BasicStroke STROKE = new BasicStroke(1.0f); + + private Color color; + private Stroke stroke; + private Rectangle2D beginBounds; + private Rectangle2D endBounds; + private Path2D lines; + private Path2D arrow; + + @PropertySetter("color") + @SyncField("color") + public void setColor(Color color) { + this.color = color; + } + + @PropertySetter("stroke") + @SyncField("stroke") + public void setStroke(Stroke stroke) { + this.stroke = stroke; + } + + @PropertySetter("beginBounds") + @SyncField("beginBounds") + public void setBeginBounds(Rectangle2D beginBounds) { + this.beginBounds = beginBounds; + } + + @PropertySetter("endBounds") + @SyncField("endBounds") + public void setEndBounds(Rectangle2D endBounds) { + this.endBounds = endBounds; + } + + @PropertySetter("lines") + @SyncField("lines") + public void setLines(Path2D lines) { + this.lines = lines; + } + + @PropertySetter("arrow") + @SyncField("arrow") + public void setArrow(Path2D arrow) { + this.arrow = arrow; + } + + public Color getColor() { + return color; + } + + public Stroke getStroke() { + return stroke; + } + + public Rectangle2D getBeginBounds() { + return beginBounds; + } + + public Rectangle2D getEndBounds() { + return endBounds; + } + + public Path2D getLines() { + return lines; + } + + public Path2D getArrow() { + return arrow; + } + + @Override + public void render(Graphics2D g) { + // Removed to let the global control handle rendering quality issues. + //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + + /* + * There are two cases, first is from Stock|Cloud to Valve and second is from Valve to Stock|Cloud + * -In the first case there is no arrow and valve is endBounds + * -In the second case there is an arrow and valve is beginBounds + */ + + boolean selected = NodeUtil.isSelected(this, 2); + if(selected) { + g.setColor(Color.PINK); + g.setStroke(STROKE); + g.draw(lines); + if(color != null) g.setColor(color); + g.setStroke(stroke); + if(lines!= null) g.draw(lines); + if(arrow != null) g.fill(arrow); + } else { + if(color != null) g.setColor(color); + if(stroke != null) g.setStroke(stroke); + if(lines!= null) g.draw(lines); + if(arrow != null) g.fill(arrow); + } + + + } + + @Override + public Rectangle2D getBoundsInLocal() { + return null; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/Flows.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/Flows.java new file mode 100644 index 00000000..051b3b18 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/Flows.java @@ -0,0 +1,257 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +import java.awt.geom.Path2D; +import java.awt.geom.PathIterator; +import java.awt.geom.Rectangle2D; + +public class Flows { + + public static double ARROW_LENGTH = 3.2; + public static double ARROW_WIDTH = 2; + + static final double OFFSET = 1.0; + static final double ARROW_OFFSET = 3.2; + + public static Path2D createArrow(Path2D arrow, Rectangle2D tail, Rectangle2D head) { + + double x = tail.getCenterX(); + double y = tail.getCenterY(); + + double cx = head.getCenterX(); + double minx = head.getMinX(); + double maxx = head.getMaxX(); + double miny = head.getMinY(); + double maxy = head.getMaxY(); + + if(arrow == null) + arrow = new Path2D.Double(); + else + arrow.reset(); + + // approach from top + if (y < miny) { + arrow.moveTo(cx, miny); + arrow.lineTo(cx + ARROW_WIDTH, miny - ARROW_LENGTH); + arrow.lineTo(cx - ARROW_WIDTH, miny - ARROW_LENGTH); + } + + // approach from beneath + else if (y > maxy) { + arrow.moveTo(cx, maxy); + arrow.lineTo(cx + ARROW_WIDTH, maxy + ARROW_LENGTH); + arrow.lineTo(cx - ARROW_WIDTH, maxy + ARROW_LENGTH); + } + + // approach from left + else if (x < minx) { + arrow.moveTo(minx, y); + arrow.lineTo(minx - ARROW_LENGTH, y - ARROW_WIDTH); + arrow.lineTo(minx - ARROW_LENGTH, y + ARROW_WIDTH); + } + + // approach from right + else if (x > maxx) { + arrow.moveTo(maxx, y); + arrow.lineTo(maxx + ARROW_LENGTH, y - ARROW_WIDTH); + arrow.lineTo(maxx + ARROW_LENGTH, y + ARROW_WIDTH); + } + else + return null; // FIXME (HN) This is just a quick bugfix, didn't understand the logic completely + + arrow.closePath(); + + return arrow; + + } + + private static Path2D createLines(Path2D lines, boolean vertical, double ... coordinates) { + if(lines == null) + lines = new Path2D.Double(); + else + lines.reset(); + createOffsetLine(lines, vertical, OFFSET, coordinates); + createOffsetLine(lines, vertical, -OFFSET, coordinates); + return lines; + } + + public static Path2D createLines(Path2D lines, boolean hasArrow, Rectangle2D valve, Rectangle2D node) { + double x0 = valve.getCenterX(); + double y0 = valve.getCenterY(); + double x1 = node.getCenterX(); + double y1 = node.getCenterY(); + + double minY = hasArrow ? node.getMinY() - ARROW_OFFSET : node.getMinY(); + double maxY = hasArrow ? node.getMaxY() + ARROW_OFFSET : node.getMaxY(); + double minX = hasArrow ? node.getMinX() - ARROW_OFFSET : node.getMinX(); + double maxX = hasArrow ? node.getMaxX() + ARROW_OFFSET : node.getMaxX(); + + boolean rotated = false; + + if( rotated ) { + if(y1 > y0) + y0 += OFFSET; + else + y0 -= OFFSET; + if(node.getMinX() <= x0 && node.getMaxX() >= x0) { + if(y1 > y0) + return createLines(lines, true, y0, x0, minY); + else + return createLines(lines, true, y0, x0, maxY); + } + else { + if(x1 > x0) + return createLines(lines, true, y0, x0, y1, minX); + else + return createLines(lines, true, y0, x0, y1, maxX); + } + } + else { + if(x1 > x0) + x0 += OFFSET; + else + x0 -= OFFSET; + if(node.getMinY() <= y0 && node.getMaxY() >= y0) { + if(x1 > x0) + return createLines(lines, false, x0, y0, minX); + else + return createLines(lines, false, x0, y0, maxX); + } + else { + if(y1 > y0) + return createLines(lines, false, x0, y0, x1, minY); + else + return createLines(lines, false, x0, y0, x1, maxY); + } + } + + + } + + public static Path2D createLine(Path2D path, boolean vertical, double ... coordinates) { + if(vertical) + path.moveTo(coordinates[1], coordinates[0]); + else + path.moveTo(coordinates[0], coordinates[1]); + for(int i=2;i procedure) { + SysdynResource sr = graph.getService(SysdynResource.class); + graph.forSingleType(elementType, sr.FlowConnection, new AsyncProcedure() { + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + procedure.exception(graph, throwable); + } + @Override + public void execute(AsyncReadGraph graph, Resource connectionType) { + procedure.execute(graph, CLASS.newClassWith(false, new StaticObjectAdapter(connectionType))); + } + }); + } + + @Override + public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource connection, + IElement element) throws DatabaseException { + + // Do we need this? + element.setHint(DiagramHints.ROUTE_ALGORITHM, new Router4(false)); + + IModelingRules modelingRules = diagram.getHint(DiagramModelHints.KEY_MODELING_RULES); + + IElement mappedElement = ElementUtils.getByData(diagram, connection); + if (mappedElement == null) + // FIXME: With undo this seems to happen, don't know why yet! + return; + + RouteGraph rg = new RouteGraph(); + + Set nodes = new HashSet(); + Set links = new HashSet(); + Map nodeByData = new HashMap(); + + // Needed to support ConnectionEntity#getTerminalConnections + Set backendonnections = new HashSet(); + + // Load all route graph interior RouteNodes: route lines and points + for (Resource interiorNode : graph.getObjects(connection, DIA.HasInteriorRouteNode)) { + if (graph.isInstanceOf(interiorNode, DIA.RouteLine)) { + Boolean isHorizontal = graph.getRelatedValue(interiorNode, DIA.IsHorizontal, Bindings.BOOLEAN); + Double position = graph.getRelatedValue(interiorNode, DIA.HasPosition, Bindings.DOUBLE); + RouteLine line = rg.addLine(isHorizontal, position); + line.setData( RouteGraphConnection.serialize(graph, interiorNode) ); + + nodes.add( interiorNode ); + nodeByData.put( interiorNode, line ); + + for (Resource connectedTo : graph.getObjects(interiorNode, DIA.AreConnected)) { + links.add( new EdgeResource(interiorNode, connectedTo) ); + } + } else if (graph.isInstanceOf(interiorNode, DIA.RoutePoint)) { + // Not supported yet. Ignore. + } + } + + Rectangle2D bounds = new Rectangle2D.Double(); + + // Load all node terminal connections as RouteTerminals + for (Statement toConnector : graph.getStatements(connection, DIA.HasConnector)) { + Resource connector = toConnector.getObject(); + Resource attachmentRelation = toConnector.getPredicate(); + + Statement terminalStm = findTerminalStatement(graph, STR, connection, connector); + if (terminalStm == null) + // Ignore broken connector: attached to the connection but not to any terminal. + continue; + + Resource terminalElement = terminalStm.getObject(); + Resource terminalElementType = graph.getPossibleType(terminalElement, DIA.Element); + if (terminalElementType == null) + // Ignore non-element terminal elements + continue; + + Resource connectionRelation = graph.getInverse(terminalStm.getPredicate()); + + // Discover node and terminal this connector is connected to. + TerminalMap terminals = graph.syncRequest(DiagramRequests.elementTypeTerminals(terminalElementType), + TransientCacheListener. instance()); + Resource terminal = terminals.getTerminal(connectionRelation); + if (terminal == null) { + System.err.println(getClass().getSimpleName() + + ": Could not find terminal for connection point " + + NameUtils.getSafeName(graph, connectionRelation, true) + + " in element " + + NameUtils.getSafeName(graph, terminalElement, true)); + continue; + } + + double[] position = graph.getRelatedValue(connector, DIA.HasRelativeLocation, Bindings.DOUBLE_ARRAY); + if (position.length != 2) + position = new double[] { 0, 0 }; + + //System.out.println("terminalStm: " + NameUtils.toString(graph, terminalStm)); + AffineTransform terminalElementTr = getWorldTransform(graph, terminalElement); + + double x = terminalElementTr.getTranslateX(); + double y = terminalElementTr.getTranslateY(); + double minx = x-1, miny = y-1, maxx = x+1, maxy = y+1; + int direction = 0x0; + + // Use modelingRules to ascertain the proper attachmentRelation + // for this terminal connection, if available. + if (modelingRules != null) { + // Get attachmentRelation from modelingRules if possible. + IAttachmentRelationMap map = modelingRules.getAttachmentRelations(graph, connection); + Resource att = map.get(graph, new CPTerminal(terminalElement, terminal)); + if (att != null) { + //System.out.println("modeling rules attachment: " + NameUtils.getSafeLabel(graph, att)); + attachmentRelation = att; + } + } + //System.out.println("attachment: " + NameUtils.getSafeLabel(graph, attachmentRelation)); + + // Get element bounds to decide allowed terminal direction(s) + IElement te = graph.syncRequest(DiagramRequests.getElement(canvas, diagram, terminalElement, null)); + + ElementUtils.getElementBounds(te, bounds); + + { + Shape shp = org.simantics.g2d.utils.GeometryUtils.transformShape(bounds, terminalElementTr); + bounds.setFrame(shp.getBounds2D()); + } + + // Valve behaves differently. The flow must start inside the valve bounds + if(te.getElementClass().containsClass(ValveSceneGraph.class)) { + bounds.setFrame(new Rectangle2D.Double(bounds.getCenterX() - 1, bounds.getCenterY() - 1, 2, 2)); + } + + x = bounds.getCenterX(); + y = bounds.getCenterY(); + + // Expand bounds by 4mm to make the connections enter the terminals + // at a straight angle and from a distance instead of coming in + // "horizontally". + GeometryUtils.expandRectangle(bounds, 4); + + minx = bounds.getMinX(); + miny = bounds.getMinY(); + maxx = bounds.getMaxX(); + maxy = bounds.getMaxY(); + + + Integer allowedDirections = graph.getPossibleRelatedValue(terminal, DIA.Terminal_AllowedDirections, Bindings.INTEGER); + + // Valve behaves differently. Allowed directions depend on the orientation of the valve + if(te.getElementClass().containsClass(ValveSceneGraph.class)) { + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.hasStatement(terminalElement, sr.HasValveOrientation, sr.Vertical)) { + allowedDirections = 10; // Directions up and down (1010) + } else { + allowedDirections = 5; // Directions left and right (0101) + } + } + if (allowedDirections != null) { + direction |= allowedDirections; + } else { + direction |= RouteGraphConnectionClass.shortestDirectionOutOfBounds(x, y, bounds); + } + + backendonnections.add( + new BackendConnection( + toEdgeEnd(graph, attachmentRelation, EdgeEnd.Begin), + terminalElement, + terminal) + ); + + if (direction == 0) + // Accept any horizontal/vertical direction if nothing is defined + direction = 0xf; + + //System.out.println("load line style: " + NameUtils.getSafeLabel(graph, attachmentRelation)); + ILineEndStyle endStyle = loadLineEndStyle(graph, te, attachmentRelation, new Rectangle2D.Double( + bounds.getX(), + bounds.getY(), + bounds.getWidth(), + bounds.getHeight()) + ); + + RouteTerminal routeTerminal = rg.addTerminal(x, y, minx, miny, maxx, maxy, direction, endStyle); + routeTerminal.setData( RouteGraphConnection.serialize(graph, connector) ); + + nodes.add( connector ); + nodeByData.put( connector, routeTerminal ); + + for (Resource connectedTo : graph.getObjects(connector, DIA.AreConnected)) { + links.add( new EdgeResource(connectedTo, connector) ); + } + } + + // Finish route graph loading by Linking route nodes together + for (EdgeResource link : links) { + RouteNode n1 = nodeByData.get(link.first()); + RouteNode n2 = nodeByData.get(link.second()); + if (n1 == null || n2 == null) { + System.err.println("Stray connection link found: " + link.toString(graph)); + continue; + } + rg.link(n1, n2); + } + + // Load connection line style + ConnectionStyle style = readConnectionStyle(graph, modelingRules, connection, element); + StyledRouteGraphRenderer renderer = new StyledRouteGraphRenderer(style); + + // Finish element load + element.setHint(RouteGraphConnectionClass.KEY_ROUTEGRAPH, rg); + element.setHint(RouteGraphConnectionClass.KEY_RENDERER, renderer); + element.setHint(RouteGraphConnectionClass.KEY_PICK_TOLERANCE, 0.5); + + // Initialize ConnectionEntity in element + // NOTE: MUST use the mapped element with class CE, not the connection (element) were loading into. + // GDS will synchronize element into mappedElement in a controlled manner. + element.setHint(ElementHints.KEY_CONNECTION_ENTITY, new CE(connection, mappedElement, backendonnections)); + + // Setup graph writeback support for route graph modifications + final Session session = graph.getSession(); + element.setHint(RouteGraphConnectionClass.KEY_RG_LISTENER, new IRouteGraphListener() { + @Override + public void routeGraphChanged(RouteGraphChangeEvent event) { + scheduleSynchronize(session, connection, event); + } + }); + } + + private EdgeEnd toEdgeEnd(ReadGraph graph, Resource attachmentRelation, EdgeEnd defaultValue) + throws DatabaseException { + if (graph.isSubrelationOf(attachmentRelation, DIA.IsTailConnectorOf)) + return EdgeEnd.Begin; + if (graph.isSubrelationOf(attachmentRelation, DIA.IsHeadConnectorOf)) + return EdgeEnd.End; + return defaultValue; + } + + private ConnectionStyle readConnectionStyle(ReadGraph graph, IModelingRules modelingRules, Resource connection, + IElement element) throws DatabaseException { + Resource connectionType = null; + if (modelingRules != null) + connectionType = modelingRules.getConnectionType(graph, connection); + if (connectionType == null) + connectionType = graph.getPossibleObject(connection, STR.HasConnectionType); + + ConnectionVisuals cv = null; + if (connectionType != null) + cv = graph.syncRequest(DiagramRequests.getConnectionVisuals(connectionType), + TransientCacheListener. instance()); + + Color lineColor = cv != null ? cv.toColor() : null; + if (lineColor == null) + lineColor = Color.DARK_GRAY; + Stroke lineStroke = cv != null ? cv.stroke : null; + if (lineStroke == null) + lineStroke = new BasicStroke(0.1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10, null, 0); + + return new FlowConnectionStyle( + lineColor, + lineStroke); + } + + /** + * @param graph + * @param STR + * @param connection + * @param connector + * @return connection relation statement from diagram connection connector + * to a node + * @throws DatabaseException + */ + private static Statement findTerminalStatement(ReadGraph graph, StructuralResource2 STR, Resource connection, + Resource connector) throws DatabaseException { + for (Statement stm : graph.getStatements(connector, STR.Connects)) { + if (connection.equals(stm.getObject())) + continue; + return stm; + } + return null; + } + + public ILineEndStyle loadLineEndStyle(ReadGraph graph, IElement te, Resource attachmentRelation, Rectangle2D bounds) + throws DatabaseException { + ILineEndStyle style; + // TODO: change bounds according to terminal type: Very small rectangle for Valves, Text box size for Stocks and Clouds + if(te.getElementClass().containsClass(ValveSceneGraph.class)) { + GeometryUtils.expandRectangle(bounds, -4); + style = new FlowArrowLineStyle("none 0 0 0", bounds); + } else { + if (graph.isSubrelationOf(attachmentRelation, DIA.HasHeadConnector)) { + GeometryUtils.expandRectangle(bounds, -2.5); + style = new FlowArrowLineStyle("fill 2 2 -1.5", bounds); + } else { + GeometryUtils.expandRectangle(bounds, -4); + style = new FlowArrowLineStyle("none 0 0 0", bounds); + } + } + return style; + } + + /** + * @param graph + * @param element + * @return + * @throws DatabaseException + */ + private static AffineTransform getWorldTransform(ReadGraph graph, Resource element) throws DatabaseException { + ModelingResources MOD = ModelingResources.getInstance(graph); + AffineTransform result = DiagramGraphUtil.getAffineTransform(graph, element); + while (true) { + Resource parentComponent = graph.getPossibleObject(element, MOD.HasParentComponent); + if (parentComponent == null) + return result; + element = graph.getPossibleObject(parentComponent, MOD.ComponentToElement); + if (element == null) + return result; + AffineTransform tr = DiagramGraphUtil.getAffineTransform(graph, element); + tr.setToTranslation(tr.getTranslateX(), tr.getTranslateY()); + result.preConcatenate(tr); + } + } + + + protected void scheduleSynchronize(Session session, Resource connection, RouteGraphChangeEvent event) { + session.asyncRequest(RouteGraphConnection.synchronizer(connection, event)); + } + + /** + * Must have this in order for {@link TopologicalSelectionExpander} to work. + * Otherwise this is pretty useless and should be deprecated altogether. + * + * @see ElementHints#KEY_CONNECTION_ENTITY + */ + static class CE implements ConnectionEntity { + + /** + * The connection instance resource in the graph backend. + */ + final Resource connection; + + /** + * The connection entity element which is a part of the diagram. + */ + final IElement connectionElement; + + /** + * @see #getTerminalConnections(Collection) + */ + final Set backendConnections; + + /** + * Cache. + */ + Set terminalConnections; + + CE(Resource connection, IElement connectionElement, Set backendConnections) { + this.connection = connection; + this.connectionElement = connectionElement; + this.backendConnections = backendConnections; + } + + @Override + public IElement getConnection() { + return connectionElement; + } + + public Object getConnectionObject() { + return connection; + } + + public IElement getConnectionElement() { + return connectionElement; + } + + @Override + public Collection getBranchPoints(Collection result) { + return result != null ? result : Collections. emptyList(); + } + + @Override + public Collection getSegments(Collection result) { + return result != null ? result : Collections. emptyList(); + } + + @Override + public Collection getTerminalConnections(Collection result) { + if (terminalConnections == null) + terminalConnections = calculateTerminalConnections(); + if (result == null) + result = new ArrayList(terminalConnections); + else + result.addAll(terminalConnections); + return terminalConnections; + } + + private Set calculateTerminalConnections() { + IDiagram diagram = connectionElement.getDiagram(); + DataElementMap dem = diagram.getDiagramClass().getSingleItem(DataElementMap.class); + Set result = new HashSet(); + ArrayList ts = new ArrayList(); + for (BackendConnection bc : backendConnections) { + IElement e = dem.getElement(diagram, bc.node); + if (e == null) + continue; + TerminalTopology tt = e.getElementClass().getSingleItem(TerminalTopology.class); + tt.getTerminals(e, ts); + for (Terminal t : ts) { + if (t instanceof ResourceTerminal) { + ResourceTerminal rt = (ResourceTerminal) t; + if (bc.terminal.equals(rt.getResource())) { + result.add(new Connection(connectionElement, bc.end, e, t)); + break; + } + } + } + } + return result; + } + + @Override + public void setListener(ConnectionListener listener) { + throw new UnsupportedOperationException(); + } + + @Override + public String toString() { + return getClass().getSimpleName() + "[resource=" + connection + ", connectionElement=" + connectionElement + + "]"; + } + + } + + public static class BackendConnection { + public final Resource node; + public final Resource terminal; + public final EdgeEnd end; + public BackendConnection(EdgeEnd end, Resource node, Resource terminal) { + assert end != null; + assert node != null; + assert terminal != null; + this.end = end; + this.node = node; + this.terminal = terminal; + } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof Connection)) + return false; + Connection other = (Connection) obj; + return other.terminal == terminal + && other.node == node + && other.end == end; + } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + end.hashCode(); + result = prime * result + ((node == null) ? 0 : node.hashCode()); + result = prime * result + ((terminal == null) ? 0 : terminal.hashCode()); + return result; + } + @Override + public String toString() { + return "BackendConnection[node=" + node + ", terminal=" + terminal + ", end=" + end + "]"; + } + } + +} + diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/RouteFlowEdgeClass.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/RouteFlowEdgeClass.java new file mode 100644 index 00000000..638e3177 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/RouteFlowEdgeClass.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +import java.util.ArrayList; +import java.util.List; + +import org.simantics.diagram.connection.RouteGraph; +import org.simantics.diagram.connection.RouteGraphConnectionClass; +import org.simantics.diagram.connection.rendering.IRouteGraphRenderer; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.ElementHandler; +import org.simantics.g2d.element.handler.SceneGraph; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.nodes.connection.IRouteGraphListener; +import org.simantics.scenegraph.g2d.nodes.connection.RouteGraphNode; + + + +public class RouteFlowEdgeClass extends RouteGraphConnectionClass { + + public static final ElementClass FLOW_CLASS = getElementClass(); + + + public static final ElementClass getElementClass() { + List oldList = CLASS.getAll(); + ArrayList list = new ArrayList(); + list.add(FlowConnectionSceneGraph.INSTANCE); + for(ElementHandler eh : oldList) { + if(!(eh instanceof SceneGraph)) { + list.add(eh); + } + } + return ElementClass.compile(list); + } + + + static final class FlowConnectionSceneGraph implements SceneGraph { + + public static final FlowConnectionSceneGraph INSTANCE = new FlowConnectionSceneGraph(); + + private static final long serialVersionUID = 1865920472882420644L; + + @Override + public void init(IElement connection, G2DParentNode parent) { + RouteGraph rg = connection.getHint(KEY_ROUTEGRAPH); + IRouteGraphRenderer renderer = connection.getHint(KEY_RENDERER); + if (rg == null || renderer == null) { + cleanup(connection); + } else { + RouteGraphNode rgn = connection.getHint(KEY_RG_NODE); + if (rgn == null) { + rgn = parent.addNode(ElementUtils.generateNodeId(connection), RouteGraphNode.class); + connection.setHint(KEY_RG_NODE, rgn); + } + rgn.setRouteGraph(rg); + rgn.setRenderer(renderer); + + IRouteGraphListener listener = connection.getHint(KEY_RG_LISTENER); + rgn.setRouteGraphListener(listener); + + Double tolerance = connection.getHint(KEY_PICK_TOLERANCE); + if (tolerance != null) + rgn.setPickTolerance(tolerance); + } + } + + @Override + public void cleanup(IElement connection) { + ElementUtils.removePossibleNode(connection, KEY_RG_NODE); + connection.removeHint(KEY_RG_NODE); + } + } + +} + + diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/RouteFlowEdgeFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/RouteFlowEdgeFactory.java new file mode 100644 index 00000000..8ee7934b --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/RouteFlowEdgeFactory.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.diagram.adapter.ElementFactoryAdapter; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementClass; + +public class RouteFlowEdgeFactory extends ElementFactoryAdapter { + + private static final ElementClass CLASS = RouteFlowEdgeClass.FLOW_CLASS; + + @Override + public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, + AsyncProcedure procedure) { + procedure.execute(graph, CLASS); + } + + @Override + public void getClass(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, + AsyncProcedure procedure) { + throw new UnsupportedOperationException(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/SysdynConnectionClass.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/SysdynConnectionClass.java new file mode 100644 index 00000000..ed1fc608 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/SysdynConnectionClass.java @@ -0,0 +1,557 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.connections; + +import java.awt.Composite; +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.Area; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.simantics.db.Resource; +import org.simantics.g2d.connection.ConnectionEntity; +import org.simantics.g2d.connection.ConnectionEntity.ConnectionEvent; +import org.simantics.g2d.connection.ConnectionEntity.ConnectionListener; +import org.simantics.g2d.connection.handler.ConnectionHandler; +import org.simantics.g2d.diagram.DiagramHints; +import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy; +import org.simantics.g2d.diagram.handler.Topology.Connection; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementHints; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.Children; +import org.simantics.g2d.element.handler.InternalSize; +import org.simantics.g2d.element.handler.Outline; +import org.simantics.g2d.element.handler.Pick; +import org.simantics.g2d.element.handler.Pick2; +import org.simantics.g2d.element.handler.SceneGraph; +import org.simantics.g2d.element.handler.SelectionOutline; +import org.simantics.g2d.element.handler.Transform; +import org.simantics.g2d.element.handler.impl.ConnectionSelectionOutline; +import org.simantics.g2d.element.handler.impl.ParentImpl; +import org.simantics.g2d.element.handler.impl.SimpleElementLayers; +import org.simantics.g2d.element.handler.impl.TextImpl; +import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform; +import org.simantics.g2d.utils.GeometryUtils; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.IG2DNode; +import org.simantics.scenegraph.g2d.nodes.SingleElementNode; +import org.simantics.utils.datastructures.ListenerList; +import org.simantics.utils.datastructures.Pair; +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; + +/** + * An element class for single connection entity elements. A sysdyn connection + * entity consists of a single edge. Sysdyn connections can't be branched. + * + * @author Tuukka Lehtonen + */ +public class SysdynConnectionClass { + + public static final ElementClass CLASS = + ElementClass.compile( + TextImpl.INSTANCE, + FixedTransform.INSTANCE, + ConnectionPick.INSTANCE, + ConnectionBounds.INSTANCE, + ConnectionSelectionOutline.INSTANCE, + ConnectionHandlerImpl.INSTANCE, + ConnectionChildren.INSTANCE, + ParentImpl.INSTANCE, + ConnectionSceneGraph.INSTANCE, + SimpleElementLayers.INSTANCE + ).setId(SysdynConnectionClass.class.getSimpleName()); + + private static class ThreadLocalList extends ThreadLocal> { + @Override + protected java.util.List initialValue() { + return new ArrayList(); + } + }; + + private static final ThreadLocal> perThreadSceneGraphList = new ThreadLocalList(); + private static final ThreadLocal> perThreadBoundsList = new ThreadLocalList(); + private static final ThreadLocal> perThreadShapeList = new ThreadLocalList(); + private static final ThreadLocal> perThreadPickList = new ThreadLocalList(); + + static class ConnectionHandlerImpl implements ConnectionHandler { + + public static final ConnectionHandlerImpl INSTANCE = new ConnectionHandlerImpl(); + + private static final long serialVersionUID = 3267139233182458330L; + + @Override + public Collection getBranchPoints(IElement connection, Collection result) { + ConnectionEntity entity = connection.getHint(ElementHints.KEY_CONNECTION_ENTITY); + if (entity == null) + return Collections.emptySet(); + return entity.getBranchPoints(result); + } + + @Override + public Collection getChildren(IElement connection, Collection result) { + ConnectionEntity entity = connection.getHint(ElementHints.KEY_CONNECTION_ENTITY); + if (entity == null) + return Collections.emptySet(); + result = entity.getSegments(result); + return entity.getBranchPoints(result); + } + + @Override + public Collection getSegments(IElement connection, Collection result) { + ConnectionEntity entity = connection.getHint(ElementHints.KEY_CONNECTION_ENTITY); + if (entity == null) + return Collections.emptySet(); + return entity.getSegments(result); + } + + @Override + public Collection getTerminalConnections(IElement connection, Collection result) { + ConnectionEntity entity = connection.getHint(ElementHints.KEY_CONNECTION_ENTITY); + if (entity == null) + return Collections.emptySet(); + return entity.getTerminalConnections(result); + } + } + + static final class ConnectionSceneGraph implements SceneGraph { + + public static final ConnectionSceneGraph INSTANCE = new ConnectionSceneGraph(); + + private static final long serialVersionUID = 4232871859964883266L; + + @Override + public void init(IElement connection, G2DParentNode parent) { + ConnectionEntity ce = connection.getHint(ElementHints.KEY_CONNECTION_ENTITY); + if (ce == null) + return; + + // Painting is single-threaded, it is OK to use a single thread-local collection here. + List children = perThreadSceneGraphList.get(); + children.clear(); + ce.getSegments(children); + ce.getBranchPoints(children); + //new Exception("painting connection entity " + ce.hashCode() + " with " + children.size() + " segments and branch points").printStackTrace(); + if (children.isEmpty()) + return; + + Set tmp = new HashSet(); + + Map> properties = connection.getHint(DiagramHints.PROPERTIES); + + int zIndex = 0; + for (IElement child : children) { + + ElementClass ec = child.getElementClass(); + + Transform transform = child.getElementClass().getSingleItem(Transform.class); + assert (transform != null); + AffineTransform at2 = transform.getTransform(child); + if (at2 == null) + continue; + + if(properties != null) + child.setHint(DiagramHints.PROPERTIES, properties); + + SingleElementNode holder = child.getHint(ElementHints.KEY_SG_NODE); + if (holder == null) { + holder = parent.addNode(ElementUtils.generateNodeId(child), SingleElementNode.class); + child.setHint(ElementHints.KEY_SG_NODE, holder); + } + holder.setZIndex(++zIndex); + + Composite composite = child.getHint(ElementHints.KEY_COMPOSITE); + + holder.setTransform((AffineTransform) at2.clone()); + holder.setComposite(composite); + holder.setVisible(true); + + // New node handler + for (SceneGraph n : ec.getItemsByClass(SceneGraph.class)) { + n.init(child, holder); + } + tmp.add(holder); + } + + // Hide unaccessed nodes (but don't remove) + for (IG2DNode node : parent.getNodes()) { + if (node instanceof SingleElementNode) { + if (!tmp.contains(node)) { + ((SingleElementNode)node).setVisible(false); + } + } else { + //System.out.println("WHAT IS THIS: "); + //NodeDebug.printSceneGraph(((Node) node)); + } + } + + // Don't leave dangling references behind. + children.clear(); + } + + @Override + public void cleanup(IElement e) { + } + } + + static final class ConnectionBounds implements InternalSize, Outline { + + public static final ConnectionBounds INSTANCE = new ConnectionBounds(); + + private static final long serialVersionUID = 4232871859964883266L; + + @Override + public Rectangle2D getBounds(IElement e, Rectangle2D size) { + ConnectionEntity ce = e.getHint(ElementHints.KEY_CONNECTION_ENTITY); + if (ce == null) + return size; + + Collection parts = perThreadBoundsList.get(); + parts.clear(); + parts = ce.getSegments(parts); + if (parts.isEmpty()) + return size; + + parts = ce.getBranchPoints(parts); + + Rectangle2D temp = null; + for (IElement part : parts) { + if (ElementUtils.isHidden(part)) + continue; + + // Using on-diagram coordinates because neither connections nor + // edges have a non-identity transform which means that + // coordinates are always absolute. Therefore branch point + // bounds also need to be calculated in absolute coordinates. + Rectangle2D bounds = ElementUtils.getElementBoundsOnDiagram(part, size); + if (bounds == null) + continue; + +// System.out.println("InternalSize BOUNDS: " + size + " for part " + part + " " + part.getElementClass()); + if (temp == null) { + temp = new Rectangle2D.Double(); + temp.setRect(bounds); + } else + Rectangle2D.union(temp, bounds, temp); + //System.out.println("InternalSize Combined BOUNDS: " + temp); + } + if (temp != null) { + if (size == null) + size = temp; + else + size.setRect(temp); + } + + // Don't leave dangling references behind. + parts.clear(); + + return size; + } + + private Shape getSelectionShape(IElement forPart) { + for (SelectionOutline so : forPart.getElementClass().getItemsByClass(SelectionOutline.class)) { + Shape shape = so.getSelectionShape(forPart); + if (shape != null) + return shape; + } + // Using on-diagram coordinates because neither connections nor + // edges have a non-identity transform which means that + // coordinates are always absolute. Therefore branch point + // shape also needs to be calculated in absolute coordinates. + Shape shape = ElementUtils.getElementShapeOrBoundsOnDiagram(forPart); + return shape; + //return shape.getBounds2D(); + } + + @Override + public Shape getElementShape(IElement e) { + ConnectionEntity ce = e.getHint(ElementHints.KEY_CONNECTION_ENTITY); + if (ce == null) + return new Rectangle2D.Double(); + + Collection parts = perThreadShapeList.get(); + parts.clear(); + parts = ce.getSegments(parts); + if (parts.isEmpty()) + return new Rectangle2D.Double(); + parts = ce.getBranchPoints(parts); + + if (parts.size() == 1) { + Shape shape = getSelectionShape(parts.iterator().next()); + //System.out.println("Outline SHAPE: " + shape); + //System.out.println("Outline BOUNDS: " + shape.getBounds2D()); + return shape; + } + + //System.out.println("Outline: " + e); + Area area = new Area(); + for (IElement part : parts) { + //System.out.println(part); + + Shape shape = getSelectionShape(part); + + Rectangle2D bounds = shape.getBounds2D(); +// System.out.println(" shape: " + shape); +// System.out.println(" bounds: " + bounds); + + if (bounds.isEmpty()) { + double w = bounds.getWidth(); + double h = bounds.getHeight(); + if (w <= 0.0 && h <= 0.0) + continue; + + // Need to expand shape in either width or height to make it visible. + final double exp = 0.1; + if (w <= 0.0) + shape = org.simantics.scenegraph.utils.GeometryUtils.expandRectangle(bounds, 0, 0, exp, exp); + else if (h <= 0.0) + shape = org.simantics.scenegraph.utils.GeometryUtils.expandRectangle(bounds, exp, exp, 0, 0); + } + + //System.out.println(" final shape: " + shape); + //shape = bounds; + + Area a = null; + if (shape instanceof Area) + a = (Area) shape; + else + a = new Area(shape); + area.add(a); + } + + // Don't leave dangling references behind. + parts.clear(); + + //System.out.println(" connection area outline: " + area); + //System.out.println(" connection area outline bounds: " + area.getBounds2D()); + return area; + } + } + + public static class ConnectionPick implements Pick2 { + + public final static ConnectionPick INSTANCE = new ConnectionPick(); + + private static final long serialVersionUID = 1L; + + @Override + public boolean pickTest(IElement e, Shape s, PickPolicy policy) { + ConnectionEntity ce = e.getHint(ElementHints.KEY_CONNECTION_ENTITY); + if (ce == null) + return false; + + // Primarily pick branch points and then edges. + Collection parts = perThreadPickList.get(); + parts.clear(); + parts = ce.getBranchPoints(parts); + parts = ce.getSegments(parts); + if (parts.isEmpty()) + return false; + + for (IElement part : parts) { + for (Pick pick : part.getElementClass().getItemsByClass(Pick.class)) { +// System.out.println("TESTING: " + part + " : " + s + " : " + policy); + if (pick.pickTest(part, s, policy)) { + //System.out.println(" HIT!"); + return true; + } + } + } + + parts.clear(); + + return false; + } + + @Override + public int pick(IElement e, Shape s, PickPolicy policy, Collection result) { + int oldResultSize = result.size(); + +// new Exception("SysdynConnectionClass.pick: " + e + " : " + s + " : " + policy).printStackTrace(); + + ConnectionEntity ce = e.getHint(ElementHints.KEY_CONNECTION_ENTITY); + if (ce == null) + return 0; + + // Primarily pick branch points and then edges. + List parts = perThreadPickList.get(); + parts.clear(); + + ce.getSegments(parts); + int edges = parts.size(); + ce.getBranchPoints(parts); + int branchPoints = parts.size() - edges; + + boolean singleEdge = branchPoints == 0 && edges == 1; + + if (parts.isEmpty()) + return 0; + + // See whether the whole connection is to be picked.. + boolean pickConnection = false; + wholeConnectionPick: + for (Outline outline : e.getElementClass().getItemsByClass(Outline.class)) { + Shape elementShape = outline.getElementShape(e); + if (elementShape == null) + continue; + + switch (policy) { + case PICK_CONTAINED_OBJECTS: + if (GeometryUtils.contains(s, elementShape)) { + pickConnection = true; + break wholeConnectionPick; + } + break; + case PICK_INTERSECTING_OBJECTS: + if (GeometryUtils.intersects(s, elementShape)) { + pickConnection = true; + break wholeConnectionPick; + } + break; + } + } + + ArrayList picks = null; + + // Pick connection segments + for (int i = 0; i < edges; ++i) { + IElement part = parts.get(i); + for (Pick pick : part.getElementClass().getItemsByClass(Pick.class)) { +// System.out.println("TESTING SEGMENT: " + part + " : " + s + " : " + policy); + if (pick.pickTest(part, s, policy)) { +// System.out.println(" HIT!"); + if (picks == null) + picks = new ArrayList(4); + picks.add(e); + break; + } + } + } + + // Pick the whole connection ? + if (pickConnection) { + if (picks == null) + picks = new ArrayList(4); + picks.add(e); + } + + // Pick branch/route points + for (int i = edges; i < parts.size(); ++i) { + IElement part = parts.get(i); + for (Pick pick : part.getElementClass().getItemsByClass(Pick.class)) { + //System.out.println("TESTING BRANCHPOINT: " + part + " : " + s + " : " + policy); + if (pick.pickTest(part, s, policy)) { + //System.out.println(" HIT!"); + if (picks == null) + picks = new ArrayList(4); + picks.add(part); + break; + } + } + } + + if (picks != null) { + // Add the discovered pickable children to the result after the + // parent to make the parent the primary pickable. + // Skip the children if there is only one child. + if (!singleEdge) { + result.addAll(picks); + } else { + result.add(e); + } + } + + parts.clear(); + +// System.out.println("pick result size = " + result.size()); + + return result.size() - oldResultSize; + } + } + + private static final Key CHILD_LISTENERS = new KeyOf(ListenerList.class, "CHILD_LISTENERS"); + + public static class ConnectionChildren implements Children, ConnectionListener { + + public final static ConnectionChildren INSTANCE = new ConnectionChildren(); + + private static final long serialVersionUID = 1L; + + @Override + public Collection getChildren(IElement element, Collection result) { + ConnectionEntity ce = element.getHint(ElementHints.KEY_CONNECTION_ENTITY); + if (ce == null) { + if (result == null) + result = new ArrayList(0); + return result; + } + result = ce.getSegments(result); + result = ce.getBranchPoints(result); + return result; + } + + @Override + public void addChildListener(IElement element, ChildListener listener) { + ListenerList ll = null; + synchronized (element) { + ll = element.getHint(CHILD_LISTENERS); + if (ll == null) { + ll = new ListenerList(ChildListener.class); + element.setHint(CHILD_LISTENERS, ll); + ConnectionEntity entity = element.getHint(ElementHints.KEY_CONNECTION_ENTITY); + entity.setListener(this); + } + } + ll.add(listener); + } + + @Override + public void removeChildListener(IElement element, ChildListener listener) { + synchronized (element) { + ListenerList ll = element.getHint(CHILD_LISTENERS); + if (ll == null) + return; + ll.remove(listener); + if (ll.isEmpty()) { + ConnectionEntity entity = element.getHint(ElementHints.KEY_CONNECTION_ENTITY); + entity.setListener(null); + } + } + } + + @Override + public void connectionChanged(ConnectionEvent event) { + fireChildrenChanged(event); + } + + private void fireChildrenChanged(ConnectionEvent event) { + ListenerList ll = event.connection.getHint(CHILD_LISTENERS); + if (ll == null) + return; + ChildEvent ce = new ChildEvent(event.connection, event.removedParts, event.addedParts); + for (ChildListener cl : ll.getListeners()) { + cl.elementChildrenChanged(ce); + } + } + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/profiles/IssueDecorationStyle.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/profiles/IssueDecorationStyle.java new file mode 100644 index 00000000..50aab8c6 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/profiles/IssueDecorationStyle.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.profiles; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.PossibleTypedParent; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.diagram.profile.StyleBase; +import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; +import org.simantics.issues.common.ErrorIssues; +import org.simantics.issues.common.FatalIssues; +import org.simantics.issues.common.WarningIssues; +import org.simantics.issues.ontology.IssueResource; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.scenegraph.INode; +import org.simantics.scenegraph.g2d.nodes.SVGNode; +import org.simantics.scenegraph.profile.EvaluationContext; +import org.simantics.scenegraph.profile.common.ProfileVariables; +import org.simantics.scenegraph.utils.NodeUtil; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.utils.datastructures.map.Tuple; + +/** + * Issue Decorations. Display an issue icon on + * a diagram element depending on the type of the issue + * . + * @author Teemu Lempinen + * + */ +public class IssueDecorationStyle extends StyleBase { + + private static final String DECORATION_NODE_NAME = "issueDecorations"; + + @Override + public IssueResult calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource element, Variable configuration) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + ModelingResources MOD = ModelingResources.getInstance(graph); + + // Find a component for the element + Resource component = graph.getPossibleObject(element, MOD.ElementToComponent); + if (component == null) + return null; + + // Get the current transform of the element to be able to move the decoration with the element + AffineTransform transform = DiagramGraphUtil.getAffineTransform(graph, element); + + // Find the model of the component + Resource model = graph.syncRequest(new PossibleTypedParent(component, SimulationResource.getInstance(graph).Model)); + if (model == null) + return null; + + // Project + Resource project = graph.getPossibleObject(model, L0.PartOf); + if (project == null) + return null; + + IssueResult result = null; + + /* + * Search for issues. Start from fatal and move to + * less important issues. This way the most important + * issue will be displayed. + * + * The issue is returned immediately after it is found. + */ + + Set fatals = graph.syncRequest(new FatalIssues(project, true)); + result = getIssue(graph, IssueResult.Severity.FATAL, fatals, component, transform); + if(result != null) return result; + + Set errors = graph.syncRequest(new ErrorIssues(project, true)); + result = getIssue(graph, IssueResult.Severity.ERROR, errors, component, transform); + if(result != null) return result; + + Set warnings = graph.syncRequest(new WarningIssues(project, true)); + result = getIssue(graph, IssueResult.Severity.WARNING, warnings, component, transform); + if(result != null) return result; + + // No issue was found + return null; + } + + /** + * See if a set of issue variables concern this component + * + * @param graph ReadGraph + * @param severity IssueResult.Severity of the issue + * @param issues Collection of issues of type severity + * @param component The component that is evaluated for issues + * @param transform AffineTransform of the diagram element + * @return IssueResult containing the severity and transform of the issue or null if no issue concerned component + * @throws DatabaseException + */ + private IssueResult getIssue(ReadGraph graph, IssueResult.Severity severity, Set issues, Resource component, AffineTransform transform) throws DatabaseException { + IssueResource ISSUE = IssueResource.getInstance(graph); + Resource list, issueResource; + for(Variable issue : issues) { + issueResource = issue.getRepresents(graph); + list = graph.getPossibleObject(issueResource, ISSUE.Issue_HasContexts); + List contexts = ListUtils.toList(graph, list); + if(!contexts.isEmpty()) { + if(ListUtils.toList(graph, list).get(0).equals(component)) { + return new IssueResult(severity, transform); + } + } + } + return null; + } + + @Override + public void applyStyleForNode(EvaluationContext observer, INode node, IssueResult result) { + + // If result == null, remove possible issue decoration + if (result == null) { + ProfileVariables.denyChild(node, "", DECORATION_NODE_NAME); + return; + } + + // Create issue decoration node + SVGNode svgNode = ProfileVariables.claimChild(node, "", DECORATION_NODE_NAME, SVGNode.class, observer); + + // Move the decoration to the upper right corner of the element + Rectangle2D bounds = NodeUtil.getLocalBounds(node, Collections.singleton(svgNode)); + double tx = bounds.getMaxX(); + double ty = bounds.getY(); + svgNode.setZIndex( Integer.MAX_VALUE ); + svgNode.setTransform( AffineTransform.getTranslateInstance(tx-1, ty-1)); + svgNode.getTransform().scale(0.5, 0.5); + + + // Apply the corresponding svg graphics to the node + IssueResult.Severity sev = result.getSeverity(); + if (IssueResult.Severity.FATAL.equals(sev)) + svgNode.setData(Activator.FATAL_SVG_TEXT); + else if (IssueResult.Severity.ERROR.equals(sev)) + svgNode.setData(Activator.ERROR_SVG_TEXT); + else if (IssueResult.Severity.WARNING.equals(sev)) + svgNode.setData(Activator.WARNING_SVG_TEXT); + } + + @Override + protected void cleanupStyleForNode(INode node) { + ProfileVariables.denyChild(node, "", DECORATION_NODE_NAME); + } + +} + +/** + * This is needed to keep the issue decoration up-to-date when its parent + * element moves. + */ +class IssueResult extends Tuple { + + public enum Severity{FATAL, ERROR, WARNING}; + + public IssueResult(Severity severity, AffineTransform transform) { + super(severity, transform); + } + public Severity getSeverity() { + return (Severity) getField(0); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/profiles/SimulationPlaybackStyle.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/profiles/SimulationPlaybackStyle.java new file mode 100644 index 00000000..89ef64d3 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/profiles/SimulationPlaybackStyle.java @@ -0,0 +1,306 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.elements2.profiles; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.diagram.G2DUtils; +import org.simantics.diagram.elements.TextNode; +import org.simantics.diagram.profile.StyleBase; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; +import org.simantics.modeling.ModelingResources; +import org.simantics.project.IProject; +import org.simantics.scenegraph.INode; +import org.simantics.scenegraph.g2d.nodes.ShapeNode; +import org.simantics.scenegraph.g2d.nodes.SingleElementNode; +import org.simantics.scenegraph.profile.EvaluationContext; +import org.simantics.scenegraph.profile.Observer; +import org.simantics.scenegraph.profile.common.ProfileVariables; +import org.simantics.scenegraph.utils.GeometryUtils; +import org.simantics.scenegraph.utils.NodeUtil; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.adapter.SysdynVariableProperties; +import org.simantics.sysdyn.adapter.VariableRVIUtils; +import org.simantics.sysdyn.manager.SysdynDataSet; +import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.Triple; +import org.simantics.utils.ui.color.Color; +import org.simantics.utils.ui.color.ColorGradient; +import org.simantics.utils.ui.color.ColorValue; + +/** + * Profile style definition for simulation playback mode. Works only with SimulationPlaybackExperiment + * + * @author Teemu Lempinen + * + */ +public class SimulationPlaybackStyle extends StyleBase> { + + Resource gradientResource; + ColorGradient cg; + byte[] gradient; + + /** + * Determine if style needs to be redrawn and return objects that are needed to redraw the style. + * + * @return All necessary components that are needed to draw this style + */ + @Override + public Triple calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource element, Variable configuration) throws DatabaseException { + + // Find SimulationPlaybackExperiment + IProject project = SimanticsUI.getProject(); + IExperimentManager em = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = em.getActiveExperiment(); + if(!(experiment instanceof SysdynPlaybackExperiment)) + return null; + + ModelingResources mr = ModelingResources.getInstance(graph); + DiagramResource dr = DiagramResource.getInstance(graph); + + ColorGradient cg = null; + + Resource component = graph.getPossibleObject(element, mr.ElementToComponent); + if (component == null) + return null; + + try { + + // Find Variable for this component + String dv = graph.getPossibleRelatedValue(runtimeDiagram, dr.RuntimeDiagram_HasVariable); + Variable rootVariable = graph.getPossibleAdapter(graph.getRootLibrary(), Variable.class); + if (rootVariable == null) + return null; + Variable diagramVariable = rootVariable.browsePossible(graph, dv.substring(6)); + if(diagramVariable == null) + return null; + + Variable var = diagramVariable.browsePossible(graph, component); + if(var == null) + return null; + + // Get simulation result values for this component + // Get values + Object object = var.getPossiblePropertyValue(graph, SysdynVariableProperties.ACTIVE_DATASETS , Bindings.VARIANT); + if(object == null || !(object instanceof ArrayList)) + return null; + + ArrayList datasets = new ArrayList(); + + for(Object o : (ArrayList)object) { + if(o instanceof SysdynDataSet) + datasets.add((SysdynDataSet)o); + } + + if(datasets.size() == 0) + return null; + + if(datasets.size() > 1) { + String range = datasets.get(0).name.substring( + datasets.get(0).name.indexOf('[') + 1, + datasets.get(0).name.indexOf(']')); + int size = range.split(",").length; + String[] filter = new String[size]; + for(int i = 0; i < size; i++) + filter[i] = "Sum"; + + ArrayList result2 = VariableRVIUtils.getDataset(datasets, filter); + if(result2 != null) { + datasets = result2; + } + + } + + // The datasets list should always be size == 1 + SysdynDataSet dataset = datasets.get(0); + + // Get values (or sum of values) + double[] va = dataset.values; + if(va.length < 2) + return null; + + // Get simulation timesteps for this component + double[] ta = dataset.times; + if(ta == null || ta.length < 2) + return null; + + if(va.length == 0 || va.length == 2) + return null; + + // Get playback time from the experiment + Double time = var.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME , Bindings.DOUBLE); + if(time == null) + return null; + + // Find minimum and maximum values for this variable + double min = va[0], max = va[0]; + for(double d : va) { + if(d < min) + min = d; + if(d > max) + max = d; + } + + // Find the index in time and value arrays for this time + // (time steps may vary, we need to loop to find the correct time) + int index = 0; + if(ta[ta.length - 1] - time > ta[ta.length / 2] ) { + index = ta.length - 1; + while(ta[index] > time && index > 0) + index--; + } else { + while(ta[index] < time && index < ta.length - 1) + index++; + } + + double value = va[index]; + + // Calculate where the value is located between min and max values [0..1]. + double multiplier = (value - min) / (max - min); + + + // Get the transform of this element + AffineTransform at = (AffineTransform) DiagramGraphUtil.getAffineTransform(graph, element, G2DResource.getInstance(graph).HasTransform, true).clone(); + + // Find the gradient used to draw this style + G2DResource g2d = G2DResource.getInstance(graph); + Resource gradient = graph.getPossibleObject(experiment.getResource(), g2d.HasColorGradient); + if(this.gradientResource == null || !this.gradientResource.equals(gradient)) { + ArrayList colorValues = new ArrayList(); + for(Resource placement : graph.syncRequest(new ObjectsWithType(gradient, g2d.HasColorPlacement, g2d.ColorPlacement))) { + Double position = graph.getPossibleRelatedValue(placement, g2d.HasGradientPosition, Bindings.DOUBLE); + Resource rColor = graph.getPossibleObject(placement, g2d.HasColor); + if (rColor != null) { + colorValues.add(new ColorValue(new Color((java.awt.Color) G2DUtils.getObject(graph, rColor)), position)); + } + } + cg = new ColorGradient(colorValues, ColorGradient.HSV); + } else { + cg = this.cg; + } + + return new Triple(at, multiplier, cg); + + } catch(Exception ignore) { + ignore.printStackTrace(); + } + return null; + } + + @Override + public void styleResultChanged(Observer observer, Resource element, Triple result) { + if (result != null) + values.put(element, result); + else + values.remove(element); + observer.update(); + } + + /** + * Apply style + */ + @Override + public void applyStyleForNode(EvaluationContext observer, INode _node, Triple result) { + Double multiplier; + if (result != null && (multiplier = result.second) != null && !multiplier.isNaN()) { + + // Create a node that will show the style effect + A node = ProfileVariables.claimChild(_node, "", "playbackColour", A.class, observer); + if (node == null) + return; + + AffineTransform at = result.first; + + if(this.cg == null || !this.cg.equals(result.third)) { + this.cg = result.third; + this.gradient = cg.getGradientArray(101); + } + + // Get integer values for red, green and blue + int i = (int)(multiplier * 100); + int r = (int)(gradient[i * 3 + 0] & 0xff); + int g = (int)(gradient[i * 3 + 1] & 0xff); + int b = (int)(gradient[i * 3 + 2] & 0xff); + // Get color with r, g and b + java.awt.Color c = new java.awt.Color(r, g, b, 200); + + // Create a node for the style + INode n = NodeUtil.getNearestChildByClass((SingleElementNode)_node, TextNode.class); + Rectangle2D expandedElementBounds = GeometryUtils.expandRectangle( NodeUtil.getLocalElementBounds(n), 0.0); + node.setFill(true); + node.setColor(c); + node.setStroke(null); + node.setValue("shape", expandedElementBounds); + node.setTransform(at); + + // Find z-index for the TextNode associated with the element and place the style node just below that text node + int zIndex = -1; + if(n != null) { + at = ((TextNode)n).getTransform(); + zIndex = ((TextNode)n).getZIndex() - 1; + } else { + n = _node; + } + node.setZIndex(zIndex); + + + } else { + cleanupStyleForNode(_node); + } + } + + @Override + protected void cleanupStyleForNode(INode node) { + ProfileVariables.denyChild(node, "", "playbackColour"); + } + + + /** + * Dummy class for displaying the style + * + * @author Teemu Lempinen + * + */ + public static class A extends ShapeNode { + + private static final long serialVersionUID = -5273246617906214956L; + + @Override + public Rectangle2D getBoundsInLocal() { + return null; + } + + @Override + public Rectangle2D getBoundsInLocal(boolean b) { + return null; + } + + @Override + public Rectangle2D getBounds() { + return null; + } + + } +} + diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ChartPanelOrientationHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ChartPanelOrientationHandler.java new file mode 100644 index 00000000..87ee362a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ChartPanelOrientationHandler.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers; + +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.commands.IElementUpdater; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.menus.UIElement; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.trend.ChartPanel; + +/** + * This handler changes the orientation of a {@link ChartPanel} + * + * @author Teemu Lempinen + * + */ +public class ChartPanelOrientationHandler extends AbstractHandler implements IElementUpdater { + + private static String COMMAND = "org.simantics.sysdyn.ui.chartPanelOrientation"; + + /** + * Read chart panel settings from IDialogSettings and change the orientation accordingly. + * Finally order the element to update its appearance. + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + IWorkbenchPart part = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart(); + if(part instanceof ChartPanel) { + IDialogSettings settings = Activator.getDefault().getDialogSettings().getSection(ChartPanel.CHART_PANEL_SETTINGS); + if (settings == null) { + settings = Activator.getDefault().getDialogSettings().addNewSection(ChartPanel.CHART_PANEL_SETTINGS); + } + + String orientation = settings.get(ChartPanel.CHART_PANEL_ORIENTATION); + if(orientation == null) + settings.put(ChartPanel.CHART_PANEL_ORIENTATION, ChartPanel.CHART_PANEL_HORIZONTAL); + + if(ChartPanel.CHART_PANEL_VERTICAL.equals(orientation)) + orientation = ChartPanel.CHART_PANEL_HORIZONTAL; + else + orientation = ChartPanel.CHART_PANEL_VERTICAL; + + settings.put(ChartPanel.CHART_PANEL_ORIENTATION, orientation); + ((ChartPanel)part).setOrientation(orientation); + + ICommandService commandService = + (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + commandService.refreshElements(COMMAND, null); + } + + return null; + } + + /** + * Update the icon of the element. The new icon and text are always opposite to the current situation. + */ + @SuppressWarnings("rawtypes") + @Override + public void updateElement(UIElement element, Map parameters) { + if(parameters == null) + return; + + IDialogSettings settings = Activator.getDefault().getDialogSettings().getSection(ChartPanel.CHART_PANEL_SETTINGS); + if(settings == null) + return; + + String orientation = settings.get(ChartPanel.CHART_PANEL_ORIENTATION); + if(orientation == null) + return; + + // Show the opposite icon and text to indicate change when the button is pressed + if(ChartPanel.CHART_PANEL_HORIZONTAL.equals(orientation)) { + element.setIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/page_white_text.png"))); + element.setTooltip("Vertical Orientation"); + } else if (ChartPanel.CHART_PANEL_VERTICAL.equals(orientation)) { + element.setIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/page_white_text_width.png"))); + element.setTooltip("Horizontal Orientation"); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DisposeExperiment.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DisposeExperiment.java new file mode 100644 index 00000000..207cadda --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DisposeExperiment.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.simantics.project.IProject; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.ui.SimanticsUI; + +public class DisposeExperiment extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + IProject project = SimanticsUI.getProject(); + IExperimentManager manager = + project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if (experiment != null) + experiment.shutdown(); + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/EnumerationPasteHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/EnumerationPasteHandler.java new file mode 100644 index 00000000..a37cb37c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/EnumerationPasteHandler.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; + +public class EnumerationPasteHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection sel = HandlerUtil.getCurrentSelection(event); + System.out.println("PASTE " + sel); + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RemoveNodeHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RemoveNodeHandler.java new file mode 100644 index 00000000..e2ee3669 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RemoveNodeHandler.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.CancelTransactionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; +import org.simantics.utils.ui.ExceptionUtils; + +/** + * @author Tuukka Lehtonen + */ +public class RemoveNodeHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + Shell shell = HandlerUtil.getActiveShellChecked(event); + ISelection sel = HandlerUtil.getCurrentSelection(event); + Resource[] resources = ResourceAdaptionUtils.toResources(sel); + if (resources.length == 0) + return null; + + MessageDialog dialog = new MessageDialog(shell, "Remove Item", null, "Are you sure?", 0, + new String[] { "OK", "Cancel" }, 0); + dialog.create(); + if (dialog.open() == 0) + deleteItem(resources); + + return null; + } + + public static void deleteItem(final Resource[] resources) { + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { + for (Resource r : resources) + RemoverUtil.remove(graph, r); + } + }); + } catch (DatabaseException e) { + ExceptionUtils.logAndShowError(e); + } + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RenameNodeHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RenameNodeHandler.java new file mode 100644 index 00000000..4cb78c8e --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RenameNodeHandler.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.browsing.ui.GraphExplorer; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.utils.ui.ISelectionUtils; + +public class RenameNodeHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection sel = HandlerUtil.getCurrentSelection(event); + NodeContext ctx = ISelectionUtils.filterSingleSelection(sel, NodeContext.class); + if (ctx == null) + return null; + + IWorkbenchPart part = HandlerUtil.getActivePart(event); + if (part == null) + return null; + + GraphExplorer graphExplorer = (GraphExplorer) part.getAdapter(GraphExplorer.class); + if (graphExplorer != null) + graphExplorer.startEditing(ctx, ColumnKeys.SINGLE); + + return null; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RunBasicExperiment.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RunBasicExperiment.java new file mode 100644 index 00000000..2b4ef65f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RunBasicExperiment.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers; + + +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.commands.IElementUpdater; +import org.eclipse.ui.menus.UIElement; +import org.simantics.simulation.experiment.ExperimentState; +import org.simantics.simulation.experiment.IDynamicExperiment; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.manager.SysdynExperiment; +import org.simantics.ui.SimanticsUI; + +public class RunBasicExperiment extends AbstractHandler implements IElementUpdater { + + public static final String COMMAND = "org.simantics.sysdyn.ui.run"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + IExperimentManager manager = + SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment instanceof IDynamicExperiment) + ((IDynamicExperiment)experiment).simulate(true); + return null; + } + + @SuppressWarnings("rawtypes") + @Override + public void updateElement(UIElement element, Map parameters) { + IExperimentManager manager = + SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment instanceof SysdynExperiment) { + ExperimentState state = experiment.getState(); + if(state == ExperimentState.RUNNING) { + this.setBaseEnabled(false); + } else { + this.setBaseEnabled(true); + } + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveResultsHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveResultsHandler.java new file mode 100644 index 00000000..84e679a9 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveResultsHandler.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.simantics.simulation.experiment.IDynamicExperiment; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.ui.SimanticsUI; + +public class SaveResultsHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + IExperimentManager manager = + SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment instanceof IDynamicExperiment) { + ((IDynamicExperiment)experiment).saveState(); + } + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java new file mode 100644 index 00000000..5a35e538 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.MissingVariableException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.modeling.ComponentUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.editor.DiagramViewer; +import org.simantics.sysdyn.ui.editor.SysdynEditorInput; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + + +public class ShowModuleHandler extends AbstractHandler { + + private static final String EDITOR_ID = "org.simantics.sysdyn.ui.diagramViewer"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection s = HandlerUtil.getCurrentSelectionChecked(event); + final Resource resources[] = ResourceAdaptionUtils.toResources(s); + final DiagramViewer viewer = (DiagramViewer)HandlerUtil.getActiveEditor(event); + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + + DiagramResource dr = DiagramResource.getInstance(graph); + Resource runtime = viewer.getRuntime(); + String uri = graph.getPossibleRelatedValue(runtime, dr.RuntimeDiagram_HasVariable, Bindings.STRING); + Variable parent = Variables.getVariable(graph, uri); + Resource model = Variables.getModel(graph, parent); + final String modelURI = graph.getURI(model); + + for(Resource element : resources) { + + ModelingResources mr = ModelingResources.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 st = StructuralResource2.getInstance(graph); + + final Resource component = graph.getPossibleObject(element, mr.ElementToComponent); + final Resource componentType = graph.getPossibleType(component, sr.Module); + final Resource configuration = graph.getPossibleObject(componentType, st.IsDefinedBy); + final Resource diagram = ComponentUtils.getPossibleCompositeDiagram(graph, configuration); + + Variable variable; + String rvi = ""; + try { + variable = parent.browse(graph, component); + rvi = Variables.getRVI(graph, variable); + } catch (MissingVariableException e ) { + variable = Variables.getVariable(graph, graph.getURI(component)); + } + final String finalRvi = rvi; + + + + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + try { + String editorId = EDITOR_ID; + WorkbenchUtils.openEditor(editorId, new SysdynEditorInput(editorId, diagram, modelURI, finalRvi)); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + }); + + } + + } + }); + + return null; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java new file mode 100644 index 00000000..8fa80b3b --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers; + +import java.util.concurrent.Semaphore; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.simantics.db.ReadGraph; +import org.simantics.db.RequestProcessor; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.AdaptionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.message.MessageService; +import org.simantics.project.IProject; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.model.ExperimentLoadingFailed; +import org.simantics.simulation.project.IExperimentActivationListener; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.ui.listeners.SysdynExperimentManagerListener; +import org.simantics.utils.DataContainer; +import org.simantics.utils.ui.ErrorLogger; +import org.simantics.utils.ui.ExceptionUtils; +import org.simantics.utils.ui.dialogs.ShowMessage; + +public class SysdynExperimentActivator { + /** + * @param project + * @param experimentManager + * @param experiment + */ + public static void scheduleActivation(RequestProcessor processor, final IProject project, final IExperimentManager experimentManager, final Resource experiment) { + String jobName = "Activate Experiment"; + String experimentName = getName(processor, experiment); + if (experimentName != null) + jobName += " '" + experimentName + "'"; + /* + // Shut down the previous active experiment + IExperiment activeExperiment = experimentManager.getActiveExperiment(); + if (experiment != null) + activeExperiment.shutdown(); + */ + // Activate a new experiment + scheduleActivation(jobName, project, experimentManager, experiment); + } + + /** + * @param project + * @param experimentManager + * @param experiment + */ + public static void scheduleActivation(String jobName, final IProject project, final IExperimentManager experimentManager, final Resource experiment) { + new Job(jobName) { + @Override + protected IStatus run(final IProgressMonitor monitor) { + return SysdynExperimentActivator.activate(monitor, project, experimentManager, experiment); + } + }.schedule(); + } + + public static IStatus activate(IProgressMonitor monitor, IProject project, IExperimentManager experimentManager, Resource experiment) { + return new SysdynExperimentActivator().activateExperiment(monitor, project, experimentManager, experiment); + } + + private static String getName(RequestProcessor processor, final Resource resource) { + try { + return processor.syncRequest(new Read() { + @Override + public String perform(ReadGraph graph) throws DatabaseException { + try { + return graph.adapt(resource, String.class); + } catch (AdaptionException e) { + return NameUtils.getSafeName(graph, resource); + } + } + }); + } catch (DatabaseException e) { + ErrorLogger.defaultLogWarning(e); + return null; + } + } + + private IStatus activateExperiment(final IProgressMonitor monitor, final IProject project, final IExperimentManager manager, final Resource experimentResource) { + monitor.beginTask("Activating experiment", IProgressMonitor.UNKNOWN); + try { + SysdynExperimentManagerListener.listenManager(manager); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment != null) { + experiment.shutdown(); + } + final Semaphore activated = new Semaphore(0); + final DataContainer problem = new DataContainer(); + manager.startExperiment(experimentResource, new IExperimentActivationListener() { + + @Override + public void onExperimentActivated(final IExperiment experiment) { + MessageService.defaultLog(new org.eclipse.core.runtime.Status(IStatus.INFO, "org.simantics.simulation.ui", 0, "Activated experiment " + experiment.getIdentifier() , null)); + activated.release(); + } + @Override + public void onFailure(Throwable e) { + problem.set(e); + activated.release(); + } + @Override + public void onMessage(IStatus message) { + MessageService.getDefault().log(message); + /*ILogger logger = MessageService.getDefault(); + MultiStatus init = new MultiStatus(Activator.PLUGIN_ID, 0, "Activating experiment", null); + for (String msg : messages) { + init.add(new Status(IStatus.INFO, Activator.PLUGIN_ID, msg)); + } + logger.log(init);*/ + } + }, true); + try { + activated.acquire(); + Throwable t = problem.get(); + if (t != null) { + if (t instanceof ExperimentLoadingFailed) { + ErrorLogger.defaultLogError(t); + ShowMessage.showError("Experiment Activation Failed", t.getMessage()); + } else { + ExceptionUtils.logAndShowError(t); + } + } + + return Status.OK_STATUS; + //return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Experiment activation failed, see exception for details.", problem.get()); + } catch (InterruptedException e) { + return Status.CANCEL_STATUS; + } + } finally { + monitor.done(); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleResultActivation.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleResultActivation.java new file mode 100644 index 00000000..5eaa2d73 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleResultActivation.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; + +public class ToggleResultActivation extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection sel = HandlerUtil.getCurrentSelection(event); + Resource[] resources = ResourceAdaptionUtils.toResources(sel); + if (resources.length == 0) + return null; + + toggleActivation(resources); + + return null; + } + + public static void toggleActivation(final Resource[] resources) { + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + for(Resource r : resources) { + if(graph.isInstanceOf(r, sr.Result)) { + if (graph.hasStatement(r, sr.ShowResult)) { + graph.denyStatement(r, sr.ShowResult, r); + } else { + graph.claim(r, sr.ShowResult, r); + } + } + } + } + + }); + } catch (DatabaseException e) { + + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleSimulation.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleSimulation.java new file mode 100644 index 00000000..bcd17050 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleSimulation.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers; + + +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.State; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.commands.IElementUpdater; +import org.eclipse.ui.menus.UIElement; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.manager.SysdynExperiment; +import org.simantics.ui.SimanticsUI; + +public class ToggleSimulation extends AbstractHandler implements IElementUpdater { + + public static final String COMMAND = "org.simantics.sysdyn.ui.toggleSimulation"; + public static final String STATE = "org.simantics.sysdyn.ui.toggleSimulation.state"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = service.getCommand(COMMAND); + State state = command.getState(STATE); + Boolean value = (Boolean) state.getValue(); + value = !value; + state.setValue(value); + service.refreshElements(RunBasicExperiment.COMMAND, null); + + IExperimentManager manager = + SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment instanceof SysdynExperiment) { + if(getState()) { + ((SysdynExperiment)experiment).toggleSimulation(true); + } else { + ((SysdynExperiment)experiment).toggleSimulation(false); + } + } + + + return null; + } + + public static Boolean getState() { + ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = service.getCommand(COMMAND); + State state = command.getState(STATE); + return (Boolean)state.getValue(); + } + + @SuppressWarnings("rawtypes") + @Override + public void updateElement(UIElement element, Map parameters) { + ICommandService commandService = + (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = commandService.getCommand(COMMAND); + boolean checked = (Boolean) command.getState(STATE).getValue(); + element.setChecked(checked); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkNodeHandler2.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkNodeHandler2.java new file mode 100644 index 00000000..e616b0a7 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkNodeHandler2.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.db.Resource; +import org.simantics.modeling.ui.modelBrowser.handlers.DeleteNodeHandler; +import org.simantics.ui.utils.ResourceAdaptionUtils; + +public class UnlinkNodeHandler2 extends DeleteNodeHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + //TODO: deletenodehandler for all resources + + Shell shell = HandlerUtil.getActiveShellChecked(event); + ISelection sel = HandlerUtil.getCurrentSelection(event); + Resource[] resources = ResourceAdaptionUtils.toResources(sel); + if (resources.length != 1) { + // Quick fix to provide some feedback to users. Removing many items should be allowed. + MessageDialog dialog = new MessageDialog(shell, "Too many items", null, "Please select only one item to remove.", 0, + new String[] { "OK" }, 0); + dialog.create(); + dialog.open(); + return null; + } + + MessageDialog dialog = new MessageDialog(shell, "Remove Item", null, "Are you sure?", 0, + new String[] { "OK", "Cancel" }, 0); + dialog.create(); + if (dialog.open() == 0) { + super.execute(event); + } + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportExternalFunctionFilesHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportExternalFunctionFilesHandler.java new file mode 100644 index 00000000..53b012c5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportExternalFunctionFilesHandler.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.exports; + +import java.io.FileOutputStream; +import java.io.IOException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; + +/** + * Exports external function files from SysdynModelicaFunctions + * + * @author Teemu Lempinen + * + */ +public class ExportExternalFunctionFilesHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + // Find shell and resources to be exported + Shell shell = HandlerUtil.getActiveShellChecked(event); + ISelection sel = HandlerUtil.getCurrentSelection(event); + final Resource[] resources = ResourceAdaptionUtils.toResources(sel); + if (resources.length < 1) + return null; + + return exportFiles(shell, resources); + } + + /** + * Exports selected file resources to files on disk. Assumes all resources are external files. + * + * @param shell SWT Shell + * @param resources External file resources + * @return null + */ + public static Object exportFiles(Shell shell, final Resource[] resources) { + + // Select a path where to export the files + DirectoryDialog dd = new DirectoryDialog(shell); + dd.setFilterPath(Platform.getLocation().toOSString()); + dd.setText("Export files to..."); + dd.setMessage("Select a directory"); + final String dir = dd.open(); + if (dir == null) { + return null; + } + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + // Get byte arrays from each resource and write them to disk + for(Resource r : resources) { + try { + String name = NameUtils.getSafeName(graph, r); + FileOutputStream fos = new FileOutputStream(dir + "\\" + name); + byte[] fileBArray = graph.getPossibleRelatedValue(r, sr.HasExternalFile, Bindings.BYTE_ARRAY); + fos.write(fileBArray); + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + }); + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java new file mode 100644 index 00000000..0b65cfd8 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportFunctionLibrary.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.exports; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Files; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.primitiverequest.PossibleRelatedValue; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.TransferableGraphRequest2; +import org.simantics.db.request.Read; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.handlers.imports.ImportFunctionLibrary; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; +import org.simantics.utils.datastructures.Pair; + +/** + * Exports a function library + * + * @author Teemu Lempinen + * + */ +public class ExportFunctionLibrary extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection sel = HandlerUtil.getCurrentSelection(event); + final Resource functionLibrary = ResourceAdaptionUtils.toSingleResource(sel); + if(functionLibrary == null) return null; + + String name = null; + try { + name = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + if (!graph.hasStatement(functionLibrary, Layer0.getInstance(graph).PartOf)) + return null; + Layer0 l0 = Layer0.getInstance(graph); + String name = graph.syncRequest(new PossibleRelatedValue(functionLibrary, l0.HasName, Bindings.STRING )); + return name; + + } + + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + // Do not export if the resource has no name + if(name == null) return null; + + // Find a location (and name) for the exported library using FileDialog + Shell shell = HandlerUtil.getActiveShellChecked(event); + FileDialog fd = new FileDialog(shell, SWT.SAVE); + fd.setText("Export Function Library"); + fd.setFileName(name); + String path = Activator.getDefault().getPreferenceStore().getString(ImportFunctionLibrary.IMPORTFUNCTIONLIBRARYPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); + String[] filterExt = {"*.tg"}; + fd.setFilterExtensions(filterExt); + final String selected = fd.open(); + if(selected == null) return null; + + // Save location to preference store + Activator.getDefault().getPreferenceStore().setValue(ImportFunctionLibrary.IMPORTFUNCTIONLIBRARYPATH, (new File(selected)).getParent()); + + // Asynchronously create the file using transferable graph + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + String name = graph.syncRequest(new PossibleRelatedValue(functionLibrary, l0.HasName, Bindings.STRING )); + ArrayList> roots = new ArrayList>(); + roots.add(Pair.make(functionLibrary, name)); + TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, functionLibrary)); + + try { + Files.createFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class), tg); + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + + } + }); + + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModelHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModelHandler.java new file mode 100644 index 00000000..2c58e90c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModelHandler.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.exports; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Files; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.primitiverequest.PossibleRelatedValue; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.TransferableGraphRequest2; +import org.simantics.db.request.Read; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.handlers.imports.ImportModelHandler; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; +import org.simantics.utils.datastructures.Pair; + +/** + * Exports a selected model + * + * @author Teemu Lempinen + * + */ +public class ExportModelHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection sel = HandlerUtil.getCurrentSelection(event); + final Resource model = ResourceAdaptionUtils.toSingleResource(sel); + if(model == null) return null; + + // FIXME: Model browser doesn't change its selection even if the selected object is removed, + // so you can try to export a removed model + String name = null; + try { + name = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + if (!graph.hasStatement(model, Layer0.getInstance(graph).PartOf)) + return null; + Layer0 l0 = Layer0.getInstance(graph); + String name = graph.syncRequest(new PossibleRelatedValue(model, l0.HasName, Bindings.STRING )); + return name; + + } + + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + // Do not export if the resource has no name + if(name == null) return null; + + // Find a location (and name) for the exported library using FileDialog + Shell shell = HandlerUtil.getActiveShellChecked(event); + FileDialog fd = new FileDialog(shell, SWT.SAVE); + fd.setText("Export Model"); + fd.setFileName(name); + String path = Activator.getDefault().getPreferenceStore().getString(ImportModelHandler.IMPORTMODELTPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); + String[] filterExt = {"*.tg"}; + fd.setFilterExtensions(filterExt); + final String selected = fd.open(); + if(selected == null) return null; + + // Save location to preference store + Activator.getDefault().getPreferenceStore().setValue(ImportModelHandler.IMPORTMODELTPATH, (new File(selected)).getParent()); + + // Asynchronously create the file using transferable graph + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + String name = graph.syncRequest(new PossibleRelatedValue(model, l0.HasName, Bindings.STRING )); + ArrayList> roots = new ArrayList>(); + roots.add(Pair.make(model, name)); + TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, model)); + + try { + Files.createFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class), tg); + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + + } + }); + + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java new file mode 100644 index 00000000..ab804371 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModuleHandler.java @@ -0,0 +1,262 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.exports; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Files; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.PossibleRelatedValue; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.TransferableGraphRequest2; +import org.simantics.db.request.Read; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.handlers.imports.ImportModuleHandler; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; +import org.simantics.utils.datastructures.Pair; + +/** + * Exports a selected module + * @author Teemu Lempinen + * + */ +public class ExportModuleHandler extends AbstractHandler { + + /** + * Temporary exception. At this phase, the system will not support exporting modules + * that depend on other modules. + * + * @author Teemu Lempinen + * + */ + class ContainsDependenciesException extends DatabaseException { + private static final long serialVersionUID = -1533706136673146020L; + + private Collection dependencies; + + ContainsDependenciesException(Collection dependencies) { + this.dependencies = dependencies; + } + + public Collection getDependencies() { + return this.dependencies; + } + + } + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection sel = HandlerUtil.getCurrentSelection(event); + final Resource modulesymbol = ResourceAdaptionUtils.toSingleResource(sel); + if(modulesymbol == null) return null; + + String name = null; + try { + name = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + ModelingResources mr = ModelingResources.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + // Start checking for module dependencies + Resource component = graph.getPossibleObject(modulesymbol, mr.SymbolToComponentType); + if (component == null || !graph.hasStatement(component, Layer0.getInstance(graph).PartOf)) + return null; + + Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy); + if (configuration == null) + return null; + + ArrayList dependencies = null; + for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Module))) { + if(dependencies == null) + dependencies = new ArrayList(); + String name = NameUtils.getSafeName(graph, r); + String instanceOf = NameUtils.getSafeName(graph, graph.getSingleObject(r, l0.InstanceOf)); + dependencies.add(name + " : " + instanceOf); + } + if(dependencies != null && !dependencies.isEmpty()) + throw new ContainsDependenciesException(dependencies); + // End checking for module dependencies. If dependencies were found, an exception was thrown + + String name = graph.getPossibleRelatedValue(component, l0.HasName, Bindings.STRING); + return name; + + } + + }); + } catch (ContainsDependenciesException e1) { + Shell shell = HandlerUtil.getActiveShellChecked(event); + MessageBox mb = new MessageBox(shell, SWT.OK); + StringBuilder sb = new StringBuilder(); + sb.append("This version does not support exporting modules with other module instances.\n\n"); + sb.append("Dependencies:\n"); + for(String s : e1.getDependencies()) + sb.append(" " + s + "\n"); + mb.setMessage(sb.toString()); + mb.setText("Module contains dependencies."); + mb.open(); + return null; + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + + // Do not export if the resource has no name + if(name == null) return null; + + // Find a location (and name) for the exported library using FileDialog + Shell shell = HandlerUtil.getActiveShellChecked(event); + FileDialog fd = new FileDialog(shell, SWT.SAVE); + fd.setText("Export Module"); + fd.setFileName(name); + String path = Activator.getDefault().getPreferenceStore().getString(ImportModuleHandler.IMPORTMODULETPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); + String[] filterExt = {"*.tg"}; + fd.setFilterExtensions(filterExt); + final String selected = fd.open(); + if(selected == null) return null; + + // Save location to preference store + Activator.getDefault().getPreferenceStore().setValue(ImportModuleHandler.IMPORTMODULETPATH, (new File(selected)).getParent()); + + // Asynchronously create the file using transferable graph + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + + final Resource component = graph.getPossibleObject(modulesymbol, mr.SymbolToComponentType); + if (component == null || !graph.hasStatement(component, Layer0.getInstance(graph).PartOf)) + return; + String name = graph.syncRequest(new PossibleRelatedValue(component, l0.HasName, Bindings.STRING )); + final ArrayList> roots = new ArrayList>(); + roots.add(Pair.make(component, name)); + + graph.asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + + Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy); + if (!graph.hasStatement(configuration, l0.PartOf, component)&& + !graph.hasStatement(modulesymbol, l0.PartOf, component)) { + // Make sure that configuration and symbol are included. + // In old versions, they were attached to model, not to module. + Resource previousPartof = graph.getSingleObject(configuration, l0.PartOf); + + graph.deny(configuration, l0.PartOf); + graph.deny(modulesymbol, l0.PartOf); + graph.claim(configuration, l0.PartOf, l0.ConsistsOf, component); + graph.claim(modulesymbol, l0.PartOf, l0.ConsistsOf, component); + + export(graph, selected, roots, component); + + graph.deny(configuration, l0.PartOf); + graph.deny(modulesymbol, l0.PartOf); + graph.claim(configuration, l0.PartOf, l0.ConsistsOf, previousPartof); + graph.claim(modulesymbol, l0.PartOf, l0.ConsistsOf, previousPartof); + } else { + // Normal export + export(graph, selected, roots, component); + } + } + }); + + } + }); + + return null; + } + + /** + * Export module (without dependencies to other modules) and write it to file. + * Disable existing enumeration replacement for during export. + * + * @param graph WriteGraph + * @param path Path for the exported file + * @param roots + * @param component Module + */ + private void export(WriteGraph graph, String path, ArrayList> roots, Resource component) { + + // FIXME: Enumeration replacement handling like this is not suitable. + try { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + + Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy); + ArrayList> replacements = new ArrayList>(); + + for(Resource enumeration : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) { + if(graph.hasStatement(enumeration, sr.ReplacedEnumeration_Inverse)) { + for(Resource replacement : graph.getObjects(enumeration, sr.ReplacedEnumeration_Inverse)) { + replacements.add(new Pair(enumeration, replacement)); + } + } + } + + for(Pair replacement : replacements) + graph.deny(replacement.first, sr.ReplacedEnumeration_Inverse, replacement.second); + + TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, component)); + Files.createFile(new File(path), Bindings.getBindingUnchecked(TransferableGraph1.class), tg); + + for(Pair replacement : replacements) + graph.claim(replacement.first, sr.ReplacedEnumeration_Inverse, replacement.second); + + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportExternalFunctionFilesHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportExternalFunctionFilesHandler.java new file mode 100644 index 00000000..f0052c6d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportExternalFunctionFilesHandler.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.imports; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.Pair; + +/** + * Imports external functions to SysdynModelicaFunctions using FileDialog. + * + * @author Teemu Lempinen + * + */ +public class ImportExternalFunctionFilesHandler extends AbstractHandler { + + public static final String[] C_EXTENSIONS = {"*.c","*.h","*.a","*.o"}; + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + Shell shell = HandlerUtil.getActiveShellChecked(event); + Pair selected = importFiles(shell, "Import...", C_EXTENSIONS); + if(selected.second == null || selected.second.length < 1) return null; + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + // TODO: include files to database + } + }); + + return null; + } + + /** + * Opens a {@link FileDialog} to select the imported files. + * + * @param shell SWT Shell + * @param text Header text for the FileDialog + * @param filter Filters for the FileDialog + * @return File names and paths for the files to be imported + */ + public static Pair importFiles(Shell shell, String text, String[] filter) { + FileDialog fd = new FileDialog(shell, SWT.OPEN); + fd.setText(text); + fd.setFilterPath(Platform.getLocation().toOSString()); + fd.setFilterExtensions(filter); + fd.open(); + return new Pair(fd.getFilterPath(), fd.getFileNames()); + } + + + /** + * Saves the given files as byte arrays to a function + * + * @param graph WriteGraph + * @param function Function where the files are to be added + * @param files Files to be added + * @throws DatabaseException + */ + public static void addFilesToFunction(WriteGraph graph, Resource function, Pair files) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + if(!graph.isInstanceOf(function, sr.SysdynModelicaFunction)) + return; + + for(String filename : files.second) { + File file = new File(files.first, filename); + + String name = file.getName(); + + Resource externalFile = GraphUtils.create2(graph, + sr.ExternalFunctionFile, + l0.PartOf, function, + l0.HasName, name); + + try { + byte[] fileBArray = new byte[(int)file.length()]; + FileInputStream fis = new FileInputStream(file); + fis.read(fileBArray); + graph.claimLiteral(externalFile, sr.HasExternalFile, fileBArray, Bindings.BYTE_ARRAY); + + FunctionUtils.createExternalFunctionFile(graph, externalFile); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportFunctionLibrary.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportFunctionLibrary.java new file mode 100644 index 00000000..b20206c4 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportFunctionLibrary.java @@ -0,0 +1,256 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.imports; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Files; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; +import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; +import org.simantics.db.request.Read; +import org.simantics.graph.representation.Root; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.ui.utils.ResourceAdaptionUtils; + +/** + * Imports an exported function library (or shared function library) transferable graph. + * @author Teemu Lempinen + * + */ +public class ImportFunctionLibrary extends AbstractHandler { + + public static String IMPORTFUNCTIONLIBRARYPATH = "IMPORT_FUNCTION_LIBRARY_PATH"; + + /** + * Called from a functions folder node + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection sel = HandlerUtil.getCurrentSelection(event); + Resource r = ResourceAdaptionUtils.toSingleResource(sel); + if(r == null) { + FunctionsFolder mn = AdaptionUtils.adaptToSingle(sel, FunctionsFolder.class); + r = mn.data; + } + if(r == null) return null; + + final Resource functionLibrary = r; + + + // Get a transferable graph file + final Shell shell = HandlerUtil.getActiveShellChecked(event); + FileDialog fd = new FileDialog(shell, SWT.OPEN); + fd.setText("Import Function Library"); + + String path = Activator.getDefault().getPreferenceStore().getString(IMPORTFUNCTIONLIBRARYPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); + String[] filterExt = {"*.tg"}; + fd.setFilterExtensions(filterExt); + String selected = fd.open(); + if(selected == null) return null; + + Activator.getDefault().getPreferenceStore().setValue(IMPORTFUNCTIONLIBRARYPATH, (new File(selected)).getParent()); + + // Load the transferable graph + TransferableGraph1 tg = null; + try { + tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class)); + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + return null; + } catch (IOException e) { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: Function Library"); + mb.open(); + return null; + } + if(tg == null) return null; + + // Make sure the "http://SharedOntologies resource exists + try { + Boolean hasSharedOntologies; + hasSharedOntologies = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + try { + graph.getResource("http://SharedOntologies"); + } catch (ResourceNotFoundException e) { + return false; + } + return true; + } + }); + + if(!hasSharedOntologies) { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + GraphUtils.create2(graph, l0.Library, + l0.HasName, "SharedOntologies", + l0.PartOf, graph.getResource("http:/")); + } + }); + + } + } catch (DatabaseException e) { + e.printStackTrace(); + return null; + } + + + // Import a function library from the transferable graph + SysdynFunctionLibraryImportAdvisor ia = new SysdynFunctionLibraryImportAdvisor(functionLibrary); + try { + DefaultPasteHandler.defaultExecute(tg, functionLibrary, ia); + } catch (Exception e) { + e.printStackTrace(); + } + + final Resource root = ia.getRoot(); // Root of the library + + // Link the imported library to the selected resource (functionLibrary) + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + /** + * Link the imported library to the selected resource (functionLibrary) + * The imported library can be either SysdynModelicaFunctionLibrary or SysdynFunctionOntology + */ + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + // Case: SharedFunctionOntology. Link to SharedOntologies + if(graph.isInstanceOf(root, SysdynResource.getInstance(graph).SharedFunctionOntology)) { + Resource library = graph.getResource("http://SharedOntologies"); + if(!graph.hasStatement(library, l0.ConsistsOf, root)) { + graph.claim(library, l0.ConsistsOf, root); + } + + // Link model to the shared library + SysdynResource sr = SysdynResource.getInstance(graph); + Resource model = functionLibrary; + while(!graph.isInstanceOf(model, sr.SysdynModel) && graph.isInstanceOf(model, l0.Ontology)) + model = graph.getSingleObject(model, l0.PartOf); + if(graph.isInstanceOf(model, sr.SysdynModel)) { + graph.claim(model, l0.IsLinkedTo, l0.IsLinkedTo_Inverse, root); + } + + // Case: not SharedFunctionOntology or SysdynModelicaFunctionLibrary. + } else if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary)) { + Resource instanceOf = graph.getPossibleObject(root,l0.InstanceOf); + String type = "..."; + if(instanceOf != null) + type = NameUtils.getSafeName(graph, instanceOf); + else { + Resource inheritedFrom = graph.getPossibleObject(root, l0.Inherits); + if(inheritedFrom != null) + type = NameUtils.getSafeName(graph, inheritedFrom); + } + final String ft = type; + + // Remove the functionLibrary ConsistsOf root relation + graph.deny(root, l0.PartOf); + + // Display error message + shell.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: Function Library (" + ft +")"); + mb.open(); + } + }); + } else { + // imported library is already in the right place. Update function library files. + FunctionUtils.updateFunctionFileForLibrary(graph, functionLibrary); + } + + } + }); + return null; + } + + /** + * Import advisor for importing function libraries to SysDyn + * + * @author Teemu Lempinen + * + */ + private class SysdynFunctionLibraryImportAdvisor extends DefaultPasteImportAdvisor { + + public SysdynFunctionLibraryImportAdvisor(Resource library) { + super(library); + } + + @Override + public void analyzeType(ReadGraph graph, Root root) throws DatabaseException { + // Change the library to http://SharedOntologies, if the imported library is of type SharedFunctionOntology + if(root.type.equals(SysdynResource.URIs.SharedFunctionOntology)) { + try { + library = graph.getResource("http://SharedOntologies"); + } catch (ResourceNotFoundException e) { + e.printStackTrace(); + } + } + } + + @Override + public Resource createRoot(WriteOnlyGraph graph, Root root) throws DatabaseException { + Layer0 l0 = graph.getService(Layer0.class); + this.root = graph.newResource(); + graph.claim(library, l0.ConsistsOf, l0.PartOf, this.root); + String name = root.name; + String newName = nameMappings.get(name); + graph.addLiteral(this.root, l0.HasName, l0.NameOf, l0.String, newName, Bindings.STRING); + return this.root; + + } + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportMdlHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportMdlHandler.java new file mode 100644 index 00000000..2ce39ec6 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportMdlHandler.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.imports; + +import java.io.File; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.mdlImport.MdlParser; +import org.simantics.sysdyn.mdlImport.mdlElements.Model; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.ui.SimanticsUI; + +/** + * Class for importing Vensim models (.mdl) to Simantics SysDyn using MdlParser + * + * @author Teemu Lempinen + * + */ +public class ImportMdlHandler extends AbstractHandler { + + public static String IMPORTMDLTPATH = "IMPORT_MDL_PATH"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + final Resource project = SimanticsUI.getProject().get(); + if(project == null) return null; + + // Get the .mdl file + Shell shell = HandlerUtil.getActiveShellChecked(event); + FileDialog fd = new FileDialog(shell, SWT.OPEN); + fd.setText("Import .mdl"); + String path = Activator.getDefault().getPreferenceStore().getString(IMPORTMDLTPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); + String[] filterExt = {"*.mdl"}; + fd.setFilterExtensions(filterExt); + String selected = fd.open(); + if(selected == null) return null; + + File file = new File(selected); + if(!file.isFile()) return null; + + Activator.getDefault().getPreferenceStore().setValue(IMPORTMDLTPATH, (new File(selected)).getParent()); + + // Convert Vensim model to Simantics SysDyn format using MdlParser + final Model model = MdlParser.parse(file); + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + model.write(graph, project); + } + }); + + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java new file mode 100644 index 00000000..ccecf5bb --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java @@ -0,0 +1,278 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.imports; + +import java.io.File; +import java.io.IOException; +import java.util.HashSet; +import java.util.UUID; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Files; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; +import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.operation.Layer0X; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.spreadsheet.resource.SpreadsheetResource; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.utils.OldTransferableGraph1; +import org.simantics.sysdyn.ui.utils.SheetUtils; +import org.simantics.ui.SimanticsUI; + +/** + * Imports models from exported transferable graph files. + * + * @author Teemu Lempinen + * + */ +public class ImportModelHandler extends AbstractHandler { + + public static String IMPORTMODELTPATH = "IMPORT_MODEL_PATH"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + Resource project = SimanticsUI.getProject().get(); + if(project == null) return null; + + // Get imported transferable graph file using FileDialog + final Shell shell = HandlerUtil.getActiveShellChecked(event); + FileDialog fd = new FileDialog(shell, SWT.OPEN); + fd.setText("Import Model"); + + String path = Activator.getDefault().getPreferenceStore().getString(IMPORTMODELTPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); + String[] filterExt = {"*.tg"}; + fd.setFilterExtensions(filterExt); + String selected = fd.open(); + if(selected == null) return null; + + Activator.getDefault().getPreferenceStore().setValue(IMPORTMODELTPATH, (new File(selected)).getParent()); + + // Get the transferable graph from file + TransferableGraph1 tg = null; + try { + tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class)); + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + } catch (IOException e) { + try { + // "Version migration". Use OldTransferableGraph1 if the file was imported using old methods + OldTransferableGraph1 otg = (OldTransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(OldTransferableGraph1.class)); + tg = new TransferableGraph1(otg.resourceCount, otg.identities, otg.statements, otg.values); + } catch (RuntimeBindingConstructionException e1) { + e1.printStackTrace(); + } catch (IOException e1) { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: Model"); + mb.open(); + return null; + } + } + if(tg == null) return null; + + try { + + DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(project); + DefaultPasteHandler.defaultExecute(tg, SimanticsUI.getProject().get(), ia); + + + // Check that imported resource was actually a model + //and fix changes made to old ontology versions + final Resource root = ia.getRoot(); + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModel)) { + // Imported model was not a SysdynModel, display error message. + Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf); + String type = "..."; + if(instanceOf != null) + type = NameUtils.getSafeName(graph, instanceOf); + else { + Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits); + if(inheritedFrom != null) + type = NameUtils.getSafeName(graph, inheritedFrom); + } + final String ft = type; + graph.deny(root, Layer0.getInstance(graph).PartOf); + + shell.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: System Dynamics Model (" + ft +")"); + mb.open(); + } + }); + + } else { + + Resource project = SimanticsUI.getProject().get(); + graph.claim(root, Layer0X.getInstance(graph).IsActivatedBy, project); + + // Do all modifications that are necessary + updateOldConfigurationToBaseRealization(graph, root); + addDefaultOntologyLinks(graph, root); + addURIsToDiagrams(graph, root); + addSpreadSheetBook(graph, root); + } + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * In old versions base realization was separate. Newer versions use configuration as base realization. + * @param graph WriteGraph + * @param model Imported model + */ + private static void updateOldConfigurationToBaseRealization(WriteGraph graph, Resource model) { + Layer0X L0X = Layer0X.getInstance(graph); + try { + Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration); + if(configuration != null && !graph.hasStatement(configuration, L0X.IsBaseRealizationOf, model)) + graph.claim(configuration, L0X.IsBaseRealizationOf, model); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + + /** + * Links should be exported and imported automatically. If it has failed, the + * default ontology links sysdyn and layer0 are added. + * + * @param graph WriteGraph + * @param model Imported model + */ + + private static void addDefaultOntologyLinks(WriteGraph graph, Resource model) { + try { + Layer0 l0 = Layer0.getInstance(graph); + // The links should be exported and imported automatically + Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.1"); + Resource layer0 = graph.getResource("http://www.simantics.org/Layer0-1.0"); + if(!graph.hasStatement(model, l0.IsLinkedTo, sysdyn)) + graph.claim(model, l0.IsLinkedTo, sysdyn); + if(!graph.hasStatement(model, l0.IsLinkedTo, layer0)) + graph.claim(model, l0.IsLinkedTo, layer0); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + + /** + * Add a container for providing URIs to diagrams. + * + * @param graph WriteGraph + * @param model Imported model + */ + private static void addURIsToDiagrams(WriteGraph graph, Resource model) { + Layer0 l0 = Layer0.getInstance(graph); + SimulationResource simu = SimulationResource.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + try { + HashSet configurations = new HashSet(); + + Resource configuration = graph.getPossibleObject(model, simu.HasConfiguration); + if(configuration != null) + configurations.add(configuration); + + for(Resource r : graph.getObjects(model, l0.ConsistsOf)) { + if(graph.isInheritedFrom(r, sr.Module)) { + Resource moduleConfiguration = graph.getPossibleObject(r, sr2.IsDefinedBy); + if(moduleConfiguration != null) + configurations.add(moduleConfiguration); + } + } + + for(Resource conf : configurations) { + Resource configurationDiagram = graph.getPossibleObject(conf, mr.CompositeToDiagram); + if(configurationDiagram != null && !graph.hasStatement(configurationDiagram, l0.PartOf)) { + GraphUtils.create2(graph, l0.Library, + l0.HasName, "__CONTAINER__", + l0.PartOf, conf, + l0.ConsistsOf, configurationDiagram); + } + } + + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + + /** + * Add a missing spreadsheet book to the model + * + * @param graph + * @param model + */ + private static void addSpreadSheetBook(WriteGraph graph, Resource model) { + try { + Layer0 l0 = Layer0.getInstance(graph); + SpreadsheetResource ssr = SpreadsheetResource.getInstance(graph); + SimulationResource simu = SimulationResource.getInstance(graph); + Resource conf = graph.getPossibleObject(model, simu.HasConfiguration); + if(conf != null && graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, ssr.Book)).isEmpty()) { + Resource book = graph.newResource(); + graph.claim(book, l0.InstanceOf, null, ssr.Book); + graph.addLiteral(book, l0.HasName, l0.NameOf, l0.String, "Book" + UUID.randomUUID().toString(), Bindings.STRING); + graph.claim(conf, l0.ConsistsOf, l0.PartOf, book); + + SheetUtils.createSheet(graph, book, "Sheet1", new String[] { }, new int[] { 50 }); + } + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModuleHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModuleHandler.java new file mode 100644 index 00000000..9a0cfceb --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModuleHandler.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.imports; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Files; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; +import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; +import org.simantics.graph.db.MissingDependencyException; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Imports modules from exported transferable graph files. + * + * @author Teemu Lempinen + * + */ +public class ImportModuleHandler extends AbstractHandler { + + public static String IMPORTMODULETPATH = "IMPORT_MODULE_PATH"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection sel = HandlerUtil.getCurrentSelection(event); + + @SuppressWarnings("unchecked") + AbstractNode node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class); + if (node == null) + return null; + + final Resource model = node.data; + + // Get imported transferable graph file using FileDialog + final Shell shell = HandlerUtil.getActiveShellChecked(event); + FileDialog fd = new FileDialog(shell, SWT.OPEN); + fd.setText("Import Module"); + + String path = Activator.getDefault().getPreferenceStore().getString(IMPORTMODULETPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + fd.setFilterPath(path); + String[] filterExt = {"*.tg"}; + fd.setFilterExtensions(filterExt); + String selected = fd.open(); + if(selected == null) return null; + + Activator.getDefault().getPreferenceStore().setValue(IMPORTMODULETPATH, (new File(selected)).getParent()); + + // Get the transferable graph from file + TransferableGraph1 tg = null; + try { + tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class)); + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + } catch (IOException e) { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: Module Type"); + mb.open(); + return null; + } + if(tg == null) return null; + + + // Import the module to model + DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(model); + try { + DefaultPasteHandler.defaultExecute(tg, model, ia); + } catch (MissingDependencyException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + + final Resource root = ia.getRoot(); + + // Check that the imported file actually was a module. Display error message otherwise. + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if(!graph.isInheritedFrom(root, SysdynResource.getInstance(graph).Module)) { + Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf); + String type = "..."; + if(instanceOf != null) + type = NameUtils.getSafeName(graph, instanceOf); + else { + Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits); + if(inheritedFrom != null) + type = NameUtils.getSafeName(graph, inheritedFrom); + } + final String ft = type; + graph.deny(root, Layer0.getInstance(graph).PartOf); + + shell.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ERROR); + mb.setText("Error"); + mb.setMessage("The imported file is not of type: System Dynamics Module (" + ft +")"); + mb.open(); + } + }); + } + } + }); + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewBarChartHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewBarChartHandler.java new file mode 100644 index 00000000..3171cc78 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewBarChartHandler.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; + +import java.util.Collections; +import java.util.UUID; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.browser.nodes.ChartsFolder; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Handler for creating a new Bar Chart + * @author Teemu Lempinen + * + */ +public class NewBarChartHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection sel = HandlerUtil.getCurrentSelection(event); + + ChartsFolder node = AdaptionUtils.adaptToSingle(sel, ChartsFolder.class); + if (node == null) + return null; + + final Resource model = node.data; + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + JFreeChartResource jfree = JFreeChartResource.getInstance(g); + G2DResource g2d = G2DResource.getInstance(g); + + Resource jfreechart = GraphUtils.create2(g, jfree.Chart, + l0.HasName, "BarChart" + UUID.randomUUID().toString(), + l0.HasLabel, NameUtils.findFreshLabel(g, "Bar Chart", model), + l0.PartOf, model, + jfree.Chart_visibleBorder, true, + jfree.Chart_borderWidth, 3, + jfree.Chart_visibleLegend, false + ); + + g.claimLiteral(jfreechart, jfree.Chart_borderColor, g2d.Color, new float[] {0,0,0,1}); + + GraphUtils.create2(g, jfree.TextTitle, + l0.HasName, "TextTitle" + UUID.randomUUID().toString(), + l0.HasLabel, "Bar Chart Title", + jfree.Title_position, jfree.Top, + l0.PartOf, jfreechart); + + Resource domainAxis = GraphUtils.create2(g, jfree.CategoryAxis, + l0.HasName, "CategoryAxis" + UUID.randomUUID().toString()); + + Resource rangeAxis = GraphUtils.create2(g, jfree.NumberAxis, + l0.HasName, "NumberAxis" + UUID.randomUUID().toString()); + + Resource renderer = GraphUtils.create2(g, jfree.BarRenderer); + + Resource dataset = GraphUtils.create2(g, jfree.CategoryDataset, + l0.HasName, "CategoryDataset" + UUID.randomUUID().toString(), + jfree.Dataset_mapToDomainAxis, domainAxis, + jfree.Dataset_mapToRangeAxis, rangeAxis, + jfree.Dataset_seriesList, ListUtils.create(g, Collections.emptyList()), + jfree.Dataset_renderer, renderer); + + GraphUtils.create2(g, jfree.CategoryPlot, + l0.HasName, "Category plot" + UUID.randomUUID().toString(), + l0.PartOf, jfreechart, + jfree.Plot_domainAxis, domainAxis, + jfree.Plot_rangeAxis, rangeAxis, + jfree.Plot_rangeAxisList, ListUtils.create(g, Collections.singletonList(rangeAxis)), + l0.ConsistsOf, dataset, + l0.ConsistsOf, domainAxis, + l0.ConsistsOf, rangeAxis); + } + + }); + + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewEnumerationNodeHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewEnumerationNodeHandler.java new file mode 100644 index 00000000..fbd774ff --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewEnumerationNodeHandler.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Creates a new Enumeration node to a configuration or module + * + * @author Teemu Lempinen + * + */ +public class NewEnumerationNodeHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection sel = HandlerUtil.getCurrentSelection(event); + + final Resource resource = AdaptionUtils.adaptToSingle(sel, Resource.class); + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + Layer0 l0 = Layer0.getInstance(g); + + // Find the actual configuration. Possible cases for resource are sr.Configuration, sr.ModuleSymbol or sr.Module. + Resource configuration = null; + if(g.isInstanceOf(resource, sr.Configuration)) { + configuration = resource; + } else if(g.isInheritedFrom(resource, sr.ModuleSymbol)) { + Resource module = g.getPossibleObject(resource,ModelingResources.getInstance(g).SymbolToComponentType); + configuration = g.getPossibleObject(module, StructuralResource2.getInstance(g).IsDefinedBy); + } else { + Resource instanceOf = g.getSingleObject(resource, l0.InstanceOf); + if(g.isInheritedFrom(instanceOf, sr.Module)) { + configuration = g.getPossibleObject(instanceOf, StructuralResource2.getInstance(g).IsDefinedBy); + } else { + return; + } + } + + // Create the enumeartion + Resource enumerationIndexes = OrderedSetUtils.create(g, sr.EnumerationIndexes); + + String name = NameUtils.findFreshName(g, "Enum", configuration, l0.ConsistsOf, "%s%d"); + + GraphUtils.create2(g, + sr.Enumeration, + l0.HasName, name, + sr.HasEnumerationIndexes, enumerationIndexes, + l0.PartOf, configuration); + } + }); + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewExperimentNodeHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewExperimentNodeHandler.java new file mode 100644 index 00000000..f8e1f331 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewExperimentNodeHandler.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.document.DocumentResource; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.ExperimentsFolder; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Creates a new normal SysDyn experiment + * + * @author Teemu Lempinen + * + */ +public class NewExperimentNodeHandler extends AbstractHandler { + + /** + * Assumes that it is called from a node that has a SysDyn model as its resource. + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection sel = HandlerUtil.getCurrentSelection(event); + + ExperimentsFolder node = AdaptionUtils.adaptToSingle(sel, ExperimentsFolder.class); + if (node == null) + return null; + + final Resource model = node.data; + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + DocumentResource DOC = DocumentResource.getInstance(g); + Resource report = GraphUtils.create2(g, DOC.Report, DOC.HasDocumentation, "===Report==="); + + String name = NameUtils.findFreshName(g, getNameSuggestion(), model, l0.ConsistsOf, "%s%d"); + + Resource experiment = GraphUtils.create2(g, getExperimentType(g), + l0.HasName, name, + l0.HasLabel, name, + DOC.HasReportFactory, report, + l0.PartOf, model); + + configureExperiment(g, experiment); + } + }); + return null; + } + + /** + * Override to do experiment-specific alterations + */ + protected void configureExperiment(WriteGraph graph, Resource experiment) throws DatabaseException { + + } + + /** + * Get the type of this experiment. + * + * @param g ReadGraph + * @return The type resource of this experiment + */ + protected Resource getExperimentType(ReadGraph g) { + return SysdynResource.getInstance(g).BasicExperiment; + } + + /** + * Returns the suggested name for this experiment. + * If the name has already been taken, appropriate prefix needs to be added. + * + * @return Suggested name for this experiment. + */ + protected String getNameSuggestion() { + return "Experiment"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java new file mode 100644 index 00000000..a9a970db --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionHandler.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Creates a new function to a SysdynModel or Library. + * + * @author Teemu Lempinen + * + */ +public class NewFunctionHandler extends AbstractHandler { + + /** + * Assumes to be called from a node with SysdynModel, Library or SysdynModelicaFunction as its resource + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection sel = HandlerUtil.getCurrentSelection(event); + + @SuppressWarnings("unchecked") + AbstractNode node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class); + if (node == null) + return null; + + final Resource data = node.data; + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + SysdynResource sr = SysdynResource.getInstance(g); + + // Library can be either SysdynModel or L0.Library. + Resource library = null; + if(g.isInstanceOf(data, sr.SysdynModel) || g.isInstanceOf(data, l0.Library)) + library = data; + else if (g.isInstanceOf(data, sr.SysdynModelicaFunction)) + library = g.getPossibleObject(data, l0.PartOf); + + if(library == null) + return; + + + String name = NameUtils.findFreshName(g, "Function", library, l0.ConsistsOf, "%s%d"); + + GraphUtils.create2(g, sr.SysdynModelicaFunction, + l0.HasName, name, + l0.HasDescription, "", + sr.HasModelicaFunctionCode, "", + l0.PartOf, library); + + FunctionUtils.updateFunctionFileForLibrary(g, library); + } + }); + + return null; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionLibraryHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionLibraryHandler.java new file mode 100644 index 00000000..98f40231 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewFunctionLibraryHandler.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Creates a new function library to a model or other library. + * + * @author Teemu Lempinen + * + */ +public class NewFunctionLibraryHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection sel = HandlerUtil.getCurrentSelection(event); + + @SuppressWarnings("unchecked") + AbstractNode node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class); + if (node == null) + return null; + + createLibrary(node.data, false); + return null; + } + + /** + * Create function library. Shared libraries are created to root, local libraries to the model. + * Shared libraries can be used in other models in the project. + * + * @param model The initial location of the command + * @param shared Shared libraries are created to root, local libraries to the model. + */ + protected void createLibrary(final Resource model, final boolean shared) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + SysdynResource sr = SysdynResource.getInstance(g); + + if(!(g.isInstanceOf(model, sr.SysdynModel) || + g.isInstanceOf(model, sr.SysdynModelicaFunctionLibrary) || + g.isInstanceOf(model, sr.SharedFunctionOntology))) + return; + + Resource root = model; + + String name = "FunctionLibrary"; + Resource libraryType = sr.SysdynModelicaFunctionLibrary; + + if(shared) { + + try { + root = g.getResource("http://SharedOntologies"); + } catch (ResourceNotFoundException e) { + root = g.getResource("http:/"); + root = GraphUtils.create2(g, l0.Library, + l0.HasName, "SharedOntologies", + l0.PartOf, root); + } + + name = "Shared" + name; + libraryType = sr.SharedFunctionOntology; + } + + name = NameUtils.findFreshName(g, name, root, l0.ConsistsOf, "%s%d"); + + Resource functionLibrary = GraphUtils.create2(g, libraryType, + l0.HasName, name, + l0.HasDescription, "", + l0.PartOf, root); + + if(shared) + g.claim(model, l0.IsLinkedTo, functionLibrary); + + FunctionUtils.updateFunctionFileForLibrary(g, functionLibrary); + } + }); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModelHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModelHandler.java new file mode 100644 index 00000000..393d5ae8 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModelHandler.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.utils.ModelUtils; +import org.simantics.ui.SimanticsUI; + +/** + * Creates a new SysDyn model. + * + * @author Teemu Lempinen + * + */ +public class NewModelHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + + Job job = new Job("Creating System Dynamics Model") { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + // Use ModelUtils to keep all model creations up-to-date + ModelUtils.createModel(graph); + } + }); + return Status.OK_STATUS; + } catch (DatabaseException e) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e); + } + } + }; + job.setUser(true); + job.schedule(); + + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java new file mode 100644 index 00000000..9c2e98e4 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModuleNodeHandler.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.Template; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.operation.Layer0X; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.ModulesNode; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.datastructures.ArrayMap; + +/** + * Creates a new module node for a model. + * + * @author Teemu Lempinen + * + */ +public class NewModuleNodeHandler extends AbstractHandler { + + /** + * Assumes to be called from a node that has a SysDyn model as its resource. + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection sel = HandlerUtil.getCurrentSelection(event); + + ModulesNode node = AdaptionUtils.adaptToSingle(sel, ModulesNode.class); + if (node == null) + return null; + + final Resource model = node.data; + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + Layer0 l0 = Layer0.getInstance(g); + Layer0X L0X = Layer0X.getInstance(g); + ModelingResources mr = ModelingResources.getInstance(g); + StructuralResource2 sr2 = StructuralResource2.getInstance(g); + DiagramResource dr = DiagramResource.getInstance(g); + + String name = NameUtils.findFreshName(g, "ModuleType", model, l0.ConsistsOf, "%s%d"); + + Resource moduleType = g.newResource(); + g.claimLiteral(moduleType, l0.HasName, name); + g.claim(moduleType, l0.Inherits, sr.Module); + g.claim(moduleType, l0.PartOf, model); + + + + Resource configuration = GraphUtils.create2(g, + sr.Configuration, + l0.HasName, name + "Configuration", + l0.PartOf, moduleType); + + g.claim(moduleType, sr2.IsDefinedBy , configuration); + + Resource diagram = g.newResource(); + g.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(g, + ArrayMap + .keys("", "diagram", "name") + .values(configuration, diagram, "Diagrammi") + ); + + + // Remove default mapping and add sysdyn mapping + for(Resource trigger : g.getObjects(diagram, L0X.HasTrigger)) { + if(g.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) { + g.deny(diagram, L0X.HasTrigger, trigger); + } + } + + GraphUtils.create2(g, + sr.Validations_Dependencies_MissingDependencyConnectionsIssueSource, + L0X.IsActivatedBy, model, + l0.PartOf, moduleType + ); + + GraphUtils.create2(g, + sr.Validations_Dependencies_DependencyConnectionsIssueSource, + L0X.IsActivatedBy, model, + l0.PartOf, moduleType + ); + + GraphUtils.create2(g, + sr.Validations_Expressions_ExpressionIssueSource, + L0X.IsActivatedBy, model, + l0.PartOf, moduleType + ); + + Resource mapping = g.newResource(); + g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); + g.claim(diagram, L0X.HasTrigger, mapping); + + Resource moduleSymbol = g.newResource(); + g.claimLiteral(moduleSymbol, l0.HasName, name + " Symbol"); + g.claimLiteral(moduleSymbol, l0.HasLabel, name + " Symbol"); + g.claim(moduleSymbol, l0.Inherits, sr.ModuleSymbol); + g.claim(moduleSymbol, mr.SymbolToComponentType, moduleType); + g.claim(moduleSymbol, l0.PartOf, moduleType); + + Resource terminal = g.newResource(); + g.claim(terminal, l0.InstanceOf, sr.SysdynTerminal); + Resource connectionVariable = g.newResource(); + g.claim(connectionVariable, l0.InstanceOf, sr2.ConnectionVariable); + g.claim(connectionVariable, sr2.Binds, sr.IsHeadOfTerminal); + g.claim(connectionVariable, sr2.IsParameterOf, moduleSymbol); + g.claim(terminal, dr.HasConnectionVariable, connectionVariable); + + + Resource terminal2 = g.newResource(); + g.claim(terminal2, l0.InstanceOf, sr.SysdynTerminal); + Resource connectionVariable2 = g.newResource(); + g.claim(connectionVariable2, l0.InstanceOf, sr2.ConnectionVariable); + g.claim(connectionVariable2, sr2.Binds, sr.IsTailOfTerminal); + g.claim(connectionVariable2, sr2.IsParameterOf, moduleSymbol); + g.claim(terminal2, dr.HasConnectionVariable, connectionVariable2); + + g.claim(moduleSymbol, sr2.IsDefinedBy, OrderedSetUtils.create(g, sr2.Composite, terminal, terminal2)); + + + } + }); + return null; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPieChartHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPieChartHandler.java new file mode 100644 index 00000000..516e49f9 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPieChartHandler.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; + +import java.util.Collections; +import java.util.UUID; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.browser.nodes.ChartsFolder; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Handler for craeting a new Pie Chart + * @author Teemu Lempinen + * + */ +public class NewPieChartHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection sel = HandlerUtil.getCurrentSelection(event); + + ChartsFolder node = AdaptionUtils.adaptToSingle(sel, ChartsFolder.class); + if (node == null) + return null; + + final Resource model = node.data; + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + JFreeChartResource jfree = JFreeChartResource.getInstance(g); + G2DResource g2d = G2DResource.getInstance(g); + + Resource jfreechart = GraphUtils.create2(g, jfree.Chart, + l0.HasName, "PieChart" + UUID.randomUUID().toString(), + l0.HasLabel, NameUtils.findFreshLabel(g, "Pie Chart", model), + l0.PartOf, model, + jfree.Chart_visibleBorder, true, + jfree.Chart_borderWidth, 3); + g.claimLiteral(jfreechart, jfree.Chart_borderColor, g2d.Color, new float[] {0,0,0,1}); + + GraphUtils.create2(g, jfree.TextTitle, + l0.HasName, "TextTitle" + UUID.randomUUID().toString(), + l0.HasLabel, "Pie Chart Title", + jfree.Title_position, jfree.Top, + l0.PartOf, jfreechart); + + Resource dataset = GraphUtils.create2(g, jfree.PieDataset, + l0.HasName, "CategoryDataset" + UUID.randomUUID().toString(), + jfree.Dataset_seriesList, ListUtils.create(g, Collections.emptyList()) + ); + + GraphUtils.create2(g, jfree.PiePlot, + l0.HasName, "PiePlot" + UUID.randomUUID().toString(), + l0.PartOf, jfreechart, + l0.ConsistsOf, dataset + ); + } + + }); + + return null; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPlaybackExperimentNodeHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPlaybackExperimentNodeHandler.java new file mode 100644 index 00000000..a54ce36f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewPlaybackExperimentNodeHandler.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; + +import java.awt.Color; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; + +/** + * Creates a new playback experiment. + * + * @author Teemu Lempinen + * + */ +public class NewPlaybackExperimentNodeHandler extends NewExperimentNodeHandler { + + protected void configureExperiment(WriteGraph graph, Resource experiment) throws DatabaseException { + G2DResource g2d = G2DResource.getInstance(graph); + Resource defaultGradient = GraphUtils.create2(graph, g2d.ColorGradient); + graph.claim(experiment, g2d.HasColorGradient, defaultGradient); + + Resource placement = GraphUtils.create2(graph, g2d.ColorPlacement, + g2d.HasGradientPosition, 0.0); + graph.claimLiteral(placement, g2d.HasColor, g2d.Color, new Color(0, 62, 133).getColorComponents(new float[4])); + graph.claim(defaultGradient, g2d.HasColorPlacement, placement); + + placement = GraphUtils.create2(graph, g2d.ColorPlacement, + g2d.HasGradientPosition, 1.0); + graph.claimLiteral(placement, g2d.HasColor, g2d.Color, new Color(255, 230, 0).getColorComponents(new float[4])); + graph.claim(defaultGradient, g2d.HasColorPlacement, placement); + } + + protected Resource getExperimentType(ReadGraph g) { + return SysdynResource.getInstance(g).PlaybackExperiment; + } + + protected String getNameSuggestion() { + return "Playback Experiment"; + } +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSharedFunctionLibraryHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSharedFunctionLibraryHandler.java new file mode 100644 index 00000000..5eba69cd --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSharedFunctionLibraryHandler.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.db.Resource; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Creates a new shared function library. + * + * @author Teemu Lempinen + * + */ +public class NewSharedFunctionLibraryHandler extends NewFunctionLibraryHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection sel = HandlerUtil.getCurrentSelection(event); + + @SuppressWarnings("unchecked") + AbstractNode node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class); + if (node == null) + return null; + + createLibrary(node.data, true); + return null; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java new file mode 100644 index 00000000..16c6a3da --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.utils.SheetUtils; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; + +/** + * Creates a new spreadsheet sheet to a book. + * @author Teemu Lempinen + * + */ +public class NewSpreadSheetHandler extends AbstractHandler { + + /** + * Called from a node that has a book as its resource. + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection sel = HandlerUtil.getCurrentSelection(event); + final Resource book = ResourceAdaptionUtils.toSingleResource(sel); + if(book == null) return null; + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SheetUtils.createSheet(graph, book, null, new String[] {}, new int[] {50}); + } + }); + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java new file mode 100644 index 00000000..98c94da8 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.newComponents; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.UUID; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.browser.nodes.ChartsFolder; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Handler for creating a new XYLineChart in model browser + * @author Teemu Lempinen + * + */ +public class NewXYLineChartHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + + ISelection sel = HandlerUtil.getCurrentSelection(event); + + ChartsFolder node = AdaptionUtils.adaptToSingle(sel, ChartsFolder.class); + if (node == null) + return null; + + final Resource model = node.data; + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + JFreeChartResource jfree = JFreeChartResource.getInstance(g); + G2DResource g2d = G2DResource.getInstance(g); + + Resource jfreechart = GraphUtils.create2(g, jfree.Chart, + l0.HasName, "Chart" + UUID.randomUUID().toString(), + l0.HasLabel, NameUtils.findFreshLabel(g, "Chart", model), + l0.PartOf, model, + jfree.Chart_visibleBorder, true, + jfree.Chart_borderWidth, 3); + g.claimLiteral(jfreechart, jfree.Chart_borderColor, g2d.Color, new float[] {0,0,0,1}); + + GraphUtils.create2(g, jfree.TextTitle, + l0.HasName, "TextTitle" + UUID.randomUUID().toString(), + l0.HasLabel, "Chart Title", + jfree.Title_position, jfree.Top, + l0.PartOf, jfreechart); + + Resource domainAxis = GraphUtils.create2(g, jfree.NumberAxis, + l0.HasName, "NumberAxis" + UUID.randomUUID().toString()); + Resource rangeAxis = GraphUtils.create2(g, jfree.NumberAxis, + l0.HasName, "NumberAxis" + UUID.randomUUID().toString()); + + Resource renderer = GraphUtils.create2(g, jfree.XYLineRenderer); + + Resource dataset = GraphUtils.create2(g, jfree.XYDataset, + l0.HasName, "XYDataset" + UUID.randomUUID().toString(), + jfree.Dataset_mapToDomainAxis, domainAxis, + jfree.Dataset_mapToRangeAxis, rangeAxis, + jfree.Dataset_seriesList, ListUtils.create(g, new ArrayList()), + jfree.Dataset_renderer, renderer); + + GraphUtils.create2(g, jfree.XYPlot, + l0.HasName, "XYPlot" + UUID.randomUUID().toString(), + l0.PartOf, jfreechart, + jfree.Plot_domainAxis, domainAxis, + jfree.Plot_rangeAxis, rangeAxis, + jfree.Plot_rangeAxisList, ListUtils.create(g, Collections.singletonList(rangeAxis)), + l0.ConsistsOf, dataset, + l0.ConsistsOf, domainAxis, + l0.ConsistsOf, rangeAxis); + } + + }); + + + + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/FastSpeedHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/FastSpeedHandler.java new file mode 100644 index 00000000..d98a44ec --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/FastSpeedHandler.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.simulationPlayback; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; + +public class FastSpeedHandler extends SpeedHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + setPlaybackSpeed(SysdynPlaybackExperiment.DURATION_FAST); + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/NormalSpeedHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/NormalSpeedHandler.java new file mode 100644 index 00000000..b2ece4d6 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/NormalSpeedHandler.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.simulationPlayback; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; + +public class NormalSpeedHandler extends SpeedHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + setPlaybackSpeed(SysdynPlaybackExperiment.DURATION_NORMAL); + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackExperimentHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackExperimentHandler.java new file mode 100644 index 00000000..72ae6ec7 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackExperimentHandler.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.simulationPlayback; + +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.commands.IElementUpdater; +import org.eclipse.ui.menus.UIElement; +import org.simantics.simulation.experiment.ExperimentState; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.ui.SimanticsUI; + +public class PlaybackExperimentHandler extends AbstractHandler implements IElementUpdater { + + public static final String COMMAND = "org.simantics.sysdyn.ui.playback"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment == null || !(experiment instanceof SysdynPlaybackExperiment)) + return null; + SysdynPlaybackExperiment spe = (SysdynPlaybackExperiment)experiment; + if(!spe.isPlaybackRunning()) + spe.startPlayback(); + else + spe.stopPlayback(); + return null; + } + + @SuppressWarnings("rawtypes") + @Override + public void updateElement(UIElement element, Map parameters) { + IExperimentManager manager = + SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment == null || !(experiment instanceof SysdynPlaybackExperiment)) + return; + SysdynPlaybackExperiment spe = (SysdynPlaybackExperiment)experiment; + + ExperimentState state = experiment.getState(); + if(state == ExperimentState.RUNNING && !spe.isPlaybackRunning()) { + // RUNNING == simulation, not playback + this.setBaseEnabled(false); + } else { + this.setBaseEnabled(true); + } + + if(spe.isPlaybackRunning()) { + element.setIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_pause.png"))); + element.setHoverIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_pause_blue.png"))); + } else { + long duration = spe.getPlaybackDuration(); + if(duration == SysdynPlaybackExperiment.DURATION_SLOW) { + element.setIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_step.png"))); + element.setHoverIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_step_blue.png"))); + } else if(duration == SysdynPlaybackExperiment.DURATION_FAST) { + element.setIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_fastforward.png"))); + element.setHoverIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_fastforward_blue.png"))); + } else { + element.setIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_play.png"))); + element.setHoverIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_play_blue.png"))); + } + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackReloadHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackReloadHandler.java new file mode 100644 index 00000000..e7d97445 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackReloadHandler.java @@ -0,0 +1,24 @@ +package org.simantics.sysdyn.ui.handlers.simulationPlayback; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; +import org.simantics.ui.SimanticsUI; + +public class PlaybackReloadHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment == null || !(experiment instanceof SysdynPlaybackExperiment)) + return null; + SysdynPlaybackExperiment spe = (SysdynPlaybackExperiment)experiment; + spe.simulate(true); + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackResetHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackResetHandler.java new file mode 100644 index 00000000..e4155b67 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackResetHandler.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.simulationPlayback; + +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.commands.IElementUpdater; +import org.eclipse.ui.menus.UIElement; +import org.simantics.simulation.experiment.ExperimentState; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; +import org.simantics.ui.SimanticsUI; + +public class PlaybackResetHandler extends AbstractHandler implements IElementUpdater { + + public static final String COMMAND = "org.simantics.sysdyn.ui.playbackReset"; + + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment == null || !(experiment instanceof SysdynPlaybackExperiment)) + return null; + SysdynPlaybackExperiment spe = (SysdynPlaybackExperiment)experiment; + spe.resetPlayback(); + return null; + } + + @SuppressWarnings("rawtypes") + @Override + public void updateElement(UIElement element, Map parameters) { + IExperimentManager manager = + SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment == null || !(experiment instanceof SysdynPlaybackExperiment)) + return; + SysdynPlaybackExperiment spe = (SysdynPlaybackExperiment)experiment; + + ExperimentState state = experiment.getState(); + if(state == ExperimentState.RUNNING && !spe.isPlaybackRunning()) { + // RUNNING == simulation, not playback + this.setBaseEnabled(false); + } else { + this.setBaseEnabled(true); + } + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/SlowSpeedHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/SlowSpeedHandler.java new file mode 100644 index 00000000..6ebeba33 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/SlowSpeedHandler.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.simulationPlayback; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; + +public class SlowSpeedHandler extends SpeedHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + setPlaybackSpeed(SysdynPlaybackExperiment.DURATION_SLOW); + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/SpeedHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/SpeedHandler.java new file mode 100644 index 00000000..4fe96910 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/SpeedHandler.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers.simulationPlayback; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; +import org.simantics.ui.SimanticsUI; + +abstract class SpeedHandler extends AbstractHandler { + + protected void setPlaybackSpeed(long duration) { + + + IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment == null || !(experiment instanceof SysdynPlaybackExperiment)) + return; + final SysdynPlaybackExperiment spe = (SysdynPlaybackExperiment)experiment; + + if(spe.getPlaybackDuration() == duration) + return; + + + spe.setPlaybackDuration(duration); + + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + ICommandService commandService = + (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + commandService.refreshElements(PlaybackExperimentHandler.COMMAND, null); + } + }); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentListener.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentListener.java new file mode 100644 index 00000000..04507781 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentListener.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.listeners; + +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.State; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.contexts.IContextActivation; +import org.simantics.simulation.experiment.ExperimentState; +import org.simantics.simulation.experiment.IExperimentListener; +import org.simantics.sysdyn.ui.handlers.RunBasicExperiment; +import org.simantics.sysdyn.ui.handlers.ToggleSimulation; +import org.simantics.sysdyn.ui.handlers.simulationPlayback.PlaybackExperimentHandler; +import org.simantics.sysdyn.ui.handlers.simulationPlayback.PlaybackResetHandler; + +public class SysdynExperimentListener implements IExperimentListener { + + IContextActivation contextActivation; + + @Override + public void stateChanged(final ExperimentState state) { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + ICommandService commandService = + (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = commandService.getCommand(ToggleSimulation.COMMAND); + State buttonState = command.getState(ToggleSimulation.STATE); + + switch(state) { + case DISPOSED: + buttonState.setValue(false); + break; + } + commandService.refreshElements(command.getId(), null); + commandService.refreshElements(RunBasicExperiment.COMMAND, null); + commandService.refreshElements(PlaybackExperimentHandler.COMMAND, null); + commandService.refreshElements(PlaybackResetHandler.COMMAND, null); + } + + }); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentManagerListener.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentManagerListener.java new file mode 100644 index 00000000..98b8f65a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentManagerListener.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.listeners; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.contexts.IContextActivation; +import org.eclipse.ui.contexts.IContextService; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.simulation.project.IExperimentManagerListener; +import org.simantics.sysdyn.manager.SysdynExperiment; +import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; + +public class SysdynExperimentManagerListener implements IExperimentManagerListener{ + + public static final String BASIC_EXPERIMENT_CONTEXT = "org.simantics.sysdyn.ui.basicExperiment"; + public static final String PLAYBACK_EXPERIMENT_CONTEXT = "org.simantics.sysdyn.ui.playbackExperiment"; + + static Set managers = + new HashSet(); + + IExperimentManager manager; + + Collection contextActivations = + new ArrayList(); + + public SysdynExperimentManagerListener(IExperimentManager manager) { + this.manager = manager; + } + + public static void listenManager(IExperimentManager manager) { + synchronized(managers) { + if(managers.contains(manager)) + return; + SysdynExperimentManagerListener listener = + new SysdynExperimentManagerListener(manager); + manager.addListener(listener); + managers.add(manager); + } + } + + @Override + public void activeExperimentLoaded(final IExperiment experiment) { + experiment.addListener(new SysdynExperimentListener()); + + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + IContextService contextService = + (IContextService)PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getService(IContextService.class); + synchronized(contextActivations) { + if(experiment instanceof SysdynPlaybackExperiment) { + contextActivations.add(contextService.activateContext(PLAYBACK_EXPERIMENT_CONTEXT)); + experiment.addListener(new SysdynPlaybackExperimentListener((SysdynPlaybackExperiment)experiment)); + } else if(experiment instanceof SysdynExperiment) { + contextActivations.add(contextService.activateContext(BASIC_EXPERIMENT_CONTEXT)); + } + } + } + + }); + } + + @Override + public void activeExperimentUnloaded() { + + synchronized(contextActivations) { + final Collection oldContextActivations = + contextActivations; + + contextActivations = new ArrayList(); + + final IWorkbench workbench = PlatformUI.getWorkbench(); + workbench.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if (workbench.isClosing()) + return; + + IContextService contextService = + (IContextService)workbench.getActiveWorkbenchWindow().getService(IContextService.class); + contextService.deactivateContexts(oldContextActivations); + } + + }); + } + + } + + @Override + public void managerDisposed() { + synchronized(managers) { + managers.remove(manager); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynPlaybackExperimentListener.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynPlaybackExperimentListener.java new file mode 100644 index 00000000..8c678cac --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynPlaybackExperimentListener.java @@ -0,0 +1,262 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.listeners; + +import java.util.HashMap; + +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Simantics; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.diagram.profile.Profiles; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.layer0.Layer0; +import org.simantics.project.IProject; +import org.simantics.simulation.experiment.ExperimentState; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.experiment.IExperimentListener; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; +import org.simantics.sysdyn.ui.editor.DiagramViewer; +import org.simantics.ui.SimanticsUI; + +/** + * Listener for playback simulations. This listener activates and reverts the playback + * profile when a playback simlation is activated or disposed. + * @author Teemu Lempinen + * + */ +public class SysdynPlaybackExperimentListener implements IExperimentListener { + + private Resource model; + private Resource previousProfile; + + public SysdynPlaybackExperimentListener(SysdynPlaybackExperiment experiment) { + this.model = experiment.getModel(); + activatePlaybackProfile(); + } + + @Override + public void stateChanged(final ExperimentState state) { + switch(state) { + case DISPOSED: + revertPlaybackProfiles(); + break; + } + } + + class DiagramInfo { + public String modelURI = null; + public Resource previousProfile = null; + } + + HashMap previousRuntimeDiagramsAndModelUris = new HashMap(); + + private void activatePlaybackProfile() { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + previousRuntimeDiagramsAndModelUris.clear(); + previousRuntimeDiagramsAndModelUris = getCurrentRuntimeDiagramInfos(); + activatePlaybackProfileRequest(previousRuntimeDiagramsAndModelUris); + } + }); + } + + private void revertPlaybackProfiles() { + + IProject project = SimanticsUI.getProject(); + if(project == null) + return; + IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + + if(experiment != null && experiment instanceof SysdynPlaybackExperiment && this.model.equals(experiment.getModel())) + return; + + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + final HashMap runtimeDiagramsAndModelUris = getCurrentRuntimeDiagramInfos(); + + VirtualGraphSupport support = Simantics.getSession().getService(VirtualGraphSupport.class); + Simantics.getSession().asyncRequest(new WriteRequest(support.getWorkspacePersistent("profiles")) { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + Resource model = SysdynPlaybackExperimentListener.this.model; + if(model == null) + return; + + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + + Resource defaultProfile = graph.syncRequest(new PossibleObjectWithType(model, l0.ConsistsOf, sr.DefaultProfile)); + if(defaultProfile == null) + return; + + setProfileForModel(graph, model, previousProfile == null ? defaultProfile : previousProfile); + + HashMap infos = getRuntimesForModel(graph, runtimeDiagramsAndModelUris, model); + for(Resource runtimeDiagram : infos.keySet()) { + Resource previous = null; + if(previousRuntimeDiagramsAndModelUris.containsKey(runtimeDiagram)) { + previous = previousRuntimeDiagramsAndModelUris.get(runtimeDiagram).previousProfile; + } + setProfileForDiagram(graph, runtimeDiagram, previous == null ? defaultProfile : previous); + } + } + }); + + } + }); + } + + /** + * Run in display thread. + * + * @return + */ + private HashMap getCurrentRuntimeDiagramInfos() { + HashMap runtimeDiagramsAndModelUris = new HashMap(); + IWorkbench workBench = PlatformUI.getWorkbench(); + IWorkbenchWindow window = workBench.getActiveWorkbenchWindow(); + IWorkbenchPage[] pages = window.getPages(); + for(IWorkbenchPage page : pages) { + for(IEditorReference reference : page.getEditorReferences()) { + IEditorPart iep = reference.getEditor(false); + if(iep instanceof DiagramViewer) { + DiagramViewer viewer = (DiagramViewer) iep; + Resource runtime = viewer.getRuntime(); + String modelUri = viewer.getResourceInput2().getModelURI(); + DiagramInfo info = new DiagramInfo(); + info.modelURI = modelUri; + runtimeDiagramsAndModelUris.put(runtime, info); + } + } + } + return runtimeDiagramsAndModelUris; + } + + + private HashMap getRuntimesForModel(WriteGraph graph, HashMap allInfos, Resource model) throws DatabaseException { + HashMap runtimeDiagramsAndModelUris = new HashMap(); + for(Resource runtimeDiagram : allInfos.keySet()) { + DiagramInfo di = allInfos.get(runtimeDiagram); + if(di == null) + continue; + Resource m = graph.getPossibleResource(di.modelURI); + if(m == null || !model.equals(m)) + continue; + + runtimeDiagramsAndModelUris.put(runtimeDiagram, di); + } + return runtimeDiagramsAndModelUris; + } + + private void activatePlaybackProfileRequest(final HashMap allDiagramInfos) { + VirtualGraphSupport support = Simantics.getSession().getService(VirtualGraphSupport.class); + Simantics.getSession().asyncRequest(new WriteRequest(support.getWorkspacePersistent("profiles")) { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + Resource model = SysdynPlaybackExperimentListener.this.model; + if(model == null) + return; + + Resource profile = getSimulationPlaybackProfile(graph, model); + if(profile == null) + return; + + DiagramResource DIA = DiagramResource.getInstance(graph); + + Resource current = graph.getPossibleObject(model, DIA.HasActiveProfile); + previousProfile = current; + + if(!profile.equals(current)) { + setProfileForModel(graph, model, profile); + } + + HashMap infos = getRuntimesForModel(graph, allDiagramInfos, model); + for(Resource runtimeDiagram : infos.keySet()) { + DiagramInfo di = infos.get(runtimeDiagram); + current = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile); + di.previousProfile = current; + if(profile.equals(current)) + continue; + setProfileForDiagram(graph, runtimeDiagram, profile); + } + } + }); + } + + + private void setProfileForDiagram(WriteGraph graph, Resource runtimeDiagram, Resource profile) throws DatabaseException { + DiagramResource DIA = DiagramResource.getInstance(graph); + + Resource current = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile); + if(profile.equals(current)) return; + + if(current != null) + graph.deny(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile, null, current); + graph.claim(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile, null, profile); + + // Set this profile as the default profile for this diagram + Resource configuration = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasConfiguration); + graph.deny(configuration, DIA.HasActiveProfile); + graph.claim(configuration, DIA.HasActiveProfile, profile); + } + + private void setProfileForModel(WriteGraph graph, Resource model, Resource profile) throws DatabaseException { + DiagramResource DIA = DiagramResource.getInstance(graph); + + // Set this profile as the default profile for this model + graph.deny(model, DIA.HasActiveProfile); + graph.claim(model, DIA.HasActiveProfile, profile); + } + + private Resource getSimulationPlaybackProfile(WriteGraph graph, Resource model) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + SimulationResource SIMU = SimulationResource.getInstance(graph); + + Resource profile = graph.syncRequest(new PossibleObjectWithType(model, l0.ConsistsOf, sr.SimulationPlaybackProfile)); + if(profile == null) { + profile = Profiles.createProfile(graph, "Simulation Playback", sr.Profiles_SimulationPlaybackColours); + graph.deny(profile, l0.InstanceOf); + graph.claim(profile, l0.InstanceOf, null, sr.SimulationPlaybackProfile); + graph.claim(model, l0.ConsistsOf, profile); + } + + if(!graph.hasStatement(profile, SIMU.IsActive)) { + graph.claim(profile, SIMU.IsActive, sr.Profiles_SimulationPlaybackColours); + } + + return profile; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/menu/PlaybackSliderContribution.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/menu/PlaybackSliderContribution.java new file mode 100644 index 00000000..f16927eb --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/menu/PlaybackSliderContribution.java @@ -0,0 +1,172 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.menu; + +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; + +import org.eclipse.jface.action.ToolBarContributionItem; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Slider; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; +import org.simantics.ui.SimanticsUI; + +/** + * Contribution to the main toolbar. PlaybackSliderContribution contains a slider + * that can be used to control the time in a playback experiment + * + * @author Teemu Lempinen + * + */ +public class PlaybackSliderContribution extends ToolBarContributionItem { + + Runnable timeListener; + SysdynPlaybackExperiment spe; + Slider s; + Double startTime, endTime; + boolean ignoreChange = false; + + @Override + public void fill(ToolBar parent, int index) + { + if (parent != null) { + + IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment == null || !(experiment instanceof SysdynPlaybackExperiment)) + return; + spe = (SysdynPlaybackExperiment)experiment; + + Double[] numbers = new Double[3]; + try { + numbers = SimanticsUI.getSession().syncRequest(new Read() { + @Override + public Double[] perform(ReadGraph graph) throws DatabaseException { + Double[] numbers = new Double[3]; + Resource model = spe.getModel(); + SysdynResource sr = SysdynResource.getInstance(graph); + numbers[0] = graph.getRelatedValue(model, sr.HasStartTime); + numbers[1] = graph.getRelatedValue(model, sr.HasStopTime); + numbers[2] = graph.getPossibleRelatedValue(model, sr.HasOutputInterval); + return numbers; + } + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + + // Separator ToolItem can contain a composite. Add a composite with a slider to this item + ToolItem ti = new ToolItem(parent, SWT.SEPARATOR); + + Composite composite = new Composite(parent, SWT.NONE); + GridLayoutFactory.fillDefaults().margins(3, SWT.DEFAULT).numColumns(2).applyTo(composite); + GridDataFactory.fillDefaults().applyTo(composite); + + s = new Slider(composite, SWT.NONE); + s.setMinimum(0); + s.setMaximum(100); + s.setIncrement(1); + s.setPageIncrement(1); + s.setThumb(1); + + final Label label = new Label(composite, SWT.NONE); + GridDataFactory.fillDefaults().hint(70, SWT.DEFAULT).applyTo(label); + label.setText("0.0"); + + ti.setWidth(270); + ti.setControl(composite); + + startTime = numbers[0]; + endTime = numbers[1]; + + // Create a DesimalFormat for rounding the time + final DecimalFormat format = new DecimalFormat(); + format.setMinimumFractionDigits(0); + format.setMaximumFractionDigits(2); + DecimalFormatSymbols symbols = new DecimalFormatSymbols(); + symbols.setDecimalSeparator('.'); + symbols.setGroupingSeparator(' '); + format.setDecimalFormatSymbols(symbols); + + // Selection listener for the slider + s.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + Slider s = (Slider)e.widget; + Double time = s.getSelection() / 99.0 * (endTime - startTime) + startTime; + spe.setTimeAndContinue(time); + if(!label.isDisposed()) { + label.setText(format.format(time)); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + if(timeListener != null) { + spe.removeTimeListener(timeListener); + } + + // Time listener for setting the time in the slider if the time is changed somewhere else + timeListener = new Runnable() { + + @Override + public void run() { + s.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if(!startTime.equals(spe.getStartTime()) || !endTime.equals(spe.getEndTime())) { + startTime = spe.getStartTime(); + endTime = spe.getEndTime(); + } + int value = (int) Math.round(((spe.getTime() - startTime) / (endTime - startTime) * 99)); + s.setSelection(value); + label.setText(format.format(spe.getTime())); + } + }); + + } + + }; + spe.addTimeListener(timeListener); + } + } + + @Override + public void dispose() { + if(this.timeListener != null && spe != null) { + spe.removeTimeListener(timeListener); + this.timeListener = null; + } + super.dispose(); + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/ModelicaSourceViewerConfiguration.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/ModelicaSourceViewerConfiguration.java new file mode 100644 index 00000000..dfc4fd80 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/ModelicaSourceViewerConfiguration.java @@ -0,0 +1,154 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.modelica; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; +import org.eclipse.jface.text.rules.ICharacterScanner; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.RuleBasedScanner; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; + +public class ModelicaSourceViewerConfiguration extends SourceViewerConfiguration { + + public IPresentationReconciler getPresentationReconciler( + ISourceViewer sourceViewer) { + PresentationReconciler pr = new PresentationReconciler(); + DefaultDamagerRepairer ddr = new DefaultDamagerRepairer( + new RuleBasedScanner() { + { + setRules(new IRule[] {new IRule() { + + @Override + public IToken evaluate(ICharacterScanner scanner) { + int ch; + try { + scanner.unread(); + ch = scanner.read(); + } catch (Throwable t) { + ch = -1; + } + if (ch <= 0 || !isIdentifierChar((char) ch)) { + ch = scanner.read(); + if(isIdentifierChar((char)ch)) { + StringBuilder b = new StringBuilder(); + do { + b.append((char)ch); + ch = scanner.read(); + } while(isIdentifierChar((char) ch)); + String str = b.toString(); + if(keywords.contains(str)) + return getModelicaKeywordToken(); + } + scanner.unread(); + } + return Token.UNDEFINED; + } + + }}); + } + } + ); + pr.setRepairer(ddr, IDocument.DEFAULT_CONTENT_TYPE); + pr.setDamager(ddr, IDocument.DEFAULT_CONTENT_TYPE); + return pr; + } + + static boolean isIdentifierChar(char c) { + return + (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') + || (c >= '0' && c <= '9') || c == '_'; + } + + static final Set keywords = new HashSet(); + + static { + keywords.add("within"); + keywords.add("final"); + keywords.add("public"); + keywords.add("protected"); + keywords.add("connect"); + keywords.add("when"); + keywords.add("then"); + keywords.add("elsewhen"); + keywords.add("if"); + keywords.add("end"); + keywords.add("elseif"); + keywords.add("else"); + keywords.add("for"); + keywords.add("while"); + keywords.add("loop"); + keywords.add("der"); + keywords.add("enumeration"); + keywords.add("extends"); + keywords.add("class"); + keywords.add("partial"); + keywords.add("encapsulated"); + keywords.add("model"); + keywords.add("record"); + keywords.add("block"); + keywords.add("expandable"); + keywords.add("connector"); + keywords.add("type"); + keywords.add("package"); + keywords.add("function"); + keywords.add("import"); + keywords.add("external"); + keywords.add("constrainedby"); + keywords.add("redeclare"); + keywords.add("replaceable"); + keywords.add("flow"); + keywords.add("discrete"); + keywords.add("parameter"); + keywords.add("constant"); + keywords.add("input"); + keywords.add("output"); + keywords.add("annotation"); + keywords.add("false"); + keywords.add("true"); + keywords.add("each"); + keywords.add("initial"); + keywords.add("algorithm"); + keywords.add("equation"); + keywords.add("or"); + keywords.add("and"); + keywords.add("not"); + keywords.add("break"); + keywords.add("return"); + } + + static IToken modelicaKeywordToken = null; + public IToken getModelicaKeywordToken() { + if(modelicaKeywordToken == null) { + modelicaKeywordToken = + new Token( + new TextAttribute( + new Color(null, 127, 0, 85), + new Color(null, 255, 255, 255), + SWT.BOLD + )); + } + return modelicaKeywordToken; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/SysdynModelicaEditor.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/SysdynModelicaEditor.java new file mode 100644 index 00000000..c5a2ed34 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/SysdynModelicaEditor.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.modelica; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.operation.IRunnableContext; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.PaintManager; +import org.eclipse.jface.text.source.AnnotationModel; +import org.eclipse.jface.text.source.AnnotationPainter; +import org.eclipse.jface.text.source.DefaultCharacterPairMatcher; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.MatchingCharacterPainter; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.editors.text.TextEditor; +import org.eclipse.ui.texteditor.AbstractDocumentProvider; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.modelica.ModelicaWriter; +import org.simantics.sysdyn.representation.Configuration; +import org.simantics.sysdyn.representation.IElement; +import org.simantics.sysdyn.representation.LoadRepresentation; +import org.simantics.sysdyn.representation.Module; +import org.simantics.sysdyn.representation.ModuleType; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.workbench.ResourceEditorInput; + + +public class SysdynModelicaEditor extends TextEditor { + + AnnotationModel annotationModel = new AnnotationModel(); + AnnotationPainter apainter; + + + public void init(final IEditorSite site, final IEditorInput input) throws PartInitException { + super.init(site, input); + try { + Configuration configuration = + LoadRepresentation.loadConfiguration(SimanticsUI.getSession(), ((ResourceEditorInput)input).getResource()); + setPartName(configuration.getLabel()); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + + public SysdynModelicaEditor() { + super(); + showOverviewRuler(); + setDocumentProvider(new AbstractDocumentProvider() { + + @Override + protected IAnnotationModel createAnnotationModel(Object element) + throws CoreException { + return annotationModel; + } + + @Override + protected IDocument createDocument(Object element) + throws CoreException { + try { + Configuration configuration = + LoadRepresentation.loadConfiguration(SimanticsUI.getSession(), ((ResourceEditorInput)element).getResource()); + ModelicaWriter writer = new ModelicaWriter(); + + HashSet configurations = new HashSet(); + configurations.add(configuration); + getConfigurations(configuration, configurations); + + for(Configuration c : configurations) + writer.write(c); + + return new Document(writer.toString()); + } catch (DatabaseException e) { + e.printStackTrace(); + throw new CoreException(STATUS_ERROR); + } + } + + @Override + protected void doSaveDocument(IProgressMonitor monitor, + Object element, IDocument document, boolean overwrite) + throws CoreException { + } + + @Override + protected IRunnableContext getOperationRunner( + IProgressMonitor monitor) { + return PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + } + + @Override + public boolean isModifiable(Object element) { + return false; + } + + @Override + public boolean isReadOnly(Object element) { + return true; + } + + }); + + setSourceViewerConfiguration(new ModelicaSourceViewerConfiguration()); + + } + + private void getConfigurations(Configuration configuration, Set configurations) { + for(IElement e : configuration.getElements()) { + if(e instanceof Module) { + ModuleType mt = ((Module) e).getType(); + configurations.add(mt.getConfiguration()); + getConfigurations(mt.getConfiguration(), configurations); + } + } + } + + @Override + protected void createActions() { + super.createActions(); + + PaintManager paintManager = new PaintManager(getSourceViewer()); + MatchingCharacterPainter matchingCharacterPainter = new MatchingCharacterPainter(getSourceViewer(), + new DefaultCharacterPairMatcher( new char[] {'(', ')', '{', '}', '[', ']'} )); + matchingCharacterPainter.setColor(new Color(Display.getCurrent(), new RGB(160, 160, 160))); + paintManager.addPainter(matchingCharacterPainter); + } + + +} + diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/TextEditorActionBarContributor.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/TextEditorActionBarContributor.java new file mode 100644 index 00000000..555b13aa --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/TextEditorActionBarContributor.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.modelica; + +import org.eclipse.ui.part.EditorActionBarContributor; + +public class TextEditorActionBarContributor extends EditorActionBarContributor { + + public TextEditorActionBarContributor() { + // TODO Auto-generated constructor stub + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/DefaultRealizationVirtualGraph.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/DefaultRealizationVirtualGraph.java new file mode 100644 index 00000000..653aa2e1 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/DefaultRealizationVirtualGraph.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.project; + +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraphContext; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.realization.RealizationVirtualGraph; +import org.simantics.db.layer0.realization.ResourceData; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.SysdynResource; + +public class DefaultRealizationVirtualGraph extends RealizationVirtualGraph { + + public DefaultRealizationVirtualGraph(Session session, Resource model) throws DatabaseException { + super(session, model, SysdynResource.getInstance(session).DefaultRealization); + } + + @Override + public void initialize(final VirtualGraphContext context, WriteGraph graph) throws DatabaseException { + + Resource configuration = graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration); + + Resource defaultsResource = graph.newResource(); + int modelNode = context.getIndex(model); + int defaultsNode = context.getIndex(defaultsResource); + graph.claim(model, L0.ConsistsOf, null, defaultsResource); + graph.claim(model, L0X.HasBaseRealization, null, defaultsResource); + +// undiscovered.put(defaultsNode, new ResourceData(modelNode, configuration, L0.Realization, "BaseRealization", null, null)); + + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryRealizationVirtualGraph.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryRealizationVirtualGraph.java new file mode 100644 index 00000000..a70d2368 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryRealizationVirtualGraph.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.project; + +import java.util.Collection; +import java.util.HashSet; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.VirtualGraphContext; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.procedure.single.SingleSetSyncListener; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.RuntimeValuations; +import org.simantics.db.layer0.realization.RealizationVirtualGraph; +import org.simantics.db.layer0.realization.ResourceData; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.utils.datastructures.Pair; + +public class HistoryRealizationVirtualGraph extends RealizationVirtualGraph { + + public HistoryRealizationVirtualGraph(Session session, Resource model) throws DatabaseException { + super(session, model, SysdynResource.getInstance(session).HistoryRealization); + } + + @Override + public void initialize(final VirtualGraphContext context, WriteGraph graph) throws DatabaseException { + + graph.asyncRequest(new Read>() { + + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { +// System.out.println("Compute runs starts"); + HashSet result = new HashSet(); + Layer0 l0 = Layer0.getInstance(graph); + SimulationResource SIMU = SimulationResource.getInstance(graph); + for(Resource config : graph.getObjects(model, l0.ConsistsOf)) { + if(graph.isInstanceOf(config, SIMU.Experiment)) { + for(Resource run : graph.getObjects(config, l0.ConsistsOf)) { + if(graph.isInstanceOf(run, SIMU.Run)) { + result.add(run); + } + } + } + } + return result; + } + + }, new SingleSetSyncListener() { + + @Override + public void add(ReadGraph graph, final Resource run) throws DatabaseException { + + final Layer0 l0 = Layer0.getInstance(graph); + final String experimentName = graph.getPossibleRelatedValue(run, l0.HasName, Bindings.STRING); + + RuntimeValuations vs = graph.getService(RuntimeValuations.class); + if(vs.supports(experimentName)) { + + graph.asyncRequest(new Read>>() { + + @Override + public Collection> perform(ReadGraph graph) throws DatabaseException { + HashSet> result = new HashSet>(); + Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration); + for(Resource part : graph.getObjects(configuration, l0.ConsistsOf)) { + String partName = graph.getPossibleRelatedValue(part, l0.HasName, Bindings.STRING); + result.add(new Pair(partName, part)); + } + return result; + } + }, new SingleSetSyncListener>() { + + @Override + public void add(ReadGraph graph, final Pair part) throws DatabaseException { + graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + int runNode = context.getIndex(run); + if(part.first != null) { + Resource partResource = graph.newResource(); + int partNode = context.getIndex(partResource); + graph.claim(run, l0.ConsistsOf, null, partResource); +// undiscovered.put(partNode, new ResourceData(runNode, part.second, valuation, part.first, experimentName, null)); + } + } + }); + } + + @Override + public void remove(ReadGraph graph, final Pair part) throws DatabaseException { + graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Integer key = null; + for(int k : undiscovered.keySet()) { + ResourceData rd = undiscovered.get(k); +// if (rd.name.equals(part.first) && rd.structureResource.equals(part.second)) { +// key = k; +// break; +// } + } + if(key != null) { + Resource r = context.getResource(key); + RemoverUtil.remove(graph, r); + undiscovered.remove(key); + } + } + }); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + } + + } + + @Override + public void exception(ReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java new file mode 100644 index 00000000..096dfc5a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.project; + +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IPerspectiveFactory; + +public class SysdynPerspectiveFactory implements IPerspectiveFactory { + + @Override + public void createInitialLayout(IPageLayout layout) { + layout.setEditorAreaVisible(true); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java new file mode 100644 index 00000000..fb9fff65 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java @@ -0,0 +1,302 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.project; + +import java.io.File; +import java.util.HashMap; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PartInitException; +import org.osgi.service.prefs.BackingStoreException; +import org.simantics.databoard.accessor.Accessor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.changeset.GenericChangeListener; +import org.simantics.db.common.request.Queries; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.RuntimeValuations; +import org.simantics.db.layer0.adapter.TrendVariable; +import org.simantics.db.layer0.genericrelation.DependenciesRelation.DependencyChangesRequest; +import org.simantics.db.layer0.genericrelation.DependencyChanges; +import org.simantics.db.layer0.service.ActivationManager; +import org.simantics.db.request.Read; +import org.simantics.db.service.GraphChangeListenerSupport; +import org.simantics.db.service.LifecycleSupport; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.issues.common.IssueUtils; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.services.CaseInsensitiveComponentNamingStrategy2; +import org.simantics.modeling.services.ComponentNamingStrategy; +import org.simantics.project.IProject; +import org.simantics.project.ProjectElementType; +import org.simantics.project.ProjectElements; +import org.simantics.project.ProjectKeys; +import org.simantics.project.exception.ProjectException; +import org.simantics.project.features.AbstractProjectFeature; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.simulation.project.IExperimentManager; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.editor.SysdynEditorNamingService; +import org.simantics.ui.workbench.IEditorNamingService; +import org.simantics.ui.workbench.action.ChooseActionRequest; +import org.simantics.ui.workbench.project.UIModelManager; +import org.simantics.ui.workbench.project.UIModelManagerBase; +import org.simantics.utils.datastructures.Callback; +import org.simantics.utils.ui.ErrorLogger; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +public class SysdynProject extends AbstractProjectFeature { + private static final String DEFAULT_PERSPECTIVE = "org.simantics.sysdyn.ui.perspective"; + + private static final String FIRST_SYSDYN_PROJECT = "firstSysdynProject"; + + class ModelManager extends UIModelManagerBase { + @Override + public void create(ProjectElementType kind, Shell parentShell, Session session, Resource container, + Callback callback, Callback errorCallback) { + + if (ProjectElements.MODEL.equals(kind)) { + //FIXME: Should not be needed anymore +// request(session, container, callback, errorCallback, CREATE_MODEL); + return; + } + + super.create(kind, parentShell, session, container, callback, errorCallback); + } + + /** + * + * + * @see org.simantics.ui.workbench.project.UIModelManager#openEditor(org.simantics.db.Session, java.lang.String) + */ + @Override + public void openEditor(Session session, String uri) throws PartInitException { + try { + Resource resource = session.syncRequest(Queries.resource(uri)); + session.syncRequest(new ChooseActionRequest(null, resource, WorkbenchUtils.getCurrentPerspectiveId())); + } catch (DatabaseException e) { + LifecycleSupport ls = session.getService(LifecycleSupport.class); + throw new PartInitException("Failed to open editor for URI '" + uri + "' with session '" + ls.getSessionReference() + "', see exception for details.", e); + } + } + } + + + + ModelManager mm; + + @Override + public void configure() throws ProjectException { + final IProject project = getProject(); + final Session session = getSession(); + + getProjectElement().setHint(ProjectKeys.DEFAULT_PERSPECTIVE, DEFAULT_PERSPECTIVE); + + getProjectElement().setHint(IEditorNamingService.KEY_EDITOR_NAMING_SERVICE, new SysdynEditorNamingService()); + + mm = new ModelManager(); + getProjectElement().setHint(UIModelManager.KEY_MODEL_MANAGER, mm); + + // Install naming strategy for model components. + GraphChangeListenerSupport changeSupport = session.peekService(GraphChangeListenerSupport.class); + if (changeSupport != null) { + getProjectElement().setHint(ComponentNamingStrategy.PROJECT_KEY, new CaseInsensitiveComponentNamingStrategy2(changeSupport, "%s%d")); + } + + try { + + Resource projectResource = project.get(); + + session.registerService(RuntimeValuations.class, new RuntimeValuations() { + + @Override + public boolean supports(String valuation) { + + IExperimentManager expMan = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + IExperiment experiment = expMan.getExperiment(valuation); + + return experiment != null; + + } + + @Override + public Accessor getAccessor(String variableIdentityPrefix, String valuation, String suffix) { + return null; + } + + @Override + public TrendVariable getVariable(String variableIdentityPrefix, String valuation, String suffix) { + + return null; + + } + + }); + + + + ActivationManager activationManager = session.getService(ActivationManager.class); + if (activationManager != null) { + activationManager.activate(session, projectResource); + } + + + VirtualGraphSupport support = session.getService(VirtualGraphSupport.class); + + support.getWorkspacePersistent("experiments"); + + } catch (DatabaseException e) { + + throw new ProjectException(e); + + } + + + cleanProjectFolder(session, project.get()); + + + // Open cheatsheets view on the first time the user creates a sysdyn project + // for a particular workspace. + IEclipsePreferences prefs = new InstanceScope().getNode(Activator.PLUGIN_ID); + boolean firstSysdynProject = prefs.getBoolean(FIRST_SYSDYN_PROJECT, true); + if (firstSysdynProject) { + // This should not be here +// Display.getDefault().asyncExec(new Runnable() { +// @Override +// public void run() { +// new OpenCheatSheetAction(CHEATSHEET_ID).run(); +// }}); + + // Make a note that the user has created a sysdyn project. + try { + prefs.putBoolean(FIRST_SYSDYN_PROJECT, false); + prefs.flush(); + } catch (BackingStoreException e) { + ErrorLogger.defaultLogError(e); + } + } + + + // Issues + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + onActivated(graph, getProject()); + } + }); + } catch (DatabaseException e) { + throw new ProjectException(e); + } + } + + @Override + public void deconfigure() throws ProjectException { + if (getProjectElement().getHint(UIModelManager.KEY_MODEL_MANAGER) == mm) + getProjectElement().removeHint(UIModelManager.KEY_MODEL_MANAGER); + mm = null; + + getProjectElement().removeHint(ComponentNamingStrategy.PROJECT_KEY); + } + + public void cleanProjectFolder(Session session, final Resource projectResource) throws ProjectException { + String projectName = null; + final HashMap resultPaths = new HashMap(); + try { + projectName = session.syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SimulationResource SIMU = SimulationResource.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + for(Resource model : graph.getObjects(projectResource, l0.ConsistsOf)) { + if(graph.isInstanceOf(model, sr.SysdynModel)){ + for(Resource experiment : graph.getObjects(model, l0.ConsistsOf)) { + if(graph.isInstanceOf(experiment, SIMU.Experiment)) { + for(Resource result : graph.getObjects(experiment, sr.HasResult)) { + String resultFile = (String)graph.getPossibleRelatedValue(result, sr.HasResultFile); + if(result != null) resultPaths.put(resultFile, result); + } + } + } + } + } + return graph.getPossibleRelatedValue(projectResource, l0.HasName); + + } + }); + } catch (DatabaseException e) { + throw new ProjectException(e); + } + + if(projectName != null) { + File root = new File(Platform.getLocation().toOSString(), "www.simantics.org"); + if(!root.isDirectory()) return; + File projectRoot = new File(root, projectName); + if(!projectRoot.isDirectory()) return; + File[] files = projectRoot.listFiles(); + + for(File file : files) { + if(resultPaths.get(file.getAbsolutePath()) == null) { + file.delete(); + } else { + resultPaths.remove(file.getAbsolutePath()); + } + } + + if (!resultPaths.keySet().isEmpty()) { + session.asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + for(String key : resultPaths.keySet()) { + Resource result = resultPaths.get(key); + graph.deny(result, l0.PartOf); + graph.deny(result, graph.getInverse(SysdynResource.getInstance(graph).HasResult)); + } + } + }) ; + } + } + } + + public void onActivated(final ReadGraph graph, final IProject project) throws DatabaseException { + + GraphChangeListenerSupport changeSupport = graph.getService(GraphChangeListenerSupport.class); + changeSupport.addMetadataListener(new GenericChangeListener() { + + @Override + public void onEvent(ReadGraph graph, DependencyChanges event) throws DatabaseException { + + WriteGraph w = (WriteGraph)graph; + w.addMetadata(event); + + } + + }); + + IssueUtils.listenActiveProjectIssueSources(graph, project.get()); + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java new file mode 100644 index 00000000..0939900e --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java @@ -0,0 +1,236 @@ +package org.simantics.sysdyn.ui.properties; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.AdaptableHintContext; +import org.simantics.browsing.ui.swt.SingleSelectionInputSource; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys; +import org.simantics.utils.datastructures.ArrayMap; + +public class ArrayIndexesTab extends LabelPropertyTabContributor implements Widget{ + + GraphExplorerComposite availableEnumerationsExplorer; + GraphExplorerComposite usedEnumerationsExplorer; + + @Override + public void createControls(Composite body, IWorkbenchSite site, + ISessionContext context, WidgetSupport support) { + support.register(this); + + GridLayoutFactory.fillDefaults().numColumns(4).applyTo(body); + + + Composite available = new Composite(body, SWT.NONE); + GridLayoutFactory.fillDefaults().applyTo(available); + GridDataFactory.fillDefaults().grab(true, true).applyTo(available); + Label label = new Label(available, SWT.None); + label.setText("Available Enumerations"); + availableEnumerationsExplorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), site, available, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI); + + availableEnumerationsExplorer + .setBrowseContexts(SysdynResource.URIs.AvailableVariableIndexes); + availableEnumerationsExplorer.setColumns(ColumnKeys.ENUMERATION_TABLE_COLUMNS); + availableEnumerationsExplorer.setInputSource(new SingleSelectionInputSource( + Resource.class)); + + availableEnumerationsExplorer.finish(); + + GridDataFactory.fillDefaults().grab(true, true).applyTo( + availableEnumerationsExplorer); + + Control c = availableEnumerationsExplorer.getExplorerControl(); + if (c instanceof Tree) + ((Tree) c).setLinesVisible(true); + + + Button add = new Button(body, support, SWT.NONE); + add.setText(" -> "); + + add.addSelectionListener(new SelectionListenerImpl(context) { + + List enumerationResources; + + @Override + public void beforeApply() { + enumerationResources = getSelectedResources(availableEnumerationsExplorer); + } + + @Override + public void apply(WriteGraph graph, Resource input) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes); + if(arrayIndexes == null) { + arrayIndexes = OrderedSetUtils.create(graph, sr.ArrayIndexes); + graph.claim(input, sr.HasArrayIndexes, arrayIndexes); + } + OrderedSetUtils.addAll(graph, arrayIndexes, enumerationResources); + } + }); + + Composite used = new Composite(body, SWT.NONE); + GridLayoutFactory.fillDefaults().applyTo(used); + GridDataFactory.fillDefaults().grab(true, true).applyTo(used); + label = new Label(used, SWT.None); + label.setText("Used Enumerations"); + + usedEnumerationsExplorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), site, used, SWT.FULL_SELECTION | SWT.BORDER); + + usedEnumerationsExplorer + .setBrowseContexts(SysdynResource.URIs.UsedVariableIndexes); + usedEnumerationsExplorer.setColumns(ColumnKeys.ENUMERATION_TABLE_COLUMNS); + usedEnumerationsExplorer.setInputSource(new SingleSelectionInputSource( + Resource.class)); + + usedEnumerationsExplorer.finish(); + + GridDataFactory.fillDefaults().grab(true, true).applyTo( + usedEnumerationsExplorer); + + Control c2 = usedEnumerationsExplorer.getExplorerControl(); + if (c2 instanceof Tree) + ((Tree) c2).setLinesVisible(true); + + Composite buttons = new Composite(body, SWT.None); + GridLayoutFactory.fillDefaults().applyTo(buttons); + + Button up = new Button(buttons, support, SWT.NONE); + up.setText("Up"); + up.addSelectionListener(new SelectionListenerImpl(context) { + + List enumerationResources; + + @Override + public void beforeApply() { + enumerationResources = getSelectedResources(usedEnumerationsExplorer); + } + + @Override + public void apply(WriteGraph graph, Resource input) + throws DatabaseException { + if(enumerationResources != null && enumerationResources.size() == 1) { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes); + if(arrayIndexes == null) + return; + + Resource enumeration = enumerationResources.get(0); + Resource prev = OrderedSetUtils.prev(graph, arrayIndexes, enumeration); + if(prev.equals(arrayIndexes)) + return; + + OrderedSetUtils.remove(graph, arrayIndexes, enumeration); + OrderedSetUtils.addBefore(graph, arrayIndexes, prev, enumeration); + } + } + }); + + Button down = new Button(buttons, support, SWT.NONE); + down.setText("Down"); + down.addSelectionListener(new SelectionListenerImpl(context) { + + List enumerationResources; + + @Override + public void beforeApply() { + enumerationResources = getSelectedResources(usedEnumerationsExplorer); + } + + + @Override + public void apply(WriteGraph graph, Resource input) + throws DatabaseException { + if(enumerationResources != null && enumerationResources.size() == 1) { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes); + if(arrayIndexes == null) + return; + Resource enumeration = enumerationResources.get(0); + Resource next = OrderedSetUtils.next(graph, arrayIndexes, enumeration); + if(next.equals(arrayIndexes)) + return; + OrderedSetUtils.remove(graph, arrayIndexes, enumeration); + OrderedSetUtils.addAfter(graph, arrayIndexes, next, enumeration); + } + } + }); + + + Button remove = new Button(buttons, support, SWT.NONE); + remove.setText("Remove"); + remove.addSelectionListener(new SelectionListenerImpl(context) { + + List enumerationResources; + + @Override + public void beforeApply() { + enumerationResources = getSelectedResources(usedEnumerationsExplorer); + } + + @Override + public void apply(WriteGraph graph, Resource input) + throws DatabaseException { + if(enumerationResources != null && enumerationResources.size() == 1) { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes); + if(arrayIndexes == null) + return; + + Resource enumeration = enumerationResources.get(0); + OrderedSetUtils.remove(graph, arrayIndexes, enumeration); + } + } + }); + } + + + private List getSelectedResources(GraphExplorerComposite explorer) { + List result = new ArrayList(); + + ISelection selection = ((ISelectionProvider) explorer + .getAdapter(ISelectionProvider.class)).getSelection(); + if (selection == null) + return result; + IStructuredSelection iss = (IStructuredSelection) selection; + @SuppressWarnings("unchecked") + List selections = iss.toList(); + for(AdaptableHintContext ahc : selections) { + Resource resource = (Resource) ahc.getAdapter(Resource.class); + result.add(resource); + } + return result; + } + + + @Override + public void setInput(ISessionContext context, Object input) { + availableEnumerationsExplorer.setInput(context, input); + usedEnumerationsExplorer.setInput(context, input); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java new file mode 100644 index 00000000..8ad18ac6 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java @@ -0,0 +1,178 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jface.dialogs.IInputValidator; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.TrackedCombo; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.factories.ComboStringPropertyModifier; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; +import org.simantics.sysdyn.ui.utils.VariableNameUtils; + +public class ConfigurationTab extends LabelPropertyTabContributor { + + private class ModelLabelModifier extends TextModifyListenerImpl { + + public ModelLabelModifier(ISessionContext context, String propertyURI) { + } + + @Override + public void applyText(WriteGraph graph, Resource issue, String text) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + graph.claimLiteral(issue, l0.HasLabel, text); + String safeName = NameUtils.findFreshName(graph, text, graph.getSingleObject(issue, l0.PartOf), l0.ConsistsOf, "%s%d"); + graph.claimLiteral(issue, l0.HasName, safeName); + } + + } + + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite); + + Label label = new Label(composite, SWT.NONE); + label.setText("Name"); + + TrackedText name = new TrackedText(composite, support, SWT.BORDER); + name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel)); + name.addModifyListener(new ModelLabelModifier(context, Layer0.URIs.HasLabel)); + name.setInputValidator(new IInputValidator() { + + @Override + public String isValid(String newText) { + if (!VariableNameUtils.isValid(newText)) + return "Sorry but spaces and special characters are not allowed for names right now"; + return null; + } + }); + + GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(name.getWidget()); + + label = new Label(composite, SWT.NONE); + label.setText("Start time"); + + TrackedText startTime = new TrackedText(composite, support, SWT.BORDER | SWT.RIGHT); + startTime.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasStartTime)); + startTime.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasStartTime)); + startTime.setInputValidator(new DoubleValidator()); + GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(startTime.getWidget()); + + label = new Label(composite, SWT.NONE); + label.setText("Stop time"); + + TrackedText stopTime = new TrackedText(composite, support, SWT.BORDER | SWT.RIGHT); + stopTime.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasStopTime)); + stopTime.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasStopTime)); + stopTime.setInputValidator(new DoubleValidator()); + GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(stopTime.getWidget()); + + label = new Label(composite, SWT.NONE); + label.setText("Step length\n(empty = default)"); + + TrackedText outputInterval = new TrackedText(composite, support, SWT.BORDER | SWT.RIGHT); + outputInterval.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasOutputInterval)); + outputInterval.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasOutputInterval)); + outputInterval.setInputValidator(new DoubleValidator()); + GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(outputInterval.getWidget()); + + label = new Label(composite, SWT.NONE); + label.setText("Method"); + + TrackedCombo method = new TrackedCombo(composite, support, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY); + method.setItemFactory(new ReadFactoryImpl>() { + + @Override + public Map perform(ReadGraph graph, final Resource input) throws DatabaseException { + + Map map = new HashMap(); + map.put("euler", "euler"); + map.put("rungekutta", "rungekutta"); + map.put("dassl", "dassl"); + map.put("dassl2", "dassl2"); + map.put("inline-euler", "inline-euler"); + map.put("inline-rungekutta", "inline-rungekutta"); + return map; + } + }); + + method.setSelectionFactory(new ReadFactoryImpl() { + + @Override + public String perform(ReadGraph graph, final Resource input) throws DatabaseException { + String s = graph.getPossibleRelatedValue(input, SysdynResource.getInstance(graph).HasSolver); + return s != null ? s : ""; + } + }); + + method.addModifyListener(new ComboStringPropertyModifier() { + + @Override + public void applyText(WriteGraph graph, Resource input, String text) + throws DatabaseException { + graph.claimLiteral(input, SysdynResource.getInstance(graph).HasSolver, text); + } + }); + + label = new Label(composite, SWT.NONE); + label.setText("Tolerance"); + + TrackedText tolerance = new TrackedText(composite, support, SWT.BORDER | SWT.RIGHT); + tolerance.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasTolerance)); + tolerance.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasTolerance)); + tolerance.setInputValidator(new DoubleValidator()); + GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(tolerance.getWidget()); + + + } + + private class DoubleValidator implements IInputValidator { + + @Override + public String isValid(String newText) { + for(int i = 0; i < newText.length(); i++){ + if(!Character.isDigit(newText.charAt(i))){ + if(newText.charAt(i) != '.') { + return "Invalid character '" + newText.charAt(i) + "'"; + } else if(newText.indexOf('.') != newText.lastIndexOf('.')) { + return "There can be only one '.'"; + } + } + } + return null; + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java new file mode 100644 index 00000000..a57da158 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java @@ -0,0 +1,201 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.util.ObjectUtils; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.elements2.connections.DependencyNode; +import org.simantics.utils.datastructures.Pair; +import org.simantics.utils.datastructures.Triple; + +public class DependencyTab extends LabelPropertyTabContributor { + + Button none, plus, minus, other, inside, outside; + TrackedText polarityText, polarityLocationText; + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite); + + Group polarityGroup = new Group(composite, SWT.NONE); + polarityGroup.setText("Polarity"); + GridDataFactory.fillDefaults().grab(true, false).applyTo(polarityGroup); + GridLayoutFactory.fillDefaults().numColumns(5).applyTo(polarityGroup); + + none = new Button(polarityGroup, support, SWT.RADIO); + none.setText("None"); + none.setSelectionFactory(new PolarityRadioSelectionFactory("")); + none.addSelectionListener(new PolaritySelectionListener(context, "")); + + plus = new Button(polarityGroup, support, SWT.RADIO); + plus.setText("+"); + plus.setSelectionFactory(new PolarityRadioSelectionFactory("+")); + plus.addSelectionListener(new PolaritySelectionListener(context, "+")); + + minus = new Button(polarityGroup, support, SWT.RADIO); + minus.setText("-"); + minus.setSelectionFactory(new PolarityRadioSelectionFactory("-")); + minus.addSelectionListener(new PolaritySelectionListener(context, "-")); + + other = new Button(polarityGroup, support, SWT.RADIO); + other.setText("other"); + other.setSelectionFactory(new OtherPolaritySelectionFactory(new String[] {null, "+", "-", ""})); + + polarityText = new TrackedText(polarityGroup, support, SWT.BORDER); + polarityText.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.Polarity)); + polarityText.addModifyListener(new StringPropertyModifier(context, SysdynResource.URIs.Polarity)); + GridDataFactory.fillDefaults().grab(true, false).applyTo(polarityText.getWidget()); + + Group locationGroup = new Group(composite, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(locationGroup); + GridLayoutFactory.fillDefaults().applyTo(locationGroup); + locationGroup.setText("Location"); + + inside = new Button(locationGroup, support, SWT.RADIO); + inside.setText("Inside"); + inside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.INSIDE)); + inside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.INSIDE)); + + outside = new Button(locationGroup, support, SWT.RADIO); + outside.setText("Outside"); + outside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.OUTSIDE)); + outside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.OUTSIDE)); + } + + class PolarityLocationSelectionListener extends SelectionListenerImpl { + private String location; + + public PolarityLocationSelectionListener(ISessionContext context, String location) { + super(context); + this.location = location; + } + + @Override + public void apply(WriteGraph graph, Resource connectionElement) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + graph.claimLiteral(connectionElement, sr.PolarityLocation, location); + } + + } + + class PolarityLocationRadioSelectionFactory extends ReadFactoryImpl { + private String location; + + public PolarityLocationRadioSelectionFactory(String location) { + this.location = location; + } + + @Override + public Object getIdentity(Object inputContents) { + return new Triple>(inputContents, location, getClass()); + } + + @Override + public Boolean perform(ReadGraph graph, Resource dependencyConnection) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + String location = graph.getPossibleRelatedValue(dependencyConnection, sr.PolarityLocation, Bindings.STRING); + if(DependencyNode.OUTSIDE.equals(this.location)) { + return ObjectUtils.objectEquals(this.location, location); + } else { + if(location == null) + return true; + else + return ObjectUtils.objectEquals(this.location, location); + } + } + } + + class PolaritySelectionListener extends SelectionListenerImpl { + private String polarity; + + public PolaritySelectionListener(ISessionContext context, String polarity) { + super(context); + this.polarity = polarity; + } + + @Override + public void apply(WriteGraph graph, Resource connectionElement) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + graph.claimLiteral(connectionElement, sr.Polarity, polarity.trim()); + } + + } + + class PolarityRadioSelectionFactory extends ReadFactoryImpl { + private String polarity; + + public PolarityRadioSelectionFactory(String polarity) { + this.polarity = polarity; + } + + @Override + public Object getIdentity(Object inputContents) { + return new Triple>(inputContents, polarity, getClass()); + } + + @Override + public Boolean perform(ReadGraph graph, Resource dependencyConnection) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + String polarity = graph.getPossibleRelatedValue(dependencyConnection, sr.Polarity, Bindings.STRING); + if(polarity == null && this.polarity.equals("")) + return true; + return ObjectUtils.objectEquals(polarity, this.polarity); + } + } + + class OtherPolaritySelectionFactory extends ReadFactoryImpl { + + String[] limits; + + public OtherPolaritySelectionFactory(String[] limits) { + this.limits = limits; + } + + @Override + public Object getIdentity(Object inputContents) { + return new Pair>(inputContents, getClass()); + } + + @Override + public Boolean perform(ReadGraph graph, Resource dependencyConnection) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + String polarity = graph.getPossibleRelatedValue(dependencyConnection, sr.Polarity, Bindings.STRING); + for(String s : limits) { + if(ObjectUtils.objectEquals(polarity, s)) + return false; + } + return true; + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java new file mode 100644 index 00000000..b0ceb8a0 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java @@ -0,0 +1,376 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import java.util.HashSet; +import java.util.List; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.swt.SingleSelectionInputSource; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.Table; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.SysdynModel; +import org.simantics.sysdyn.manager.SysdynModelManager; +import org.simantics.sysdyn.ui.properties.widgets.arrays.EnumerationIndexNode; +import org.simantics.sysdyn.ui.properties.widgets.arrays.ReplaceableIndexesWidget; +import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier; +import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameValidator; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.datastructures.ArrayMap; + +public class EnumerationTab extends LabelPropertyTabContributor implements Widget { + + GraphExplorerComposite indexExplorer; + + Button showAll; + Variable variable; + + Table table; + @Override + public void createControls(Composite body, IWorkbenchSite site, + final ISessionContext context, WidgetSupport support) { + + support.register(this); + + Composite container = new Composite(body, SWT.None); + GridDataFactory.fillDefaults().grab(true, true).applyTo(container); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(container); + + TrackedText nameText = new TrackedText(container, support, SWT.BORDER); + nameText.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasName)); + nameText.addModifyListener(new VariableNamePropertyModifier(context, Layer0.URIs.HasName)); + nameText.setInputValidator(new VariableNameValidator(support)); + GridDataFactory.fillDefaults().grab(true, false).span(4,1).applyTo(nameText.getWidget()); + + indexExplorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), site, container, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI | SWT.CHECK); + + indexExplorer + .setBrowseContexts(SysdynResource.URIs.EnumerationIndexes); + indexExplorer.setInputSource(new SingleSelectionInputSource( + Resource.class)); + ((Tree)indexExplorer.getExplorerControl()).addListener(SWT.Selection, new Listener () { + + @Override + public void handleEvent (Event event) { + if(event.detail == SWT.CHECK) { + final TreeItem item = (TreeItem)event.item; + final boolean checked = item.getChecked(); + NodeContext context = (NodeContext)item.getData(); + final EnumerationIndexNode node = (EnumerationIndexNode) context.getAdapter(EnumerationIndexNode.class); + node.setShowInChartsSelected(checked); + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + updateModelResults(graph); + } + }); + } + } + }); + + + indexExplorer.finish(); + + GridDataFactory.fillDefaults().grab(true, true).span(4, 1).applyTo( + indexExplorer); + + Control c = indexExplorer.getExplorerControl(); + if (c instanceof Tree) + ((Tree) c).setLinesVisible(true); + + + final Button add = new Button(container, support, SWT.None); + add.setText("Add"); + add.addSelectionListener(new addEnumerationIndexListener(support)); + + final Button remove = new Button(container, support, SWT.None); + remove.setText("Remove"); + remove.addSelectionListener(new removeEnumerationIndexListener(support)); + + ReplaceableIndexesWidget externalIndexes = new ReplaceableIndexesWidget(container, support, SWT.NULL); + GridDataFactory.fillDefaults().applyTo(externalIndexes.getWidget()); + + showAll = new Button(container, support, SWT.CHECK); + showAll.setText("Show all in charts"); + showAll.addSelectionListener(new ShowAllIndexesListener(support)); + + } + + private class addEnumerationIndexListener implements SelectionListener, Widget { + + Resource enumerationIndexes; + + public addEnumerationIndexListener(WidgetSupport support) { + support.register(this); + } + + @Override + public void setInput(ISessionContext context, Object input) { + final Resource enumeration = AdaptionUtils.adaptToSingle(input, Resource.class); + try { + context.getSession().syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + enumerationIndexes = graph.getSingleObject(enumeration, SysdynResource.getInstance(graph).HasEnumerationIndexes); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + @Override + public void widgetSelected(SelectionEvent e) { + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + HashSet names = new HashSet(); + for(Resource r : OrderedSetUtils.toList(graph, enumerationIndexes)) { + names.add(NameUtils.getSafeName(graph, r)); + } + + Resource ei = GraphUtils.create2(graph, + sr.EnumerationIndex, + l0.HasName, NameUtils.findFreshName(graph, "index", names, "")); + OrderedSetUtils.add(graph, enumerationIndexes, ei); + } + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + + } + + } + + private class removeEnumerationIndexListener implements SelectionListener, Widget { + + Resource enumerationIndexes; + + public removeEnumerationIndexListener(WidgetSupport support) { + support.register(this); + } + + @Override + public void setInput(ISessionContext context, Object input) { + final Resource enumeration = AdaptionUtils.adaptToSingle(input, Resource.class); + try { + context.getSession().syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + enumerationIndexes = graph.getSingleObject(enumeration, SysdynResource.getInstance(graph).HasEnumerationIndexes); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + @Override + public void widgetSelected(SelectionEvent e) { + ISelectionProvider selectionProvider = (ISelectionProvider)indexExplorer.getAdapter(ISelectionProvider.class); + final IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection(); + + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + for(Object o : selection.toList()) { + Resource r = AdaptionUtils.adaptToSingle(o, Resource.class); + if(r == null) + continue; + OrderedSetUtils.remove(graph, enumerationIndexes, r); + } + } + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + + + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + + } + + } + + private class ShowAllIndexesListener implements SelectionListener, Widget { + + Resource enumerationIndexes; + + public ShowAllIndexesListener(WidgetSupport support) { + support.register(this); + } + + @Override + public void setInput(ISessionContext context, Object input) { + final Resource enumeration = AdaptionUtils.adaptToSingle(input, Resource.class); + + context.getSession().asyncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + enumerationIndexes = graph.getSingleObject(enumeration, sr.HasEnumerationIndexes); + List indexes = OrderedSetUtils.toList(graph, enumerationIndexes); + for(Resource index : indexes) { + Boolean show = graph.getPossibleRelatedValue(index, sr.ShowEnumerationIndexInCharts, Bindings.BOOLEAN); + if(!Boolean.TRUE.equals(show)) + return false; + } + return true; + } + + }, new org.simantics.db.procedure.Listener() { + + @Override + public void execute(final Boolean result) { + showAll.getWidget().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + showAll.getWidget().setSelection(result.booleanValue()); + } + }); + } + + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + if(showAll == null) + return true; + return showAll.getWidget().isDisposed(); + } + }); + + } + + @Override + public void widgetSelected(SelectionEvent e) { + final boolean selected = showAll.getWidget().getSelection(); + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + List indexes = OrderedSetUtils.toList(graph, enumerationIndexes); + for(Resource index : indexes) { + Boolean show = graph.getPossibleRelatedValue(index, sr.ShowEnumerationIndexInCharts, Bindings.BOOLEAN); + if(selected && !Boolean.TRUE.equals(show)) { + graph.claimLiteral(index, sr.ShowEnumerationIndexInCharts, true, Bindings.BOOLEAN); + } else if(!selected && !Boolean.FALSE.equals(show)) { + graph.claimLiteral(index, sr.ShowEnumerationIndexInCharts, false, Bindings.BOOLEAN); + } + } + + updateModelResults(graph); + } + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + + + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + + } + + } + + private void updateModelResults(ReadGraph graph) { + try { + if(variable != null ) { + Resource modelResource = Variables.getModel(graph, variable); + if(modelResource != null) { + Resource configuration = graph.getSingleObject( + modelResource, + SimulationResource.getInstance(graph).HasConfiguration); + SysdynModel model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration); + // update results in graphs + model.resultChanged(); + } + } + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + @Override + public void setInput(ISessionContext context, Object input) { + variable = AdaptionUtils.adaptToSingle(input, Variable.class); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java new file mode 100644 index 00000000..74fc5cac --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java @@ -0,0 +1,633 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.custom.VerifyKeyListener; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.ui.IWorkbenchPartReference; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.platform.PropertyPageView; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.TrackedCombo; +import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener; +import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.request.WriteResultRequest; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.AsyncListener; +import org.simantics.db.request.Read; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.ArrayExpressionCombo; +import org.simantics.sysdyn.ui.properties.widgets.ExpressionTypes; +import org.simantics.sysdyn.ui.properties.widgets.ExpressionTypes.ExpressionType; +import org.simantics.sysdyn.ui.properties.widgets.ExpressionWidget; +import org.simantics.sysdyn.ui.properties.widgets.IsOutputWidget; +import org.simantics.sysdyn.ui.properties.widgets.ShortcutTabWidget; +import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameValidator; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.datastructures.Pair; + +/** + * Tab for displaying equation information of a variable + * @author Teemu Lempinen + * + */ +public class EquationTab extends LabelPropertyTabContributor implements Widget { + + private TrackedCombo expressionTypeCombo, unitCombo, arrayEquationCombo; + private ShortcutTabWidget shortcutTabWidget; + private ExpressionWidget expressionWidget; + private org.eclipse.ui.IPartListener2 focusLostListener; + private IWorkbenchSite site; + private Button deleteExpression, newExpression; + private WidgetSupportImpl expressionSupport = new WidgetSupportImpl(); + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + this.site = site; + support.register(this); + + // Composite for the whole tab + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite); + + // Composite holding name controls and controls for adding and removing expressions + Composite nameComposite = new Composite(composite, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(nameComposite); + GridDataFactory.fillDefaults().grab(true, false).applyTo(nameComposite); + + arrayEquationCombo = new ArrayExpressionCombo(nameComposite, support, SWT.DROP_DOWN | SWT.BORDER); + arrayEquationCombo.setInputValidator(new VariableNameValidator(support)); + GridDataFactory.fillDefaults().grab(true, false).applyTo(arrayEquationCombo.getWidget()); + + deleteExpression = new Button(nameComposite, support, SWT.NONE); + deleteExpression.setText("Delete"); + GridDataFactory.fillDefaults().applyTo(deleteExpression.getWidget()); + + newExpression = new Button(nameComposite, support, SWT.NONE); + newExpression.setText("New"); + GridDataFactory.fillDefaults().applyTo(newExpression.getWidget()); + + // Shortcut widget. Tabular widget containing tabs for functions and connected variables + shortcutTabWidget = new ShortcutTabWidget(composite, support, SWT.NONE); + GridDataFactory.fillDefaults().span(1, 3).grab(false, true).applyTo(shortcutTabWidget.getWidget()); + + // Type and unit selection composite + Composite TypeAndUnit = new Composite(composite, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(TypeAndUnit); + GridLayoutFactory.fillDefaults().numColumns(5).applyTo(TypeAndUnit); + + Label label = new Label(TypeAndUnit, SWT.SINGLE ); + label.setText("Type:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + expressionTypeCombo = new TrackedCombo(TypeAndUnit, support, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY); + GridDataFactory.fillDefaults().applyTo(expressionTypeCombo.getWidget()); + + label = new Label(TypeAndUnit, SWT.SINGLE ); + label.setText("Unit:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + + unitCombo = new TrackedCombo(TypeAndUnit, support, SWT.DROP_DOWN | SWT.BORDER); + GridDataFactory.fillDefaults().applyTo(unitCombo.getWidget()); + + IsOutputWidget isOutput = new IsOutputWidget(TypeAndUnit, support, SWT.NULL); + GridDataFactory.fillDefaults().grab(true, false).align(SWT.END, SWT.FILL).applyTo(isOutput.getWidget()); + + // The actual expression + Composite expressionComposite = new Composite(composite, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(expressionComposite); + expressionWidget = new ExpressionWidget(expressionComposite, expressionSupport, SWT.NONE); + expressionWidget.setVariableTable(shortcutTabWidget.getVariableTable()); + + addListeners(context); + } + + @Override + public void setInput(ISessionContext context, final Object input) { + final Resource variable = AdaptionUtils.adaptToSingle(input, Resource.class); + Resource expression = null; + try { + expression = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + return getActiveExpression(graph, AdaptionUtils.adaptToSingle(input, Resource.class)); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + // The variable has no expressions -> creating a new ordered set expressions and the active expression + if(expression == null && variable != null) { + try { + expression = SimanticsUI.getSession().syncRequest(new WriteResultRequest() { + + @Override + public Resource perform(WriteGraph graph) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource expressions = OrderedSetUtils.create(graph, sr.Expressions); + graph.claim(variable, sr.HasExpressions, expressions); + final Resource expression = graph.newResource(); + + if(graph.isInstanceOf(variable, sr.Auxiliary) || + graph.isInstanceOf(variable, sr.Valve)) { + graph.claim(expression, l0.InstanceOf, null, sr.NormalExpression); + graph.claimLiteral(expression, sr.HasEquation, ""); + } + else if(graph.isInstanceOf(variable, sr.Stock)) { + graph.claim(expression, l0.InstanceOf, null, sr.StockExpression); + graph.claimLiteral(expression, sr.HasInitialEquation, ""); + } + OrderedSetUtils.add(graph, expressions, expression); + graph.claim(variable, l0.ConsistsOf, expression); + + VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class); + final Session session = graph.getSession(); + session.asyncRequest(new WriteRequest(support.getWorkspacePersistent("expressions")) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + VirtualGraph runtime = graph.getService(VirtualGraph.class); + session.asyncRequest(new WriteRequest(runtime) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.hasStatement(variable, sr.HasActiveExpression)) + graph.deny(variable, sr.HasActiveExpression); + graph.claim(variable, sr.HasActiveExpression, expression); + } + } + ); + } + }); + return expression; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + // Now the variable should have an expression + SimanticsUI.getSession().asyncRequest(new Read>() { + + /** + * Find out if user can add a new expression or delete the current expression + */ + @Override + public Pair perform(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource expressions = graph.getPossibleObject(variable, sr.HasExpressions); + if(expressions == null) { + return new Pair(false, false); + } + List expressionList = OrderedSetUtils.toList(graph, expressions); + if(expressionList.isEmpty()) { + return new Pair(false, false); + } + + boolean canAdd = true; + boolean canDelete = false; + // If there are multiple expressions, one can be removed + if(expressionList.size() > 1) + canDelete = true; + String defaultRange = ArrayExpressionCombo.getDefaultRange(graph, variable); + + /* If the variable is an array variable, a range has been set to all expressions and none of + * the ranges is the default range, an expression can be added + */ + for(Resource expression : expressionList) { + String range = graph.getPossibleRelatedValue(expression, sr.HasArrayRange); + if(range == null || range.equals("") || range.equals(defaultRange)) { + canAdd = false; + break; + } + } + return new Pair(canAdd, canDelete); + } + }, new AsyncListener>() { + + @Override + public void execute(AsyncReadGraph graph, + final Pair result) { + newExpression.getWidget().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if(!newExpression.getWidget().isDisposed()) + newExpression.getWidget().setEnabled(result.first); + if(!deleteExpression.getWidget().isDisposed()) + deleteExpression.getWidget().setEnabled(result.second); + } + }); + + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return newExpression.getWidget().isDisposed() || deleteExpression.getWidget().isDisposed(); + } + }); + + // Set input to widgets using expressionSupport + StructuredSelection ss = new StructuredSelection(expression); + expressionSupport.fireInput(context, ss); + } + + /** + * Adds listeners to widgets in this tab + * + * @param context ISessionContext + */ + private void addListeners(ISessionContext context) { + + // Validate expression fields when a dependency has been added or removed + shortcutTabWidget.addDependencyListener(new Runnable() { + + @Override + public void run() { + expressionWidget.validateFields(); + } + }); + + // Deletes a selected expression + deleteExpression.addSelectionListener(new SelectionListenerImpl(context) { + + @Override + public void apply(WriteGraph graph, final Resource input) + throws DatabaseException { + + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + // Currently active expressin should be located in (Model sr.HasActiveExpression expression) + Resource activeExpression = graph.getPossibleObject(input, sr.HasActiveExpression); + if(activeExpression == null) + return; + + Resource expressionList = OrderedSetUtils.getSingleOwnerList(graph, activeExpression); + if(OrderedSetUtils.toList(graph, expressionList).size() <= 1) + return; + + // Get the previous expression in expression list to be activated + Resource prev = OrderedSetUtils.prev(graph, expressionList, activeExpression); + OrderedSetUtils.remove(graph, expressionList, activeExpression); + graph.deny(input, l0.ConsistsOf, activeExpression); + + if(prev.equals(expressionList)) { + // If the removed expression was last on the list, prev returns the list. + // Get a proper list element to be activated + Iterator iterator = OrderedSetUtils.iterator(graph, expressionList); + prev = iterator.next(); + } + + // Set prev as active in virtual graph + final Resource newActive = prev; + VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class); + final Session session = graph.getSession(); + session.asyncRequest(new WriteRequest(support.getWorkspacePersistent("expressions")) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + VirtualGraph runtime = graph.getService(VirtualGraph.class); + session.asyncRequest(new WriteRequest(runtime) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.hasStatement(input, sr.HasActiveExpression)) + graph.deny(input, sr.HasActiveExpression); + graph.claim(input, sr.HasActiveExpression, newActive); + } + } + ); + } + }); + } + }); + + // Creates a new expression + newExpression.addSelectionListener(new SelectionListenerImpl(context) { + + @Override + public void apply(WriteGraph graph, Resource input) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Resource expressions = graph.getPossibleObject(input, sr.HasExpressions); + if(expressions == null) { + return; + } + // Get the currently active expression + Resource activeExpression = graph.getPossibleObject(input, sr.HasActiveExpression); + Resource newExpression = graph.newResource(); + if(activeExpression != null) { + // Create a new expression based on the old expression + graph.claim(newExpression, l0.InstanceOf, graph.getSingleObject(activeExpression, l0.InstanceOf)); + if(graph.isInstanceOf(newExpression, sr.StockExpression)) { + graph.claimLiteral(newExpression, sr.HasInitialEquation, ""); + } + } else { + // If there was no active expression, create a normal expression + graph.claim(newExpression, l0.InstanceOf, sr.NormalExpression); + } + OrderedSetUtils.add(graph, expressions, newExpression); + graph.claim(input, l0.ConsistsOf, newExpression); + } + }); + + // Item factory for expression type combo + expressionTypeCombo.setItemFactory(new ReadFactoryImpl>() { + + @Override + public Map perform(ReadGraph graph, final Resource input) throws DatabaseException { + + Map map = new HashMap(); + SysdynResource sr = SysdynResource.getInstance(graph); + + // Select expression types based on the type of the variable + final ExpressionType[] expressionTypes; + if(graph.isInstanceOf(input, sr.Auxiliary)) + expressionTypes = ExpressionTypes.auxiliaryExpressions; + else if(graph.isInstanceOf(input, sr.Stock)) + expressionTypes = ExpressionTypes.stockExpressions; + else if(graph.isInstanceOf(input, sr.Valve)) + expressionTypes = ExpressionTypes.valveExpressions; + else + expressionTypes = new ExpressionType[] {}; + + for(ExpressionType et : expressionTypes) { + map.put(et.toString(), et); + } + return map; + } + }); + + // Initial selection to the combo from active expression + expressionTypeCombo.setSelectionFactory(new ReadFactoryImpl() { + + @Override + public String perform(ReadGraph graph, final Resource input) throws DatabaseException { + Resource activeExpression = getActiveExpression(graph, input); + if(activeExpression == null) + return null; + return ExpressionTypes.getExpressionType(graph, activeExpression).toString(); + } + }); + + // Modify listener for selecting expression type + expressionTypeCombo.addModifyListener(new TextModifyListener() { + + @Override + public void modifyText(TrackedModifyEvent e) { + expressionWidget.displayExpression(e.getText(), false); + expressionWidget.save(); + } + }); + + + // Add all units used in the model to the unit combo + unitCombo.setItemFactory(new ReadFactoryImpl>() { + + @Override + public Map perform(ReadGraph graph, final Resource input) throws DatabaseException { + Map map = new HashMap(); + + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource model = graph.getPossibleObject(input, l0.PartOf); + if (model != null) { + Collection variables = graph.getObjects(model, l0.ConsistsOf); + for(Resource v : variables) { + Object unit = graph.getPossibleRelatedValue(v, sr.HasUnit); + if (unit != null && !map.keySet().contains((String) unit)) { + map.put((String)unit, (String)unit); + + } + } + } + return map; + } + }); + + // Set initial selection of unit combo + unitCombo.setSelectionFactory(new ReadFactoryImpl() { + + @Override + public String perform(ReadGraph graph, final Resource input) throws DatabaseException { + String unit = graph.getPossibleRelatedValue(input, SysdynResource.getInstance(graph).HasUnit); + if(unit == null) + return ""; + else + return unit; + } + }); + + // Modify unit + unitCombo.addModifyListener(new ComboModifyListenerImpl() { + + @Override + public void applyText(WriteGraph graph, Resource input, String text) throws DatabaseException { + graph.claimLiteral(input, SysdynResource.getInstance(graph).HasUnit, text); + } + }); + + + /* + * Double-clicking something in shortcut tab widget + * writes the clicked element into expression widget, + * sets focus on expression widget and validates its fields + */ + shortcutTabWidget.addMouseListener(new MouseListener(){ + + @Override + public void mouseDoubleClick(MouseEvent e) { + Table table = (Table)e.widget; + TableItem item = table.getItem(new Point(e.x, e.y)); + if(item != null) { + final String var = (String)item.getData(); + table.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if(expressionWidget!= null) { + expressionWidget.getExpression().focus(); + expressionWidget.getExpression().replaceSelection(var); + expressionWidget.validateFieldsTimed(); + } + } + }); + } + } + + @Override + public void mouseDown(MouseEvent e) { + expressionWidget.getExpression().focus(); + } + + @Override + public void mouseUp(MouseEvent e) { + } + + }); + + /* + * Shortcut tab widget should not maintain any selections for visual reasons + */ + shortcutTabWidget.addFocusListener(new FocusListener() { + + @Override + public void focusGained(FocusEvent e) { + } + + @Override + public void focusLost(FocusEvent e) { + ((Table)e.widget).deselectAll(); + } + + }); + + /* Modifying an expression sets a timed validation. The timer is + * reset after each modification + */ + expressionWidget.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + expressionWidget.validateFieldsTimed(); + } + }); + + // Pressing return without shift key triggers saving the expression + expressionWidget.addVerifyKeyListener(new VerifyKeyListener() { + + @Override + public void verifyKey(VerifyEvent event) { + if(event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) { + if((event.stateMask & SWT.SHIFT) == 0) { + event.doit = false; + ((StyledText)event.widget).getParent().forceFocus(); + expressionWidget.save(); + } + } + } + }); + + // Triggers save when equation tab loses focus + if(focusLostListener == null) { + focusLostListener = new org.eclipse.ui.IPartListener2() + { + public void partInputChanged(IWorkbenchPartReference partRef) {} + public void partVisible(IWorkbenchPartReference partRef) {} + public void partHidden(IWorkbenchPartReference partRef) {} + public void partOpened(IWorkbenchPartReference partRef) {} + public void partDeactivated(IWorkbenchPartReference partRef) + { + if(partRef.getPart(false) instanceof PropertyPageView) { + PropertyPageView ppv = (PropertyPageView)partRef.getPart(false); + if(ppv.getCurrentPage() instanceof SysdynPropertyPage) { + // Save expressions + if(expressionWidget != null) { + expressionWidget.save(); + } + site.getPage().removePartListener(this); + } + } + } + public void partClosed(IWorkbenchPartReference partRef) {} + public void partBroughtToTop(IWorkbenchPartReference partRef) {} + public void partActivated(IWorkbenchPartReference partRef) {} + }; + site.getPage().addPartListener(focusLostListener); + } + } + + @Override + public void dispose() { + if(focusLostListener != null && site != null) + site.getPage().removePartListener(focusLostListener); + super.dispose(); + } + + /** + * Get the currently active expression of the first expression in expression list if + * no expression has been set to active + * + * @param graph ReadGraph + * @param variable Variable + * @return active expression or the first expression in variables expression list + * @throws DatabaseException + */ + private Resource getActiveExpression(ReadGraph graph, Resource variable) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource expression = graph.getPossibleObject(variable, sr.HasActiveExpression); + if(expression == null) { + Resource expressions = graph.getPossibleObject(variable, sr.HasExpressions); + if(expressions == null) { + return null; + } + List expressionList = OrderedSetUtils.toList(graph, expressions); + if(expressionList.isEmpty()) { + return null; + } + expression = expressionList.get(0); + } + return expression; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExperimentTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExperimentTab.java new file mode 100644 index 00000000..8d4aa90b --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExperimentTab.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; + +public class ExperimentTab extends LabelPropertyTabContributor { + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExternalFilesTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExternalFilesTab.java new file mode 100644 index 00000000..47ba4e84 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExternalFilesTab.java @@ -0,0 +1,207 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.AdaptableHintContext; +import org.simantics.browsing.ui.swt.SingleSelectionInputSource; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.handlers.RemoveNodeHandler; +import org.simantics.sysdyn.ui.handlers.exports.ExportExternalFunctionFilesHandler; +import org.simantics.sysdyn.ui.handlers.imports.ImportExternalFunctionFilesHandler; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.ArrayMap; +import org.simantics.utils.datastructures.Pair; + +/** + * Tab for properties of a SysdynModelicaFunction containing all external files added to that function + * + * @author Teemu Lempinen + * + */ +public class ExternalFilesTab extends LabelPropertyTabContributor implements Widget { + + GraphExplorerComposite externalFilesExplorer; + Button importButton, exportButton, removeButton; + + @Override + public void createControls(Composite body, IWorkbenchSite site, + final ISessionContext context, WidgetSupport support) { + support.register(this); + + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite); + + // Create the graph explorer displaying external files + externalFilesExplorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), site, composite, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI); + + externalFilesExplorer + .setBrowseContexts(SysdynResource.URIs.ExternalFiles); + externalFilesExplorer.setInputSource(new SingleSelectionInputSource( + Resource.class)); + + externalFilesExplorer.setContextMenuId("#ExternalFunctionFileBrowser"); + externalFilesExplorer.finish(); + + GridDataFactory.fillDefaults().grab(true, true).applyTo( + externalFilesExplorer); + + Control c = externalFilesExplorer.getExplorerControl(); + if (c instanceof Tree) + ((Tree) c).setLinesVisible(true); + + + // Create controls for importing, exporting and removing external files + Composite buttonRow = new Composite(composite, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonRow); + GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonRow); + + importButton = new Button(buttonRow, support, SWT.NONE); + importButton.setText("Import"); + importButton.addSelectionListener(new SelectionListenerImpl(context) { + + @Override + public void apply(WriteGraph graph, final Resource input) + throws DatabaseException { + + importButton.getWidget().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + Shell shell = importButton.getWidget().getShell(); + + final Pair importedFiles = ImportExternalFunctionFilesHandler.importFiles(shell, "Import files", ImportExternalFunctionFilesHandler.C_EXTENSIONS); + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + ImportExternalFunctionFilesHandler.addFilesToFunction(graph, input, importedFiles); + } + }); + } + }); + + + } + }); + + exportButton = new Button(buttonRow, support, SWT.NONE); + exportButton.setText("Export"); + exportButton.addSelectionListener(new SelectionListenerImpl(context) { + + @Override + public void apply(WriteGraph graph, final Resource input) + throws DatabaseException { + + exportButton.getWidget().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + Shell shell = exportButton.getWidget().getShell(); + List resourceList = getSelectedResources(externalFilesExplorer); + Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]); + if (resources.length > 0) + ExportExternalFunctionFilesHandler.exportFiles(shell, resources); + } + }); + + + } + }); + + removeButton = new Button(buttonRow, support, SWT.NONE); + removeButton.setText("Remove"); + removeButton.addSelectionListener(new SelectionListenerImpl(context) { + + @Override + public void apply(WriteGraph graph, final Resource input) + throws DatabaseException { + + removeButton.getWidget().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + Shell shell = removeButton.getWidget().getShell(); + + List resourceList = getSelectedResources(externalFilesExplorer); + Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]); + if(resources.length > 0) { + MessageDialog dialog = new MessageDialog(shell, resources.length > 1 ? "Remove selected items" : "Remove selected item" , null, "Are you sure?", 0, + new String[] { "OK", "Cancel" }, 0); + dialog.create(); + if (dialog.open() == 0) { + RemoveNodeHandler.deleteItem(resources); + } + } + } + }); + + + } + }); + } + + @Override + public void setInput(ISessionContext context, Object input) { + externalFilesExplorer.setInput(context, input); + } + + /** + * Method for retreiving selected resources from a GraphExplorerComposite + * @param explorer + * @return + */ + private List getSelectedResources(GraphExplorerComposite explorer) { + List result = new ArrayList(); + + ISelection selection = ((ISelectionProvider) explorer + .getAdapter(ISelectionProvider.class)).getSelection(); + if (selection == null) + return result; + IStructuredSelection iss = (IStructuredSelection) selection; + @SuppressWarnings("unchecked") + List selections = iss.toList(); + for(AdaptableHintContext ahc : selections) { + Resource resource = (Resource) ahc.getAdapter(Resource.class); + result.add(resource); + } + return result; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionLibraryTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionLibraryTab.java new file mode 100644 index 00000000..b198c15d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionLibraryTab.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; + +public class FunctionLibraryTab extends LabelPropertyTabContributor { + + @Override + public void createControls(Composite body, IWorkbenchSite site, + ISessionContext context, WidgetSupport support) { + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite); + + + TrackedText nameText = new TrackedText(composite, support, SWT.BORDER); + nameText.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasName)); + nameText.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasName)); + GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText.getWidget()); + + + TrackedText information = new TrackedText(composite, support, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP); + information.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasDescription)); + information.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasDescription)); + GridDataFactory.fillDefaults().grab(true, true).applyTo(information.getWidget()); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java new file mode 100644 index 00000000..9d9eec4d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.Label; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.sysdyn.ui.properties.widgets.FunctionLabelFactory; +import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionField; +import org.simantics.sysdyn.ui.properties.widgets.functions.FunctionCodeWidget; + +public class FunctionTab extends LabelPropertyTabContributor { + + ExpressionField modelicaCode; + + @Override + public void createControls(Composite body, IWorkbenchSite site, + ISessionContext context, WidgetSupport support) { + + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); + + TrackedText nameText = new TrackedText(composite, support, SWT.BORDER); + nameText.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasName)); + nameText.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasName)); + nameText.addModifyListener(new TextModifyListenerImpl() { + + @Override + public void applyText(WriteGraph graph, Resource input, String text) + throws DatabaseException { + Resource library = graph.getSingleObject(input, Layer0.getInstance(graph).PartOf); + FunctionUtils.updateFunctionFileForLibrary(graph, library); + } + }); + GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(nameText.getWidget()); + + + Group modelicaGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); + modelicaGroup.setText("Modelica code"); + GridDataFactory.fillDefaults().grab(true, true).applyTo(modelicaGroup); + GridLayoutFactory.fillDefaults().spacing(0, 0).margins(3, 3).applyTo(modelicaGroup); + + Label startLabel = new Label(modelicaGroup, support, SWT.NONE); + startLabel.setTextFactory(new FunctionLabelFactory(Layer0.URIs.HasName, false)); + + new FunctionCodeWidget(modelicaGroup, support, SWT.BORDER); + /* + TrackedText modelicaCode = new TrackedText(modelicaGroup, support, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.WRAP); + modelicaCode.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.HasModelicaFunctionCode)); + modelicaCode.addModifyListener(new StringPropertyModifier(context, SysdynResource.URIs.HasModelicaFunctionCode)); + modelicaCode.addModifyListener(new TextModifyListenerImpl() { + + @Override + public void applyText(WriteGraph graph, Resource input, String text) + throws DatabaseException { + Resource library = graph.getSingleObject(input, Layer0.getInstance(graph).PartOf); + FunctionUtils.updateFunctionFileForLibrary(graph, library); + } + }); + + GridDataFactory.fillDefaults().grab(true, true).applyTo(modelicaCode.getWidget()); + */ + Label endLabel = new Label(modelicaGroup, support, SWT.NONE); + endLabel.setTextFactory(new FunctionLabelFactory(Layer0.URIs.HasName, true)); + + Group documentationGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); + documentationGroup.setText("Documentation"); + GridDataFactory.fillDefaults().grab(true, true).applyTo(documentationGroup); + GridLayoutFactory.fillDefaults().spacing(0, 0).margins(3, 3).applyTo(documentationGroup); + + TrackedText information = new TrackedText(documentationGroup, support, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP); + information.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasDescription)); + information.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasDescription)); + GridDataFactory.fillDefaults().grab(true, true).applyTo(information.getWidget()); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/InputVariableTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/InputVariableTab.java new file mode 100644 index 00000000..4ee58758 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/InputVariableTab.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.IsOutputWidget; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; +import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier; +import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameValidator; +import org.simantics.utils.ui.validators.DoubleValidator; + +/** + * Properties for input variables: Name, default value, isOutput + * + * @author Teemu Lempinen + * + */ +public class InputVariableTab extends LabelPropertyTabContributor { + + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).grab(false, true).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite); + + TrackedText nameText = new TrackedText(composite, support, SWT.BORDER); + nameText.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasName)); + nameText.addModifyListener(new VariableNamePropertyModifier(context, Layer0.URIs.HasName)); + nameText.setInputValidator(new VariableNameValidator(support)); + GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText.getWidget()); + + Composite defaultValueComposite = new Composite(composite, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(defaultValueComposite); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(defaultValueComposite); + + Label label = new Label(defaultValueComposite, SWT.NULL); + label.setText("Default Value:"); + + TrackedText defaultValue = new TrackedText(defaultValueComposite, support, SWT.RIGHT | SWT.BORDER); + defaultValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasDefaultInputValue)); + defaultValue.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasDefaultInputValue)); + defaultValue.setInputValidator(new DoubleValidator()); + GridDataFactory.fillDefaults().grab(true, false).applyTo(defaultValue.getWidget()); + + new IsOutputWidget(composite, support, SWT.NULL); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LabelPropertyTabContributor.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LabelPropertyTabContributor.java new file mode 100644 index 00000000..35e7c357 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LabelPropertyTabContributor.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.AsyncListener; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.selectionview.PropertyTabContributorImpl; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.datastructures.Callback; + +public abstract class LabelPropertyTabContributor extends PropertyTabContributorImpl { + + private boolean isDisposed = false; + + + public void createControl(Composite parent, final IWorkbenchSite site, final ISessionContext context, final WidgetSupportImpl support) { + super.createControl(parent, site, context, support); + + // Add dispose listener to make sure name listening receives the correct isDisposed -value + parent.addDisposeListener(new DisposeListener() { + + @Override + public void widgetDisposed(DisposeEvent e) { + LabelPropertyTabContributor.this.dispose(); + } + }); + } + + @Override + public void updatePartName(ISelection forSelection, final Callback updateCallback) { + final Resource resource = AdaptionUtils.adaptToSingle(forSelection, Resource.class); + if(resource == null) { + updateCallback.run("Selection properties"); + return; + } + + SimanticsUI.getSession().asyncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + Resource r = resource; + if(graph.hasStatement(r, mr.ElementToComponent)) { + r = graph.getSingleObject(r, mr.ElementToComponent); + } + String label = graph.getPossibleRelatedValue(r, l0.HasLabel); + if(label != null) + return label; + label = graph.getPossibleRelatedValue(r, l0.HasName); + if(label != null) + return label; + return "No name for selection"; + } + }, new AsyncListener() { + + @Override + public void execute(AsyncReadGraph graph, String result) { + updateCallback.run(result); + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + + } + + @Override + public boolean isDisposed() { + return isDisposed; + } + }); + } + + @Override + protected void dispose() { + this.isDisposed = true; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LookupTableTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LookupTableTab.java new file mode 100644 index 00000000..678227ff --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LookupTableTab.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.ChartTableWidget; +import org.simantics.sysdyn.ui.properties.widgets.ChartWidget; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; + +public class LookupTableTab extends LabelPropertyTabContributor { + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + + + Composite baseContainer = new Composite(body, SWT.NONE); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(baseContainer); + GridDataFactory.fillDefaults().grab(true, true).applyTo(baseContainer); + + Composite Ycontainer = new Composite(baseContainer, SWT.NONE); + GridLayoutFactory.fillDefaults().applyTo(Ycontainer); + GridDataFactory.fillDefaults().grab(false, true).applyTo(Ycontainer); + + TrackedText maxYText = new TrackedText(Ycontainer, support, SWT.BORDER); + maxYText.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasMaxY)); + maxYText.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasMaxY)); + + Label l = new Label(Ycontainer, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).grab(false, true).applyTo(l); + + TrackedText minYText = new TrackedText(Ycontainer, support, SWT.BORDER); + minYText.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasMinY)); + minYText.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasMinY)); + + + Composite chartContainer = new Composite(baseContainer, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(chartContainer); + GridDataFactory.fillDefaults().grab(true, true).applyTo(chartContainer); + + @SuppressWarnings("unused") + ChartWidget chartWidget = new ChartWidget(chartContainer, support, SWT.NONE); + + Composite chartTableContainer = new Composite(baseContainer, SWT.NONE); + GridLayoutFactory.fillDefaults().applyTo(chartTableContainer); + GridDataFactory.fillDefaults().grab(false, true).span(1, 2).applyTo(chartTableContainer); + + @SuppressWarnings("unused") + ChartTableWidget chartTableWidget = new ChartTableWidget(chartTableContainer, support, SWT.NONE); + + l = new Label(baseContainer, SWT.NONE); + + Composite Xcontainer = new Composite(baseContainer, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(Xcontainer); + GridDataFactory.fillDefaults().grab(true, false).applyTo(Xcontainer); + + TrackedText minXText = new TrackedText(Xcontainer, support, SWT.BORDER); + minXText.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasMinX)); + minXText.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasMinX)); + + l = new Label(Xcontainer, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, false).applyTo(l); + + TrackedText maxXText = new TrackedText(Xcontainer, support, SWT.BORDER); + maxXText.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasMaxX)); + maxXText.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasMaxX)); + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java new file mode 100644 index 00000000..f188749c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import java.util.ArrayList; + +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.ModuleInputEditingSupport; +import org.simantics.sysdyn.ui.properties.widgets.ReferenceRow; +import org.simantics.sysdyn.ui.properties.widgets.ReferenceRowLabelProvider; +import org.simantics.sysdyn.ui.properties.widgets.ReferenceTable; +import org.simantics.sysdyn.ui.properties.widgets.RowProvider; + +public class ModuleInputTab extends LabelPropertyTabContributor { + + public static final String FIRSTCOLUMN = "Input in Module"; + public static final String SECONDCOLUMN = "Refers to output"; + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + ReferenceTable referenceTable = new ReferenceTable(body, support, SWT.NONE); + + String[] titles = { FIRSTCOLUMN, SECONDCOLUMN}; + int[] bounds = { 100, 100, 100, 100 }; + for (int i = 0; i < titles.length; i++) { + TableViewerColumn column = new TableViewerColumn(referenceTable.getTableViewer(), SWT.NONE); + column.getColumn().setText(titles[i]); + column.getColumn().setWidth(bounds[i]); + column.getColumn().setResizable(true); + column.getColumn().setMoveable(false); + // enable editing support + column.setEditingSupport(new ModuleInputEditingSupport(referenceTable.getTableViewer(), i)); + } + referenceTable.setContentProvider (new ArrayContentProvider()); + referenceTable.setLabelProvider (new ReferenceRowLabelProvider()); + + RowProvider rp = new RowProvider() { + + @Override + public ArrayList getRows(ReadGraph graph, Resource module) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + ArrayList result = new ArrayList(); + Resource instanceOf = graph.getPossibleObject(module, l0.InstanceOf); + if(instanceOf == null) return result; + Resource configuration = graph.getSingleObject(instanceOf, sr2.IsDefinedBy); + for(Resource input : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Input))) { + Resource dependency = null; + for(Resource dep : graph.getObjects(module, sr.IsHeadOf)) { + Resource refersTo = graph.getPossibleObject(dep, sr.RefersTo); + if(refersTo != null && refersTo.equals(input)) { + dependency = dep; + break; + } + } + ReferenceRow rr = new ReferenceRow(module, dependency, input); + result.add(rr); + } + return result; + } + }; + referenceTable.setRowProvider(rp); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleOutputTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleOutputTab.java new file mode 100644 index 00000000..29c2819f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleOutputTab.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import java.util.ArrayList; + +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.ModuleOutputEditingSupport; +import org.simantics.sysdyn.ui.properties.widgets.ReferenceRow; +import org.simantics.sysdyn.ui.properties.widgets.ReferenceRowLabelProvider; +import org.simantics.sysdyn.ui.properties.widgets.ReferenceTable; +import org.simantics.sysdyn.ui.properties.widgets.RowProvider; + +public class ModuleOutputTab extends LabelPropertyTabContributor { + + public static final String FIRSTCOLUMN = "Output in module"; + public static final String SECONDCOLUMN = "Referes to input"; + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + ReferenceTable referenceTable = new ReferenceTable(body, support, SWT.NONE); + + String[] titles = { FIRSTCOLUMN, SECONDCOLUMN}; + int[] bounds = { 100, 100, 100, 100 }; + for (int i = 0; i < titles.length; i++) { + TableViewerColumn column = new TableViewerColumn(referenceTable.getTableViewer(), SWT.NONE); + column.getColumn().setText(titles[i]); + column.getColumn().setWidth(bounds[i]); + column.getColumn().setResizable(true); + column.getColumn().setMoveable(false); + // enable editing support + column.setEditingSupport(new ModuleOutputEditingSupport(referenceTable.getTableViewer(), i)); + } + referenceTable.setContentProvider (new ArrayContentProvider()); + referenceTable.setLabelProvider (new ReferenceRowLabelProvider()); + + RowProvider rp = new RowProvider() { + + @Override + public ArrayList getRows(ReadGraph graph, Resource module) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + ArrayList result = new ArrayList(); + Resource instanceOf = graph.getPossibleObject(module, l0.InstanceOf); + if(instanceOf == null) return result; + Resource configuration = graph.getSingleObject(instanceOf, sr2.IsDefinedBy); + for(Resource variable : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Variable))) { + if(!graph.hasStatement(variable, sr.IsOutput)) continue; + + Resource dependency = null; + for(Resource dep : graph.getObjects(module, sr.IsTailOf)) { + Resource refersTo = graph.getPossibleObject(dep, sr.RefersTo); + if(refersTo != null && refersTo.equals(variable)) { + dependency = dep; + break; + } + } + ReferenceRow rr = new ReferenceRow(module, dependency, variable); + result.add(rr); + } + return result; + } + }; + referenceTable.setRowProvider(rp); + } +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTab.java new file mode 100644 index 00000000..34f5ac22 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTab.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.SingleSelectionInputSource; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.Resource; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys; +import org.simantics.utils.datastructures.ArrayMap; + +public class ModuleTab extends LabelPropertyTabContributor implements Widget { + + GraphExplorerComposite enumerationRedeclarationExplorer; + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + support.register(this); + + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite); + TrackedText nameText = new TrackedText(composite, support, SWT.BORDER); + nameText.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasName)); + nameText.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasName)); + GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText.getWidget()); + + Label label = new Label(composite, SWT.NONE); + label.setText("Replaceable enumerations"); + enumerationRedeclarationExplorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), site, composite, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI); + + enumerationRedeclarationExplorer + .setBrowseContexts(SysdynResource.URIs.EnumerationReplacement); + enumerationRedeclarationExplorer.setColumns(ColumnKeys.ENUMERATION_REDECLARATION_COLUMNS); + enumerationRedeclarationExplorer.setInputSource(new SingleSelectionInputSource( + Resource.class)); + + enumerationRedeclarationExplorer.finish(); + + GridDataFactory.fillDefaults().grab(true, true).applyTo( + enumerationRedeclarationExplorer); + + Control c = enumerationRedeclarationExplorer.getExplorerControl(); + if (c instanceof Tree) + ((Tree) c).setLinesVisible(true); + + } + + + @Override + public void setInput(ISessionContext context, Object input) { + enumerationRedeclarationExplorer.setInput(context, input); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTypeTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTypeTab.java new file mode 100644 index 00000000..fe40aee7 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleTypeTab.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; + +public class ModuleTypeTab extends LabelPropertyTabContributor { + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(6).applyTo(composite); + TrackedText nameText = new TrackedText(composite, support, SWT.BORDER); + nameText.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasName)); + nameText.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasName)); + GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText.getWidget()); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/PlaybackExperimentTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/PlaybackExperimentTab.java new file mode 100644 index 00000000..4b7eb906 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/PlaybackExperimentTab.java @@ -0,0 +1,210 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import java.util.ArrayList; +import java.util.Collection; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.db.management.ISessionContext; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.utils.datastructures.Triple; +import org.simantics.utils.ui.color.Color; +import org.simantics.utils.ui.color.ColorGradient; +import org.simantics.utils.ui.color.ColorValue; + +public class PlaybackExperimentTab extends LabelPropertyTabContributor { + + private static int gradientWidth = 250; + private static int gradientHeight = 20; + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(composite); + + Group gradientGroup = new Group(composite, SWT.NONE); + gradientGroup.setText("Color scale"); + GridDataFactory.fillDefaults().applyTo(gradientGroup); + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(gradientGroup); + + + ColorValue cv1 = new ColorValue(new Color(0, 62, 133), 0.0); + ColorValue cv2 = new ColorValue(new Color(255, 230, 0), 1.0); + ColorValue[] values = new ColorValue[] {cv1, cv2}; + ColorGradient cg = new ColorGradient(values, ColorGradient.HSV); + Image image = cg.getGradientImage(gradientWidth, gradientHeight, SWT.HORIZONTAL); + Button b = new Button(gradientGroup, support, SWT.RADIO); + GridDataFactory.fillDefaults().hint(gradientWidth, gradientHeight).applyTo(b.getWidget()); + b.setImage(image); + b.addSelectionListener(new GradientSelectionListener(context, values)); + b.setSelectionFactory(new GradientSelectionFactory(values)); + + cv1 = new ColorValue(new Color(255, 230, 0), 0.0); + cv2 = new ColorValue(new Color(0, 62, 133), 1.0); + values = new ColorValue[] {cv1, cv2}; + cg = new ColorGradient(values, ColorGradient.HSV); + image = cg.getGradientImage(gradientWidth, gradientHeight, SWT.HORIZONTAL); + b = new Button(gradientGroup, support, SWT.RADIO); + GridDataFactory.fillDefaults().hint(gradientWidth, gradientHeight).applyTo(b.getWidget()); + b.setImage(image); + b.addSelectionListener(new GradientSelectionListener(context, values)); + b.setSelectionFactory(new GradientSelectionFactory(values)); + + cv1 = new ColorValue(new Color(0, 0, 0), 0.0); + cv2 = new ColorValue(new Color(255, 255, 255), 1.0); + values = new ColorValue[] {cv1, cv2}; + cg = new ColorGradient(values, ColorGradient.HSV); + image = cg.getGradientImage(gradientWidth, gradientHeight, SWT.HORIZONTAL); + b = new Button(gradientGroup, support, SWT.RADIO); + GridDataFactory.fillDefaults().hint(gradientWidth, gradientHeight).applyTo(b.getWidget()); + b.setImage(image); + b.addSelectionListener(new GradientSelectionListener(context, values)); + b.setSelectionFactory(new GradientSelectionFactory(values)); + + cv1 = new ColorValue(new Color(0, 0, 255), 0.0); + cv2 = new ColorValue(new Color(255, 0, 0), 1.0); + values = new ColorValue[] {cv1, cv2}; + cg = new ColorGradient(values, ColorGradient.HSV); + image = cg.getGradientImage(gradientWidth, gradientHeight, SWT.HORIZONTAL); + b = new Button(gradientGroup, support, SWT.RADIO); + GridDataFactory.fillDefaults().hint(gradientWidth, gradientHeight).applyTo(b.getWidget()); + b.setImage(image); + b.addSelectionListener(new GradientSelectionListener(context, values)); + b.setSelectionFactory(new GradientSelectionFactory(values)); + + + cv1 = new ColorValue(new Color(255, 0, 0), 0.0); + cv2 = new ColorValue(new Color(0, 0, 255), 1.0); + values = new ColorValue[] {cv1, cv2}; + cg = new ColorGradient(values, ColorGradient.HSV); + image = cg.getGradientImage(gradientWidth, gradientHeight, SWT.HORIZONTAL); + b = new Button(gradientGroup, support, SWT.RADIO); + GridDataFactory.fillDefaults().hint(gradientWidth, gradientHeight).applyTo(b.getWidget()); + b.setImage(image); + b.addSelectionListener(new GradientSelectionListener(context, values)); + b.setSelectionFactory(new GradientSelectionFactory(values)); + } + + + class GradientSelectionListener extends SelectionListenerImpl { + private ArrayList colorValues; + + public GradientSelectionListener(ISessionContext context, ColorValue[] colorValues) { + super(context); + this.colorValues = new ArrayList(); + for(ColorValue cv : colorValues) + this.colorValues.add(cv); + } + + @Override + public void apply(WriteGraph graph, Resource experiment) throws DatabaseException { + G2DResource g2d = G2DResource.getInstance(graph); + + Resource gradient = graph.getPossibleObject(experiment, g2d.HasColorGradient); + + if(gradient != null) { + graph.denyStatement(experiment, g2d.HasColorGradient, gradient); + RemoverUtil.remove(graph, gradient); + } + + gradient = GraphUtils.create2(graph, g2d.ColorGradient); + graph.claim(experiment, g2d.HasColorGradient, gradient); + + for(ColorValue cv : colorValues) { + Resource placement = GraphUtils.create2(graph, g2d.ColorPlacement, + g2d.HasGradientPosition, cv.getValue()); + graph.claimLiteral(placement, g2d.HasColor, g2d.Color, cv.getColor().getAWTColor().getColorComponents(new float[4])); + graph.claim(gradient, g2d.HasColorPlacement, placement); + } + } + + } + + class GradientSelectionFactory extends ReadFactoryImpl { + private ArrayList colorValues; + + public GradientSelectionFactory(ColorValue[] colorValues) { + this.colorValues = new ArrayList(); + for(ColorValue cv : colorValues) + this.colorValues.add(cv); + } + + @Override + public Object getIdentity(Object inputContents) { + return new Triple>(inputContents, colorValues, getClass()); + } + + @Override + public Boolean perform(ReadGraph graph, Resource experiment) throws DatabaseException { + G2DResource g2d = G2DResource.getInstance(graph); + Resource gradient = graph.getPossibleObject(experiment, g2d.HasColorGradient); + if(gradient == null) { + return Boolean.FALSE; + } + Collection placements = graph.syncRequest(new ObjectsWithType(gradient, g2d.HasColorPlacement, g2d.ColorPlacement)); + if(placements.isEmpty()) + return Boolean.FALSE; + + for(Resource placement : placements) { + Double position = graph.getPossibleRelatedValue(placement, g2d.HasGradientPosition); + if(position == null) + return Boolean.FALSE; + int index = -1; + + // First look for a color with matching value + for(int i = 0; i < colorValues.size(); i++) { + if(position.equals(colorValues.get(i).getValue())) { + + index = i; + break; + } + } + + // If matching value was found, see if the color is the same + if(index >= 0) { + Color c = colorValues.get(index).getColor(); + float[] cArray = c.getAWTColor().getColorComponents(new float[4]); + float[] color = graph.getPossibleRelatedValue(placement, g2d.HasColor, Bindings.FLOAT_ARRAY); + for(int i = 0; i < color.length; i++) { + if(cArray[i] != color[i]) + // Some inconsistency found in colors, return false + return Boolean.FALSE; + } + } + } + + // Everything matched + return Boolean.TRUE; + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ReferenceDependencyTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ReferenceDependencyTab.java new file mode 100644 index 00000000..cc8f4384 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ReferenceDependencyTab.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; + +public class ReferenceDependencyTab extends LabelPropertyTabContributor { + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java new file mode 100644 index 00000000..6ba81d70 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java @@ -0,0 +1,389 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.eclipse.jface.viewers.ISelection; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.exception.ServiceException; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.selectionview.ComparableTabContributor; +import org.simantics.selectionview.SelectionProcessor; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder; +import org.simantics.sysdyn.ui.trend.chart.properties.ChartTab; +import org.simantics.sysdyn.ui.trend.chart.properties.bar.BarAxisTab; +import org.simantics.sysdyn.ui.trend.chart.properties.bar.BarGeneralPropertiesTab; +import org.simantics.sysdyn.ui.trend.chart.properties.bar.BarSeriesTab; +import org.simantics.sysdyn.ui.trend.chart.properties.pie.PieGeneralPropertiesTab; +import org.simantics.sysdyn.ui.trend.chart.properties.pie.PieSeriesTab; +import org.simantics.sysdyn.ui.trend.chart.properties.xyline.XYLineAxisAndVariablesTab; +import org.simantics.sysdyn.ui.trend.chart.properties.xyline.XYLineGeneralPropertiesTab; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * SelectionProcessor for processing selections for property view in system dynamics + * + * @author Teemu Lempinen + * + */ +public class ResourceSelectionProcessor implements SelectionProcessor { + + @Override + public Collection process(Object selection, ReadGraph backend) { + Collection tabs = new ArrayList(); + SysdynResource sr = SysdynResource.getInstance(backend); + DiagramResource dr = DiagramResource.getInstance(backend); + ModelingResources mr = ModelingResources.getInstance(backend); + SimulationResource simu = SimulationResource.getInstance(backend); + JFreeChartResource jfree = JFreeChartResource.getInstance(backend); + + try { + // Many elements + if (selection instanceof ArrayList && ((ArrayList) selection).size() > 1) { + List independentVariables = new ArrayList(); + Resource model = null; + for(Object o : (ArrayList)selection) { + Resource r = AdaptionUtils.adaptToSingle(o, Resource.class); + if(r != null && backend.isInstanceOf(r, sr.IndependentVariable)) { + if(model == null) + model = backend.getSingleObject(r, Layer0.getInstance(backend).PartOf); + if(model.equals( backend.getSingleObject(r, Layer0.getInstance(backend).PartOf))) + independentVariables.add(r); + } + } + + tabs.add(new ComparableTabContributor( + new ArrayIndexesTab(), + 1, + independentVariables, + "Indexes")); + + return tabs; + } + + + // Single element + Resource r = AdaptionUtils.adaptToSingle(selection, Resource.class); + + if(r == null) { + // SharedFunctionsFolder has properties but no adapted resource + SharedFunctionsFolder sff = AdaptionUtils.adaptToSingle(selection, SharedFunctionsFolder.class); + if (sff != null) { + return Collections.singleton(new ComparableTabContributor( + new SharedFunctionLibrariesTab(), + 2, + sff.data, + "Shared Functions")); + } + + return Collections.emptyList(); + } + + + // if r == diagram element, change it to component + if (backend.isInstanceOf(r, dr.Element)) { + Resource component = backend.getPossibleObject(r, mr.ElementToComponent); + if (component != null) { + r = component; + } else { + Resource connection = backend.getPossibleObject(r, mr.DiagramConnectionToConnection); + if(connection != null) + r = connection; + } + } + + // Independent variable + if (backend.isInstanceOf(r, sr.IndependentVariable)) { + Resource activeExpression = backend.getPossibleObject(r, sr.HasActiveExpression); + Resource expression = null; + if(activeExpression != null) + // if variable has active expression, display it + expression = activeExpression; + else if (backend.hasStatement(r, sr.HasExpressions)){ + // else display the first expression of the variable + Resource expressions = backend.getPossibleObject(r, sr.HasExpressions); + List expressionList = OrderedSetUtils.toList(backend, expressions); + if(expressionList.isEmpty()) { + System.err.println("expressionList is empty for " + r); + return Collections.emptyList(); + } + expression = expressionList.get(0); + } + tabs.add(new ComparableTabContributor( + new EquationTab(), + 3, + r, + "Equation")); + if(expression != null && backend.isInstanceOf(expression, sr.WithLookupExpression)) { + // WithLookupExpression has its own extra tab for visual configuration + tabs.add(new ComparableTabContributor( + new LookupTableTab(), + 2, + expression, + "Lookup Table")); + } + + tabs.add(new ComparableTabContributor( + new ArrayIndexesTab(), + 1, + r, + "Indexes")); + + tabs.add(new ComparableTabContributor( + new VariableInformationTab(), + 0, + r, + "Additional Information")); + return tabs; + } + + // Input variable + if (backend.isInstanceOf(r, sr.Input)) { + tabs.add(new ComparableTabContributor( + new InputVariableTab(), + 2, + r, + "Input")); + + tabs.add(new ComparableTabContributor( + new ArrayIndexesTab(), + 1, + r, + "Indexes")); + + tabs.add(new ComparableTabContributor( + new VariableInformationTab(), + 0, + r, + "Additional Information")); + return tabs; + } + + // Enumeration + if (backend.isInstanceOf(r, sr.Enumeration)) { + Object s = AdaptionUtils.adaptToSingle(selection, ISelection.class); + if(s == null) + s = r; + // give either variable or the actual resource + return Collections.singleton(new ComparableTabContributor( + new EnumerationTab(), + 2, + s, + "Enumeration")); + } + + // Configuration and model. They both show the properties of the configuration + if ( backend.isInstanceOf(r, sr.Configuration) || backend.isInstanceOf(r, sr.SysdynModel)) { + if(!backend.isInstanceOf(r, sr.SysdynModel)) + r = backend.getPossibleObject(r, SimulationResource.getInstance(backend).IsConfigurationOf); + if (r != null) + return Collections.singleton( + new ComparableTabContributor( + new ConfigurationTab(), + 0, + r, + "Model Properties")); + } + + // Module + if (backend.isInstanceOf(r, sr.Module)){ + tabs.add(new ComparableTabContributor( + new ModuleTab(), + 3, + r, + "Module Properties")); + tabs.add(new ComparableTabContributor( + new ModuleInputTab(), + 2, + r, + "Inputs")); + tabs.add(new ComparableTabContributor( + new ModuleOutputTab(), + 1, + r, + "Outputs")); + return tabs; + } + + // Playback experiment + if (backend.isInstanceOf(r, sr.PlaybackExperiment)) + return Collections.singleton( + new ComparableTabContributor( + new PlaybackExperimentTab(), + 0, + r, + "Experiment Properties")); + + // Default experiment + if (backend.isInstanceOf(r, simu.Experiment)) + return Collections.singleton( + new ComparableTabContributor( + new ExperimentTab(), + 0, + r, + "Experiment Properties")); + + // Saved simulation result + if (backend.isInstanceOf(r, sr.Result)) + return Collections.singleton( + new ComparableTabContributor( + new ResultTab(), + 0, + r, + "Result Properties")); + + // Dependency + if (backend.isInstanceOf(r, sr.Dependency)) + if (backend.hasStatement(r, sr.RefersTo)) + return Collections.singleton( + new ComparableTabContributor( + new ReferenceDependencyTab(), + 0, + r, + "Reference Properties")); + else { + Resource diaConnection = backend.getPossibleObject(r, ModelingResources.getInstance(backend).ConnectionToDiagramConnection); + return Collections.singleton( + new ComparableTabContributor( + new DependencyTab(), + 0, + diaConnection, + "Dependency Properties")); + } + + // Module symbol. Modules in modules-folder are actually symbol resources + if (backend.isInheritedFrom(r, sr.ModuleSymbol)) { + // Find the component resource + r = backend.getPossibleObject(r, mr.SymbolToComponentType); + if(r != null) + return Collections.singleton( + new ComparableTabContributor( + new ModuleTypeTab(), + 0, + r, + "Module Type Properties")); + } + + // Function + if (backend.isInstanceOf(r, sr.SysdynModelicaFunction)) { + tabs.add(new ComparableTabContributor( + new FunctionTab(), + 2, + r, + "Function")); + tabs.add(new ComparableTabContributor( + new ExternalFilesTab(), + 1, + r, + "External files")); + return tabs; + } + + // Function library + if (backend.isInstanceOf(r, sr.SysdynModelicaFunctionLibrary)) { + Object s = AdaptionUtils.adaptToSingle(selection, ISelection.class); + if(s == null) + s = r; + // give either variable or the actual resource + return Collections.singleton(new ComparableTabContributor( + new FunctionLibraryTab(), + 2, + s, + "Function library")); + } + + // Chart Element + if(backend.isInstanceOf(r, jfree.ChartElement)) { + if(backend.hasStatement(r, jfree.ChartElement_component)) + r = backend.getSingleObject(r, jfree.ChartElement_component); + } + // Chart + if (backend.isInstanceOf(r, jfree.Chart)) { + + Collection plots = backend.syncRequest(new ObjectsWithType(r, Layer0.getInstance(backend).ConsistsOf, jfree.Plot)); + if(!plots.isEmpty()) { + Resource plot = plots.iterator().next(); + + if(backend.isInstanceOf(plot, jfree.XYPlot)) { + tabs.add(new ComparableTabContributor( + new XYLineGeneralPropertiesTab(), + 10, + r, + "General")); + tabs.add(new ComparableTabContributor( + new XYLineAxisAndVariablesTab(), + 9, + r, + "Axis and Variables")); + } else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) { + tabs.add(new ComparableTabContributor( + new BarGeneralPropertiesTab(), + 10, + r, + "General")); + tabs.add(new ComparableTabContributor( + new BarSeriesTab(), + 9, + r, + "Variables")); + tabs.add(new ComparableTabContributor( + new BarAxisTab(), + 8, + r, + "Axis")); + } else if(backend.isInstanceOf(plot, jfree.PiePlot)) { + tabs.add(new ComparableTabContributor( + new PieGeneralPropertiesTab(), + 10, + r, + "General")); + tabs.add(new ComparableTabContributor( + new PieSeriesTab(), + 9, + r, + "Variables")); + } + + tabs.add(new ComparableTabContributor( + new ChartTab(), + 1, + r, + "Chart")); + return tabs; + + } + } + + } catch (ServiceException e) { + e.printStackTrace(); + } catch (ManyObjectsForFunctionalRelationException e) { + e.printStackTrace(); + } catch (DatabaseException e) { + e.printStackTrace(); + } + return Collections.emptyList(); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResultTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResultTab.java new file mode 100644 index 00000000..306cd840 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResultTab.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; + +public class ResultTab extends LabelPropertyTabContributor { + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SharedFunctionLibrariesTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SharedFunctionLibrariesTab.java new file mode 100644 index 00000000..e0172573 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SharedFunctionLibrariesTab.java @@ -0,0 +1,238 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.swt.AdaptableHintContext; +import org.simantics.browsing.ui.swt.SingleSelectionInputSource; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.datastructures.ArrayMap; + +public class SharedFunctionLibrariesTab extends LabelPropertyTabContributor implements Widget { + + GraphExplorerComposite availableSharedFunctionLibraries; + GraphExplorerComposite usedSharedFunctionLibraries; + Resource model; + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + support.register(this); + + GridLayoutFactory.fillDefaults().numColumns(4).applyTo(body); + + + Composite available = new Composite(body, SWT.NONE); + GridLayoutFactory.fillDefaults().applyTo(available); + GridDataFactory.fillDefaults().grab(true, true).applyTo(available); + Label label = new Label(available, SWT.None); + label.setText("Available Shared Function Libraries"); + availableSharedFunctionLibraries = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), site, available, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI) { + + @Override + protected void handleDrop(Object data, NodeContext target) { + if (!(data instanceof IStructuredSelection)) + return; + + IStructuredSelection iss = (IStructuredSelection)data; + if (iss == null || iss.isEmpty()) + return; + + for (Iterator iterator = iss.iterator(); iterator.hasNext();) { + Object o = iterator.next(); + if(o instanceof IAdaptable) { + IAdaptable a = (IAdaptable)o; + final SharedFunctionLibraryNode node = (SharedFunctionLibraryNode)a.getAdapter(SharedFunctionLibraryNode.class); + if(node != null) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if(getModel() != null && node.data != null) + graph.deny(getModel(), Layer0.getInstance(graph).IsLinkedTo, node.data); + } + }); + } + } + } + } + }; + + availableSharedFunctionLibraries + .setBrowseContexts(SysdynResource.URIs.AvailableSharedFunctionLibraries); + availableSharedFunctionLibraries.setInputSource(new SingleSelectionInputSource( + Resource.class)); + + availableSharedFunctionLibraries.finish(); + + GridDataFactory.fillDefaults().grab(true, true).applyTo( + availableSharedFunctionLibraries); + + Composite middleButtons = new Composite(body, SWT.NONE); + GridLayoutFactory.fillDefaults().applyTo(middleButtons); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, true).applyTo(middleButtons); + + Button add = new Button(middleButtons, support, SWT.NONE); + add.setText(" -> "); + + add.addSelectionListener(new SelectionListenerImpl(context) { + + List selectedLibraries; + + public void beforeApply() { + selectedLibraries = getSelectedResources(availableSharedFunctionLibraries); + } + + @Override + public void apply(WriteGraph graph, Resource input) + throws DatabaseException { + if(selectedLibraries != null) { + Layer0 l0 = Layer0.getInstance(graph); + for(Resource library : selectedLibraries) { + graph.claim(input, l0.IsLinkedTo, library); + } + } + } + }); + + Button remove = new Button(middleButtons, support, SWT.NONE); + remove.setText(" <- "); + + remove.addSelectionListener(new SelectionListenerImpl(context) { + + List selectedLibraries; + + public void beforeApply() { + selectedLibraries = getSelectedResources(usedSharedFunctionLibraries); + } + + @Override + public void apply(WriteGraph graph, Resource input) + throws DatabaseException { + if(selectedLibraries != null) { + Layer0 l0 = Layer0.getInstance(graph); + for(Resource library : selectedLibraries) { + graph.deny(input, l0.IsLinkedTo, library); + } + } + } + }); + + + Composite used = new Composite(body, SWT.NONE); + GridLayoutFactory.fillDefaults().applyTo(used); + GridDataFactory.fillDefaults().grab(true, true).applyTo(used); + label = new Label(used, SWT.None); + label.setText("Selected Shared Function Libraries"); + + usedSharedFunctionLibraries = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), site, used, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI) { + + @Override + protected void handleDrop(Object data, NodeContext target) { + if (!(data instanceof IStructuredSelection)) + return; + + IStructuredSelection iss = (IStructuredSelection)data; + if (iss == null || iss.isEmpty()) + return; + + for (Iterator iterator = iss.iterator(); iterator.hasNext();) { + Object o = iterator.next(); + if(o instanceof IAdaptable) { + IAdaptable a = (IAdaptable)o; + final SharedFunctionLibraryNode node = (SharedFunctionLibraryNode)a.getAdapter(SharedFunctionLibraryNode.class); + if(node != null) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if(getModel() != null && node.data != null) + graph.claim(getModel(), Layer0.getInstance(graph).IsLinkedTo, node.data); + } + }); + } + } + } + } + }; + + usedSharedFunctionLibraries + .setBrowseContexts(SysdynResource.URIs.SelectedSharedFunctionLibraries); + usedSharedFunctionLibraries.setInputSource(new SingleSelectionInputSource( + Resource.class)); + + usedSharedFunctionLibraries.finish(); + + GridDataFactory.fillDefaults().grab(true, true).applyTo( + usedSharedFunctionLibraries); + } + + + private List getSelectedResources(GraphExplorerComposite explorer) { + List result = new ArrayList(); + + ISelection selection = ((ISelectionProvider) explorer + .getAdapter(ISelectionProvider.class)).getSelection(); + if (selection == null) + return result; + IStructuredSelection iss = (IStructuredSelection) selection; + @SuppressWarnings("unchecked") + List selections = iss.toList(); + for(AdaptableHintContext ahc : selections) { + Resource resource = (Resource) ahc.getAdapter(Resource.class); + result.add(resource); + } + return result; + } + + private Resource getModel() { + return model; + } + + @Override + public void setInput(ISessionContext context, Object input) { + availableSharedFunctionLibraries.setInput(context, input); + usedSharedFunctionLibraries.setInput(context, input); + this.model = AdaptionUtils.adaptToSingle(input, Resource.class); + } + +} + diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SysdynPropertyPage.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SysdynPropertyPage.java new file mode 100644 index 00000000..59e61e5f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SysdynPropertyPage.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import java.util.Set; + +import org.eclipse.ui.IWorkbenchPartSite; +import org.simantics.selectionview.StandardPropertyPage; + +public class SysdynPropertyPage extends StandardPropertyPage { + + public SysdynPropertyPage(IWorkbenchPartSite site, Set set) { + super(site, set); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java new file mode 100644 index 00000000..0aa38816 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.ValveOrientationGroup; +import org.simantics.sysdyn.ui.properties.widgets.ValveTextLocationGroup; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; +import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.ui.validators.DoubleValidator; + +/** + * Information tab for additional information of variables. + * @author Teemu Lempinen + * + */ +public class VariableInformationTab extends LabelPropertyTabContributor implements Widget { + Composite orientationComposite; + WidgetSupport support; + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + this.support = support; + support.register(this); + + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); + + Group informationGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); + informationGroup.setText("Information"); + GridDataFactory.fillDefaults().grab(false, true).applyTo(informationGroup); + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(informationGroup); + + // Textual format documentation + TrackedText information = new TrackedText(informationGroup, support, SWT.MULTI | SWT.BORDER); + information.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasDescription)); + information.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasDescription)); + GridDataFactory.fillDefaults().grab(true, true).applyTo(information.getWidget()); + + // Orientation information for valves + orientationComposite = new Composite(composite, SWT.NONE); + GridDataFactory.fillDefaults().span(1, 2).applyTo(orientationComposite); + GridLayoutFactory.fillDefaults().margins(3,3).applyTo(orientationComposite); + + // Range of a variable (e.g. from 0 to 10). Does not affect simulation, but the infor can be used for example in charts + Group rangeGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); + rangeGroup.setText("Range"); + GridDataFactory.fillDefaults().applyTo(rangeGroup); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(6).applyTo(rangeGroup); + + Label label = new Label(rangeGroup, SWT.NONE); + label.setText("Start"); + + TrackedText rangeStart = new TrackedText(rangeGroup, support, SWT.RIGHT | SWT.BORDER); + rangeStart.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasRangeStart)); + rangeStart.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasRangeStart)); + rangeStart.setInputValidator(new DoubleValidator()); + GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeStart.getWidget()); + + + label = new Label(rangeGroup, SWT.NONE); + label.setText("End"); + + + TrackedText rangeEnd = new TrackedText(rangeGroup, support, SWT.RIGHT | SWT.BORDER); + rangeEnd.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasRangeEnd)); + rangeEnd.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasRangeEnd)); + rangeEnd.setInputValidator(new DoubleValidator()); + GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeEnd.getWidget()); + + label = new Label(rangeGroup, SWT.NONE); + label.setText("Step"); + + TrackedText rangeStep = new TrackedText(rangeGroup, support, SWT.RIGHT | SWT.BORDER); + rangeStep.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasRangeStep)); + rangeStep.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasRangeStep)); + rangeStep.setInputValidator(new DoubleValidator()); + GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeStep.getWidget()); + + } + + @Override + public void setInput(ISessionContext context, Object input) { + final Resource valve = AdaptionUtils.adaptToSingle(input, Resource.class); + // is the displayed variable a valve? + Boolean isValve = false; + try { + isValve = context.getSession().syncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + return graph.isInstanceOf(valve, sr.Valve); + } + + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + // if it is a valve, display the orientation information + if(isValve) { + ValveOrientationGroup vog = new ValveOrientationGroup(orientationComposite, context, support, SWT.NONE); + vog.setInput(context, input); + ValveTextLocationGroup vtlg = new ValveTextLocationGroup(orientationComposite, context, support, SWT.NONE); + vtlg.setInput(context, input); + orientationComposite.getParent().layout(); + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrayExpressionCombo.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrayExpressionCombo.java new file mode 100644 index 00000000..51144d80 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrayExpressionCombo.java @@ -0,0 +1,274 @@ +package org.simantics.sysdyn.ui.properties.widgets; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.Map; +import java.util.StringTokenizer; +import java.util.LinkedHashMap; + +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.simantics.browsing.ui.swt.widgets.TrackedCombo; +import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.Listener; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.utils.VariableNameUtils; + +public class ArrayExpressionCombo extends TrackedCombo { + + int lastSelectedIndex = -2; + + public ArrayExpressionCombo(Composite parent, WidgetSupport support, + int style) { + super(parent, support, style); + + /* + this.setInputValidator(new VariableNameValidator(support)); + */ + + this.setItemFactory(new ReadFactoryImpl>() { + + @Override + public Map perform(ReadGraph graph, final Resource input) throws DatabaseException { + Map map = new LinkedHashMap(); + if(input == null) { + return map; + } + + Layer0 l0 = Layer0.getInstance(graph); + String name = graph.getPossibleRelatedValue(input, l0.HasName); + if(name == null) + return map; + + SysdynResource sr = SysdynResource.getInstance(graph); + + String defaultRange = getDefaultRange(graph, input); + for(Resource expression : getExpressions(graph, input)) { + String arrayRange = graph.getPossibleRelatedValue(expression, sr.HasArrayRange); + if(arrayRange != null) { + map.put(name + arrayRange, expression); + } else if(defaultRange != null) { + map.put(name + defaultRange, expression); + } else { + map.put(name, expression); + } + } + if(map.isEmpty()) { + map.put(name, input); + } + return map; + } + + }); + + + this.setSelectionFactory(new ReadFactoryImpl() { + + @Override + public String perform(ReadGraph graph, final Resource input) throws DatabaseException { + String name = graph.getPossibleRelatedValue(input, Layer0.getInstance(graph).HasName); + if(name == null) + return ""; + + String defaultRange = getDefaultRange(graph, input); + if(defaultRange == null) + return name; + + SysdynResource sr = SysdynResource.getInstance(graph); + + Resource activeExpression = graph.getPossibleObject(input, sr.HasActiveExpression); + Resource expression; + if(activeExpression == null) { + ArrayList expressions = getExpressions(graph, input); + if(expressions == null || expressions.isEmpty()) + return name; + expression = expressions.get(0); + } else { + expression = activeExpression; + } + String range = graph.getPossibleRelatedValue(expression, sr.HasArrayRange); + if(range != null) + return name + range; + else + return name + defaultRange; + } + }); + + this.addModifyListener(new NameAndArrayRangeModifyListener(support)); + } + + + @Override + public void setInput(ISessionContext context, Object input) { + super.setInput(context, input); + + if(selectionFactory != null) { + selectionFactory.listen(context, input, new Listener() { + + @Override + public void execute(final String result) { + if(getWidget().isDisposed()) return; + getWidget().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + Combo combo = getWidget(); + if(combo != null && !combo.isDisposed() && result != null) { + Object o = getWidget().getData(result); + if(o != null) + lastSelectedIndex = (Integer)o; + } + + } + }); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return getWidget().isDisposed(); + } + + }); + } + } + + private ArrayList getExpressions(ReadGraph graph, Resource variable) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource hasExpressions = graph.getPossibleObject(variable, sr.HasExpressions); + if(hasExpressions == null) + return new ArrayList(); + else + return new ArrayList(OrderedSetUtils.toList(graph, hasExpressions)); + } + + public static String getDefaultRange(ReadGraph graph, Resource variable) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource hasArrayIndexes = graph.getPossibleObject(variable, sr.HasArrayIndexes); + + if(hasArrayIndexes == null) + return null; + + Iterator iterator = OrderedSetUtils.iterator(graph, hasArrayIndexes); + if(!iterator.hasNext()) + return null; + + StringBuilder sb = new StringBuilder(); + sb.append("["); + + while(iterator.hasNext()) { + sb.append(NameUtils.getSafeName(graph, iterator.next())); + if(iterator.hasNext()) { + sb.append(", "); + } + } + sb.append("]"); + return sb.toString(); + } + + private class NameAndArrayRangeModifyListener extends ComboModifyListenerImpl implements Widget { + + Resource lastExpression; + + public NameAndArrayRangeModifyListener(WidgetSupport support) { + support.register(this); + } + + @Override + public void setInput(ISessionContext context, Object input) { + super.setInput(context, input); + } + + @Override + public void modifyText(TrackedModifyEvent e) { + + Combo combo = (Combo)e.getWidget(); + LinkedHashMap data = (LinkedHashMap) combo.getData(); + + Resource expression = (Resource) data.get(combo.getText()); + if(expression != null) { + lastExpression = expression; + lastSelectedIndex = combo.getSelectionIndex(); + } else { + for(Object key : data.keySet()) { + int index = lastSelectedIndex < 0 ? 0 : lastSelectedIndex; + if((Integer)combo.getData((String)key) == index) { + lastExpression = (Resource) data.get((String)key); + break; + } + } + } + + super.modifyText(e); + } + + @Override + public void applyText(WriteGraph graph, final Resource variable, String text) + throws DatabaseException { + StringTokenizer st = new StringTokenizer(text, "[]"); + final String newName = st.nextToken(); + String range = null; + if(st.hasMoreTokens()) { + range = st.nextToken(); + } + String originalName = graph.getRelatedValue(variable, Layer0.getInstance(graph).HasName); + if(!originalName.equals(newName)) { + VariableNameUtils.renameInEquations(graph, variable, originalName, newName); + graph.claimLiteral(variable, Layer0.getInstance(graph).HasName, newName); + } + + SysdynResource sr = SysdynResource.getInstance(graph); + + if(range != null && lastExpression != null) { + String oldRange = graph.getPossibleRelatedValue(lastExpression, sr.HasArrayRange); + if(oldRange == null || !range.equals(oldRange)) { + graph.claimLiteral(lastExpression, sr.HasArrayRange, "[" + range + "]"); + } + } + + Resource activeExpression = graph.getPossibleObject(variable, sr.HasActiveExpression); + + if(lastExpression != null && !lastExpression.equals(activeExpression)) { + VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class); + final Session session = graph.getSession(); + session.asyncRequest(new WriteRequest(support.getWorkspacePersistent("expressions")) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + VirtualGraph runtime = graph.getService(VirtualGraph.class); + session.asyncRequest(new WriteRequest(runtime) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.hasStatement(variable, sr.HasActiveExpression)) + graph.deny(variable, sr.HasActiveExpression); + graph.claim(variable, sr.HasActiveExpression, lastExpression); + } + } + ); + } + }); + } + } + } +} + diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ChartTableWidget.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ChartTableWidget.java new file mode 100644 index 00000000..bc78c153 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ChartTableWidget.java @@ -0,0 +1,247 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import java.awt.event.MouseEvent; +import java.awt.geom.Point2D; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.tableParser.ParseException; +import org.simantics.sysdyn.tableParser.TableParser; +import org.simantics.sysdyn.tableParser.Token; +import org.simantics.sysdyn.ui.properties.widgets.expressions.LookupInputOutputTable; +import org.simantics.sysdyn.ui.properties.widgets.expressions.LookupInputOutputTable.InputOutput; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ISelectionUtils; + +public class ChartTableWidget implements Widget { + + Text input, output; + Button add; + LookupInputOutputTable table; + Resource expression; + + public ChartTableWidget(Composite parent, WidgetSupport support, int style) { + support.register(this); + Composite valueTableComposite = new Composite(parent, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(valueTableComposite); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(valueTableComposite); + + table = new LookupInputOutputTable(valueTableComposite, SWT.NONE); + GridDataFactory.fillDefaults().span(3, 1).grab(false, true).applyTo(table); + table.getTableViewer().getTable().addMouseListener(new MouseListener() { + + @Override + public void mouseUp(org.eclipse.swt.events.MouseEvent e) { + if(e.button == MouseEvent.BUTTON3) { + Table t = (Table)e.widget; + TableItem item = (TableItem)t.getItem(new org.eclipse.swt.graphics.Point(e.x, e.y)); + table.removeItem(t.indexOf(item)); + tableModified(); + } + } + @Override + public void mouseDown(org.eclipse.swt.events.MouseEvent e) { } + @Override + public void mouseDoubleClick(org.eclipse.swt.events.MouseEvent e) { } + }); + + input = new Text(valueTableComposite, SWT.BORDER | SWT.RIGHT); + input.setText(""); + output = new Text(valueTableComposite, SWT.BORDER | SWT.RIGHT); + output.setText(""); + + add = new Button(valueTableComposite, SWT.None); + add.setText("Add"); + add.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + try { + Double in = Double.parseDouble(input.getText()); + Double out = Double.parseDouble(output.getText()); + table.addLocation(new Point2D.Double(in, out)); + tableModified(); + } catch (NumberFormatException e1) { + } + input.setText(""); + output.setText(""); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) {} + }); + + FocusListener flistener = new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + Text text = (Text)e.widget; + text.setSelection(0, text.getCharCount()); + } + @Override + public void focusLost(FocusEvent e) { } + }; + + + KeyListener listener = new KeyListener() { + + @Override + public void keyPressed(KeyEvent e) { + if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { + try { + Double in = Double.parseDouble(input.getText()); + Double out = Double.parseDouble(output.getText()); + table.addLocation(new Point2D.Double(in, out)); + tableModified(); + } catch (NumberFormatException e1) { + if(input.getText().isEmpty() && output.getText().isEmpty()) { + add.forceFocus(); + return; + } + } + input.setText(""); + output.setText(""); + input.setFocus(); + } + } + + @Override + public void keyReleased(KeyEvent e) { } + + }; + + input.addFocusListener(flistener); + input.addKeyListener(listener); + output.addFocusListener(flistener); + output.addKeyListener(listener); + } + + @Override + public void setInput(ISessionContext context, Object input) { + + expression = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class); + + + try { + SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(!graph.isInstanceOf(expression, sr.WithLookupExpression)) + return null; + return graph.getPossibleRelatedValue(expression, sr.HasLookup); + } + }, new Listener() { + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public void execute(String lookup) { + if(lookup == null) return; + TableParser parser = new TableParser(new StringReader("")); + parser.ReInit(new StringReader(lookup)); + table.clearTable(); + try { + parser.table(); + ArrayList xTokens = parser.getXTokens(); + ArrayList yTokens = parser.getYTokens(); + for(int i = 0; i < xTokens.size(); i++) { + table.addLocation(new Point2D.Double( + Double.parseDouble(xTokens.get(i).image), + Double.parseDouble(yTokens.get(i).image))); + } + } catch (ParseException e1) { + } + } + + @Override + public boolean isDisposed() { + return table.isDisposed(); + } + + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + table.addListener(SWT.Modify, new org.eclipse.swt.widgets.Listener() { + + @Override + public void handleEvent(Event event) { + tableModified(); + } + }); + } + + + @SuppressWarnings("unchecked") + private void tableModified() { + StringBuilder b = new StringBuilder(); + b.append("{"); + ArrayList inputOutputList = (ArrayList)table.getTableViewer().getInput(); + Collections.sort(inputOutputList, table.new InputOutputComparator()); + Iterator iterator = inputOutputList.iterator(); + while(iterator.hasNext()){ + InputOutput io = iterator.next(); + b.append("{" + io.getInput(String.class) + "," + io.getOutput(String.class) + "}"); + if(iterator.hasNext()) + b.append(","); + } + b.append("}"); + final String table = b.toString(); + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + graph.claimLiteral(expression, sr.HasLookup, table); + } + }); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ChartWidget.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ChartWidget.java new file mode 100644 index 00000000..742264c1 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ChartWidget.java @@ -0,0 +1,240 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.GridLayout; +import java.awt.geom.Ellipse2D; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Iterator; + +import javax.swing.JComponent; +import javax.swing.JPanel; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.jfree.data.general.SeriesChangeEvent; +import org.jfree.data.general.SeriesChangeListener; +import org.jfree.data.xy.XYDataItem; +import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.tableParser.ParseException; +import org.simantics.sysdyn.tableParser.TableParser; +import org.simantics.sysdyn.tableParser.Token; +import org.simantics.sysdyn.ui.properties.widgets.expressions.LookupChartPanel; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ISelectionUtils; +import org.simantics.utils.ui.SWTAWTComponent; + +public class ChartWidget implements Widget { + + JFreeChart chart; + LookupChartPanel chartPanel; + SWTAWTComponent swtawtcomponent; + + public ChartWidget(Composite parent, WidgetSupport support, int style) { + support.register(this); + chartPanel = new LookupChartPanel(createChart()); + chartPanel.setMouseZoomable(true, false); + chartPanel.setDomainZoomable(false); + chartPanel.setRangeZoomable(false); + + swtawtcomponent = new SWTAWTComponent(parent, SWT.BORDER) { + @Override + protected JComponent createSwingComponent() { + JPanel panel = new JPanel(); + panel.setLayout(new GridLayout(1, 1)); + panel.add(chartPanel); + panel.doLayout(); + return panel; + } + }; + GridDataFactory.fillDefaults().grab(true, true).applyTo(swtawtcomponent); + swtawtcomponent.populate(); + + } + + @Override + public void setInput(ISessionContext context, Object input) { + + final Resource expression = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class); + + class Auxiliary { + Double minX, minY, maxX, maxY; + String table; + } + + try { + SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Auxiliary perform(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(!graph.isInstanceOf(expression, sr.WithLookupExpression)) + return null; + Auxiliary auxiliary = new Auxiliary(); + auxiliary.minX = graph.getPossibleRelatedValue(expression, sr.HasMinX); + auxiliary.maxX = graph.getPossibleRelatedValue(expression, sr.HasMaxX); + auxiliary.minY = graph.getPossibleRelatedValue(expression, sr.HasMinY); + auxiliary.maxY = graph.getPossibleRelatedValue(expression, sr.HasMaxY); + auxiliary.table = graph.getPossibleRelatedValue(expression, sr.HasLookup); + return auxiliary; + } + }, new Listener() { + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public void execute(Auxiliary result) { + if(result == null) return; + XYDataset dataset = createDataset(result.table); + chartPanel.resetChart(dataset); + chartPanel.addSeriesChangeListener(new _SeriesChangeListener(expression)); + + XYPlot plot = (XYPlot) chart.getPlot(); + ValueAxis rangeAxis = plot.getRangeAxis(); + rangeAxis.setAutoRange(false); + if(result.minY == null) result.minY = rangeAxis.getLowerBound(); + if(result.maxY == null) result.maxY = rangeAxis.getUpperBound(); + rangeAxis.setRange(result.minY, result.maxY); + ValueAxis domainAxis = plot.getDomainAxis(); + domainAxis.setAutoRange(false); + if(result.minX == null) result.minX = domainAxis.getLowerBound(); + if(result.maxX == null) result.maxX = domainAxis.getUpperBound(); + domainAxis.setRange(result.minX, result.maxX); + + } + + @Override + public boolean isDisposed() { + return swtawtcomponent.isDisposed(); + } + + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + private JFreeChart createChart() { + XYDataset dataset = createDataset(null); + chart = ChartFactory.createXYLineChart(null, null, null, + dataset, PlotOrientation.VERTICAL, false, true, false); + XYPlot plot = (XYPlot) chart.getPlot(); + XYLineAndShapeRenderer renderer + = (XYLineAndShapeRenderer) plot.getRenderer(); + renderer.setBaseShapesVisible(true); + renderer.setDrawOutlines(true); + renderer.setUseFillPaint(true); + renderer.setBaseFillPaint(Color.white); + renderer.setSeriesStroke(0, new BasicStroke(3.0f)); + renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f)); + renderer.setSeriesShape(0, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0)); + return chart; + } + + public XYDataset createDataset(String table) { + XYSeries series = new XYSeries("Series"); + + if(table != null) { + TableParser parser = new TableParser(new StringReader("")); + parser.ReInit(new StringReader(table)); + try { + parser.table(); + ArrayList xTokens = parser.getXTokens(); + ArrayList yTokens = parser.getYTokens(); + for(int i = 0; i < xTokens.size(); i++) { + series.add( + Double.parseDouble(xTokens.get(i).image), + Double.parseDouble(yTokens.get(i).image)); + } + } catch (ParseException e1) { + } + } + + XYSeriesCollection dataset = new XYSeriesCollection(); + dataset.addSeries(series); + return dataset; + } + + public LookupChartPanel getChartPanel() { + return this.chartPanel; + } + + public JFreeChart getChart() { + return this.chart; + } + + private class _SeriesChangeListener implements SeriesChangeListener { + + Resource expression; + + public _SeriesChangeListener(Resource expression) { + this.expression = expression; + } + @Override + public void seriesChanged(SeriesChangeEvent event) { + if(chartPanel.isDragging()) return; + + StringBuilder b = new StringBuilder(); + b.append("{"); + XYSeriesCollection collection = (XYSeriesCollection) ((XYPlot)chart.getPlot()).getDataset(); + XYSeries series = collection.getSeries(0); + if(series.isEmpty()) + return; + Iterator iterator = series.getItems().iterator(); + while(iterator.hasNext()){ + XYDataItem item = (XYDataItem)iterator.next(); + b.append("{" + item.getX() + "," + item.getY() + "}"); + if(iterator.hasNext()) + b.append(","); + } + b.append("}"); + final String table = b.toString(); + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + graph.claimLiteral(expression, sr.HasLookup, table); + } + }); + + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ColumnKeys.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ColumnKeys.java new file mode 100644 index 00000000..06168d19 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ColumnKeys.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import org.simantics.browsing.ui.Column; +import org.simantics.browsing.ui.Column.Align; + +public class ColumnKeys { + + public static final String ENUMERATION = "Enumeration"; + public static final String INDEXES = "Indexes"; + public static final String SHOW_IN_CHARTS = "ShowInCharts"; + public static final String REPLACED_WITH = "Replaced with"; + + public static String[] ENUMERATION_COLUMNS_KEYS = { ENUMERATION, INDEXES }; + public static Column[] ENUMERATION_TABLE_COLUMNS = new Column[] { + new Column(ENUMERATION, Align.LEFT, 100, "Enumeration", false), + new Column(INDEXES, Align.LEFT, 100, "Indexes", true), + }; + + + public static String[] ENUMERATION_INDEX_COLUMNS_KEYS = { ENUMERATION, SHOW_IN_CHARTS }; + public static Column[] ENUMERATION_INDEX_TABLE_COLUMNS = new Column[] { + new Column(ENUMERATION, Align.LEFT, 100, "Enumeration", true), + new Column(SHOW_IN_CHARTS, Align.LEFT, 20, "Show in charts", false), + }; + + public static String[] ENUMERATION_REDECLARATION_KEYS = { ENUMERATION, REPLACED_WITH }; + public static Column[] ENUMERATION_REDECLARATION_COLUMNS = new Column[] { + new Column(ENUMERATION, Align.LEFT, 200, "Enumeration in module", false), + new Column(REPLACED_WITH, Align.LEFT, 200, "Replaced with", true), + }; + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionTypes.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionTypes.java new file mode 100644 index 00000000..7b3b20bf --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionTypes.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; + +/** + * Expression type representations + * @author Teemu Lempinen + * + */ +public class ExpressionTypes { + + public static enum ExpressionType {Auxiliary, Parameter, Constant, Lookup, WithLookup, Stock, Delay, Empty}; + + public static ExpressionType[] auxiliaryExpressions = new ExpressionType[] { + ExpressionType.Auxiliary, + ExpressionType.Parameter, + ExpressionType.Constant, + ExpressionType.Delay, + // ExpressionType.Lookup, + ExpressionType.WithLookup}; + + public static ExpressionType[] valveExpressions = new ExpressionType[] { + ExpressionType.Auxiliary, + ExpressionType.Parameter, + ExpressionType.Constant, + ExpressionType.Delay, + ExpressionType.WithLookup}; + + public static ExpressionType[] stockExpressions = new ExpressionType[] { + ExpressionType.Stock}; + + public static ExpressionType getExpressionType(final Resource expression) { + try { + return SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public ExpressionType perform(ReadGraph graph) throws DatabaseException { + return getExpressionType(graph, expression); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + return null; + } + + } + + public static ExpressionType getExpressionType(ReadGraph graph, final Resource expression) throws DatabaseException { + ExpressionType et = null; + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.isInstanceOf(expression, sr.NormalExpression)) { + et = ExpressionType.Auxiliary; + } else if (graph.isInstanceOf(expression, sr.StockExpression)) { + et = ExpressionType.Stock; + } else if (graph.isInstanceOf(expression, sr.ParameterExpression)) { + et = ExpressionType.Parameter; + } else if (graph.isInstanceOf(expression, sr.ConstantExpression)) { + et = ExpressionType.Constant; + } else if (graph.isInstanceOf(expression, sr.DelayExpression)) { + et = ExpressionType.Delay; + } else if (graph.isInstanceOf(expression, sr.LookupExpression)) { + et = ExpressionType.Lookup; + } else if (graph.isInstanceOf(expression, sr.WithLookupExpression)) { + et = ExpressionType.WithLookup; + } else { + et = ExpressionType.Empty; + } + return et; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java new file mode 100644 index 00000000..5da8f765 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java @@ -0,0 +1,261 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.Timer; + +import org.eclipse.swt.custom.VerifyKeyListener; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Table; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.ExpressionTypes.ExpressionType; +import org.simantics.sysdyn.ui.properties.widgets.expressions.AuxiliaryExpression; +import org.simantics.sysdyn.ui.properties.widgets.expressions.ConstantExpression; +import org.simantics.sysdyn.ui.properties.widgets.expressions.DelayExpression; +import org.simantics.sysdyn.ui.properties.widgets.expressions.EmptyExpression; +import org.simantics.sysdyn.ui.properties.widgets.expressions.IExpression; +import org.simantics.sysdyn.ui.properties.widgets.expressions.LookupExpression; +import org.simantics.sysdyn.ui.properties.widgets.expressions.ParameterExpression; +import org.simantics.sysdyn.ui.properties.widgets.expressions.StockExpression; +import org.simantics.sysdyn.ui.properties.widgets.expressions.WithLookupExpression; +import org.simantics.sysdyn.ui.utils.ExpressionUtils; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Widget for displaying an expression. Widget creates the IExpression for displaying + * properties for each expression type and adds validation, saving and other services + * to the active IExpression. + * + * @author Teemu Lempinen + * + */ +public class ExpressionWidget implements Widget { + + private Resource expr; + private Composite parent; + private Map data; + private IExpression expression; + private ModifyListener modifyListener; + private FocusListener focusListener; + private Table variableTable; + private VerifyKeyListener verifyKeyListener; + private Timer validationTimer; + private static int VALIDATION_DELAY_TIME = 500; + + /** + * Create a new expression widget + * @param parent + * @param support + * @param style + */ + public ExpressionWidget(Composite parent, WidgetSupport support, int style) { + support.register(this); + this.parent = parent; + this.data = new HashMap(); + + /* + * Create a validation timer for expression fields. Validation timer + * validates the field as the modeler is typing an expression + */ + validationTimer = new Timer(VALIDATION_DELAY_TIME, new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if(variableTable == null || variableTable.isDisposed()) + return; + variableTable.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + validateFields(); + } + }); + } + }); + validationTimer.setRepeats(false); + } + + @Override + public void setInput(ISessionContext context, Object input) { + // Update IExpression based on the newly selected expression + expr = AdaptionUtils.adaptToSingle(input, Resource.class); + ExpressionType et = ExpressionTypes.getExpressionType(expr); + displayExpression(et.toString(), true); + } + + /** + * Displays IExpression corresponding to expressionType. + * @param expressionType Expression type + * @param original Is the displayed expression for a newly selected expression (true) or did the + * expression change its type (false) + */ + public void displayExpression(String expressionType, boolean original) { + if(expressionType == null) { + return; + } + + // Get up-to-date data to data-map + if(this.expression != null) expression.updateData(data); + + // Create the new expression + ExpressionType et = ExpressionType.valueOf(expressionType); + IExpression exp = null; + switch (et) { + case Auxiliary: + exp = new AuxiliaryExpression(); break; + case Parameter: + exp = new ParameterExpression(); break; + case Constant: + exp = new ConstantExpression(); break; + case Lookup: + exp = new LookupExpression(); break; + case WithLookup: + exp = new WithLookupExpression(expr); break; + case Stock: + exp = new StockExpression(); break; + case Delay: + exp = new DelayExpression(expr); break; + default: + exp = new EmptyExpression(); + } + + if (exp != null) { + // If expression was created, remove the old one + for(Control c : parent.getChildren()) { + c.dispose(); + } + + // If a completely new expression was selected, read data + if(original) + exp.readData(expr, data); + + // Create the visual representation of the expression type + exp.createExpressionFields(parent, data); + + // Add listeners + if(modifyListener != null) + exp.addModifyListener(modifyListener); + if(focusListener != null) + exp.addFocusListener(focusListener); + if(verifyKeyListener != null) + exp.addVerifyKeyListener(verifyKeyListener); + this.expression = exp; + this.parent.layout(); + validateFieldsTimed(); + + save(); + } + } + + /** + * Get current IExpression + * @return current IExpression + */ + public IExpression getExpression() { + return expression; + } + + /** + * Set the variable table that contains information about variables that are connected + * to this expression + * @param table + */ + public void setVariableTable(Table table) { + this.variableTable = table; + } + + /** + * Set timed field validation with default delay time + */ + public void validateFieldsTimed() { + validateFieldsTimed(VALIDATION_DELAY_TIME); + } + + /** + * Set timed field validation + * @param delay Delay time for validation + */ + public void validateFieldsTimed(int delay) { + validationTimer.setDelay(delay); + if(!validationTimer.isRunning()) + validationTimer.start(); + else + validationTimer.restart(); + } + + /** + * Validates expression fields in current IExpression + */ + public void validateFields() { + if(this.variableTable == null) return; + + try { + // Find the variable for this experession + Resource variable = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Collection expressionLists = OrderedSetUtils.getOwnerLists(graph, expr, l0.OrderedSet); + Resource variable = null; + if(expressionLists.size() == 1) + variable = graph.getPossibleObject(expressionLists.iterator().next(), sr.HasExpressions_Inverse); + return variable; + } + }); + // Validate the variable + if(variable != null) + ExpressionUtils.validateExpressionFields(variable, expression, variableTable); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + + public void addModifyListener(ModifyListener listener) { + this.modifyListener = listener; + } + + public void addVerifyKeyListener(VerifyKeyListener listener) { + this.verifyKeyListener = listener; + } + + public void addFocusListener(FocusListener listener) { + this.focusListener = listener; + } + + public void save() { + if(this.expression != null) + this.expression.save(expr, data); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/FunctionLabelFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/FunctionLabelFactory.java new file mode 100644 index 00000000..2b4cdcbf --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/FunctionLabelFactory.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.utils.datastructures.Quad; + + + +public class FunctionLabelFactory extends ReadFactoryImpl { + + private final String propertyURI; + private boolean end; + + public FunctionLabelFactory(String propertyURI, boolean end) { + this.propertyURI = propertyURI; + this.end = end; + } + + @Override + public Object getIdentity(Object inputContents) { + return new Quad((Resource) inputContents, propertyURI, getClass(), end); + } + + + @Override + public String perform(ReadGraph graph, Resource resource) throws DatabaseException { + String value = graph.getPossibleRelatedValue(resource, graph.getResource(propertyURI)); + if(end) { + return "end " + value + ";"; + } else { + return "function " + value; + } + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/IsOutputWidget.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/IsOutputWidget.java new file mode 100644 index 00000000..5297182d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/IsOutputWidget.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.utils.ui.ISelectionUtils; + +public class IsOutputWidget implements Widget{ + + Resource variable = null; + org.simantics.browsing.ui.swt.widgets.Button isOutputButton; + + public IsOutputWidget(Composite parent, WidgetSupport support, int style) { + support.register(this); + isOutputButton = new org.simantics.browsing.ui.swt.widgets.Button(parent, support, style |= SWT.CHECK); + isOutputButton.setText("Is Output"); + } + + @Override + public void setInput(ISessionContext context, Object input) { + if(input instanceof ISelection) { + ISelection selection = (ISelection)input; + if(selection instanceof IStructuredSelection) { + Resource resource = ISelectionUtils.filterSingleSelection(selection, Resource.class); + if(resource != null) { + variable = resource; + } + } + } + + if(variable == null) return; + + try { + context.getSession().syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + final boolean isOutput = graph.hasStatement(variable, sr.IsOutput); + final Button button = getWidget(); + button.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if(button.isDisposed()) return; + + if(isOutput) + button.setSelection(true); + else + button.setSelection(false); + } + }); + + + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + isOutputButton.addSelectionListener(new SelectionListenerImpl(context) { + + @Override + public void apply(WriteGraph graph, Resource input) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.hasStatement(input, sr.IsOutput)) { + graph.deny(input, sr.IsOutput); + } else { + graph.claim(input, SysdynResource.getInstance(graph).IsOutput, null, input); + } + } + }); + } + + public Button getWidget() { + return isOutputButton.getWidget(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ModuleInputEditingSupport.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ModuleInputEditingSupport.java new file mode 100644 index 00000000..cfc2810c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ModuleInputEditingSupport.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import java.util.HashMap; + +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.ComboBoxCellEditor; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.swt.SWT; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; + +public class ModuleInputEditingSupport extends EditingSupport { + private CellEditor editor; + private int column; + private HashMap optionResources; + private String[] options; + private TableViewer tableViewer; + + public ModuleInputEditingSupport(TableViewer viewer, int column) { + super(viewer); + this.tableViewer = (TableViewer)viewer; + this.column = column; + } + + @Override + protected boolean canEdit(Object element) { + switch (this.column) { + case 0: return false; + default: return true; + } + } + + + @Override + protected CellEditor getCellEditor(Object element) { + // Create the correct editor based on the column index + switch (column) { + case 0: + editor = new TextCellEditor(this.tableViewer.getTable()); + case 1: + ReferenceRow row = (ReferenceRow)element; + final Resource module = row.getModule(); + final Resource inputVariable = row.getVariable(); + + optionResources = new HashMap(); + try { + optionResources = SimanticsUI.getSession().syncRequest(new Read>() { + + @Override + public HashMap perform(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + HashMap result = new HashMap(); + for(Resource dependency : graph.syncRequest(new ObjectsWithType(module, sr.IsHeadOf, sr.Dependency))) { + if(graph.getPossibleObject(dependency, sr.RefersTo) == null || + graph.getPossibleObject(dependency, sr.RefersTo).equals(inputVariable)) { + Resource output = graph.getSingleObject(dependency, sr.HasTail); + result.put((String)graph.getRelatedValue(output, l0.HasName), dependency); + } + } + return result; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + options = optionResources.keySet().toArray(new String[optionResources.keySet().size() + 1]); + options[optionResources.keySet().size()] = ""; + ComboBoxCellEditor ceditor = new ComboBoxCellEditor(this.tableViewer.getTable(), options, SWT.READ_ONLY); + ceditor.setActivationStyle(1); + editor = ceditor; + break; + default: + editor = null; + } + + return editor; + } + + @Override + protected Object getValue(Object element) { + ReferenceRow referenceRow = (ReferenceRow) element; + + switch (this.column) { + case 0: + return referenceRow.getName(); + case 1: + String refersToName = referenceRow.getValue(); + if (refersToName == null) return options.length - 1; + for(int i = 0; i < options.length ; i++) { + if(refersToName.equals(options[i])) return i; + } + return options[options.length - 1]; + default: + break; + } + return null; + } + + @Override + protected void setValue(Object element, Object value) { + ReferenceRow referenceRow = (ReferenceRow) element; + String valueString = String.valueOf(value); + switch (this.column) { + case 0: + break; + case 1: + referenceRow.setRefersTo(optionResources.get(options[Integer.parseInt(valueString)])); + break; + default: + break; + } + + getViewer().update(element, null); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ModuleOutputEditingSupport.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ModuleOutputEditingSupport.java new file mode 100644 index 00000000..7a69d742 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ModuleOutputEditingSupport.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import java.util.HashMap; + +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.ComboBoxCellEditor; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.swt.SWT; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; + +public class ModuleOutputEditingSupport extends EditingSupport { + private CellEditor editor; + private int column; + private HashMap optionResources; + private String[] options; + private TableViewer tableViewer; + + public ModuleOutputEditingSupport(TableViewer viewer, int column) { + super(viewer); + this.tableViewer = (TableViewer)viewer; + this.column = column; + } + + @Override + protected boolean canEdit(Object element) { + switch (this.column) { + case 0: return false; + default: return true; + } + } + + + @Override + protected CellEditor getCellEditor(Object element) { + // Create the correct editor based on the column index + switch (column) { + case 0: + editor = new TextCellEditor(this.tableViewer.getTable()); + case 1: + ReferenceRow row = (ReferenceRow)element; + final Resource module = row.getModule(); + final Resource outputVariable = row.getVariable(); + + optionResources = new HashMap(); + try { + optionResources = SimanticsUI.getSession().syncRequest(new Read>() { + + @Override + public HashMap perform(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + HashMap result = new HashMap(); + for(Resource dependency : graph.syncRequest(new ObjectsWithType(module, sr.IsTailOf, sr.Dependency))) { + if(graph.getPossibleObject(dependency, sr.RefersTo) == null + || !graph.hasStatement(graph.getPossibleObject(dependency, sr.RefersTo), l0.HasName) + || graph.getPossibleObject(dependency, sr.RefersTo).equals(outputVariable)) { + Resource input = graph.getSingleObject(dependency, sr.HasHead); + result.put((String)graph.getRelatedValue(input, l0.HasName), dependency); + } + } + return result; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + options = optionResources.keySet().toArray(new String[optionResources.keySet().size() + 1]); + options[optionResources.keySet().size()] = ""; + ComboBoxCellEditor ceditor = new ComboBoxCellEditor(this.tableViewer.getTable(), options, SWT.READ_ONLY); + ceditor.setActivationStyle(1); + editor = ceditor; + break; + default: + editor = null; + } + + return editor; + } + + @Override + protected Object getValue(Object element) { + ReferenceRow referenceRow = (ReferenceRow) element; + + switch (this.column) { + case 0: + return referenceRow.getName(); + case 1: + String refersToName = referenceRow.getValue(); + if (refersToName == null) return options.length - 1; + for(int i = 0; i < options.length ; i++) { + if(refersToName.equals(options[i])) return i; + } + return options[options.length - 1]; + default: + break; + } + return null; + } + + @Override + protected void setValue(Object element, Object value) { + ReferenceRow referenceRow = (ReferenceRow) element; + String valueString = String.valueOf(value); + switch (this.column) { + case 0: + break; + case 1: + referenceRow.setRefersTo(optionResources.get(options[Integer.parseInt(valueString)])); + break; + default: + break; + } + + getViewer().update(element, null); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRow.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRow.java new file mode 100644 index 00000000..5aeeaec7 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRow.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; + +public class ReferenceRow { + + Resource variable, module, dependency; + String name; + + public ReferenceRow(Resource module, Resource dependency, Resource variable) { + this.module = module; + this.variable = variable; + this.dependency = dependency; + } + + + public Resource getModule() { + return this.module; + } + + public Resource getVariable() { + return this.variable; + } + + public Resource getDependency() { + return this.dependency; + } + + public String getName() { + String name = null; + try { + name = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + return (String)graph.getRelatedValue(getVariable(), Layer0.getInstance(graph).HasName); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + return name; + } + + public String getValue() { + if(dependency == null) return ""; + + String value = null; + try { + value = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + Resource valueResource = graph.getPossibleObject(dependency, sr.HasTail); + if(!graph.isInstanceOf(valueResource, sr.Variable)) + valueResource = graph.getPossibleObject(dependency, sr.HasHead); + if(!graph.isInstanceOf(valueResource, sr.Variable)) + return ""; + return (String)graph.getRelatedValue(valueResource, l0.HasName, Bindings.STRING); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + return value; + } + + public void setRefersTo(final Resource dependency) { + if(dependency != null && dependency.equals(this.dependency)) return; + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(getDependency() != null && graph.hasStatement(getDependency(), sr.RefersTo)) + graph.deny(getDependency(), sr.RefersTo); + if(dependency != null && graph.hasStatement(dependency, sr.RefersTo)) + graph.deny(dependency, sr.RefersTo); + setDependency(null); + if(dependency != null) { + setDependency(dependency); + graph.claim(getDependency(), SysdynResource.getInstance(graph).RefersTo, getVariable()); + } + } + }); + } + + private void setDependency(Resource dependency) { + this.dependency = dependency; + } +} + diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRowLabelProvider.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRowLabelProvider.java new file mode 100644 index 00000000..b44432a0 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRowLabelProvider.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; + +public class ReferenceRowLabelProvider extends LabelProvider implements ITableLabelProvider { + + @Override + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + @Override + public String getColumnText(Object element, int columnIndex) { + ReferenceRow referenceRow = (ReferenceRow) element; + switch (columnIndex) { + case 0: + return referenceRow.getName(); + case 1: + return referenceRow.getValue(); + default: + throw new RuntimeException("Should not happen"); + } + } +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceTable.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceTable.java new file mode 100644 index 00000000..29066345 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceTable.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import java.util.ArrayList; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.IBaseLabelProvider; +import org.eclipse.jface.viewers.IContentProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ISelectionUtils; + +public class ReferenceTable implements Widget{ + + private TableViewer tableViewer; + private RowProvider rowProvider; + + public static final String FIRSTCOLUMN = "Inputs"; + public static final String SECONDCOLUMN = "Outputs"; + + public ReferenceTable(Composite parent, WidgetSupport support, int style) { + support.register(this); + + Composite base = new Composite(parent, style); + GridLayoutFactory.fillDefaults().applyTo(base); + GridDataFactory.fillDefaults().grab(true, true).applyTo(base); + + Table table = new Table(base, SWT.BORDER|SWT.SINGLE|SWT.FULL_SELECTION); + GridDataFactory.fillDefaults().grab(true, true).applyTo(table); + table.setHeaderVisible (true); + table.setLinesVisible(true); + table.getVerticalBar().setVisible(true); + + tableViewer = new TableViewer (table); + tableViewer.setComparator(new ReferenceRowComparator()); + } + + public TableViewer getTableViewer() { + return this.tableViewer; + } + + public void setRowProvider(RowProvider rowProvider) { + this.rowProvider = rowProvider; + } + + public void setContentProvider(IContentProvider provider) { + tableViewer.setContentProvider(provider); + } + + public void setLabelProvider(IBaseLabelProvider labelProvider) { + tableViewer.setLabelProvider(labelProvider); + } + + @Override + public void setInput(ISessionContext context, Object input) { + final Resource module = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class); + if(this.rowProvider != null) { + try { + SimanticsUI.getSession().syncRequest(new Read>() { + + @Override + public ArrayList perform(ReadGraph graph) throws DatabaseException { + return rowProvider.getRows(graph, module); + } + } , new Listener>() { + + @Override + public boolean isDisposed() { + if(tableViewer != null && tableViewer.getTable() != null) + return getTableViewer().getTable().isDisposed(); + else + return true; + } + + @Override + public void execute(final ArrayList result) { + if(!isDisposed()) + getTableViewer().getTable().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if(!isDisposed()) + getTableViewer().setInput(result); + } + }); + } + + @Override + public void exception(Throwable t) { + } + } + ); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + } + + private class ReferenceRowComparator extends ViewerComparator { + @Override + public int compare(Viewer viewer, Object e1, Object e2) { + ReferenceRow rr1 = (ReferenceRow)e1; + ReferenceRow rr2 = (ReferenceRow)e2; + return rr1.getName().compareTo(rr2.getName()); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/RowProvider.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/RowProvider.java new file mode 100644 index 00000000..cd36f387 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/RowProvider.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import java.util.ArrayList; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; + +public abstract class RowProvider { + public abstract ArrayList getRows(ReadGraph graph, Resource module) throws DatabaseException; +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java new file mode 100644 index 00000000..4e8374e7 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java @@ -0,0 +1,270 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.AsyncListener; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ISelectionUtils; + +public class ShortcutTabWidget implements Widget { + + TabFolder tabFolder; + TabItem variables; + TabItem functions; + Table variableTable; + Table functionTable; + Composite composite; + TableItem item2; + + CopyOnWriteArrayList dependencyListeners = + new CopyOnWriteArrayList(); + + public ShortcutTabWidget(Composite parent, WidgetSupport support, int style) { + if(support!=null) + support.register(this); + + composite = new Composite(parent, style); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite); + + tabFolder = new TabFolder (composite, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(tabFolder); + GridLayoutFactory.fillDefaults().applyTo(tabFolder); + variables = new TabItem(tabFolder, SWT.NULL); + variables.setText("Variables"); + variableTable = new Table (tabFolder, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); + + variables.setControl(variableTable); + + functions = new TabItem(tabFolder, SWT.NULL); + functions.setText("Functions"); + + functionTable = new Table (tabFolder, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); + TableItem item = new TableItem(functionTable, SWT.NONE); + + //Finding functions + ArrayList funktio = new ArrayList(); + try { + funktio = SimanticsUI.getSession().syncRequest(new Read>() { + @Override + public ArrayList perform(ReadGraph graph) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + ArrayList funktiot = new ArrayList(); + + Resource funktionlibrary = graph.getPossibleResource(SysdynResource.URIs.Built$in_Functions); + for(Resource r : graph.syncRequest(new ObjectsWithType(funktionlibrary, l0.ConsistsOf, sr.SysdynModelicaFunction))) { + String name = NameUtils.getSafeName(graph, r); + funktiot.add(name); + } + + Resource subfunktionlibrary = graph.getPossibleResource(SysdynResource.URIs.Built$in_Functions_Vensim_Functions); + for(Resource r : graph.syncRequest(new ObjectsWithType(subfunktionlibrary, l0.ConsistsOf, sr.SysdynModelicaFunction))) { + String name = NameUtils.getSafeName(graph, r); + funktiot.add(name); + } + + return funktiot; + } + }); + } + catch (DatabaseException e) { + e.printStackTrace(); + } + + Collections.sort(funktio); + + for(int a=0; a < funktio.size(); a++){ + item.setText(funktio.get(a)+"()"); + item.setData(funktio.get(a)+"({})"); + item = new TableItem(functionTable, SWT.NONE); + } + +// TableItem item = new TableItem(functionTable, SWT.NONE); +// item.setText("min()"); +// item.setData("min({ })"); +// item = new TableItem(functionTable, SWT.NONE); +// item.setText("max()"); +// item.setData("max({ })"); +// item = new TableItem(functionTable, SWT.NONE); +// item.setText("abs()"); +// item.setData("abs({ })"); +// item = new TableItem(functionTable, SWT.NONE); +// item.setText("if then else"); +// item.setData("if then else"); +// item = new TableItem(functionTable, SWT.NONE); +// item.setText("xidz()"); +// item.setData("xidz( number, divisor , x)"); +// item = new TableItem(functionTable, SWT.NONE); +// item.setText("interpolate()"); +// item.setData("interpolate( x, table)"); +// item = new TableItem(functionTable, SWT.NONE); +// item.setText("delay()"); +// item.setData("delay( expression, delayTime)"); + functions.setControl(functionTable); + } + + public Composite getWidget() { + return composite; + } + + @Override + public void setInput(ISessionContext context, Object input) { + if(input instanceof IStructuredSelection) { + final Resource variable = ISelectionUtils.filterSingleSelection((IStructuredSelection)input, Resource.class); + if(variable != null) { + + SimanticsUI.getSession().asyncRequest(new Read>() { + + @Override + public HashSet perform(ReadGraph graph) + throws DatabaseException { + return getDependencies(graph, variable); + } + }, new AsyncListener>() { + + @Override + public void execute(AsyncReadGraph graph, + HashSet result) { + + final HashSet dependencies = result; + variableTable.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if(variableTable.isDisposed()) return; + + TableItem[] items = variableTable.getItems(); + + // Remove deleted dependencies and create the list of current dependencies (itemStrings) + ArrayList itemStrings = new ArrayList(); + for(TableItem i : items) { + String text = i.getText(); + if(dependencies.contains(text)) + itemStrings.add(text); + else + variableTable.remove(variableTable.indexOf(i)); + } + + // Add all new dependencies + TableItem item; + for(String d : dependencies) { + if(!itemStrings.contains(d)) { + item = new TableItem(variableTable, SWT.NONE); + item.setText(d); + item.setData(d); + } + } + + synchronized(dependencyListeners) { + for(Runnable listener : dependencyListeners) + listener.run(); + } + } + }); + } + + @Override + public void exception(AsyncReadGraph graph, + Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return variableTable.isDisposed(); + } + }); + } + } + } + + // Returns the names of the related variables (dependencies) + private HashSet getDependencies(ReadGraph graph, Resource r) throws DatabaseException { + HashSet variables = new HashSet(); + if(graph != null && r != null) { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Collection dependencies = graph.getObjects(r, sr.IsHeadOf); + + for(Resource d : dependencies) { + if(graph.isInstanceOf(d, sr.Dependency)) { + Resource tail = graph.getPossibleObject(d, sr.HasTail); + if(tail != null) { + Object name = graph.getPossibleRelatedValue(tail, l0.HasName); + if(name != null) + variables.add((String)name); + } + } + } + } + return variables; + } + + public void addFocusListener(FocusListener listener) { + this.functionTable.addFocusListener(listener); + this.variableTable.addFocusListener(listener); + } + + public void addMouseListener(MouseListener listener) { + this.functionTable.addMouseListener(listener); + this.variableTable.addMouseListener(listener); + } + + public void addDependencyListener(Runnable listener) { + synchronized(dependencyListeners) { + dependencyListeners.add(listener); + } + } + + public void removeDependencyListener(Runnable listener) { + synchronized(dependencyListeners) { + dependencyListeners.remove(listener); + } + } + + public Table getVariableTable() { + return variableTable; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveOrientationGroup.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveOrientationGroup.java new file mode 100644 index 00000000..6f7546ed --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveOrientationGroup.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.WidgetImpl; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.modeling.ModelingResources; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.utils.datastructures.Quad; + +public class ValveOrientationGroup extends WidgetImpl { + + Group group; + Button vertical, horizontal; + + public ValveOrientationGroup(Composite parent, ISessionContext context, WidgetSupport support, int style) { + super(support); + group = new Group(parent, SWT.NONE); + group.setText("Valve orientation"); + GridDataFactory.fillDefaults().applyTo(group); + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(group); + + horizontal = new Button(group, support, SWT.RADIO); + horizontal.setText("Horizontal"); + horizontal.setSelectionFactory(new OrientationSelectionFactory(horizontal, SysdynResource.URIs.Horizontal, true)); + horizontal.addSelectionListener(new OrientationSelectionListener(context, SysdynResource.URIs.Horizontal)); + + vertical = new Button(group, support, SWT.RADIO); + vertical.setText("Vertical"); + vertical.setSelectionFactory(new OrientationSelectionFactory(vertical, SysdynResource.URIs.Vertical)); + vertical.addSelectionListener(new OrientationSelectionListener(context, SysdynResource.URIs.Vertical)); + } + + @Override + public void setInput(ISessionContext context, Object input) { + horizontal.setInput(context, input); + vertical.setInput(context, input); + } + + @Override + public Control getControl() { + return this.group; + } + + private class OrientationSelectionFactory extends ReadFactoryImpl { + + boolean defaultSelected; + String uri; + Button button; + + public OrientationSelectionFactory(Button button, String uri) { + this(button, uri, false); + } + + public OrientationSelectionFactory(Button button, String uri, boolean defaultSelected) { + this.uri = uri; + this.defaultSelected = defaultSelected; + this.button = button; + } + + public Object getIdentity(Object inputContents) { + return new Quad>(button, uri, defaultSelected, getClass()); + } + + @Override + public Boolean perform(ReadGraph graph, Resource valve) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + if(!graph.isInstanceOf(valve, sr.Valve)) + return Boolean.FALSE; + + Resource symbol = graph.getPossibleObject(valve, mr.ComponentToElement); + if(symbol == null) + return Boolean.FALSE; + + Resource orientation = graph.getPossibleObject(symbol, sr.HasValveOrientation); + + if(orientation == null) + return defaultSelected; + + return orientation.equals(graph.getResource(uri)); + } + + } + + + private class OrientationSelectionListener extends SelectionListenerImpl { + + String uri; + + public OrientationSelectionListener(ISessionContext context, String uri) { + super(context); + this.uri = uri; + } + + @Override + public void apply(WriteGraph graph, Resource valve) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + if(!graph.isInstanceOf(valve, sr.Valve)) + return; + + Resource symbol = graph.getPossibleObject(valve, mr.ComponentToElement); + if(symbol == null) + return; + + if(graph.hasStatement(symbol, sr.HasValveOrientation)) + graph.deny(symbol, sr.HasValveOrientation); + graph.claim(symbol, sr.HasValveOrientation, graph.getResource(uri)); + + if(graph.hasStatement(symbol, sr.HasTextLocation)) + graph.deny(symbol, sr.HasTextLocation); + if(sr.Vertical.equals(graph.getResource(uri))) + graph.claim(symbol, sr.HasTextLocation, sr.Right); + + } + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveTextLocationGroup.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveTextLocationGroup.java new file mode 100644 index 00000000..69d8376a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ValveTextLocationGroup.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.WidgetImpl; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.modeling.ModelingResources; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.utils.datastructures.Quad; + +public class ValveTextLocationGroup extends WidgetImpl { + + Group group; + Button top, bottom, left, right; + + public ValveTextLocationGroup(Composite parent, ISessionContext context, WidgetSupport support, int style) { + super(support); + + group = new Group(parent, SWT.NONE); + group.setText("Text location"); + GridDataFactory.fillDefaults().applyTo(group); + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(group); + + top = new Button(group, support, SWT.RADIO); + top.setText("Top"); + top.setSelectionFactory(new LocationSelectionFactory(top, SysdynResource.URIs.Top)); + top.addSelectionListener(new LocationSelectionListener(context, SysdynResource.URIs.Top)); + + bottom = new Button(group, support, SWT.RADIO); + bottom.setText("Bottom"); + bottom.setSelectionFactory(new LocationSelectionFactory(bottom, SysdynResource.URIs.Bottom, true)); + bottom.addSelectionListener(new LocationSelectionListener(context, SysdynResource.URIs.Bottom)); + + left = new Button(group, support, SWT.RADIO); + left.setText("Left"); + left.setSelectionFactory(new LocationSelectionFactory(left, SysdynResource.URIs.Left)); + left.addSelectionListener(new LocationSelectionListener(context, SysdynResource.URIs.Left)); + + right = new Button(group, support, SWT.RADIO); + right.setText("Right"); + right.setSelectionFactory(new LocationSelectionFactory(right, SysdynResource.URIs.Right)); + right.addSelectionListener(new LocationSelectionListener(context, SysdynResource.URIs.Right)); + + } + + @Override + public void setInput(ISessionContext context, Object input) { + top.setInput(context, input); + bottom.setInput(context, input); + left.setInput(context, input); + right.setInput(context, input); + } + + @Override + public Control getControl() { + return this.group; + } + + + private class LocationSelectionFactory extends ReadFactoryImpl { + + boolean defaultSelected; + String uri; + Button button; + + public LocationSelectionFactory(Button button, String uri) { + this(button, uri, false); + } + + public LocationSelectionFactory(Button button, String uri, boolean defaultSelected) { + this.uri = uri; + this.defaultSelected = defaultSelected; + this.button = button; + } + + public Object getIdentity(Object inputContents) { + return new Quad>(button, uri, defaultSelected, getClass()); + } + + @Override + public Boolean perform(ReadGraph graph, Resource valve) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + if(!graph.isInstanceOf(valve, sr.Valve)) + return Boolean.FALSE; + + Resource symbol = graph.getPossibleObject(valve, mr.ComponentToElement); + if(symbol == null) + return Boolean.FALSE; + + Resource location = graph.getPossibleObject(symbol, sr.HasTextLocation); + + if(location == null) + return defaultSelected; + + return location.equals(graph.getResource(uri)); + } + + } + + + private class LocationSelectionListener extends SelectionListenerImpl { + + String uri; + + public LocationSelectionListener(ISessionContext context, String uri) { + super(context); + this.uri = uri; + } + + @Override + public void apply(WriteGraph graph, Resource valve) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + if(!graph.isInstanceOf(valve, sr.Valve)) + return; + + Resource symbol = graph.getPossibleObject(valve, mr.ComponentToElement); + if(symbol == null) + return; + + if(graph.hasStatement(symbol, sr.HasTextLocation)) + graph.deny(symbol, sr.HasTextLocation); + graph.claim(symbol, sr.HasTextLocation, graph.getResource(uri)); + } + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/AvailableEnumerations.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/AvailableEnumerations.java new file mode 100644 index 00000000..9b2c37e2 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/AvailableEnumerations.java @@ -0,0 +1,39 @@ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; + +public class AvailableEnumerations extends ViewpointContributorImpl { + + @Override + public Collection getContribution(ReadGraph graph, Resource input) + throws DatabaseException { + if(input == null) return null; + Layer0 l0 = Layer0.getInstance(graph); + Resource configuration = graph.getPossibleObject(input, l0.PartOf); + ArrayList> result = new ArrayList>(); + SysdynResource sr = SysdynResource.getInstance(graph); + if(configuration == null) + return result; + for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) { + result.add(new EnumerationNode(r)); + } + return result; + } + + @Override + public String getViewpointId() { + return "Used enumerations"; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ComboBoxModifier.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ComboBoxModifier.java new file mode 100644 index 00000000..d45b1a2a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ComboBoxModifier.java @@ -0,0 +1,136 @@ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.common.modifiers.EnumeratedValue; +import org.simantics.browsing.ui.common.modifiers.Enumeration; +import org.simantics.browsing.ui.content.Labeler.CustomModifier; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.utils.ObjectUtils; + +public abstract class ComboBoxModifier implements CustomModifier { + + private final Enumeration enumeration; + private final EnumeratedValue value; + private final List values; + private final Session session; + private Combo combo; + int select; + + public ComboBoxModifier(Session session, Enumeration enumeration, T value) { + this(session, enumeration, enumeration.find(value)); + } + + public ComboBoxModifier(Session session, Enumeration enumeration, + EnumeratedValue value) { + if (session == null) + throw new NullPointerException("null session"); + if (enumeration == null) + throw new NullPointerException("null enumeration"); + if (enumeration.size() == 0) + throw new IllegalArgumentException(""); + + this.enumeration = enumeration; + this.value = value; + this.session = session; + + select = 0; + boolean found = false; + + this.values = new ArrayList(); + for (EnumeratedValue v : enumeration.values()) { + values.add(v.getName()); + + if(v == value) + found = true; + + if(found == false) + select++; + } + } + + @Override + public Object createControl(Object parentControl, Object controlItem, + int columnIndex, NodeContext context) { + + combo = new Combo((Composite) parentControl, SWT.DROP_DOWN + | SWT.BORDER | SWT.READ_ONLY); + + for (String item : values) { + combo.add(item); + } + + combo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + String index = ((Combo) e.getSource()).getText(); + modify(index); + } + }); + + combo.select(select); + + return combo; + + } + + @Override + public String getValue() { + return enumeration.values().get(0).getName(); + } + + @Override + public final String isValid(String label) { + if (enumeration.findByName(label) == null) + return "Value '" + label + "' is not among the enumerated values " + enumeration.values(); + return null; + } + + @Override + public void modify(String label) { + + int index = values.indexOf(label); + if (index == -1) + throw new IllegalArgumentException("Cannot modify enumeration with value '" + label + "', not among the enumerated values " + values); + + EnumeratedValue oldEnumValue = value; + EnumeratedValue newEnumValue = enumeration.values().get(index); + + final T oldObject = oldEnumValue != null ? oldEnumValue.getObject() : null; + final T newObject = newEnumValue != null ? newEnumValue.getObject() : null; + + if (ObjectUtils.objectEquals(oldObject, newObject)) + return; + + try { + session.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + modifyWithObject(graph, oldObject, newObject); + } + }); + } catch (DatabaseException e) { + handleException(e); + } + + combo.dispose(); + } + + protected abstract void modifyWithObject(WriteGraph graph, T oldEnumObject, T enumObject) throws DatabaseException; + + protected void handleException(DatabaseException e) { + throw new RuntimeException(e); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexLabeler.java new file mode 100644 index 00000000..a740831f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexLabeler.java @@ -0,0 +1,20 @@ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; + +public class EnumerationIndexLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, EnumerationIndexNode index) throws DatabaseException { + Resource r = index.data; + if(r == null) return "Null resource"; + String name = graph.getPossibleRelatedValue(r, Layer0.getInstance(graph).HasName); + return name == null ? "No name" : name; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexNode.java new file mode 100644 index 00000000..da74629d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexNode.java @@ -0,0 +1,93 @@ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.IDoubleClickableNode; +import org.simantics.browsing.ui.common.node.IModifiableNode; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.utils.VariableNameUtils; +import org.simantics.ui.SimanticsUI; + +public class EnumerationIndexNode extends AbstractNode implements IModifiableNode, IDoubleClickableNode { + + public EnumerationIndexNode(Resource resource) { + super(resource); + } + + @Override + public Modifier getModifier(String columnId) { + Modifier modifier = new Modifier() { + + @Override + public String getValue() { + Read request = + new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + String name = graph.getPossibleRelatedValue(data, Layer0.getInstance(graph).HasName); + return name != null ? name : ""; + } + + }; + try { + return SimanticsUI.getSession().syncRequest(request); + } catch (DatabaseException e) { + e.printStackTrace(); + return ""; + } + } + + @Override + public String isValid(String label) { + if(!VariableNameUtils.isValid(label)) + return "Not valid"; + return null; + } + + @Override + public void modify(final String label) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.claimLiteral(data, Layer0.getInstance(graph).HasName, label); + } + }); + } + + }; + + return modifier; + + + + + } + + @Override + public boolean handleDoubleClick() { + return true; + } + + public void setShowInChartsSelected(final boolean selected) { + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + graph.claimLiteral(data, sr.ShowEnumerationIndexInCharts, selected); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexes.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexes.java new file mode 100644 index 00000000..fcf13e91 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexes.java @@ -0,0 +1,40 @@ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; + +public class EnumerationIndexes extends ViewpointContributorImpl { + + @Override + public Collection getContribution(ReadGraph graph, Resource input) + throws DatabaseException { + if(input == null) + return null; + SysdynResource sr = SysdynResource.getInstance(graph); + if(!graph.isInstanceOf(input, sr.Enumeration)) + return null; + Resource enumerationIndexList = graph.getPossibleObject(input, sr.HasEnumerationIndexes); + if(enumerationIndexList == null) + return null; + ArrayList> result = new ArrayList>(); + for(Resource r : OrderedSetUtils.toList(graph, enumerationIndexList)) { + result.add(new EnumerationIndexNode(r)); + } + return result; + } + + @Override + public String getViewpointId() { + return "Enumeration indexes"; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationLabeler.java new file mode 100644 index 00000000..bbaaa54a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationLabeler.java @@ -0,0 +1,52 @@ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import java.util.HashMap; +import java.util.ListIterator; +import java.util.Map; + +import org.simantics.browsing.ui.graph.impl.contributor.labeler.ColumnLabelerContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys; + +public class EnumerationLabeler extends ColumnLabelerContributorImpl{ + + @Override + public Map getLabel(ReadGraph graph, EnumerationNode input) + throws DatabaseException { + + String name = NameUtils.getSafeName(graph, input.data); + HashMap map = new HashMap(); + map.put(ColumnKeys.ENUMERATION, name); + + SysdynResource sr = SysdynResource.getInstance(graph); + + Resource enumerationIndexes = graph.getPossibleObject(input.data, sr.HasEnumerationIndexes); + ListIterator indexes = OrderedSetUtils.iterator(graph, enumerationIndexes); + StringBuilder sb = new StringBuilder(); + sb.append("["); + while(indexes.hasNext()) { + Resource i = indexes.next(); + sb.append(NameUtils.getSafeName(graph, i)); + if(indexes.hasNext()) + sb.append(", "); + } + sb.append("]"); + + Boolean relaceable = graph.getPossibleRelatedValue(input.data, sr.IsReplaceable); + if(Boolean.TRUE.equals(relaceable)) { + sb.append(" Replaceable"); + } + + map.put(ColumnKeys.INDEXES, sb.toString()); + + return map; + } + + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationNode.java new file mode 100644 index 00000000..2d960058 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationNode.java @@ -0,0 +1,12 @@ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.db.Resource; + +public class EnumerationNode extends AbstractNode { + + public EnumerationNode(Resource resource) { + super(resource); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/RedeclarationNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/RedeclarationNode.java new file mode 100644 index 00000000..0d5f3fb8 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/RedeclarationNode.java @@ -0,0 +1,172 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import java.util.ArrayList; + +import org.simantics.browsing.ui.common.modifiers.EnumeratedValue; +import org.simantics.browsing.ui.common.modifiers.Enumeration; +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.IModifiableNode; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys; +import org.simantics.ui.SimanticsUI; + +public class RedeclarationNode extends AbstractNode implements IModifiableNode { + + private Resource module; + + public RedeclarationNode(ReadGraph graph, final Resource module, Resource enumeration) { + super(enumeration); + this.module = module; + } + + /** + * + * @param graph + * @return + */ + public Resource getReplacingEnumeration(ReadGraph graph) { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource result = null; + try { + Resource redeclaration = getRedeclaration(graph); + if(redeclaration != null) { + result = graph.getSingleObject(redeclaration, sr.ReplacingEnumeration); + } + } catch(DatabaseException e) { + e.printStackTrace(); + } + + return result; + } + + + public Resource getModule() { + return module; + } + + public void setModule(Resource module) { + this.module = module; + } + + public Resource getRedeclaration(ReadGraph graph) { + try { + SysdynResource sr = SysdynResource.getInstance(graph); + for(Resource redeclaration : graph.syncRequest(new ObjectsWithType(module, sr.HasRedeclaration, sr.Redeclaration))) { + Resource replacedEnumeration = graph.getPossibleObject(redeclaration, sr.ReplacedEnumeration); + if(replacedEnumeration != null && replacedEnumeration.equals(getReplacedEnumeration())) { + return redeclaration; + } + } + } catch (DatabaseException e) { + e.printStackTrace(); + } + return null; + } + + public void setRedeclaration(WriteGraph graph, Resource redeclaration) { + try { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource oldRedeclaration = getRedeclaration(graph); + if(oldRedeclaration != null || redeclaration == null) { + graph.deny(module, sr.HasRedeclaration, oldRedeclaration); + } + + if(redeclaration != null) + graph.claim(module, sr.HasRedeclaration, redeclaration); + + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + public Resource getReplacedEnumeration() { + return this.data; + } + + @Override + public Modifier getModifier(String columnId) { + + if(!ColumnKeys.REPLACED_WITH.equals(columnId)) + return null; + + ComboBoxModifier cbm = null; + + try { + cbm = SimanticsUI.getSession().syncRequest(new Read>() { + + @Override + public ComboBoxModifier perform(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + ArrayList> values = new ArrayList>(); + + + Resource configuration = graph.getSingleObject(module, l0.PartOf); + + for(Resource enumeration : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) { + String name = NameUtils.getSafeName(graph, enumeration); + values.add(new EnumeratedValue(name, enumeration)); + } + + if(values.size() == 0) + return null; + + values.add(0, new EnumeratedValue("", null)); + Enumeration enumeration = new Enumeration(values); + + ComboBoxModifier cbm = new ComboBoxModifier(graph.getSession(), enumeration, getReplacingEnumeration(graph)) { + + @Override + protected void modifyWithObject(WriteGraph graph, Resource oldEnumObject, + Resource enumObject) throws DatabaseException { + + if(enumObject == null) { + setRedeclaration(graph, null); + } else if(!enumObject.equals(oldEnumObject)) { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource redeclaration = GraphUtils.create2(graph, + sr.Redeclaration, + sr.ReplacedEnumeration, getReplacedEnumeration(), + sr.ReplacingEnumeration, enumObject); + setRedeclaration(graph, redeclaration); + } + + } + }; + + return cbm; + + } + }); + } catch (DatabaseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return cbm; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerations.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerations.java new file mode 100644 index 00000000..78faa6b3 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerations.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; + +public class ReplaceableEnumerations extends ViewpointContributorImpl { + + @Override + public Collection getContribution(ReadGraph graph, Resource input) + throws DatabaseException { + ArrayList result = new ArrayList(); + if(input == null) + return result; + + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + + Resource moduleType = graph.getPossibleObject(input, l0.InstanceOf); + if(moduleType == null) + return result; + Resource configuration = graph.getPossibleObject(moduleType, sr2.IsDefinedBy); + if(configuration == null) + return result; + + for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) { + if(Boolean.TRUE.equals(graph.getRelatedValue(r, sr.IsReplaceable))) + result.add(new RedeclarationNode(graph, input, r)); + } + + return result; + } + + @Override + public String getViewpointId() { + return "Replaceable enumerations"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerationsLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerationsLabeler.java new file mode 100644 index 00000000..68a44dba --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableEnumerationsLabeler.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import java.util.HashMap; +import java.util.Map; + +import org.simantics.browsing.ui.graph.impl.contributor.labeler.ColumnLabelerContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys; + +public class ReplaceableEnumerationsLabeler extends ColumnLabelerContributorImpl{ + + @Override + public Map getLabel(ReadGraph graph, RedeclarationNode input) + throws DatabaseException { + HashMap map = new HashMap(); + + String name = NameUtils.getSafeName(graph, input.data); + map.put(ColumnKeys.ENUMERATION, name); + + Resource replacingEnumeration = input.getReplacingEnumeration(graph); + String replacingEnumerationName = ""; + if(replacingEnumeration != null) + replacingEnumerationName = NameUtils.getSafeName(graph, replacingEnumeration); + + map.put(ColumnKeys.REPLACED_WITH, replacingEnumerationName); + return map; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableIndexesWidget.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableIndexesWidget.java new file mode 100644 index 00000000..06caf4d4 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableIndexesWidget.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.utils.ui.ISelectionUtils; + +public class ReplaceableIndexesWidget implements Widget { + + Resource variable = null; + boolean selected = false; + org.simantics.browsing.ui.swt.widgets.Button isReplaceableButton; + + public ReplaceableIndexesWidget(Composite parent, WidgetSupport support, int style) { + support.register(this); + isReplaceableButton = new org.simantics.browsing.ui.swt.widgets.Button(parent, support, style |= SWT.CHECK); + isReplaceableButton.setText("Can be replaced by parent module"); + } + + @Override + public void setInput(ISessionContext context, Object input) { + if(input instanceof ISelection) { + ISelection selection = (ISelection)input; + if(selection instanceof IStructuredSelection) { + Resource resource = ISelectionUtils.filterSingleSelection(selection, Resource.class); + if(resource != null) { + variable = resource; + } + } + } + + if(variable == null) return; + + try { + context.getSession().syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + final Boolean replaceable = graph.getPossibleRelatedValue(variable, sr.IsReplaceable); + if(replaceable != null) + selected = replaceable; + final Button button = getWidget(); + button.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if(button.isDisposed()) return; + + if(replaceable) + button.setSelection(true); + else + button.setSelection(false); + } + }); + + + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + isReplaceableButton.addSelectionListener(new SelectionListenerImpl(context) { + + @Override + public void apply(WriteGraph graph, Resource input) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Boolean replaceable = graph.getPossibleRelatedValue(input, sr.IsReplaceable); + if(Boolean.TRUE.equals(replaceable)) { + graph.claimLiteral(input, sr.IsReplaceable, false); + selected = false; + } else { + graph.claimLiteral(input, sr.IsReplaceable, true); + selected = true; + } + } + }); + } + + public Button getWidget() { + return isReplaceableButton.getWidget(); + } + + public boolean getSelection() { + return selected; + } + + public void addSelectionListener(SelectionListener listener) { + isReplaceableButton.addSelectionListener(listener); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ShowInChartsCheckBox.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ShowInChartsCheckBox.java new file mode 100644 index 00000000..232db37b --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ShowInChartsCheckBox.java @@ -0,0 +1,21 @@ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import org.simantics.browsing.ui.CheckedState; +import org.simantics.browsing.ui.graph.contributor.labeler.CheckedStateContributor; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; + +public class ShowInChartsCheckBox extends CheckedStateContributor { + + @Override + public CheckedState getState(ReadGraph graph, EnumerationIndexNode input) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Boolean selected = graph.getPossibleRelatedValue(input.data, sr.ShowEnumerationIndexInCharts, Bindings.BOOLEAN); + return selected ? CheckedState.CHECKED : CheckedState.NOT_CHECKED; + } + +} + diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/UsedEnumerations.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/UsedEnumerations.java new file mode 100644 index 00000000..35d094f0 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/UsedEnumerations.java @@ -0,0 +1,37 @@ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; + +public class UsedEnumerations extends ViewpointContributorImpl { + + @Override + public Collection getContribution(ReadGraph graph, Resource input) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + + ArrayList> result = new ArrayList>(); + + Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes); + if(arrayIndexes == null) { + return result; + } + for(Resource r : OrderedSetUtils.toList(graph, arrayIndexes)) { + result.add(new EnumerationNode(r)); + } + return result; + } + + @Override + public String getViewpointId() { + return "Available enumerations"; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/UsedEnumerationsManyVariables.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/UsedEnumerationsManyVariables.java new file mode 100644 index 00000000..4ce3cf5a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/UsedEnumerationsManyVariables.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; + +public class UsedEnumerationsManyVariables extends ViewpointContributorImpl> { + + @Override + public Collection getContribution(ReadGraph graph, List input) + throws DatabaseException { + + ArrayList> result = new ArrayList>(); + +// SysdynResource sr = SysdynResource.getInstance(graph); + +// Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes); +// if(arrayIndexes == null) { +// return result; +// } +// for(Resource r : OrderedSetUtils.toList(graph, arrayIndexes)) { +// result.add(new EnumerationNode(r)); +// } + return result; + } + + @Override + public String getViewpointId() { + return "Available enumerations"; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/AuxiliaryExpression.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/AuxiliaryExpression.java new file mode 100644 index 00000000..85c7ec14 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/AuxiliaryExpression.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; + +public class AuxiliaryExpression extends BasicExpression { + + public AuxiliaryExpression() { + try { + this.expressionType = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + return SysdynResource.getInstance(graph).NormalExpression; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java new file mode 100644 index 00000000..96c6268e --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java @@ -0,0 +1,222 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.VerifyKeyListener; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.utils.ExpressionUtils; +import org.simantics.ui.SimanticsUI; + +/** + * Basic expression that is used with parameter, auxiliary and constant + * @author Teemu Lempinen + * + */ +public class BasicExpression implements IExpression { + + private ExpressionField expression; + protected Resource expressionType; + + @Override + public void createExpressionFields(Composite parent, Map data) { + // Create the single field + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(parent); + String equation = data.get("equation") != null ? (String)data.get("equation") : ""; + + Label l = new Label(parent, SWT.NONE); + l.setText("="); + + expression = new ExpressionField(parent, SWT.BORDER); + expression.setExpression(equation); + GridDataFactory.fillDefaults().grab(true, true).applyTo(expression); + + } + + @Override + public void focus() { + this.expression.focus(); + + } + + @Override + public List getExpressionFields() { + return Arrays.asList(this.expression); + } + + @Override + public void readData(final Resource expression, Map data) { + String equation = null; + if (expression != null && data.get("equation") == null) { + try { + equation = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if (expression != null) { + String equation = graph.getPossibleRelatedValue(expression, sr.HasEquation); + if(equation != null) + return equation; + } + + return ""; + + } + + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + data.put("equation", equation); + } + } + + @Override + public void replaceSelection(String var) { + if(expression != null) { + IDocument doc = expression.getDocument(); + try { + Point selection = expression.getSelection(); + doc.replace(selection.x, selection.y, var); + expression.setSelection(selection.x + var.length()); + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + } + + @Override + public void save(final Resource expression, Map data) { + final String currentText = this.expression.getExpression(); + final String oldEquation = (String)data.get("equation"); + if(oldEquation == null || + (currentText != null && expressionType != null)) { + data.put("equation", currentText); + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + Layer0 l0 = Layer0.getInstance(g); + + // Force change to parameter, if the equation is a parameter + if(ExpressionUtils.isParameter(currentText)) { + if(!expressionType.equals(sr.ConstantExpression)) + expressionType = sr.ParameterExpression; + } else { + expressionType = sr.NormalExpression; + } + + // If nothing has changed, do nothing + if (oldEquation != null + && expression != null + && g.isInstanceOf(expression, expressionType) + && currentText.equals(oldEquation)) { + return; + } + + // If the current expression type is different than the target expression type, create a new expression + if(!g.isInstanceOf(expression, expressionType)) { + Collection ownerLists = OrderedSetUtils.getOwnerLists(g, expression, l0.OrderedSet); + if(ownerLists.size() != 1) + return; + Resource ownerList = ownerLists.iterator().next(); + final Resource newExpression = GraphUtils.create2(g, expressionType, + sr.HasEquation, currentText); + String arrayRange = g.getPossibleRelatedValue(expression, sr.HasArrayRange, Bindings.STRING); + if(arrayRange != null) + g.claimLiteral(newExpression, sr.HasArrayRange, arrayRange); + + final Resource variable = g.getSingleObject(ownerList, sr.HasExpressions_Inverse); + OrderedSetUtils.replace(g, ownerList, expression, newExpression); + g.deny(expression, l0.PartOf); + g.claim(newExpression, l0.PartOf, variable); + + + VirtualGraph runtime = g.getService(VirtualGraph.class); + g.syncRequest(new WriteRequest(runtime) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(variable != null) { + if(graph.hasStatement(variable, sr.HasActiveExpression)) + graph.deny(variable, sr.HasActiveExpression); + graph.claim(variable, sr.HasActiveExpression, newExpression); + } + } + } + ); + } else { + // Claim value for the expression + g.claimLiteral(expression, sr.HasEquation, currentText); + } + } + + }); + } + } + + @Override + public void updateData(Map data) { + if(this.expression != null && this.expression.getExpression() != null) + data.put("equation", this.expression.getExpression()); + } + + @Override + public void addKeyListener(KeyListener listener) { + this.expression.getSourceViewer().getTextWidget().addKeyListener(listener); + + } + + @Override + public void addModifyListener(ModifyListener listener) { + this.expression.getSourceViewer().getTextWidget().addModifyListener(listener); + + } + + @Override + public void addFocusListener(FocusListener listener) { + this.expression.getSourceViewer().getTextWidget().addFocusListener(listener); + } + + @Override + public void addVerifyKeyListener(VerifyKeyListener listener) { + this.expression.getSourceViewer().getTextWidget().addVerifyKeyListener(listener); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ColorManager.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ColorManager.java new file mode 100644 index 00000000..d9cef77c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ColorManager.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + +import java.util.HashMap; + +import org.eclipse.jface.text.source.ISharedTextColors; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; + +public class ColorManager implements ISharedTextColors { + + protected HashMap colorTable = new HashMap(); + + @Override + public void dispose() { + for(Color c : colorTable.values()) + c.dispose(); + colorTable.clear(); + } + + @Override + public Color getColor(RGB rgb) { + Color color = colorTable.get(rgb); + if (color == null) { + color = new Color(Display.getCurrent(), rgb); + colorTable.put(rgb, color); + } + return color; + + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ConstantExpression.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ConstantExpression.java new file mode 100644 index 00000000..d1c1fbd9 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ConstantExpression.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; + +public class ConstantExpression extends BasicExpression { + + public ConstantExpression() { + try { + this.expressionType = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + return SysdynResource.getInstance(graph).ConstantExpression; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/DelayExpression.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/DelayExpression.java new file mode 100644 index 00000000..8494a8c9 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/DelayExpression.java @@ -0,0 +1,320 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.VerifyKeyListener; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; + +/** + * IExpression for displaying fields of DelayExpression + * @author Teemu Lempinen + * + */ +public class DelayExpression implements IExpression { + + private ExpressionField equation, delayTime, initialValue; + private ExpressionField lastSelectedText = equation; + private Spinner order; + private Resource expression; + + /** + * Creates a new DelayExpression + * @param expression + */ + public DelayExpression(Resource expression) { + this.expression = expression; + } + + /** + * Displays the fields for delayExpression + */ + @Override + public void createExpressionFields(Composite parent, final Map data) { + // Get possible existing data + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(parent); + String eq = data.get("equation") != null ? (String)data.get("equation") : ""; + String dt = data.get("delayTime") != null ? (String)data.get("delayTime") : ""; + String iv = data.get("initialValue") != null ? (String)data.get("initialValue") : ""; + int o = data.get("order") != null ? (Integer)data.get("order") : 3; + + Label l = new Label(parent, SWT.NONE); + l.setText("expression"); + + // Equation that is delayed + equation = new ExpressionField(parent, SWT.BORDER); + equation.setExpression(eq); + GridDataFactory.fillDefaults().grab(true, true).applyTo(equation); + equation.getSourceViewer().getTextWidget().addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent e) { + lastSelectedText = equation; + } + }); + + l = new Label(parent, SWT.NONE); + l.setText("delay time"); + + // How much the equation is delayed + delayTime = new ExpressionField(parent, SWT.BORDER); + delayTime.setExpression(dt); + GridDataFactory.fillDefaults().grab(true, true).applyTo(delayTime); + + delayTime.getSourceViewer().getTextWidget().addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent e) { + lastSelectedText = delayTime; + } + }); + + l = new Label(parent, SWT.NONE); + l.setText("initial value"); + + // What is the initial value of the delay (empty == same as equation) + initialValue = new ExpressionField(parent, SWT.BORDER); + initialValue.setExpression(iv); + GridDataFactory.fillDefaults().grab(true, true).applyTo(initialValue); + + initialValue.getSourceViewer().getTextWidget().addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent e) { + lastSelectedText = initialValue; + } + }); + + + l = new Label(parent, SWT.NONE); + l.setText("order"); + + // The order of the delay (default == 3) + order = new Spinner(parent, SWT.BORDER); + order.setMinimum(1); + order.setSelection(o); + order.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + save(expression, data); + } + }); + GridDataFactory.fillDefaults().applyTo(order); + } + + @Override + public void focus() { + lastSelectedText.setFocus(); + } + + @Override + public List getExpressionFields() { + return Arrays.asList(equation, delayTime, initialValue); + } + + @Override + public void readData(final Resource expression, Map data) { + class Auxiliary { + String equation, delayTime, initialValue; + Integer order; + } + + Auxiliary results = null; + + try { + results = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Auxiliary perform(ReadGraph graph) throws DatabaseException { + Auxiliary results = new Auxiliary(); + SysdynResource sr = SysdynResource.getInstance(graph); + if (expression != null && graph.isInstanceOf(expression, sr.DelayExpression)) { + results.equation = graph.getPossibleRelatedValue(expression, sr.DelayExpression_expression); + results.delayTime = graph.getPossibleRelatedValue(expression, sr.DelayExpression_delayTime); + results.initialValue = graph.getPossibleRelatedValue(expression, sr.DelayExpression_initialValue); + results.order = graph.getPossibleRelatedValue(expression, sr.DelayExpression_order); + } else { + results.equation = ""; + results.delayTime = ""; + results.order = 1; + } + return results; + } + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + if(results.equation != null) + data.put("equation", results.equation); + if(results.delayTime != null) + data.put("delayTime", results.delayTime); + if(results.initialValue != null) + data.put("initialValue", results.initialValue); + if(results.order != null) + data.put("order", results.order); + } + + @Override + public void replaceSelection(String var) { + if(lastSelectedText != null) { + IDocument doc = lastSelectedText.getDocument(); + try { + Point selection = lastSelectedText.getSelection(); + doc.replace(selection.x, selection.y, var); + lastSelectedText.setSelection(selection.x + var.length()); + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + } + + @Override + public void save(Resource expr, Map data) { + this.expression = expr; + final String currentEquation = this.equation.getExpression(); + final String currentDelayTime = this.delayTime.getExpression(); + final String currentInitialValue = this.initialValue.getExpression(); + final Integer currentOrder = this.order.getSelection(); + + String oldEquation = (String)data.get("equation"); + String oldDelayTime = (String)data.get("delayTime"); + String oldInitialValue = (String)data.get("initialValue"); + Integer oldOrder = (Integer)data.get("order"); + + if((oldEquation == null || oldDelayTime == null || oldOrder == null || oldInitialValue == null) || + !oldEquation.equals(currentEquation) || !oldDelayTime.equals(currentDelayTime) || + !oldOrder.equals(currentOrder) || !oldInitialValue.equals(currentInitialValue)) { + // old value was null or value has changed -> Do save + + data.putAll(data); + data.put("equation", currentEquation); + data.put("delayTime", currentDelayTime); + data.put("initialValue", currentInitialValue); + data.put("order", currentOrder); + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + Layer0 l0 = Layer0.getInstance(g); + + if(!g.isInstanceOf(expression, sr.DelayExpression)) { + // Create a new DelayExpression, if the old expression was something else + Resource ownerList = OrderedSetUtils.getSingleOwnerList(g, expression); + final Resource newExpression = GraphUtils.create2(g, sr.DelayExpression); + String arrayRange = g.getPossibleRelatedValue(expression, sr.HasArrayRange, Bindings.STRING); + if(arrayRange != null) + g.claimLiteral(newExpression, sr.HasArrayRange, arrayRange); + + final Resource variable = g.getSingleObject(ownerList, sr.HasExpressions_Inverse); + OrderedSetUtils.replace(g, ownerList, expression, newExpression); + g.deny(expression, l0.PartOf); + g.claim(newExpression, l0.PartOf, variable); + + VirtualGraph runtime = g.getService(VirtualGraph.class); + g.syncRequest(new WriteRequest(runtime) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.hasStatement(variable, sr.HasActiveExpression)) + graph.deny(variable, sr.HasActiveExpression); + graph.claim(variable, sr.HasActiveExpression, newExpression); + } + } + ); + expression = newExpression; + } + + // Claim values + g.claimLiteral(expression, sr.DelayExpression_expression, currentEquation); + g.claimLiteral(expression, sr.DelayExpression_delayTime, currentDelayTime); + g.claimLiteral(expression, sr.DelayExpression_initialValue, currentInitialValue); + g.claimLiteral(expression, sr.DelayExpression_order, currentOrder); + } + }); + } + + } + + @Override + public void updateData(Map data) { + if(this.equation != null && this.equation.getExpression() != null) + data.put("equation", this.equation.getExpression()); + if(this.delayTime != null && this.delayTime.getExpression() != null) + data.put("delayTime", this.delayTime.getExpression()); + if(this.initialValue != null && this.initialValue.getExpression() != null) + data.put("initialValue", this.initialValue.getExpression()); + if(this.order != null) + data.put("order", this.order.getSelection()); + } + + @Override + public void addKeyListener(KeyListener listener) { + this.equation.getSourceViewer().getTextWidget().addKeyListener(listener); + this.delayTime.getSourceViewer().getTextWidget().addKeyListener(listener); + this.initialValue.getSourceViewer().getTextWidget().addKeyListener(listener); + } + + @Override + public void addModifyListener(ModifyListener listener) { + this.equation.getSourceViewer().getTextWidget().addModifyListener(listener); + this.delayTime.getSourceViewer().getTextWidget().addModifyListener(listener); + this.initialValue.getSourceViewer().getTextWidget().addModifyListener(listener); + } + + @Override + public void addFocusListener(FocusListener listener) { + this.equation.getSourceViewer().getTextWidget().addFocusListener(listener); + this.delayTime.getSourceViewer().getTextWidget().addFocusListener(listener); + this.initialValue.getSourceViewer().getTextWidget().addFocusListener(listener); + } + + @Override + public void addVerifyKeyListener(VerifyKeyListener listener) { + this.equation.getSourceViewer().getTextWidget().addVerifyKeyListener(listener); + this.delayTime.getSourceViewer().getTextWidget().addVerifyKeyListener(listener); + this.initialValue.getSourceViewer().getTextWidget().addVerifyKeyListener(listener); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/EmptyExpression.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/EmptyExpression.java new file mode 100644 index 00000000..6de6e82a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/EmptyExpression.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + +import java.util.List; +import java.util.Map; + +import org.eclipse.swt.custom.VerifyKeyListener; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Composite; +import org.simantics.db.Resource; + +public class EmptyExpression implements IExpression { + + @Override + public void createExpressionFields(Composite parent, Map data) { + // TODO Auto-generated method stub + + } + + @Override + public void focus() { + // TODO Auto-generated method stub + + } + + @Override + public List getExpressionFields() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void readData(Resource variable, Map data) { + // TODO Auto-generated method stub + + } + + @Override + public void replaceSelection(String var) { + // TODO Auto-generated method stub + + } + + @Override + public void save(Resource variable, Map data) { + // TODO Auto-generated method stub + + } + + @Override + public void updateData(Map data) { + // TODO Auto-generated method stub + + } + + @Override + public void addKeyListener(KeyListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public void addModifyListener(ModifyListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public void addFocusListener(FocusListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public void addVerifyKeyListener(VerifyKeyListener listener) { + // TODO Auto-generated method stub + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java new file mode 100644 index 00000000..2904c0d0 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java @@ -0,0 +1,299 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + +import java.util.List; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.PaintManager; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.source.Annotation; +import org.eclipse.jface.text.source.AnnotationModel; +import org.eclipse.jface.text.source.AnnotationPainter; +import org.eclipse.jface.text.source.DefaultCharacterPairMatcher; +import org.eclipse.jface.text.source.IAnnotationAccess; +import org.eclipse.jface.text.source.MatchingCharacterPainter; +import org.eclipse.jface.text.source.SourceViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess; +import org.eclipse.swt.graphics.Point; +import org.simantics.sysdyn.expressionParser.Token; + +/** + * Field for displaying a part of an expression. Expression field uses SourceViewer + * to display annotations and other visual elements just like any other + * source viewer in eclipse. + * + * @author Teemu Lempinen + * + */ +public class ExpressionField extends Composite { + + protected SourceViewer _sourceViewer; + protected IDocument _document; + protected AnnotationModel _annotationModel; + + public static final String MISSING_LINK = "MissingLink"; + public static final String NO_SUCH_VARIABLE = "NoSuchVariable"; + public static final String SYNTAX_ERROR = "SyntaxError"; + + String oldExpression; + + ColorManager cManager = new ColorManager(); + + IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess(); + + /** + * Create a new expression field + * @param parent + * @param style + */ + public ExpressionField(Composite parent, int style) { + super(parent, style); + + GridLayoutFactory.fillDefaults().applyTo(this); + + int styles = SWT.V_SCROLL + | SWT.MULTI + | SWT.FULL_SELECTION + | SWT.WRAP; + + _document = new Document(); + _document.set(""); + + _annotationModel = new AnnotationModel(); + _annotationModel.connect(_document); + + _sourceViewer = new SourceViewer(this, + + null, + null, + true, + styles); + + // Configuration for color management + _sourceViewer.configure(new ExpressionFieldConfiguration(cManager)); + AnnotationPainter painter = new AnnotationPainter(_sourceViewer, annotationAccess); + _sourceViewer.addPainter(painter); + + // Annotation types + painter.addAnnotationType(MISSING_LINK); + painter.setAnnotationTypeColor(MISSING_LINK, new Color(this.getDisplay(), 255,215,0)); + painter.addAnnotationType(NO_SUCH_VARIABLE); + painter.setAnnotationTypeColor(NO_SUCH_VARIABLE, new Color(this.getDisplay(), 255,0,0)); + painter.addAnnotationType(SYNTAX_ERROR); + painter.setAnnotationTypeColor(SYNTAX_ERROR, new Color(this.getDisplay(), 255,0,0)); + + _sourceViewer.setDocument(_document, _annotationModel); + + GridDataFactory.fillDefaults().grab(true, true).applyTo(_sourceViewer.getControl()); + + // Parenthesis matching + PaintManager paintManager = new PaintManager(_sourceViewer); + MatchingCharacterPainter matchingCharacterPainter = new MatchingCharacterPainter(_sourceViewer, + new DefaultCharacterPairMatcher( new char[] {'(', ')', '{', '}', '[', ']'} )); + matchingCharacterPainter.setColor(new Color(Display.getCurrent(), new RGB(160, 160, 160))); + paintManager.addPainter(matchingCharacterPainter); + + + // Listener for canceling editing. ESC -> revert back to original text + _sourceViewer.getTextWidget().addKeyListener(new KeyListener() { + + @Override + public void keyReleased(KeyEvent e) { + } + + @Override + public void keyPressed(KeyEvent e) { + if(e.keyCode == SWT.ESC && getExpression() != null) { + ((StyledText)e.widget).setText(oldExpression); + ((StyledText)e.widget).setSelection(getExpression().length()); + } + } + }); + + /* Focus listener saving and restoring selections + * When focus is lost, current selection is saved, but the selection is removed. + * When focus is gained back, the selection is restored + */ + _sourceViewer.getTextWidget().addFocusListener(new FocusListener() { + + Point selection = null; + @Override + public void focusLost(FocusEvent e) { + selection = ((StyledText)e.widget).getSelection(); + ((StyledText)e.widget).setSelection(0); + } + + @Override + public void focusGained(FocusEvent e) { + if(selection != null) + ((StyledText)e.widget).setSelection(selection); + } + }); + } + + /** + * Returns the {@link SourceViewer} of this ExpressionField + * @return Returns the {@link SourceViewer} of this ExpressionField + */ + public SourceViewer getSourceViewer() { + return this._sourceViewer; + } + + /** + * Sets missing link annotations to given positions + * @param positions Positions for missing link annotations + */ + public void setMissingLinkAnnotations(List positions){ + for(Position p : positions) { + Annotation annotation = new Annotation(false); + annotation.setType(MISSING_LINK); + annotation.setText("No link to this variable"); + _annotationModel.addAnnotation(annotation, p); + } + } + + /** + * Sets no such variable annotations to given positions + * @param positions Positions for no such variable annotations + */ + public void setNoSuchVariableAnnotations(List positions){ + for(Position p : positions) { + Annotation annotation = new Annotation(false); + annotation.setType(NO_SUCH_VARIABLE); + annotation.setText("No such variable in model"); + _annotationModel.addAnnotation(annotation, p); + } + } + + /** + * Sets syntax error for the given token + * @param token Token with syntax error + * @param message Message to be displayed in tool tips + */ + public void setSyntaxError(Token token, String message){ + setSyntaxError(token.image, message, token.beginLine, token.beginColumn, token.endLine, token.endColumn); + } + + /** + * Sets syntax error for the given token + * @param token Token with syntax error + * @param message Message to be displayed in tool tips + */ + public void setSyntaxError(org.simantics.sysdyn.tableParser.Token token, String message){ + setSyntaxError(token.image, message, token.beginLine, token.beginColumn, token.endLine, token.endColumn); + } + + /** + * Sets syntax error to given location + * @param image Token image + * @param message Message to be displayed in tool tips + * @param beginLine Begin line + * @param beginColumn Begin column + * @param endLine End line + * @param endColumn End column + */ + public void setSyntaxError(String image, String message, int beginLine, int beginColumn, int endLine, int endColumn) { + int start = 0; + int offset = this._document.getLength(); + if(image != null && this._document.getLength() > 0) { + try { + start = this._document.getLineOffset(beginLine - 1) + beginColumn - 1; + offset = this._document.getLineOffset(endLine - 1) + endColumn - start; + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + setSyntaxError(start, offset, SYNTAX_ERROR, message == null ? "Syntax Error" : message); + } + + /** + * Sets syntax error to given start and offset + * @param start Start location + * @param offset Offset + * @param type Error type (SYNTAX_ERROR, MISSING_LINK, NO_SUCH_VARIABLE) + * @param text Message to be displayedin tool tips + */ + public void setSyntaxError(int start, int offset, String type, String text) { + Annotation annotation = new Annotation(false); + annotation.setType(type); + annotation.setText(text); + Position p = new Position(start, offset); + _annotationModel.addAnnotation(annotation, p); + } + + /** + * Resets all annotations + */ + public void resetAnnotations() { + _annotationModel.removeAllAnnotations(); + } + + /** + * Sets an expression to this expression field + * @param expression + */ + public void setExpression(String expression) { + _document.set(expression); + this.oldExpression = expression; + } + + /** + * Returns the expression of this expression field + * @return + */ + public String getExpression() { + return this._document.get(); + } + + /** + * Returns the current selection + * @return current selection + */ + public Point getSelection() { + return _sourceViewer.getSelectedRange(); + } + + /** + * Set selection for this expression field. The length of the selection is 0 + * @param selection Selection location + */ + public void setSelection(int selection) { + this._sourceViewer.setSelectedRange(selection, 0); + } + + public IDocument getDocument() { + return _document; + } + + /** + * Focus to this expression field + */ + public void focus() { + this._sourceViewer.getTextWidget().forceFocus(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java new file mode 100644 index 00000000..ba5d08be --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + +import org.eclipse.jface.text.DefaultTextHover; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextHover; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.ITokenScanner; +import org.eclipse.jface.text.rules.IWordDetector; +import org.eclipse.jface.text.rules.MultiLineRule; +import org.eclipse.jface.text.rules.RuleBasedScanner; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.rules.WordRule; +import org.eclipse.jface.text.source.DefaultAnnotationHover; +import org.eclipse.jface.text.source.IAnnotationHover; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.RGB; +import org.simantics.sysdyn.ui.utils.VariableNameUtils; + +public class ExpressionFieldConfiguration extends SourceViewerConfiguration { + + + ColorManager colorManager; + + public ExpressionFieldConfiguration(ColorManager colorManager) { + super(); + this.colorManager = colorManager; + } + + public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { + return new String[] { + IDocument.DEFAULT_CONTENT_TYPE + }; + } + + public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { + PresentationReconciler reconciler = new PresentationReconciler(); + + DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSclTokenScanner()); + + reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); + + return reconciler; + } + + + ITokenScanner getSclTokenScanner() { + RuleBasedScanner scanner = new RuleBasedScanner(); + + final Token reserved = new Token( + new TextAttribute( + colorManager.getColor(new RGB(127, 0, 85)), + null, + SWT.BOLD + )); + final Token defaultToken = new Token(new TextAttribute(colorManager.getColor(new RGB(0, 0, 0)))); + + final Token comment = new Token(new TextAttribute(colorManager.getColor(new RGB(63, 127, 95)))); + + + WordRule reservedWord = new WordRule(new IWordDetector() { + @Override + public boolean isWordStart(char c) { + return Character.isLetter(c); + } + + @Override + public boolean isWordPart(char c) { + return Character.isLetter(c); + } + }, defaultToken); + + + for(String s : VariableNameUtils.keywords) { + reservedWord.addWord(s, reserved); + } + + IRule[] rules = new IRule[] { + reservedWord, + new MultiLineRule("/*", "*/", comment), + new MultiLineRule("\"", "\"", comment) + }; + scanner.setRules(rules); + + return scanner; + } + + @Override + public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { + return new DefaultTextHover(sourceViewer); + } + + @Override + public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { + return new DefaultAnnotationHover(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/IExpression.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/IExpression.java new file mode 100644 index 00000000..1491cd32 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/IExpression.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + +import java.util.List; +import java.util.Map; + +import org.eclipse.swt.custom.VerifyKeyListener; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Composite; +import org.simantics.db.Resource; + +public interface IExpression { + + public void createExpressionFields(Composite parent, Map data); + + public void readData(final Resource expression, Map data); + + public void save(final Resource expression, Map data); + + public void focus(); + + public void replaceSelection(String var); + + public void updateData(Map data); + + public List getExpressionFields(); + + public void addModifyListener(ModifyListener listener); + + public void addKeyListener(KeyListener listener); + + public void addVerifyKeyListener(VerifyKeyListener listener); + + public void addFocusListener(FocusListener listener); +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupChartPanel.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupChartPanel.java new file mode 100644 index 00000000..44db3f03 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupChartPanel.java @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +import org.jfree.chart.ChartPanel; +import org.jfree.chart.ChartRenderingInfo; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.entity.ChartEntity; +import org.jfree.chart.entity.PlotEntity; +import org.jfree.chart.entity.XYItemEntity; +import org.jfree.chart.plot.XYPlot; +import org.jfree.data.general.SeriesChangeListener; +import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +@SuppressWarnings("serial") +public class LookupChartPanel extends ChartPanel { + + private XYItemEntity dragPrevEntity; + private boolean drawing; + private XYSeries series; + private JFreeChart chart; + private SeriesChangeListener changeListener; + + public LookupChartPanel(JFreeChart chart) { + super(chart); + this.chart = chart; + XYSeriesCollection collection = (XYSeriesCollection) ((XYPlot)chart.getPlot()).getDataset(); + series = collection.getSeries(0); + } + + public void mouseDragged(MouseEvent e) + { + if(dragPrevEntity != null) { + + int item = dragPrevEntity.getItem(); + XYPlot plot = (XYPlot)chart.getPlot(); + ValueAxis rangeAxis = plot.getRangeAxis(); + ValueAxis domainAxis = plot.getDomainAxis(); + Point2D location = getLocationOnChart(getMouseLocation(e)); + Number prevX = item == 0 ? null : series.getX(item - 1); + Number nextX = item == series.getItemCount() - 1 ? null : series.getX(item + 1); + + + if(series.indexOf(location.getX()) >= 0 && series.indexOf(location.getX()) != item) + return; + else if (prevX != null && location.getX() < prevX.doubleValue()) + location.setLocation(series.getX(item).doubleValue(), location.getY()); + else if (nextX != null && location.getX() > nextX.doubleValue()) + location.setLocation(series.getX(item).doubleValue(), location.getY()); + else if (location.getX() > domainAxis.getUpperBound()) + location.setLocation(domainAxis.getUpperBound(), location.getY()); + else if (location.getX() < domainAxis.getLowerBound()) + location.setLocation(domainAxis.getLowerBound(), location.getY()); + + if (location.getY() > rangeAxis.getUpperBound()) + location.setLocation(location.getX(), rangeAxis.getUpperBound()); + else if (location.getY() < rangeAxis.getLowerBound()) + location.setLocation(location.getX(), rangeAxis.getLowerBound()); + + removeItemFromSeries(dragPrevEntity.getItem()); + addLocationToSeries(location); + } else { + ChartEntity currEntity = this.getEntityForPoint(e.getX(),e.getY()); + if(!drawing && currEntity instanceof XYItemEntity) { + dragPrevEntity = ((XYItemEntity)currEntity); + } else if (currEntity instanceof PlotEntity){ + drawing = true; + Point2D locationOnChart = getLocationOnChart(getMouseLocation(e)); + int item = series.indexOf(locationOnChart.getX()); + if (item >= 0) { + Point2D location = new Point2D.Double(series.getX(item).doubleValue(), series.getY(item).doubleValue()); + Point2D javaLocation = getLocationOnJava2D(location); + removeItemFromSeries(item); + addLocationToSeries(getLocationOnChart(new Point2D.Double(javaLocation.getX(), e.getY()))); + } + } + } + + } + + public void mouseReleased(MouseEvent e) { + if(isDragging()) { + dragPrevEntity = null; + if(changeListener != null) + changeListener.seriesChanged(null); + } + drawing = false; + + } + + public void mouseClicked(MouseEvent e) + { + if(e.getButton() == MouseEvent.BUTTON1) { + addLocationToSeries(getLocationOnChart(getMouseLocation(e))); + } else if (e.getButton() == MouseEvent.BUTTON3) { + ChartEntity entity = this.getEntityForPoint(e.getX(),e.getY()); + if(entity instanceof XYItemEntity) { + XYItemEntity xyentity = ((XYItemEntity)entity); + removeItemFromSeries(xyentity.getItem()); + } + } + } + + private Point2D getLocationOnChart(Point2D coordinates) { + XYPlot plot = (XYPlot)chart.getPlot(); + ChartRenderingInfo info = getChartRenderingInfo(); + Rectangle2D dataArea = info.getPlotInfo().getDataArea(); + double chartX = plot.getDomainAxis().java2DToValue(coordinates.getX(), dataArea, + plot.getDomainAxisEdge()); + double chartY = plot.getRangeAxis().java2DToValue(coordinates.getY(), dataArea, + plot.getRangeAxisEdge()); + return new Point2D.Double(chartX, chartY); + } + + private Point2D getLocationOnJava2D(Point2D location) { + XYPlot plot = (XYPlot)chart.getPlot(); + ChartRenderingInfo info = getChartRenderingInfo(); + Rectangle2D dataArea = info.getPlotInfo().getDataArea(); + double javaX = plot.getDomainAxis().valueToJava2D(location.getX(), dataArea, + plot.getDomainAxisEdge()); + double javaY = plot.getRangeAxis().valueToJava2D(location.getY(), dataArea, + plot.getRangeAxisEdge()); + return new Point2D.Double(javaX, javaY); + } + + public void addLocationToSeries(Point2D location) { + if(series.indexOf(location.getX()) < 0) { + series.add(location.getX(), location.getY()); + } + } + + public void removeItemFromSeries(int item){ + series.remove(item); + } + + public void resetChart(XYDataset dataset) { + XYPlot plot = (XYPlot)chart.getPlot(); + plot.setDataset(dataset); + XYSeriesCollection collection = (XYSeriesCollection) plot.getDataset(); + series = collection.getSeries(0); + } + + private Point2D getMouseLocation(MouseEvent e) { + int mouseX = e.getX(); + int mouseY = e.getY(); + Point2D p = translateScreenToJava2D( + new Point(mouseX, mouseY)); + return p; + } + + public void addSeriesChangeListener(SeriesChangeListener listener) { + this.changeListener = listener; + this.series.addChangeListener(changeListener); + } + + public boolean isDragging() { + return dragPrevEntity != null; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupExpression.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupExpression.java new file mode 100644 index 00000000..3cebc8c0 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupExpression.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + +import java.util.List; +import java.util.Map; + +import org.eclipse.swt.custom.VerifyKeyListener; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Composite; +import org.simantics.db.Resource; + +public class LookupExpression implements IExpression { + + @Override + public void focus() { + // TODO Auto-generated method stub + + } + + @Override + public List getExpressionFields() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void readData(final Resource variable, Map data) { + // TODO Auto-generated method stub + + } + + @Override + public void replaceSelection(String var) { + // TODO Auto-generated method stub + + } + + @Override + public void save(final Resource variable, Map data) { + // TODO Auto-generated method stub + + } + + @Override + public void updateData(Map data) { + // TODO Auto-generated method stub + + } + + @Override + public void createExpressionFields(Composite parent, Map data) { + // TODO Auto-generated method stub + + } + + @Override + public void addKeyListener(KeyListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public void addModifyListener(ModifyListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public void addFocusListener(FocusListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public void addVerifyKeyListener(VerifyKeyListener listener) { + // TODO Auto-generated method stub + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupInputOutputTable.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupInputOutputTable.java new file mode 100644 index 00000000..e6eb4775 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupInputOutputTable.java @@ -0,0 +1,279 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.ICellModifier; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Item; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; + +public class LookupInputOutputTable extends Composite { + + public static final String INPUT = "Input"; + public static final String OUTPUT = "Output"; + public static final String[] PROPS = { INPUT, OUTPUT }; + + private Table table; + private TableViewer tableViewer; + private List tableRows; + + public LookupInputOutputTable(Composite parent, int style) { + super(parent, style); + + GridLayoutFactory.fillDefaults().applyTo(this); + GridDataFactory.fillDefaults().grab(true, true).applyTo(this); + table = new Table(this, SWT.BORDER|SWT.SINGLE|SWT.FULL_SELECTION); + GridDataFactory.fillDefaults().grab(true, true).applyTo(table); + table.setHeaderVisible (true); + table.setLinesVisible(true); + table.getVerticalBar().setVisible(true); + TableColumn column1 = new TableColumn (table, SWT.LEFT); + column1.setText (INPUT); + column1.setWidth (85); + + TableColumn column2 = new TableColumn (table, SWT.LEFT); + column2.setText (OUTPUT); + column2.setWidth (85); + + // Create the viewer and connect it to the view + tableViewer = new TableViewer (table); + + tableViewer.setContentProvider (new ArrayContentProvider()); + tableViewer.setLabelProvider (new InputOutputLabelProvider()); + tableViewer.setCellModifier(new InputOutputCellModifier()); + + tableRows = new ArrayList(); + tableViewer.setInput(tableRows); + + CellEditor[] editors = new CellEditor[2]; + editors[0] = new TextCellEditor(table); + editors[1] = new TextCellEditor(table); + tableViewer.setCellEditors(editors); + tableViewer.setColumnProperties(PROPS); + + } + + private class InputOutputLabelProvider extends LabelProvider implements ITableLabelProvider { + public Image getColumnImage (Object element, int columnIndex) { + return null; + } + public String getColumnText (Object element, int columnIndex) { + if(element instanceof InputOutput) { + InputOutput io = (InputOutput)element; + switch (columnIndex) { + case 0: return (String)io.getInput(String.class); + case 1: return (String)io.getOutput(String.class); + } + } + return ""; + } + } + + public void addLocation(Point2D location) { + tableRows.add(new InputOutput(location.getX(), location.getY())); + tableViewer.getTable().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + refresh(); + } + }); + + } + + public void removeItem(int index) { + tableRows.remove(index); + tableViewer.getTable().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + refresh(); + } + }); + } + + public void clearTable() { + this.tableRows.clear(); + tableViewer.getTable().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + refresh(); + } + }); + } + + + public class InputOutput { + private double input, output; + + public InputOutput(double input, double output) { + this.input = input; + this.output = output; + } + + /** + * + * @param clazz String.class or Double.class + * @return input as string or double or null if asked for something else + */ + @SuppressWarnings("rawtypes") + public Object getInput(Class clazz) { + if(clazz == String.class) { + return "" + input; + } else if (clazz == Double.class) { + return input; + } + return null; + } + + public Double setInput(String input) { + try { + this.input = Double.parseDouble(input); + return this.input; + } catch (NumberFormatException e) { + return null; + } + } + + public void setInput(double input) { + this.input = input; + } + + /** + * + * @param clazz String.class or Double.class + * @return output as string or double or null if asked for something else + */ + @SuppressWarnings("rawtypes") + public Object getOutput(Class clazz) { + if(clazz == String.class) { + return "" + output; + } else if (clazz == Double.class) { + return output; + } + return null; + } + + public void setOutput(String output) { + try { + this.output = Double.parseDouble(output); + } catch (NumberFormatException e) { + + } + } + + public void setOutput(double output) { + this.output = output; + } + + } + + public class InputOutputComparator extends ViewerComparator implements Comparator{ + @Override + public int compare(Viewer viewer, Object e1, Object e2) { + if ((e1 instanceof InputOutput) && + (e2 instanceof InputOutput)) { + return compare((InputOutput)e1, (InputOutput)e2); + } else { + return 0; + } + } + + @Override + public int compare(InputOutput e1, InputOutput e2) { + InputOutput io1 = (InputOutput)e1; + InputOutput io2 = (InputOutput)e2; + Double d1 = (Double)io1.getInput((Double.class)); + Double d2 = (Double)io2.getInput((Double.class)); + return d1.compareTo(d2); + } + } + + public TableViewer getTableViewer() { + return this.tableViewer; + } + + public void refresh() { + if(!tableViewer.getTable().isDisposed()) { + tableViewer.setComparator(new InputOutputComparator()); + tableViewer.refresh(); + } + } + + class InputOutputCellModifier implements ICellModifier { + + public InputOutputCellModifier() {} + + public boolean canModify(Object element, String property) { + return true; + } + + public Object getValue(Object element, String property) { + InputOutput io = (InputOutput)element; + if (LookupInputOutputTable.INPUT.equals(property)) + return (String)io.getInput(String.class); + else if (LookupInputOutputTable.OUTPUT.equals(property)) + return (String)io.getOutput(String.class); + else + return null; + } + + public void modify(Object element, String property, Object value) { + if (element instanceof Item) element = ((Item) element).getData(); + + InputOutput io = (InputOutput)element; + + if (LookupInputOutputTable.INPUT.equals(property)) { + io.setInput((String)value); + } else if (LookupInputOutputTable.OUTPUT.equals(property)) { + io.setOutput((String)value); + } + tableModified(); + refresh(); + } + } + + private void tableModified() { + tableViewer.getTable().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + for (Listener listener : getListeners(SWT.Modify)) { + Event e = new Event(); + listener.handleEvent(e); + } + } + }); + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ParameterExpression.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ParameterExpression.java new file mode 100644 index 00000000..bfa05b48 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ParameterExpression.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; + +public class ParameterExpression extends BasicExpression { + + + public ParameterExpression() { + try { + this.expressionType = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + return SysdynResource.getInstance(graph).ParameterExpression; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java new file mode 100644 index 00000000..96d833dc --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java @@ -0,0 +1,246 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.VerifyKeyListener; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.SysdynModel; +import org.simantics.sysdyn.manager.SysdynModelManager; +import org.simantics.sysdyn.representation.Stock; +import org.simantics.sysdyn.representation.Valve; +import org.simantics.ui.SimanticsUI; + +public class StockExpression implements IExpression { + + private Text integral; + private ExpressionField expression; + + @Override + public void createExpressionFields(Composite parent, Map data) { + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(parent); + String initialEquation = data.get("initialEquation") != null ? (String)data.get("initialEquation") : ""; + String integralEquation = data.get("integral") != null ? (String)data.get("integral") : ""; + + + Label label = new Label(parent, SWT.NONE); + label.setText("Integral"); + + integral = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER); + integral.setEditable(false); + integral.setText(integralEquation); + GridDataFactory.fillDefaults().grab(true, true).applyTo(integral); + + + label = new Label(parent, SWT.NONE); + label.setText("Initial\nValue"); + + expression = new ExpressionField(parent, SWT.BORDER); + expression.setExpression(initialEquation); + + GridDataFactory.fillDefaults().grab(true, true).applyTo(expression); + + } + + @Override + public void focus() { + this.expression.focus(); + } + + @Override + public List getExpressionFields() { + return Arrays.asList(this.expression); + } + + @Override + public void readData(final Resource expression, Map data) { + String initialEquation = null; + + if (expression != null && data.get("initialEquation") == null) { + try { + initialEquation = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if (graph.isInstanceOf(expression, sr.StockExpression)) { + String initialEquation = graph.getPossibleRelatedValue(expression, sr.HasInitialEquation); + return initialEquation != null ? initialEquation : ""; + } else { + return ""; + } + } + + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + data.put("initialEquation", initialEquation); + } + + data.put("integral", getIntegral(expression)); + + } + + @Override + public void replaceSelection(String var) { + if(expression != null) { + IDocument doc = expression.getDocument(); + try { + Point selection = expression.getSelection(); + doc.replace(selection.x, selection.y, var); + expression.setSelection(selection.x + var.length()); + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + } + + @Override + public void save(final Resource expression, Map data) { + final String currentText = this.expression.getExpression(); + if(currentText != null) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph g) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + Layer0 l0 = Layer0.getInstance(g); + + if(!g.isInstanceOf(expression, sr.StockExpression)) { + Resource expressionList = g.getSingleObject(expression, l0.HasNext); + Resource temp = g.newResource(); + OrderedSetUtils.replace(g, expressionList, expression, temp); + for(Resource predicate : g.getPredicates(expression)) { + g.deny(expression, predicate); + } + g.claim(expression, l0.InstanceOf, null, sr.StockExpression); + + Resource variable = g.getSingleObject(expressionList, sr.HasExpressions_Inverse); + OrderedSetUtils.replace(g, expressionList, temp, expression); + g.deny(expression, l0.PartOf); + g.claim(expression, l0.PartOf, variable); + } + g.claimLiteral(expression, sr.HasInitialEquation, currentText); + } + + }); + } + this.expression.setExpression(currentText); + } + + @Override + public void updateData(Map data) { + if(this.expression != null && this.expression.getExpression() != null) + data.put("initialEquation", this.expression.getExpression()); + if(this.integral != null && this.integral.getText() != null) + data.put("integral", this.integral.getText()); + } + + + private String getIntegral(final Resource expression) { + + String integral = ""; + if(expression == null) + return integral; + try { + integral = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + // find the variable + Resource expressionList = OrderedSetUtils.getSingleOwnerList(graph, expression); + Resource variable = graph.getPossibleObject(expressionList, sr.HasExpressions_Inverse); + if(variable == null) + return ""; + + SysdynModelManager sdm = SysdynModelManager.getInstance(graph.getSession()); + SysdynModel model = sdm.getModel(graph, graph.getSingleObject(variable, l0.PartOf)); + model.update(graph); + + Stock stock = (Stock)model.getElement(variable); + + String range = graph.getPossibleRelatedValue(expression, sr.HasArrayRange); + if(range == null) + range = ""; + + StringBuilder builder = new StringBuilder(); + builder.append(""); + for(Valve in : stock.getIncomingValves()) { + builder.append(" + " + in.getName() + range); + } + for(Valve out : stock.getOutgoingValves()) { + builder.append(" - " + out.getName() + range); + } + if (builder.indexOf(" + ") == 0) + builder.delete(0, 3); + + return builder.toString().trim(); + } + + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + return integral; + } + + @Override + public void addKeyListener(KeyListener listener) { + this.expression.getSourceViewer().getTextWidget().addKeyListener(listener); + + } + + @Override + public void addModifyListener(ModifyListener listener) { + this.expression.getSourceViewer().getTextWidget().addModifyListener(listener); + + } + + @Override + public void addFocusListener(FocusListener listener) { + this.expression.getSourceViewer().getTextWidget().addFocusListener(listener); + } + + @Override + public void addVerifyKeyListener(VerifyKeyListener listener) { + this.expression.getSourceViewer().getTextWidget().addVerifyKeyListener(listener); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java new file mode 100644 index 00000000..9af73a64 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java @@ -0,0 +1,408 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.expressions; + +import java.awt.BasicStroke; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.geom.Point2D; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import javax.swing.Timer; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.swt.SWT; +import org.eclipse.swt.awt.SWT_AWT; +import org.eclipse.swt.custom.VerifyKeyListener; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.tableParser.ParseException; +import org.simantics.sysdyn.tableParser.TableParser; +import org.simantics.sysdyn.tableParser.Token; +import org.simantics.ui.SimanticsUI; + +public class WithLookupExpression implements IExpression { + + private ExpressionField expression; + private ExpressionField lookup; + private ExpressionField lastSelectedText = expression; + private Timer updateChartTimer; + + private ChartPanel smallPanel; + private Frame smallFrame; + + private Resource expr; + + public WithLookupExpression(Resource expression) { + this.expr = expression; + } + + @Override + public void createExpressionFields(Composite parent, final Map data) { + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(parent); + + updateChartTimer = new Timer(1000, new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + updateChart(); + } + }); + updateChartTimer.setRepeats(false); + + String equation = data.get("equation") != null ? (String)data.get("equation") : ""; + String lookupTable = data.get("lookup") != null ? (String)data.get("lookup") : ""; + + Label l = new Label(parent, SWT.NONE); + l.setText("With\nLookup"); + + expression = new ExpressionField(parent, SWT.BORDER); + expression.setExpression(equation); + GridDataFactory.fillDefaults().grab(true, true).applyTo(expression); + + expression.getSourceViewer().getTextWidget().addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent e) { + lastSelectedText = expression; + } + }); + + Composite chartContainer = new Composite(parent, SWT.NONE); + createChart(chartContainer, data); + + + l = new Label(parent, SWT.NONE); + l.setText("Lookup\ntable"); + + lookup = new ExpressionField(parent, SWT.BORDER); + lookup.setExpression(lookupTable); + GridDataFactory.fillDefaults().grab(true, true).applyTo(lookup); + + lookup.getSourceViewer().getTextWidget().addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent e) { + lastSelectedText = lookup; + save(expr, data); + } + }); + + lookup.getSourceViewer().getTextWidget().addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + if(!updateChartTimer.isRunning()) + updateChartTimer.start(); + else + updateChartTimer.restart(); + } + }); + + + SimanticsUI.getSession().asyncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + String result = ""; + if (expr != null && graph.isInstanceOf(expr, sr.WithLookupExpression)) { + result = graph.getPossibleRelatedValue(expr, sr.HasLookup); + } + return result; + } + }, new Listener() { + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public void execute(final String result) { + if(lookup != null) + lookup.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + lookup.setExpression(result); + } + }); + updateChart(); + } + + @Override + public boolean isDisposed() { + if(lookup != null && !lookup.isDisposed()) { + return false; + } + return true; + } + }); + + updateChart(); + } + + @Override + public void focus() { + if(this.lastSelectedText != null) this.lastSelectedText.focus(); + } + + @Override + public List getExpressionFields() { + return Arrays.asList(this.expression, this.lookup); + } + + @Override + public void readData(final Resource expression, Map data) { + + class Auxiliary { + String equation, lookup; + } + + Auxiliary results = null; + + if (data.get("equation") == null) { + try { + results = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Auxiliary perform(ReadGraph graph) throws DatabaseException { + Auxiliary results = new Auxiliary(); + SysdynResource sr = SysdynResource.getInstance(graph); + if (expression != null && graph.isInstanceOf(expression, sr.WithLookupExpression)) { + results.equation = graph.getPossibleRelatedValue(expression, sr.HasEquation); + results.lookup = graph.getPossibleRelatedValue(expression, sr.HasLookup); + } else { + results.equation = ""; + results.lookup = ""; + } + return results; + } + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + data.put("equation", results.equation == null ? "" : results.equation); + data.put("lookup", results.lookup == null ? "" : results.lookup); + } + + } + + @Override + public void replaceSelection(String var) { + if(lastSelectedText != null) { + IDocument doc = lastSelectedText.getDocument(); + try { + Point selection = lastSelectedText.getSelection(); + doc.replace(selection.x, selection.y, var); + lastSelectedText.setSelection(selection.x + var.length()); + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + } + + @Override + public void save(final Resource expression, Map data) { + final String currentExpression = this.expression.getExpression(); + final String currentLookupTable = lookup.getExpression(); + String oldExpression = (String)data.get("equation"); + String oldLookupTable = (String)data.get("lookup"); + + if(oldExpression == null || oldLookupTable == null || + (currentExpression != null && currentLookupTable != null + && (!currentExpression.equals(oldExpression) || + !currentLookupTable.equals(oldLookupTable)))) { + data.putAll(data); + data.put("equation", currentExpression); + data.put("lookup", currentLookupTable); + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph g) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + Layer0 l0 = Layer0.getInstance(g); + + if(!g.isInstanceOf(expr, sr.WithLookupExpression)) { + + + Resource ownerList = OrderedSetUtils.getSingleOwnerList(g, expression); + final Resource newExpression = GraphUtils.create2(g, sr.WithLookupExpression, + sr.HasMinX, 0.0, + sr.HasMaxX, 10.0, + sr.HasMinY, 0.0, + sr.HasMaxY, 10.0); + String arrayRange = g.getPossibleRelatedValue(expression, sr.HasArrayRange, Bindings.STRING); + if(arrayRange != null) + g.claimLiteral(newExpression, sr.HasArrayRange, arrayRange); + + final Resource variable = g.getSingleObject(ownerList, sr.HasExpressions_Inverse); + OrderedSetUtils.replace(g, ownerList, expression, newExpression); + g.deny(expression, l0.PartOf); + g.claim(newExpression, l0.PartOf, variable); + + VirtualGraph runtime = g.getService(VirtualGraph.class); + g.syncRequest(new WriteRequest(runtime) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.hasStatement(variable, sr.HasActiveExpression)) + graph.deny(variable, sr.HasActiveExpression); + graph.claim(variable, sr.HasActiveExpression, newExpression); + } + } + ); + expr = newExpression; + + } + g.claimLiteral(expr, sr.HasEquation, currentExpression); + g.claimLiteral(expr, sr.HasLookup, currentLookupTable); + } + }); + } + + } + + @Override + public void updateData(Map data) { + if(this.expression != null && this.expression.getExpression() != null) + data.put("equation", this.expression.getExpression()); + if(this.lookup != null && this.lookup.getExpression() != null) + data.put("lookup", this.lookup.getExpression()); + } + + @Override + public void addKeyListener(KeyListener listener) { + this.expression.getSourceViewer().getTextWidget().addKeyListener(listener); + this.lookup.getSourceViewer().getTextWidget().addKeyListener(listener); + } + + @Override + public void addVerifyKeyListener(VerifyKeyListener listener) { + this.expression.getSourceViewer().getTextWidget().addVerifyKeyListener(listener); + this.lookup.getSourceViewer().getTextWidget().addVerifyKeyListener(listener); + } + + @Override + public void addModifyListener(ModifyListener listener) { + this.expression.getSourceViewer().getTextWidget().addModifyListener(listener); + this.lookup.getSourceViewer().getTextWidget().addModifyListener(listener); + } + + @Override + public void addFocusListener(FocusListener listener) { + this.expression.getSourceViewer().getTextWidget().addFocusListener(listener); + this.lookup.getSourceViewer().getTextWidget().addFocusListener(listener); + } + + private void createChart(Composite composite, final Map data) { + GridLayoutFactory.fillDefaults().applyTo(composite); + GridDataFactory.fillDefaults().span(1, 2).hint(150, SWT.DEFAULT).applyTo(composite); + final Composite chartComposite = new Composite(composite, + SWT.NO_BACKGROUND | SWT.EMBEDDED); + GridDataFactory.fillDefaults().grab(true, true).applyTo(chartComposite); + smallFrame = SWT_AWT.new_Frame(chartComposite); + + XYDataset dataset = new XYSeriesCollection(new XYSeries("Lookup Table")); + JFreeChart chart = createChart(dataset); + smallPanel = new ChartPanel(chart); + smallFrame.add(smallPanel); + + } + + private static JFreeChart createChart(XYDataset dataset) { + JFreeChart chart = ChartFactory.createXYLineChart( + null, + null, + null, + dataset, + PlotOrientation.VERTICAL, + true, + true, + false + ); + chart.removeLegend(); + chart.getXYPlot().getDomainAxis().setTickLabelsVisible(true); + chart.getXYPlot().getDomainAxis().setAxisLineVisible(false); + chart.getXYPlot().getDomainAxis().setTickMarksVisible(true); + chart.getXYPlot().getRangeAxis().setTickLabelsVisible(true); + chart.getXYPlot().getRangeAxis().setAxisLineVisible(false); + chart.getXYPlot().getRangeAxis().setTickMarksVisible(true); + chart.getXYPlot().getRenderer().setSeriesStroke(0, new BasicStroke(3.0f)); + return chart; + } + + private void updateChart() { + ArrayList dataPoints = new ArrayList(); + TableParser parser = new TableParser(new StringReader("")); + parser.ReInit(new StringReader(lookup.getExpression())); + try { + parser.table(); + ArrayList xTokens = parser.getXTokens(); + ArrayList yTokens = parser.getYTokens(); + for(int i = 0; i < xTokens.size(); i++) { + dataPoints.add(new Point2D.Double( + Double.parseDouble(xTokens.get(i).image), + Double.parseDouble(yTokens.get(i).image))); + } + } catch (ParseException e1) { + this.lookup.setSyntaxError(e1.currentToken, "Syntax Error"); + System.out.println("MESSAGE: " + e1.getMessage()); + return; + } + + XYSeries series = new XYSeries("Lookup Table"); + for(Point2D point : dataPoints) { + series.add(point.getX(), point.getY()); + } + XYSeriesCollection dataset = new XYSeriesCollection(series); + smallPanel.getChart().getXYPlot().setDataset(dataset); + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFileImager.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFileImager.java new file mode 100644 index 00000000..9af9a0d0 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFileImager.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.externalFiles; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.swt.ImagerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; + +public class ExternalFileImager extends ImagerContributor { + + @Override + public ImageDescriptor getDescriptor(ReadGraph graph, ExternalFileNode input) + throws DatabaseException { + return null; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFileLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFileLabeler.java new file mode 100644 index 00000000..ee94d5ad --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFileLabeler.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.externalFiles; + +import org.simantics.browsing.ui.graph.impl.contributor.labeler.LabelerContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; + +public class ExternalFileLabeler extends LabelerContributorImpl{ + + @Override + public String getLabel(ReadGraph graph, ExternalFileNode input) + throws DatabaseException { + return NameUtils.getSafeName(graph, input.data); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFileNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFileNode.java new file mode 100644 index 00000000..726ab4ac --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFileNode.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.externalFiles; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.DeleteException; +import org.simantics.browsing.ui.common.node.IDeletableNode; +import org.simantics.browsing.ui.common.node.IModifiableNode; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.db.request.Write; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.ui.SimanticsUI; + +public class ExternalFileNode extends AbstractNode implements IModifiableNode, IDeletableNode { + + public ExternalFileNode(Resource data) { + super(data); + } + + @Override + public Modifier getModifier(String columnId) { + try { + final Resource hasName = Layer0.getInstance(SimanticsUI.getSession()).HasName; + LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data, hasName) { + @Override + public String isValid(String label) { + if (label.isEmpty()) + return "Empty label not allowed"; + if (label.contains(" ")) + return "Spaces are not allowed"; + return null; + } + + @Override + protected Write getWriteRequest(final String label) { + return new WriteRequest() { + @Override + public void perform(WriteGraph g) throws DatabaseException { + FunctionUtils.removeExternalFunctionFile(g, data); + g.claimLiteral(data, hasName, label); + FunctionUtils.createExternalFunctionFile(g, data); + } + }; + } + }; + return modifier; + } catch (DatabaseException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void delete() throws DeleteException { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + FunctionUtils.removeExternalFunctionFile(graph, data); + RemoverUtil.remove(graph, data); + } + }); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFiles.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFiles.java new file mode 100644 index 00000000..59ad535e --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/externalFiles/ExternalFiles.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.externalFiles; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; + +public class ExternalFiles extends ViewpointContributorImpl { + + @Override + public Collection getContribution(ReadGraph graph, Resource input) + throws DatabaseException { + + if(input == null) + return null; + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + ArrayList result = new ArrayList(); + for(Resource r : graph.syncRequest(new ObjectsWithType(input, l0.ConsistsOf, sr.ExternalFunctionFile))) { + result.add(new ExternalFileNode(r)); + } + + return result; + } + + @Override + public String getViewpointId() { + return "External Files"; + } + + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java new file mode 100644 index 00000000..a029acd3 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.factories; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Combo; +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener; +import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.utils.ReflectionUtils; +import org.simantics.utils.ui.ISelectionUtils; + +abstract public class ComboStringPropertyModifier implements TextModifyListener, Widget { + + private ISessionContext context; + private Object lastInput = null; + + final private Class clazz; + + public ComboStringPropertyModifier() { + clazz = ReflectionUtils.getSingleParameterType(getClass()); + } + + @Override + public void setInput(ISessionContext context, Object input) { + this.context = context; + lastInput = input; + } + + @Override + public void modifyText(TrackedModifyEvent e) { + Combo text = (Combo)e.getWidget(); + final String textValue = text.getText(); + final Object input = lastInput; + + try { + context.getSession().syncRequest(new WriteRequest() { + + @SuppressWarnings("unchecked") + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + T single = (T) ISelectionUtils.filterSingleSelection((ISelection)input, clazz); + applyText(graph, single, textValue); + + } + + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + + } + + abstract public void applyText(WriteGraph graph, T input, String text) throws DatabaseException; + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/DoublePropertyFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/DoublePropertyFactory.java new file mode 100644 index 00000000..1cc23fe2 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/DoublePropertyFactory.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.factories; + +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.utils.datastructures.Triple; + +public class DoublePropertyFactory extends ReadFactoryImpl { + + final private String propertyURI; + + public DoublePropertyFactory(String propertyURI) { + this.propertyURI = propertyURI; + } + + @Override + public Object getIdentity(Object inputContents) { + return new Triple((Resource)inputContents, propertyURI, getClass()); + } + + @Override + public String perform(ReadGraph graph, Resource issue) throws DatabaseException { + + Double value = graph.getPossibleRelatedValue(issue, graph.getResource(propertyURI)); + if (value != null) + return value.toString(); + else + return ""; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/DoublePropertyModifier.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/DoublePropertyModifier.java new file mode 100644 index 00000000..58dc654e --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/DoublePropertyModifier.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.factories; + +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; + +public class DoublePropertyModifier extends TextModifyListenerImpl { + + final private String propertyURI; + + public DoublePropertyModifier(ISessionContext context, String propertyURI) { + this.propertyURI = propertyURI; + } + + @Override + public void applyText(WriteGraph graph, Resource input, String text) throws DatabaseException { + if (text == null || text.equals("")) { + if(graph.hasStatement(input, graph.getResource(propertyURI))) + graph.deny(input, graph.getResource(propertyURI)); + } else { + graph.claimLiteral(input, graph.getResource(propertyURI), Double.parseDouble(text), Bindings.DOUBLE); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNamePropertyModifier.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNamePropertyModifier.java new file mode 100644 index 00000000..eba5f967 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNamePropertyModifier.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.factories; + +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.ui.utils.VariableNameUtils; + +public class VariableNamePropertyModifier extends TextModifyListenerImpl { + + final private String propertyURI; + + public VariableNamePropertyModifier(ISessionContext context, String propertyURI) { + this.propertyURI = propertyURI; + } + + /** + * Overrides the original applyText. Renames variables also in equations in the same configuration. + */ + @Override + public void applyText(WriteGraph graph, Resource variable, String text) throws DatabaseException { + + // TODO: separate possible array indexes + + // TODO: add enumerations to the variable + String originalName = graph.getRelatedValue(variable, Layer0.getInstance(graph).HasName); + VariableNameUtils.renameInEquations(graph, variable, originalName, text); + graph.claimLiteral(variable, graph.getResource(propertyURI), text, Bindings.STRING); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNameValidator.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNameValidator.java new file mode 100644 index 00000000..9d635e71 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNameValidator.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.factories; + +import org.eclipse.jface.dialogs.IInputValidator; +import org.eclipse.jface.viewers.ISelection; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.Resource; +import org.simantics.db.management.ISessionContext; +import org.simantics.sysdyn.ui.utils.VariableNameUtils; +import org.simantics.utils.ui.ISelectionUtils; + +public class VariableNameValidator implements IInputValidator, Widget { + + private Resource lastInput = null; + + public VariableNameValidator(WidgetSupport support) { + support.register(this); + } + + /** + * Checks that the syntax of the given name is valid and there + * are no other components that have the same name in the configuration. + */ + @Override + public String isValid(final String newText) { + if (!VariableNameUtils.isValid(lastInput, newText, true)) + return "Not valid"; + else + return null; + /* + if(lastInput == null) return null; + String result = null; + try { + result = SimanticsUI.getSession().syncRequest(new Read(){ + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + if(VariableNameUtils.nameIsTaken(graph, lastInput, newText)) { + return "Name is taken."; + } + return null; + } + + }) ; + } catch (DatabaseException e) { + e.printStackTrace(); + } + return result; + */ + + } + + @Override + public void setInput(ISessionContext context, Object input) { + lastInput = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java new file mode 100644 index 00000000..7c07e305 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java @@ -0,0 +1,205 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.functions; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.StringReader; + +import javax.swing.Timer; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.custom.VerifyKeyListener; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Listener; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.modelParser.ModelParser; +import org.simantics.sysdyn.modelParser.ParseException; +import org.simantics.sysdyn.modelParser.Token; +import org.simantics.sysdyn.modelParser.TokenMgrError; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionField; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +public class FunctionCodeWidget implements Widget { + + private ExpressionField modelicaCode; + private Resource function; + + private Timer updateChartTimer; + private static int VALIDATION_DELAY_TIME = 500; + + public FunctionCodeWidget(Composite parent, WidgetSupport support, int style) { + support.register(this); + + modelicaCode = new ExpressionField(parent, SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, true).applyTo(modelicaCode); + + + // Support shift+enter for line change + modelicaCode.getSourceViewer().getTextWidget().addVerifyKeyListener(new VerifyKeyListener() { + + @Override + public void verifyKey(VerifyEvent event) { + if(event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) { + if((event.stateMask & SWT.SHIFT) == 0) { + event.doit = false; + Listener[] listeners = modelicaCode.getSourceViewer().getTextWidget().getListeners(SWT.FocusOut); + for(Listener l : listeners) { + modelicaCode.getSourceViewer().getTextWidget().removeListener(SWT.FocusOut, l); + } + ((StyledText)event.widget).getParent().forceFocus(); + save(); + for(Listener l : listeners) { + modelicaCode.getSourceViewer().getTextWidget().addListener(SWT.FocusOut, l); + } + + } + } + } + }); + + + modelicaCode.getSourceViewer().getTextWidget().addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + validateFieldsTimed(); + } + }); + + modelicaCode.getSourceViewer().getTextWidget().addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + save(); + } + }); + + + updateChartTimer = new Timer(VALIDATION_DELAY_TIME, new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if(modelicaCode == null || modelicaCode.isDisposed()) + return; + modelicaCode.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + validate(); + } + }); + } + }); + updateChartTimer.setRepeats(false); + } + + @Override + public void setInput(ISessionContext context, Object input) { + function = AdaptionUtils.adaptToSingle(input, Resource.class); + + try { + String code = context.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + String code = graph.getPossibleRelatedValue( + function, SysdynResource.getInstance(graph).HasModelicaFunctionCode); + return code; + } + + }); + if(code != null) { + modelicaCode.setExpression(code); + validate(); + } + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + + public void validateFieldsTimed() { + validateFieldsTimed(VALIDATION_DELAY_TIME); + } + + public void validateFieldsTimed(int delay) { + updateChartTimer.setDelay(delay); + if(!updateChartTimer.isRunning()) + updateChartTimer.start(); + else + updateChartTimer.restart(); + } + + public void validate() { + modelicaCode.resetAnnotations(); + String code = modelicaCode.getExpression(); + StringReader sr = new StringReader(code); + ModelParser modelParser = new ModelParser(sr); + try { + modelParser.parse_composition(); + } catch (ParseException e1) { + Token token = e1.currentToken; + modelicaCode.setSyntaxError(token.image, "Syntax error", token.beginLine, token.beginColumn, token.endLine, token.endColumn); + } catch (TokenMgrError err) { + String message = err.getMessage(); + String line = message.substring(0, message.indexOf(",")); + line = line.substring(line.lastIndexOf(" ") + 1); + String column = message.substring(message.indexOf(",") + 1, message.indexOf(".")); + column = column.substring(column.lastIndexOf(" ") + 1); + try { + Integer endLine = Integer.parseInt(line); + Integer endColumn = Integer.parseInt(column); + Token token = modelParser.token; + modelicaCode.setSyntaxError(token.image, "Syntax error", token.endLine, token.endColumn, endLine, endColumn); + } catch (NumberFormatException e) { + + } + + } + } + + private void save() { + final String code = modelicaCode.getExpression(); + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.claimLiteral( + function, + SysdynResource.getInstance(graph).HasModelicaFunctionCode, + code); + Resource library = graph.getSingleObject(function, Layer0.getInstance(graph).PartOf); + FunctionUtils.updateFunctionFileForLibrary(graph, library); + } + }); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SelectedSharedFunctionLibraries.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SelectedSharedFunctionLibraries.java new file mode 100644 index 00000000..255555b9 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SelectedSharedFunctionLibraries.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.functions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode; + +public class SelectedSharedFunctionLibraries extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, Resource input) + throws DatabaseException { + ArrayList> result = new ArrayList>(); + + + for(Resource sharedLibrary : graph.syncRequest(new ObjectsWithType( + input, + Layer0.getInstance(graph).IsLinkedTo, + SysdynResource.getInstance(graph).SharedFunctionOntology))) + { + result.add(new SharedFunctionLibraryNode(sharedLibrary)); + } + + return result; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SharedFunctionLibraries.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SharedFunctionLibraries.java new file mode 100644 index 00000000..70dbb6f7 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/SharedFunctionLibraries.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties.widgets.functions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode; + +public class SharedFunctionLibraries extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, Resource input) + throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + + ArrayList> result = new ArrayList>(); + + // Find shared ontologies. graph.getPossibleResource("http://SharedOntologies") does not update if it was null for the first time. + Resource sharedOntologies = null; + Resource root = input; + while(graph.getPossibleObject(root, l0.PartOf) != null) + root = graph.getPossibleObject(root, l0.PartOf); + + for(Resource r : graph.getObjects(root, l0.ConsistsOf)) { + if("SharedOntologies".equals(NameUtils.getSafeName(graph, r))) { + sharedOntologies = r; + break; + } + } + + if(sharedOntologies == null) { + return result; + } + + // Find all shared function ontologies. + // (Don't know why ObjectsWithType works only the first time, then gives nothing) + ArrayList sharedFunctionLibraries = new ArrayList(); + for(Resource r : graph.getObjects(sharedOntologies, l0.ConsistsOf)) { + if(graph.isInstanceOf(r, sr.SharedFunctionOntology)) + sharedFunctionLibraries.add(r); + } + + // Find all shared function ontologies that have already been selected + Collection selectedSharedFunctionLibraries = graph.syncRequest(new ObjectsWithType( + input, l0.IsLinkedTo, sr.SharedFunctionOntology)); + + // Remove all selected ontologies from the shared function ontologies + sharedFunctionLibraries.removeAll(selectedSharedFunctionLibraries); + + for(Resource ontology : sharedFunctionLibraries) { + result.add(new SharedFunctionLibraryNode(ontology)); + } + + return result; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationModelContributor.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationModelContributor.java new file mode 100644 index 00000000..72a68e33 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationModelContributor.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.property; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; + +public class OperationModelContributor extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, OperationModelNode model) throws DatabaseException { + + Variable modelVariable = model.data; + Variable config = modelVariable.getChild(graph, "BaseRealization"); + ArrayList result = new ArrayList(); + result.addAll(config.browseChildren(graph)); + return result; + + } + + @Override + public String getViewpointId() { + return "Standard"; + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationModelLabels.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationModelLabels.java new file mode 100644 index 00000000..04667c43 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationModelLabels.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.property; + +import java.util.Map; + +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.graph.contributor.labeler.ColumnLabelerContributor; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.utils.datastructures.ArrayMap; + +public class OperationModelLabels extends ColumnLabelerContributor { + + @Override + public Map getLabel(ReadGraph graph, OperationModelNode model) throws DatabaseException { + + String label = model.data.getPropertyValue(graph, "Name", Bindings.STRING); + + return new ArrayMap(new String[] { ColumnKeys.SINGLE } , new String[] { label }); + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationModelNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationModelNode.java new file mode 100644 index 00000000..e44e1957 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationModelNode.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.property; + +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.common.imagers.ImageURLs; +import org.simantics.browsing.ui.common.imagers.SingleImageURLs; +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.sysdyn.ui.Activator; + +public class OperationModelNode extends AbstractNode { + + public OperationModelNode(Variable data) { + super(data); + } + + @Override + protected ImageURLs getImageURLs() { + return new SingleImageURLs(ColumnKeys.SINGLE, Activator.getDefaultResource("icons/chart_organisation.png")); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationProjectContributor.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationProjectContributor.java new file mode 100644 index 00000000..6d9a27e9 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationProjectContributor.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.property; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.Tester; +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.browsing.ui.graph.tester.GraphTesters; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.layer0.Layer0; +import org.simantics.project.ontology.ProjectResource; +import org.simantics.simulation.ontology.SimulationResource; + +public class OperationProjectContributor extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, Resource project) throws DatabaseException { + + ArrayList result = new ArrayList(); + for(Resource model : graph.syncRequest(new ObjectsWithType(project, Layer0.getInstance(graph).ConsistsOf, SimulationResource.getInstance(graph).Model))) { + result.add(new OperationModelNode(graph.adapt(model, Variable.class))); + } + return result; + + } + + @Override + public Tester getNodeContextTester() { + + return GraphTesters.type(ProjectResource.URIs.Project); + } + + @Override + public String getViewpointId() { + return "Standard"; + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationVariableContributor.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationVariableContributor.java new file mode 100644 index 00000000..35499be5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationVariableContributor.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.property; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; + +public class OperationVariableContributor extends ViewpointContributorImpl { + + @Override + public Collection getContribution(ReadGraph graph, Variable input) throws DatabaseException { + ArrayList result = new ArrayList(); + result.addAll(input.browseProperties(graph)); + result.addAll(input.browseChildren(graph)); + return result; + } + + @Override + public String getViewpointId() { + return "Properties"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationVariableImager.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationVariableImager.java new file mode 100644 index 00000000..cbb5394a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationVariableImager.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.property; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.swt.ImagerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.modeling.ui.Activator; + +public class OperationVariableImager extends ImagerContributor { + + @Override + public ImageDescriptor getDescriptor(ReadGraph graph, Variable var) throws DatabaseException { + return Activator.BULLET_GREEN_ICON; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationVariableLabels.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationVariableLabels.java new file mode 100644 index 00000000..bdcd46d9 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/property/OperationVariableLabels.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.property; + +import java.util.Map; + +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.graph.contributor.labeler.ColumnLabelerContributor; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.utils.datastructures.ArrayMap; + +public class OperationVariableLabels extends ColumnLabelerContributor { + + @Override + public Map getLabel(ReadGraph graph, Variable variable) throws DatabaseException { + + String label = variable.getPropertyValue(graph, "Name", Bindings.STRING); + + return new ArrayMap(new String[] { ColumnKeys.SINGLE } , new String[] { label }); + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartDropTarget.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartDropTarget.java new file mode 100644 index 00000000..f641a3c7 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartDropTarget.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DropTargetAdapter; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.widgets.Display; +import org.simantics.db.Resource; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Drop target for dropping charts in chart panel + * @author Teemu Lempinen + * + */ +public class ChartDropTarget extends DropTargetAdapter { + + private ChartPanelSeparator separator; + private ChartPanelElement element; + private Display display; + private ChartPanel panel; + + public ChartDropTarget(ChartPanelSeparator separator, ChartPanelElement element, ChartPanel panel) { + this.separator = separator; + this.display = separator.getDisplay(); + this.element = element; + this.panel = panel; + } + + + + /** + * Display effect on the composite when drag entered + */ + @Override + public void dragEnter(DropTargetEvent event) { + if ((event.operations & DND.DROP_COPY) != 0) { + event.detail = DND.DROP_COPY; + } else if ((event.operations & DND.DROP_MOVE) != 0) { + event.detail = DND.DROP_MOVE; + } else { + event.detail = DND.DROP_NONE; + } + separator.setBackground(display.getSystemColor(SWT.COLOR_DARK_GRAY)); + } + + /** + * Revert effect when drag leaves + */ + @Override + public void dragLeave(DropTargetEvent event) { + separator.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); + } + + /** + * Drop the data to chart panel + */ + @Override + public void drop(DropTargetEvent event) { + Resource chartResource = AdaptionUtils.adaptToSingle(event.data, Resource.class); + if(chartResource != null) + panel.addChart(chartResource, element); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java new file mode 100644 index 00000000..a82b6c29 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java @@ -0,0 +1,460 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend; + +import java.util.ArrayList; +import java.util.LinkedHashMap; + +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DropTarget; +import org.eclipse.swt.dnd.DropTargetAdapter; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.IViewSite; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.part.ViewPart; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncListener; +import org.simantics.db.request.Read; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.dnd.LocalObjectTransfer; +import org.simantics.utils.RunnableWithObject; + +/** + * Chart panel displays multiple charts in a single view. The view can be oriented + * vertically or horizontally, the default is vertical. Charts can be added, removed + * minimized or expanded. The order of the charts can be changed by dragging the charts. + * + * @author Teemu Lempinen + * + */ +public class ChartPanel extends ViewPart { + + private Composite body; + private ScrolledComposite sc; + + private IDialogSettings settings; + private LinkedHashMap charts; + private ArrayList minimizedResources; + + private ArrayList chartElements; + + public static final String CHART_PANEL_SETTINGS = "CHART_PANEL_SETTINGS"; + public static final String CHARTS = "CHART_PANEL_CHARTS"; + public static final String MINIMIZED_CHARTS = "CHART_PANEL_MINIMIZED_CHARTS"; + public static final String CHART_PANEL_ORIENTATION = "CHART_PANEL_ORIENTATION"; + + public static final String CHART_PANEL_VERTICAL = "CHART_PANEL_ORIENTATION_VERTICAL"; + public static final String CHART_PANEL_HORIZONTAL = "CHART_PANEL_ORIENTATION_HORIZONTAL"; + + private boolean vertical = true; + + /** + * Initialize the view. Load charts that have previously been open (if there are any). + */ + @Override + public void init(IViewSite site, IMemento memento) throws PartInitException { + super.init(site, memento); + + minimizedResources = new ArrayList(); + + settings = Activator.getDefault().getDialogSettings().getSection(CHART_PANEL_SETTINGS); + + // Initialize settings if there are no settings + if (settings == null) { + settings = Activator.getDefault().getDialogSettings().addNewSection(CHART_PANEL_SETTINGS); + } + + if(settings.getArray(CHARTS) == null) { + String[] chartUris = new String[] {}; + settings.put(CHARTS, chartUris); + } + + if(settings.getArray(MINIMIZED_CHARTS) == null) { + String[] minimizedChartUris = new String[] {}; + settings.put(MINIMIZED_CHARTS, minimizedChartUris); + } + + // initialize chart lists + charts = new LinkedHashMap(); + + // add chart resources to chart lists from settings + try { + SimanticsUI.getSession().syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Resource chart = null; + String[] chartURIs = settings.getArray(CHARTS); + for(String uri : chartURIs) { + chart = graph.getPossibleResource(uri); + if(chart != null && graph.isInstanceOf(chart, jfree.Chart)) { + charts.put(chart, null); + setChartExistingListener(chart); + } + } + + String[] minimizedUris = settings.getArray(MINIMIZED_CHARTS); + for(String uri : minimizedUris) { + chart = graph.getPossibleResource(uri); + if(chart != null && graph.isInstanceOf(chart, jfree.Chart)) { + minimizedResources.add(chart); + } + } + } + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + + // set the orientation of the panel + String orientation = settings.get(CHART_PANEL_ORIENTATION); + if(CHART_PANEL_VERTICAL.equals(orientation)) + this.vertical = true; + else if(CHART_PANEL_HORIZONTAL.equals(orientation)) + this.vertical = false; + + } + + /** + * Create a scrolled composite that will contain all the charts, then call the actual + * content creator. + */ + @Override + public void createPartControl(Composite parent) { + sc = new ScrolledComposite(parent, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL); + GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(sc); + GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); + sc.setExpandHorizontal(true); + sc.setExpandVertical(true); + sc.getVerticalBar().setIncrement(sc.getVerticalBar().getIncrement()*3); + sc.getHorizontalBar().setIncrement(sc.getHorizontalBar().getIncrement()*3); + setupDropTarget(); + + body = new Composite(sc, SWT.NONE); + GridLayoutFactory.fillDefaults().margins(3, 0).spacing(0, 0).applyTo(body); + GridDataFactory.fillDefaults().grab(true, true).applyTo(body); + + sc.setContent(body); + createContents(); + } + + /** + * Creates the contents of this chart panel. + * Removes all old contents before creating new content + */ + private void createContents() { + chartElements = new ArrayList(); + + for(Control child : body.getChildren()) { + child.dispose(); + } + + // Set the initial layout + ElementContainer elementHolder; + for(Resource e : charts.keySet()) { + elementHolder = new ElementContainer(body, SWT.NONE); + elementHolder.setBackground(new Color(elementHolder.getDisplay(), 255, 0, 0)); + ChartPanelElement element = new ChartPanelElement(elementHolder, this, e, SWT.NONE); + elementHolder.setLayout(GridLayoutFactory.copyLayout((GridLayout)element.getLayout())); + chartElements.add(element); + charts.put(e, element); + if(minimizedResources.contains(e)) { + element.toggleMinimize(); + } + } + + elementHolder = new ElementContainer(body, SWT.NONE); + elementHolder.setBackground(new Color(elementHolder.getDisplay(), 0, 255, 0)); + ChartPanelElement element = new ChartPanelElement(elementHolder, this, null, SWT.NONE); // Last element is empty -> only the separator + elementHolder.setLayout(GridLayoutFactory.copyLayout((GridLayout)element.getLayout())); + chartElements.add(element); + + layout(); + saveState(); + + } + + /** + * Lays out this panel (the body composite) + */ + public void layout() { + if(vertical) { + GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(body); + GridDataFactory.fillDefaults().grab(true, true).applyTo(body); + } else { + // Need to calculate horizontal elements for gridLayout + int chartPanels = chartElements.size(); + GridLayoutFactory.fillDefaults().spacing(0, 0).numColumns(chartPanels).applyTo(body); + GridDataFactory.fillDefaults().grab(true, true).applyTo(body); + } + body.layout(); + sc.setMinSize(body.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + } + + @Override + public void setFocus() { + if(!sc.isDisposed()) + sc.setFocus(); + } + + @Override + public void saveState(IMemento memento) { + super.saveState(memento); + saveState(); + } + + /** + * Save the current state of the view to IDialogSettings + */ + public void saveState() { + try { + SimanticsUI.getSession().syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + if (settings != null) { + String[] uris = new String[chartElements.size() - 1]; + ArrayList minimized = new ArrayList(); + minimizedResources.clear(); + for(int i = 0; i < uris.length; i++) { + ChartPanelElement e = chartElements.get(i); + Resource r = e.getResource(); + if(r != null) { + uris[i] = graph.getURI(r); + if(e.isMinimized()) { + minimized.add(uris[i]); + minimizedResources.add(r); + } + } else { + uris[i] = ""; + } + } + settings.put(CHARTS, uris); + if(!minimized.isEmpty()) + settings.put(MINIMIZED_CHARTS, minimized.toArray(new String[minimized.size()])); + else + settings.put(MINIMIZED_CHARTS, new String[0]); + + if(vertical) + settings.put(CHART_PANEL_ORIENTATION, CHART_PANEL_VERTICAL); + else + settings.put(CHART_PANEL_ORIENTATION, CHART_PANEL_HORIZONTAL); + } + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + /** + * Set the orientation for this chart panel. + * + * @param orientation Orientation (ChartPanel.CHART_PANEL_VERTICAL or ChartPanel.CHART_PANEL_HORIZONTAL) + */ + public void setOrientation(String orientation) { + if(CHART_PANEL_VERTICAL.equals(orientation)) + this.vertical = true; + else { + this.vertical = false; + } + createContents(); + } + + /** + * Removes a chart from this panel + * + * @param chart The chart to be removed + */ + public void removeChart(Resource chart) { + ChartPanelElement element = charts.get(chart); + chartElements.remove(element); + element.getParent().dispose(); + charts.remove(chart); + minimizedResources.remove(chart); + saveState(); + layout(); + } + + /** + * Sets up drag-scrolling for a scrolled composite + * + * @param control + */ + protected void setupDropTarget() { + DropTarget target = new DropTarget(sc, DND.DROP_MOVE); + target.setTransfer(new Transfer[] { LocalObjectTransfer.getTransfer() }); + + target.addDropListener(new DropTargetAdapter() { + + private int activeMargin = 20; + private int moveAmount = 1; + + @Override + public void dragOver(DropTargetEvent event) { + Point original = sc.getOrigin(); + Point origin = sc.getOrigin(); + Point pointer = sc.toControl(event.x, event.y); + Rectangle bounds = sc.getBounds(); + + if(pointer.y < activeMargin) + origin.y = origin.y - moveAmount; + else if(bounds.height - pointer.y < activeMargin) + origin.y = origin.y + moveAmount; + if(pointer.x < activeMargin) + origin.x = origin.x - moveAmount; + else if(bounds.width - pointer.x < activeMargin) + origin.x = origin.x + moveAmount; + + if(origin != original) { + sc.setOrigin (origin.x, origin.y); + sc.redraw(); + } + } + + }); + + } + + /** + * Is the panel vertically oriented + * @return Is the panel vertically oriented + */ + public boolean isVertical() { + return vertical; + } + + /** + * Adds chart after given element. If element == null, adds chart to the top. + * + * @param element To which place the chart will be placed. (null allowed) + */ + public void addChart(Resource chartResource, ChartPanelElement element) { + addChart(chartResource, element, true); + } + + /** + * Adds chart after given element. If element == null, adds chart to the top. + * + * @param element To which place the chart will be placed. (null allowed) + * @param layout refresh layout. use with vertical layout. + */ + public void addChart(Resource chartResource, ChartPanelElement element, boolean layout) { + int index = chartElements.indexOf(element); + if(index >= 0) { + ChartPanelElement e = chartElements.get(index); + ChartPanelElement newElement; + + if(charts.containsKey(chartResource)) { + // Old element being moved to a new place + newElement = charts.get(chartResource); + int oldIndex = chartElements.indexOf(newElement); + if(newElement.equals(element) || oldIndex == index - 1) + return; // Not moving anywhere, do nothing + Composite oldParent = newElement.getParent(); + newElement.setParent(e.getParent()); + oldParent.dispose(); + if(oldIndex < index) + index--; + chartElements.remove(newElement); + } else { + newElement = new ChartPanelElement(e.getParent(), this, chartResource, SWT.NONE); + } + + // Add a new chart element to the location of the old element + chartElements.add(index, newElement); + charts.put(chartResource, newElement); + + ElementContainer elementHolder; + // Move elements back after index + for(int i = index + 1 /*indexes after the new element*/; i < chartElements.size(); i++) { + e = chartElements.get(i); + if(i == chartElements.size() - 1) { + // last element (the empty element) element to a new container + elementHolder = new ElementContainer(body, SWT.NONE); + elementHolder.setBackground(new Color(elementHolder.getDisplay(), 0, 0, 255)); + elementHolder.setLayout(GridLayoutFactory.copyLayout((GridLayout)e.getLayout())); + e.setParent(elementHolder); + } else { + // element to the next elements container + elementHolder = (ElementContainer)chartElements.get(i + 1).getParent(); + e.setParent(elementHolder); + } + } + + layout(); + saveState(); + } + } + + /** + * Set a listener to listen if the chart resource has been removed. + * If the resource has been removed, close also the chart element in this panel. + * + * @param chart Listened chart resource + */ + private void setChartExistingListener(final Resource chart) { + SimanticsUI.getSession().asyncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + return graph.hasStatement(chart); + } + }, new AsyncListener() { + + boolean disposed = false; + + @Override + public void execute(AsyncReadGraph graph, Boolean result) { + if(result != null && result == false && body != null && !body.isDisposed()) { + body.getDisplay().asyncExec(new RunnableWithObject(chart){ + public void run() { + removeChart((Resource)getObject()); + } + }) ; + disposed = true; + } + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return !disposed && !charts.containsKey(chart); + } + }); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelElement.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelElement.java new file mode 100644 index 00000000..5c830dc5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelElement.java @@ -0,0 +1,188 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DropTarget; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.simantics.db.Resource; +import org.simantics.sysdyn.ui.trend.chart.ChartComposite; +import org.simantics.ui.dnd.LocalObjectTransfer; + +/** + * This class represents an expanded chart element in {@link ChartPanel}. It contains + * a header {@link ChartPanelHeader} and the actual chart. + * + * @author Teemu Lempinen + * + */ +public class ChartPanelElement extends Composite { + + public static int CHART_MINIMUM_WIDTH = 300; + public static int CHART_MINIMUM_HEIGHT = 200; + + private ChartPanel panel; + private ChartComposite chartComposite; + private Resource chartResource; + private boolean minimized = false; + + public Resource getResource() { + return chartResource; + } + + @Override + public Object getLayoutData () { + checkWidget(); + Object oldData = super.getLayoutData(); + if(oldData == null || !(oldData instanceof GridData)) { + oldData = GridDataFactory.fillDefaults().create(); + } + + GridData data = (GridData) oldData; + // Horizontal data + data.widthHint = CHART_MINIMUM_WIDTH; + if(chartResource == null && !panel.isVertical()){ + data.grabExcessHorizontalSpace = false; + data.widthHint = SWT.DEFAULT; + } else if(minimized && !panel.isVertical()) { + data.grabExcessHorizontalSpace = false; + data.widthHint = SWT.DEFAULT; + } else { + data.grabExcessHorizontalSpace = true; + } + + // Vertical data + if(!minimized && getResource() != null) { + data.grabExcessVerticalSpace = true; + data.heightHint = CHART_MINIMUM_HEIGHT; + } else if(!panel.isVertical()){ + data.grabExcessVerticalSpace = true; + } else { + data.grabExcessVerticalSpace = false; + data.heightHint = SWT.DEFAULT; + } + return data; + } + + /** + * Creates an expanded chart panel element into parent composite. + * + * @param parent The parent composite where the chart element is created + * @param panel The {@link ChartPanel} containing the chart element + * @param name The name of the chart + * @param style The Style of the created chart element + */ + public ChartPanelElement(Composite parent, ChartPanel panel, Resource chartResource, int style) { + this(parent, panel, chartResource, false, style); + } + + /** + * Creates a chart panel element into parent composite. + * @param parent The parent composite where the chart element is created + * @param panel The {@link ChartPanel} containing the chart element + * @param name The name of the chart + * @param minimized Is the chart-section minimized + * @param style The Style of the created chart element + */ + public ChartPanelElement(Composite parent, ChartPanel panel, Resource chartResource, boolean minimized, int style) { + super(parent, style | SWT.NONE); + + this.panel = panel; + this.chartResource = chartResource; + this.minimized = minimized; + + if(panel.isVertical() || getResource() == null) + GridLayoutFactory.fillDefaults().spacing(0,0).applyTo(this); + else + GridLayoutFactory.fillDefaults().numColumns(2).spacing(0,0).applyTo(this); + + GridDataFactory.fillDefaults().applyTo(this); + + // Separator for dropping other elements + ChartPanelSeparator separator = new ChartPanelSeparator(this, panel, this, SWT.NONE); + + if (chartResource != null) { + Composite c = new Composite(this, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(c); + GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(c); + // Header + new ChartPanelHeader(c, this, chartResource, SWT.BORDER); + + // Chart + chartComposite = new ChartComposite(c, chartResource, SWT.BORDER); + } + + DropTarget target = new DropTarget(this, DND.DROP_COPY | DND.DROP_MOVE); + target.setTransfer(new Transfer[] { LocalObjectTransfer.getTransfer() }); + target.addDropListener(new ChartDropTarget(separator, this, panel)); + + } + + /** + * Returns the chart resource associated with this element + * @return chart resource + */ + public Resource getChartResource() { + return this.chartResource; + } + + /** + * Returns the minimized state of this element + * @return is the element minimized + */ + public boolean isMinimized() { + return minimized; + } + + /** + * Change the minimized state of this element + */ + public void toggleMinimize() { + toggleMinimize(false); + } + /** + * Change the minimized state of this element + */ + public void toggleMinimize(boolean callSave) { + minimized = Boolean.FALSE.equals(minimized); + GridData data = (GridData) chartComposite.getLayoutData(); + if(panel.isVertical()) + data.exclude = minimized; + else + data.exclude = false; + chartComposite.setVisible(!minimized); + + Composite parent = getParent(); + data = (GridData) getLayoutData(); + GridData parentData = (GridData)parent.getLayoutData(); + parentData.grabExcessHorizontalSpace = data.grabExcessHorizontalSpace; + parentData.grabExcessVerticalSpace = data.grabExcessVerticalSpace; + parentData.heightHint = data.heightHint; + + if(callSave) { + panel.saveState(); + } + panel.layout(); + } + + /** + * Remove this chart panel element from its panel + */ + public void remove() { + panel.removeChart(chartResource); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelHeader.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelHeader.java new file mode 100644 index 00000000..03955086 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelHeader.java @@ -0,0 +1,397 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DragSource; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.DragSourceListener; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.dnd.LocalObjectTransfer; +import org.simantics.utils.datastructures.Pair; + +/** + * Header of a chart element in {@link ChartPanel}. Only this header is + * shown if a chart is minimized. If a chart is expanded, this header is added + * to the charts {@link ChartPanelElement}. + * + * @author Teemu Lempinen + * + */ +public class ChartPanelHeader extends Composite { + + public static int HEADER_MINIMUM_WIDTH = 250; + private ChartPanelElement element; + private Resource resource; + private Label name; + private Canvas iconCanvas; + private Image icon; + private ToolItem minimize, remove; + private Color defaultColor, darker, evenDarker; + private Image gradientBackgroundImage, borderImage; + + private static ImageDescriptor closeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/close.gif")); + private static Image closeImage = closeDescriptor.createImage(); + + private static ImageDescriptor minimizeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/minimize.gif")); + private static Image minimizeImage = minimizeDescriptor.createImage(); + + private static ImageDescriptor maximizeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/maximize.gif")); + private static Image maximizeImage = maximizeDescriptor.createImage(); + + private static ImageDescriptor lineChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_line_light.png")); + private static Image lineChartImage = lineChartDescriptor.createImage(); + + private static ImageDescriptor barChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar_light.png")); + private static Image barChartImage = barChartDescriptor.createImage(); + + private static ImageDescriptor pieChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_pie_light.png")); + private static Image pieChartImage = pieChartDescriptor.createImage(); + + + /** + * Chart panel header with minimize and close buttons. + * + * @param parent The composite where the header is added + * @param panel The {@link ChartPanel} containing the header + * @param name The name of the chart + * @param style he Style of the created chart element + */ + public ChartPanelHeader(Composite c, ChartPanelElement element, Resource chartResource, int style) { + super(c, style); + this.resource = chartResource; + this.element = element; + + GridLayoutFactory.fillDefaults().margins(3, 0).numColumns(3).applyTo(this); + GridDataFactory.fillDefaults().grab(true, false).applyTo(this); + + // Colors + + // Chart icon + iconCanvas = new Canvas (this, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).hint(16, 16).applyTo(iconCanvas); + iconCanvas.addPaintListener (new PaintListener() { + + @Override + public void paintControl(PaintEvent e) { + if(icon != null) + e.gc.drawImage (icon, 0, 0); + } + }); + + // Label for the chart name (also minimize/expand) + name = new Label(this, SWT.NONE); + + try { + // name updater + Pair result = SimanticsUI.getSession().syncRequest(new Read>() { + + @Override + public Pair perform(ReadGraph graph) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + String label = graph.getPossibleRelatedValue(resource, l0.HasLabel); + Image image = null; + Resource plot = graph.syncRequest(new PossibleObjectWithType(resource, l0.ConsistsOf, jfree.Plot)); + if(plot != null) { + if(graph.isInstanceOf(plot, jfree.CategoryPlot)) + image = barChartImage; + else if(graph.isInstanceOf(plot, jfree.PiePlot)) + image = pieChartImage; + else + image = lineChartImage; + } + return new Pair(label, image); + } + + }, new Listener>() { + + @Override + public void execute(final Pair result) { + if(result == null) + return; + + name.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if(!name.isDisposed() && result.first != null) + name.setText(result.first); + + if(!iconCanvas.isDisposed() && result.second != null) { + icon = result.second; + iconCanvas.redraw(); + ChartPanelHeader.this.layout(); + } + } + }); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return name.isDisposed(); + } + + }); + name.setText(result.first); + } catch (DatabaseException e) { + e.printStackTrace(); + name.setText("No label"); + } + GridDataFactory.fillDefaults().grab(true, false).applyTo(name); + + ToolBar toolbar = new ToolBar(this, SWT.FLAT); + // item for minimizing/expanding chart + minimize = new ToolItem(toolbar, SWT.PUSH); + minimize.addSelectionListener(new MinimizeListener()); + if(isMinimized()) { + minimize.setToolTipText("Expand"); + minimize.setImage(maximizeImage); + } else { + minimize.setToolTipText("Minimize"); + minimize.setImage(minimizeImage); + } + + // item for closing/removing the chart + remove = new ToolItem(toolbar, SWT.PUSH); + remove.setImage(closeImage); + remove.addSelectionListener(new RemoveChartListener()); + remove.setToolTipText("Remove"); + + + /* ******************************** + * DnD + * ********************************/ + + // Allow data to be copied or moved from the drag source + int operations = DND.DROP_MOVE; + source = new DragSource(name, operations); + + // Provide data in Text format + Transfer[] types = new Transfer[] { LocalObjectTransfer.getTransfer() }; + source.setTransfer(types); + dragSourceListener = new DragSourceListener() { + + @Override + public void dragStart(DragSourceEvent event) { + if(name.isDisposed()) + event.doit = false; + event.detail = DND.DROP_LINK; + + } + + @Override + public void dragSetData(DragSourceEvent event) { + event.data = new StructuredSelection(resource); + } + + @Override + public void dragFinished(DragSourceEvent event) { + } + }; + source.addDragListener(dragSourceListener); + + name.addDisposeListener(new DisposeListener() { + + @Override + public void widgetDisposed(DisposeEvent e) { + if(dragSourceListener != null && source != null && !source.isDisposed()) { + source.removeDragListener(dragSourceListener); + } + } + }); + this.setBackgroundImage(getGradientBackgroundImage()); + this.setBackgroundMode(SWT.INHERIT_FORCE); + + this.addListener(SWT.MouseEnter, new EnterListener()); + this.addListener(SWT.MouseExit, new ExitListener()); + + for(Control child : this.getChildren()) { + child.addListener(SWT.MouseEnter, new EnterListener()); + child.addListener(SWT.MouseExit, new ExitListener()); + + } + } + + private class EnterListener implements org.eclipse.swt.widgets.Listener { + public void handleEvent(Event event) { + ChartPanelHeader.this.setBackgroundImage(getHighlightedGradientBackgroundImage()); + } + } + + private class ExitListener implements org.eclipse.swt.widgets.Listener { + public void handleEvent(Event event) { + ChartPanelHeader.this.setBackgroundImage(getGradientBackgroundImage()); + } + } + + private void createColors() { + if(defaultColor == null) { + defaultColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); + try { + defaultColor = new Color(getDisplay(), defaultColor.getRed() + 500, defaultColor.getGreen() + 10, defaultColor.getBlue() + 10); + } catch (IllegalArgumentException e) { + // Do nothing, use the default color + } + } + + if(darker == null) { + try { + darker = new Color(getDisplay(), defaultColor.getRed() - 30, defaultColor.getGreen() - 30, defaultColor.getBlue() - 30); + } catch (IllegalArgumentException e) { + // Do nothing, use the default color + darker = defaultColor; + } + } + + if(evenDarker == null) { + try { + evenDarker = new Color(getDisplay(), defaultColor.getRed() - 50, defaultColor.getGreen() - 50, defaultColor.getBlue() - 50); + } catch (IllegalArgumentException e) { + // Do nothing, use the default color + evenDarker = defaultColor; + } + } + + } + + private Image getHighlightedGradientBackgroundImage() { + createColors(); + this.layout(); + Point size = this.getSize(); + + borderImage = new Image(this.getDisplay(), 1, Math.max(1, size.y)); + GC gc = new GC(borderImage); + gc.setForeground(defaultColor); + gc.setBackground(evenDarker); + gc.fillGradientRectangle(0, 0, 1, size.y, true); + gc.dispose(); + + return borderImage; + } + + private Image getGradientBackgroundImage() { + createColors(); + this.layout(); + Point size = this.computeSize(SWT.DEFAULT, SWT.DEFAULT); + if(gradientBackgroundImage == null) { + gradientBackgroundImage = new Image(this.getDisplay(), 1, Math.max(1, size.y)); + GC gc = new GC(gradientBackgroundImage); + gc.setForeground(defaultColor); + gc.setBackground(darker); + gc.fillGradientRectangle(0, 0, 1, size.y, true); + gc.dispose(); + } + + return gradientBackgroundImage; + } + + private DragSourceListener dragSourceListener; + private DragSource source; + + /** + * Return true if this element is minimized, false if expanded + * @return true if this element is minimized, false if expanded + */ + private boolean isMinimized() { + return element.isMinimized(); + } + + /** + * Listener to minimize chart button. Expands and minimizes + * the chart of this header. + * + * @author Teemu Lempinen + * + */ + private class MinimizeListener implements SelectionListener { + @Override + public void widgetSelected(SelectionEvent e) { + if(ChartPanelHeader.this.isDisposed()) + return; + + element.toggleMinimize(true); + + if(!name.isDisposed() && !minimize.isDisposed()) { + if(isMinimized()) { + minimize.setToolTipText("Expand"); + } else { + minimize.setToolTipText("Minimize"); + } + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + + } + + /** + * Listener for removing this chart from the chart panel. + * + * @author Teemu Lempinen + * + */ + private class RemoveChartListener implements SelectionListener { + @Override + public void widgetSelected(SelectionEvent e) { + if(!ChartPanelHeader.this.isDisposed()) { + element.remove(); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelSeparator.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelSeparator.java new file mode 100644 index 00000000..d529a865 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelSeparator.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; + +/** + * Class for separating charts in {@link ChartPanel}. Acts as a drop participant for adding + * and moving charts in {@link ChartPanel}. + * + * @author Teemu Lempinen + * + */ +public class ChartPanelSeparator extends Composite { + + private ChartPanel panel; + + @Override + public Object getLayoutData() { + checkWidget(); + Object oldData = super.getLayoutData(); + if(oldData == null || !(oldData instanceof GridData)) { + oldData = GridDataFactory.fillDefaults().create(); + } + GridData data = (GridData) oldData; + if(panel.isVertical()) { + data.grabExcessHorizontalSpace = true; + data.grabExcessVerticalSpace = false; + } else { + data.grabExcessHorizontalSpace = false; + data.grabExcessVerticalSpace = true; + } + return data; + } + + /** + * Set up a small horizontal or vertical separator depending on SWT style + * + * @param parent + * @param style + */ + public ChartPanelSeparator(Composite parent, ChartPanel panel, ChartPanelElement element, int style) { + super(parent, style); + GridLayoutFactory.fillDefaults().margins(2, 2).applyTo(this); + GridDataFactory.fillDefaults().applyTo(this); + this.panel = panel; + addMouseListener(new SCFocusListener(panel)); + } + + + /** + * Listener for directing focus to scrollableComposite + * @author Teemu Lempinen + * + */ + private class SCFocusListener extends MouseAdapter { + ChartPanel panel; + public SCFocusListener(ChartPanel panel) { + this.panel = panel; + } + public void mouseDown(MouseEvent e) { + panel.setFocus(); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ElementContainer.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ElementContainer.java new file mode 100644 index 00000000..56d9fa8c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ElementContainer.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +/** + * Container for a chart panel element. Needed for + * moving chart panel elements around using setParent() + * @author Teemu Lempinen + * + */ +public class ElementContainer extends Composite { + + @Override + public Object getLayoutData () { + Control[] children = getChildren(); + if(children.length == 1) { + if(children[0] instanceof ChartPanelElement) { + ChartPanelElement element = (ChartPanelElement)children[0]; + return element.getLayoutData(); + } + } + return super.getLayoutData(); + } + + public ElementContainer(Composite parent, int style) { + super(parent, style); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/PinTrend.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/PinTrend.java new file mode 100644 index 00000000..a3509989 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/PinTrend.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.State; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; + + +public class PinTrend extends AbstractHandler { + + public static final String COMMAND = "org.simantics.sysdyn.ui.trend.view.pin"; + public static final String STATE = "org.simantics.sysdyn.ui.trend.view.pin.state"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = service.getCommand(COMMAND); + State state = command.getState(STATE); + Boolean value = (Boolean) state.getValue(); + value = !value; + state.setValue(value); + + return null; + } + + public static Boolean getState() { + ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = service.getCommand(COMMAND); + State state = command.getState(STATE); + return (Boolean)state.getValue(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendToPng.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendToPng.java new file mode 100644 index 00000000..e0555cae --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendToPng.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; + +/** + * Exports the current chart in TrendView + * @author Teemu Lempinen + * + */ +public class TrendToPng extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + int width = TrendView.panel.getSize().width; + int height = TrendView.panel.getSize().height; + int compressionLevel = 0; + + final Shell shell = HandlerUtil.getActiveShellChecked(event); + FileDialog fd = new FileDialog(shell, SWT.SAVE); + fd.setText("Export trend to PNG"); + String[] ext = {"*.png"}; + fd.setFilterExtensions(ext); + String selected = fd.open(); + + if (!(selected == null)){ + File file = new File(selected); + JFreeChart chart = TrendView.panel.getChart(); + + try { + ChartUtilities.saveChartAsPNG(file, chart, width, height, null, true, compressionLevel); + } catch (IOException e) { + e.printStackTrace(); + } + } + return null; + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendToSvg.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendToSvg.java new file mode 100644 index 00000000..0bd78c8a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendToSvg.java @@ -0,0 +1,74 @@ +package org.simantics.sysdyn.ui.trend; + +//import java.awt.geom.Rectangle2D; +//import java.io.File; +//import java.io.FileNotFoundException; +//import java.io.FileOutputStream; +//import java.io.OutputStreamWriter; +//import java.io.UnsupportedEncodingException; +//import java.io.Writer; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +//import org.eclipse.swt.SWT; +//import org.eclipse.swt.widgets.FileDialog; +//import org.eclipse.swt.widgets.Shell; +//import org.eclipse.ui.handlers.HandlerUtil; +//import org.jfree.chart.JFreeChart; +//import org.w3c.dom.DOMImplementation; +//import org.w3c.dom.Document; +//import org.apache.batik.*; +//import org.apache.batik.dom.GenericDOMImplementation; +//import org.apache.batik.svggen.SVGGraphics2D; +//import org.apache.batik.svggen.SVGGraphics2DIOException; + +//This class needs Batik libraries to be imported, if SVG picture is really needed. + +public class TrendToSvg extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + +// final Shell shell = HandlerUtil.getActiveShellChecked(event); +// FileDialog fd = new FileDialog(shell, SWT.SAVE); +// fd.setText("Export trend to PNG"); +// String[] ext = {"*.svg"}; +// fd.setFilterExtensions(ext); +// String selected = fd.open(); +// +// File file = new File(selected); +// JFreeChart chart = TrendView.chart; +// +// DOMImplementation domImpl +// = GenericDOMImplementation.getDOMImplementation(); +// // Create an instance of org.w3c.dom.Document +// Document document = domImpl.createDocument(null, "svg", null); +// // Create an instance of the SVG Generator +// SVGGraphics2D svgGenerator = new SVGGraphics2D(document); +// // set the precision to avoid a null pointer exception in Batik 1.5 +// svgGenerator.getGeneratorContext().setPrecision(6); +// // Ask the chart to render into the SVG Graphics2D implementation +// chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, 400, 300), null); +// // Finally, stream out SVG to a file using UTF-8 character to +// // byte encoding +// boolean useCSS = true; +// Writer out = null; +// try { +// out = new OutputStreamWriter( +// new FileOutputStream(file), "UTF-8"); +// } catch (UnsupportedEncodingException e) { +// e.printStackTrace(); +// } catch (FileNotFoundException e) { +// e.printStackTrace(); +// } +// try { +// svgGenerator.stream(out, useCSS); +// } catch (SVGGraphics2DIOException e) { +// e.printStackTrace(); +// } + System.out.println("Add Batik-libraries"); + return null; + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java new file mode 100644 index 00000000..f0d36edf --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java @@ -0,0 +1,238 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend; + +import java.awt.Frame; +import java.util.Collection; + +import javax.swing.SwingUtilities; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.awt.SWT_AWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.part.ViewPart; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.jfree.data.xy.AbstractXYDataset; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.sysdyn.manager.SysdynDataSet; +import org.simantics.sysdyn.ui.trend.chart.IJFreeChart; +import org.simantics.sysdyn.ui.viewUtils.SysdynDatasetSelectionListener; + +/** + * Trend view that shows all active simulation results for selected variables. + * + * @author Teemu Lempinen + * + */ +public class TrendView extends ViewPart { + + private Frame frame; + public static ChartPanel panel; + private SysdynDatasets sysdynDatasets = new SysdynDatasets(); + private SysdynDatasetSelectionListener sysdynDatasetSelectionListener; + public static JFreeChart defaultchart; + private Composite composite; + private CustomChartListener listener; + + /** + * Dataset for jFreeChart + * + * @author Teemu Lempinen + * + */ + @SuppressWarnings("serial") + class SysdynDatasets extends AbstractXYDataset { + + SysdynDataSet[] sets = new SysdynDataSet[0]; + + public void setDatasets(SysdynDataSet[] sets) { + this.sets = sets; + fireDatasetChanged(); + } + + @Override + public Number getY(int series, int item) { + return sets[series].values[item]; + } + + @Override + public Number getX(int series, int item) { + return sets[series].times[item]; + } + + @Override + public int getItemCount(int series) { + return sets[series].times.length; + } + + @Override + public Comparable getSeriesKey(int series) { + SysdynDataSet sds = sets[series]; + if(sds.result == null) + return sds.name; + else + return sds.name + " : " + sds.result; + } + + @Override + public int getSeriesCount() { + return sets.length; + } + + } + + @Override + public void createPartControl(Composite parent) { + + composite = new Composite(parent, + SWT.NO_BACKGROUND | SWT.EMBEDDED); + frame = SWT_AWT.new_Frame(composite); + + // Create the chart + displayDefaultChart(); + + // Add a dataset listener that updates datasets for the chart according to current selection + sysdynDatasetSelectionListener = new SysdynDatasetSelectionListener() { + + @Override + protected void selectionChanged(final Collection activeDatasets) { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + if(listener != null) { + listener.dispose(); + } + sysdynDatasets.setDatasets(activeDatasets.toArray(new SysdynDataSet[activeDatasets.size()])); + displayDefaultChart(); + } + + }); + } + + @Override + protected void selectionChanged(ReadGraph graph, final Resource chartResource) { + + if(listener != null) { + listener.dispose(); + } + + listener = new CustomChartListener(); + + graph.asyncRequest(new Read() { + + @Override + public JFreeChart perform(ReadGraph graph) throws DatabaseException { + if(graph.hasStatement(chartResource)) { + IJFreeChart chart = graph.adapt(chartResource, IJFreeChart.class); + if(chart != null) { + return chart.getChart(); + } + } + return null; + } + }, listener); + } + }; + + getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(sysdynDatasetSelectionListener); + + } + + private class CustomChartListener implements Listener { + + private boolean disposed = false; + + @Override + public void execute(JFreeChart result) { + if(!disposed) + displayChart(result); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return disposed; + } + + public void dispose() { + this.disposed = true; + } + + } + + /** + * Displays jFreeChart + * @param jFreeChart + */ + private void displayChart(final JFreeChart jFreeChart) { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + frame.removeAll(); + if(jFreeChart != null) { + panel = new ChartPanel(jFreeChart); + frame.add(panel); + } + frame.repaint(); + frame.validate(); + panel.requestFocus(); + } + + }); + } + + /** + * displays a default chart + */ + private void displayDefaultChart() { + if(defaultchart == null) { + XYPlot plot = new XYPlot( + sysdynDatasets, + new NumberAxis("time"), + new NumberAxis(""), + new XYLineAndShapeRenderer(true, false) + ); + defaultchart = new JFreeChart(plot); + } + displayChart(defaultchart); + } + + @Override + public void dispose() { + super.dispose(); + getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(sysdynDatasetSelectionListener); + } + + @Override + public void setFocus() { + if(panel != null) + panel.requestFocus(); + } + + + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractAxis.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractAxis.java new file mode 100644 index 00000000..9f37e5ee --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractAxis.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import java.awt.Color; + +import org.jfree.chart.axis.Axis; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.G2DUtils; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Abstract axis class for all JFreeChart axis + * @author Teemu Lempinen + * + */ +public abstract class AbstractAxis implements IAxis { + + protected Axis axis; + protected String label; + protected Boolean tMarksVisible, tLabelsVisible, labelVisible, lineVisible; + protected Color color; + protected Double min, max, rotate; + + /** + * Creates a new axis + * @param graph ReadGraph + * @param axisResource resource of type JFreeChart.NumberAxis + */ + public AbstractAxis(ReadGraph graph, Resource axisResource) { + try { + /* + * Axis is practically always called from a listener, + * so it is safe to always create a new axis every time. + * + * The parent listener takes care that the axis is updated. + * (And the code stays much more readable) + */ + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + label = graph.getPossibleRelatedValue(axisResource, l0.HasLabel); + tMarksVisible = graph.getPossibleRelatedValue(axisResource, jfree.Axis_visibleTickMarks, Bindings.BOOLEAN); + tLabelsVisible = graph.getPossibleRelatedValue(axisResource, jfree.Axis_visibleTickLabels, Bindings.BOOLEAN); + labelVisible = graph.getPossibleRelatedValue(axisResource, jfree.Axis_visibleLabel, Bindings.BOOLEAN); + lineVisible = graph.getPossibleRelatedValue(axisResource, jfree.Axis_visibleAxisLine, Bindings.BOOLEAN); + Resource c = graph.getPossibleObject(axisResource, jfree.color); + color = c == null ? null : G2DUtils.getColor(graph, c); + min = graph.getPossibleRelatedValue(axisResource, jfree.Axis_min, Bindings.DOUBLE); + max = graph.getPossibleRelatedValue(axisResource, jfree.Axis_max, Bindings.DOUBLE); + rotate = graph.getPossibleRelatedValue(axisResource, jfree.Axis_rotateLabelDegrees, Bindings.DOUBLE); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + @Override + public void dispose() { + + } + + @Override + public Axis getAxis() { + if(tMarksVisible != null && tMarksVisible == false) + axis.setTickMarksVisible(false); + if(tLabelsVisible != null && tLabelsVisible == false) + axis.setTickLabelsVisible(false); + if(lineVisible != null && lineVisible == false) + axis.setAxisLineVisible(false); + + if(color != null) { + axis.setAxisLinePaint(color); + axis.setLabelPaint(color); + axis.setTickLabelPaint(color); + axis.setTickMarkPaint(color); + } + // label exists and its visibility == null or true + if((labelVisible == null || labelVisible == true) && label != null) + axis.setLabel(label); + return axis; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractDataset.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractDataset.java new file mode 100644 index 00000000..31a91128 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractDataset.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + + +/** + * Abstract dataset class for all JFreeChart datasets + * + * @author Teemu Lempinen + * + */ +public abstract class AbstractDataset implements IDataset { + + protected Resource resource; + + public AbstractDataset(ReadGraph graph, Resource resource) { + this.resource = resource; + } + + @Override + public void dispose() { + + } + + @Override + public Resource getResource() { + return resource; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractPlot.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractPlot.java new file mode 100644 index 00000000..48e0f693 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractPlot.java @@ -0,0 +1,212 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import java.util.ArrayList; +import java.util.HashMap; + +import javax.swing.SwingUtilities; + +import org.jfree.chart.axis.Axis; +import org.jfree.chart.plot.Plot; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.ui.SimanticsUI; + +/** + * Abstract plot class for all JFreeChart plots + * + * @author Teemu Lempinen + * + */ +public abstract class AbstractPlot implements IPlot { + + protected Resource resource; + protected Plot plot; + protected PlotProperties currentProperties; + private PlotPropertyListener listener; + + + public AbstractPlot(ReadGraph graph, Resource resource) { + this.resource = resource; + } + + @Override + public void dispose() { + if(currentProperties != null) { + for(IAxis axis : currentProperties.ranges) + axis.dispose(); + + for(IAxis axis : currentProperties.domains) + axis.dispose(); + + for(IDataset dataset : currentProperties.datasets) + dataset.dispose(); + } + if(listener != null) + listener.dispose(); + } + + @Override + public Resource getResource() { + return resource; + } + + protected abstract Plot newPlot(); + protected abstract void setPlotProperties(PlotProperties properties); + protected abstract void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException; + + @Override + public Plot getPlot() { + if(plot == null) + plot = newPlot(); + + if(listener == null || listener.isDisposed()) { + listener = new PlotPropertyListener(); + SimanticsUI.getSession().asyncRequest(new Read() { + + @Override + public PlotProperties perform(ReadGraph graph) throws DatabaseException { + + PlotProperties properties = new PlotProperties(); + + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + HashMap axisMap = new HashMap(); + + // Get all range axis + Resource rangeList = graph.getPossibleObject(resource, jfree.Plot_rangeAxisList); + if(rangeList != null) { + for(Resource axisResource : ListUtils.toList(graph, rangeList)) { + IAxis axis = graph.adapt(axisResource, IAxis.class); + if(axis.getAxis() instanceof Axis) { + properties.ranges.add(axis); + axisMap.put(axisResource, axis); + } + } + } + + // Get all domain axis + // There usually is only one domain axis, but this supports also multiple domain axis + for(Resource axisResource : graph.syncRequest(new ObjectsWithType(resource, jfree.Plot_domainAxis, jfree.Axis))) { + IAxis axis = graph.adapt(axisResource, IAxis.class); + if(axis.getAxis() instanceof Axis) { + properties.domains.add(axis); + axisMap.put(axisResource, axis); + } + } + + // Get all datasets and map them to axis + for(Resource datasetResource : graph.syncRequest(new ObjectsWithType(resource, l0.ConsistsOf, jfree.Dataset))) { + IDataset dataset = graph.adapt(datasetResource, IDataset.class); + if(dataset != null) { + properties.datasets.add(dataset); + Resource axisResource = graph.getPossibleObject(datasetResource, jfree.Dataset_mapToRangeAxis); + IAxis axis; + if(axisMap.containsKey(axisResource)) { + axis = axisMap.get(axisResource); + properties.rangeMappings.put(dataset, axis); + } + + axisResource = graph.getPossibleObject(datasetResource, jfree.Dataset_mapToDomainAxis); + if(axisMap.containsKey(axisResource)) { + axis = axisMap.get(axisResource); + properties.domainMappings.put(dataset, axis); + } + } + } + getOtherProperties(graph, properties); + return properties; + + } + }, listener); + } + + return plot; + } + + protected class PlotProperties { + public ArrayList ranges; + public ArrayList domains; + public ArrayList datasets; + public HashMap rangeMappings; + public HashMap domainMappings; + public HashMap otherProperties; + + public PlotProperties() { + datasets = new ArrayList(); + rangeMappings = new HashMap(); + domainMappings = new HashMap(); + ranges = new ArrayList(); + domains = new ArrayList(); + otherProperties = new HashMap(); + } + + @Override + public boolean equals(Object other) { + if(!this.getClass().equals(other.getClass())) + return false; + PlotProperties p = (PlotProperties)other; + if(!ranges.equals(p.ranges)) + return false; + if(!domains.equals(p.domains)) + return false; + if(!datasets.equals(p.datasets)) + return false; + if(!rangeMappings.equals(p.rangeMappings)) + return false; + if(!domainMappings.equals(p.domainMappings)) + return false; + if(!otherProperties.equals(p.otherProperties)) + return false; + return true; + } + } + + private class PlotPropertyListener implements Listener { + + private boolean disposed = false; + + public void dispose() { + disposed = true; + } + @Override + public void execute(final PlotProperties result) { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + setPlotProperties(result); + } + }); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return disposed; + } + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractRenderer.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractRenderer.java new file mode 100644 index 00000000..c38bd23a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractRenderer.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + +/** + * Abstract renderer class for all JFreeChart renderers + * @author Teemu Lempinen + * + */ +public abstract class AbstractRenderer implements IRenderer { + + protected Resource resource; + + public AbstractRenderer(ReadGraph graph, Resource resource) { + this.resource = resource; + } + + @Override + public void dispose() { + } + + @Override + public Resource getResource() { + return resource; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/BarRenderer.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/BarRenderer.java new file mode 100644 index 00000000..7d80fb88 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/BarRenderer.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.labels.StandardCategoryToolTipGenerator; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + + +/** + * Normal bar renderer + * @author Teemu Lempinen + * + */ +public class BarRenderer extends AbstractRenderer { + + public BarRenderer(ReadGraph graph, Resource resource) { + super(graph, resource); + } + + private org.jfree.chart.renderer.category.BarRenderer renderer; + + @Override + public org.jfree.chart.renderer.AbstractRenderer getRenderer() { + if(renderer == null) { + renderer = new org.jfree.chart.renderer.category.BarRenderer(); + renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); + } + return renderer; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryAxis.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryAxis.java new file mode 100644 index 00000000..bd58da1e --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryAxis.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.axis.Axis; +import org.jfree.chart.axis.CategoryLabelPositions; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + +/** + * Class representing a JFreeChart.CategoryAxis + * + * @author Teemu Lempinen + * + */ +public class CategoryAxis extends AbstractAxis { + + public CategoryAxis(ReadGraph graph, Resource axisResource) { + super(graph, axisResource); + } + + @Override + public Axis getAxis() { + axis = new org.jfree.chart.axis.CategoryAxis(); + + if(rotate != null && rotate > 0) { + ((org.jfree.chart.axis.CategoryAxis)axis).setCategoryLabelPositions( + CategoryLabelPositions.createUpRotationLabelPositions(Math.toRadians(rotate))); + } + + return super.getAxis(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java new file mode 100644 index 00000000..11f57127 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java @@ -0,0 +1,300 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.SwingUtilities; + +import org.jfree.chart.plot.DefaultDrawingSupplier; +import org.jfree.chart.renderer.AbstractRenderer; +import org.jfree.chart.renderer.category.BarRenderer; +import org.jfree.data.category.DefaultCategoryDataset; +import org.jfree.data.general.Dataset; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.MissingVariableException; +import org.simantics.db.layer0.request.PossibleActiveExperiment; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.operation.Layer0X; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.adapter.SysdynVariableProperties; +import org.simantics.sysdyn.adapter.VariableRVIUtils; +import org.simantics.sysdyn.manager.SysdynDataSet; +import org.simantics.ui.SimanticsUI; + +/** + * Class representing a JFreeChart.CategoryDataset + * + * @author Teemu Lempinen + * + */ +public class CategoryDataset extends AbstractDataset { + + private List seriesList; + private String realizationURI; + private IRenderer renderer; + private DefaultCategoryDataset dataset; + + public CategoryDataset(ReadGraph graph, Resource resource) { + super(graph, resource); + + try { + Layer0 l0 = Layer0.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + // Find the model where the chart is located + Resource model = resource; + do { + model = graph.getPossibleObject(model, l0.PartOf); + } while(model != null && !graph.isInstanceOf(model, mr.StructuralModel)); + + // Find the variable realization of the current experiment + realizationURI = null; + Resource realization = graph.syncRequest(new PossibleActiveExperiment(model)); + if (realization == null) { + Layer0X L0X = Layer0X.getInstance(graph); + realization = graph.getPossibleObject(model, L0X.HasBaseRealization); + } + if (realization != null) + realizationURI = graph.getURI(realization); + + if(realizationURI == null) + return; // No experiment -> No results + + Resource seriesList = graph.getPossibleObject(resource, jfree.Dataset_seriesList); + if(seriesList != null) + this.seriesList = ListUtils.toList(graph, seriesList); + + Resource rendererResource = graph.getPossibleObject(resource, jfree.Dataset_renderer); + renderer = graph.adapt(rendererResource, IRenderer.class); + + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + private DatasetListener listener; + + @Override + public Dataset getDataset() { + + if(seriesList == null || seriesList.isEmpty()) + return null; + + if(dataset == null) { + dataset = new DefaultCategoryDataset(); + } + + if(listener == null || listener.isDisposed()) { + listener = new DatasetListener(); + SimanticsUI.getSession().asyncRequest(new Read>() { + + @Override + public ArrayList perform(ReadGraph graph) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + ArrayList series = new ArrayList(); + // Get properties for all series + if(seriesList != null) { + for(Resource r : seriesList) { + String rvi = graph.getPossibleRelatedValue(r, jfree.variableRVI); + if(rvi == null) + continue; + + try { + // Get a variable for the series + Variable v = Variables.getVariable(graph, realizationURI + rvi); + + // Get values + Object object = v.getPossiblePropertyValue(graph, SysdynVariableProperties.ACTIVE_DATASETS , Bindings.VARIANT); + if(object == null || !(object instanceof ArrayList)) + return series; + + ArrayList datasets = new ArrayList(); + + for(Object o : (ArrayList)object) { + if(o instanceof SysdynDataSet) + datasets.add((SysdynDataSet)o); + } + + String[] filter = graph.getPossibleRelatedValue(r, jfree.variableFilter); + if(filter != null) { + ArrayList result2 = VariableRVIUtils.getDataset(datasets, filter); + if(result2 != null) { + datasets = result2; + } + } + + // Find if a specific time is set for this chart + Double chartTime = null; + if(!datasets.isEmpty()) { + Layer0 l0 = Layer0.getInstance(graph); + Resource datasetResource = graph.getPossibleObject(r, l0.PartOf); + if(datasetResource != null) { + Resource plot = graph.getPossibleObject(datasetResource, l0.PartOf); + if(plot != null) { + Resource chart = graph.getPossibleObject(plot, l0.PartOf); + if(chart != null) + chartTime = graph.getPossibleRelatedValue(chart, jfree.Chart_time); + } + } + } + + for(SysdynDataSet dataset : datasets) { + double[] va = dataset.values; + + + if(va == null || va.length == 0) + continue; + + /* + * Time + * + * 1. find time for the individual series. + * 2. find time for the whole chart + * 3. find simulation time + */ + Double time = graph.getPossibleRelatedValue(r, jfree.Series_time, Bindings.DOUBLE); + if(time == null) + time = chartTime; + if(time == null) + time = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME, Bindings.DOUBLE); + + // Value + Double value = null; + if(time == null) { + value = va[va.length - 1]; + } else { + double[] ta = dataset.times; + for(int i = 0; i < ta.length; i++) { + double t = ta[i]; + if(time <= t) { + value = va[i]; + break; + } + } + + if(value == null) + value = va[va.length - 1]; + } + String label = graph.getPossibleRelatedValue(r, Layer0.getInstance(graph).HasLabel); // Called to refresh paints when label changes + String name = dataset.name; + series.add(new TempSeries(label == null || label.isEmpty() ? name : label, dataset.result, value)); + } + } catch (MissingVariableException e) { + // Do nothing, if variable was not found. Move on to the next series + } + } + } + return series; + } + + }, listener); + } + return dataset; + } + + @Override + public AbstractRenderer getRenderer() { + return renderer.getRenderer(); + } + + private class DatasetListener implements Listener> { + private boolean disposed = false; + + public void dispose() { + disposed = true; + } + + @Override + public void execute(final ArrayList series) { + // Modify series in AWT thread to avoid synchronization problems + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + // Remove all unused series + dataset.clear(); + BarRenderer renderer = ((BarRenderer)getRenderer()); + renderer.getPlot().setDrawingSupplier(new DefaultDrawingSupplier()); + + // Add found series + for(int i = 0; i < series.size(); i++) { + TempSeries s = series.get(i); + if(renderer instanceof org.jfree.chart.renderer.category.StackedBarRenderer && s.name.contains("[")) { + String category = s.name.substring(0, s.name.indexOf('[')); + if(s.result != null) + category = category + " : " + s.result; + String series = s.name.substring(s.name.indexOf('[')); + dataset.addValue(s.value, series, category); + } else { + dataset.addValue(s.value, s.result == null ? "Current" : s.result, s.name); + } + } + } + }); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return disposed; + } + }; + + @Override + public void dispose() { + super.dispose(); + if(listener != null) { + listener.dispose(); + listener = null; + } + } + + /** + * Auxiliary class containing all information needed to define a single series + * @author Teemu Lempinen + * + */ + private class TempSeries { + public String name; + public String result; + public Double value; + + public TempSeries(String name, String result, Double value) { + this.name = name; + this.value = value; + this.result = result; + } + + @Override + public String toString() { + return "TempSeries: " + name + ", " + value + ", " + result; + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java new file mode 100644 index 00000000..14a37955 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.axis.CategoryAxis; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.Plot; +import org.jfree.chart.renderer.category.CategoryItemRenderer; +import org.jfree.ui.RectangleInsets; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Class representing a CategoryPlot for JFreeChart + * @author Teemu Lempinen + * + */ +public class CategoryPlot extends AbstractPlot { + + public CategoryPlot(ReadGraph graph, Resource resource) { + super(graph, resource); + } + + @Override + protected Plot newPlot() { + return new org.jfree.chart.plot.CategoryPlot(null, null, null, null); + } + + @Override + protected void setPlotProperties(PlotProperties properties) { + if(!(plot instanceof org.jfree.chart.plot.CategoryPlot)) + return; + + org.jfree.chart.plot.CategoryPlot cplot = (org.jfree.chart.plot.CategoryPlot) plot; + /* Support using multiple axis, but prefer using only one domain and + * one range axis + */ + for(int i = 0; i < properties.ranges.size(); i++) { + cplot.setRangeAxis(i, (ValueAxis)properties.ranges.get(i).getAxis()); + } + + for(int i = 0; i < properties.domains.size(); i++) { + cplot.setDomainAxis(i, (CategoryAxis)properties.domains.get(i).getAxis()); + } + + IAxis axis; + for(int i = 0; i < properties.datasets.size(); i++) { + IDataset dataset = properties.datasets.get(i); + org.jfree.data.category.CategoryDataset ds = (org.jfree.data.category.CategoryDataset)dataset.getDataset(); + cplot.setDataset(i, ds); +// System.out.println("setting dataset " + i + ": " + ds); + cplot.setRenderer(i, (CategoryItemRenderer)dataset.getRenderer()); + axis = properties.rangeMappings.get(dataset); + if(axis != null && properties.ranges.contains(axis)) + cplot.mapDatasetToRangeAxis(i, properties.ranges.indexOf(axis)); + axis = properties.domainMappings.get(dataset); + if(axis != null && properties.ranges.contains(axis)) + cplot.mapDatasetToDomainAxis(i, properties.domains.indexOf(axis)); + } + + Boolean visibleGrid = (Boolean)properties.otherProperties.get("visibleGrid"); + if(visibleGrid != null) { + cplot.setRangeGridlinesVisible(visibleGrid); + cplot.setDomainGridlinesVisible(false); + } + + // Cleaner look: no outline borders + cplot.setInsets(new RectangleInsets(2,5,2,2), false); + cplot.setOutlineVisible(false); + } + + @Override + protected void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Boolean visibleGrid = graph.getPossibleRelatedValue(resource, jfree.Plot_visibleGrid); + properties.otherProperties.put("visibleGrid", visibleGrid); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java new file mode 100644 index 00000000..5db0e809 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import java.awt.Frame; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.awt.SWT_AWT; +import org.eclipse.swt.widgets.Composite; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Simantics; +import org.simantics.db.procedure.AsyncListener; +import org.simantics.db.request.Read; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.RunnableWithObject; + +/** + * Composite containing a single chart defined by a JFreeChart.Chart + * + * @author Teemu Lempinen + * + */ +public class ChartComposite extends Composite { + + private Frame frame; + private ChartPanel panel; + private Composite composite; + private IJFreeChart chart; + + /** + * A new ChartComposite with a definition in chartResourceURI + * @param parent Composite + * @param chartResourceURI URI for a JFreeChart.Chart definition + * @param style SWT style + */ + public ChartComposite(Composite parent, final String chartResourceURI, int style) { + super(parent, style | SWT.NO_BACKGROUND | SWT.EMBEDDED); + + try { + Resource chartResource = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + return graph.getPossibleResource(chartResourceURI); + } + + }); + if(chartResource != null) + CreateContent(chartResource); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + /** + * A new ChartComposite with a chartResource definition + * @param parent Composite + * @param chartResource JFreeChart.Chart resource + * @param style SWT style + */ + public ChartComposite(Composite parent, final Resource chartResource, int style) { + super(parent, style | SWT.NO_BACKGROUND | SWT.EMBEDDED); + CreateContent(chartResource); + } + + /** + * Creates and displays the chart defined in chartResource + * @param chartResource + */ + private void CreateContent(final Resource chartResource) { + composite = this; + + GridLayoutFactory.fillDefaults().applyTo(composite); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + frame = SWT_AWT.new_Frame(composite); + + // Add a listener displaying the contents of the chart. Chart is re-drawn if the definition changes + Simantics.getSession().asyncRequest(new Read() { + + @Override + public IJFreeChart perform(ReadGraph graph) throws DatabaseException { + // Adapt chartResource to a chart (XY, pie, bar, ...) + if(graph.isInstanceOf(chartResource, JFreeChartResource.getInstance(graph).Chart)) { + if(chart != null) + chart.dispose(); + chart = graph.adapt(chartResource, IJFreeChart.class); + return chart; + } else { + return null; + } + } + + } , new AsyncListener() { + + @Override + public boolean isDisposed() { + return composite.isDisposed(); + } + + @Override + public void execute(AsyncReadGraph graph, IJFreeChart chart) { + if(chart == null || composite.isDisposed()) + return; + + JFreeChart jfreeChart = chart.getChart(); + // Display the result chart + composite.getDisplay().asyncExec(new RunnableWithObject(jfreeChart) { + + @Override + public void run() { + if(composite.isDisposed()) + return; + if(panel != null) + frame.remove(panel); + composite.layout(); + JFreeChart chart = (JFreeChart)getObject(); + panel = new ChartPanel(chart, false, true, true, true, true); + frame.add(panel); + frame.repaint(); + frame.validate(); + } + }); + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + + } + }); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartUtils.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartUtils.java new file mode 100644 index 00000000..92e8ba4d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartUtils.java @@ -0,0 +1,150 @@ +package org.simantics.sysdyn.ui.trend.chart; + +import java.util.ArrayList; +import java.util.UUID; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.PossibleActiveExperiment; +import org.simantics.db.layer0.request.PossibleModel; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.operation.Layer0X; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Utilities for handling charts + * + * @author Teemu Lempinen + * + */ +public class ChartUtils { + + /** + * Creates a new range axis of type jfree.NumberAxis to a plot + * + * @param graph WriteGraph + * @param plot Plot resource + * @return Created number axis, null if not successful + * @throws DatabaseException + */ + public static Resource createNumberRangeAxis(WriteGraph graph, Resource plot) throws DatabaseException { + Resource axis = null; + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + if(plot != null) { + // Create range axis + axis = GraphUtils.create2(graph, jfree.NumberAxis, + l0.HasName, "NumberAxis" + UUID.randomUUID().toString(), + l0.HasLabel, NameUtils.findFreshLabel(graph, "Range", plot), + jfree.Plot_rangeAxis_Inverse, plot, + l0.PartOf, plot); + + // Add range axis to the plot's range axis list + Resource axisList = graph.getPossibleObject(plot, jfree.Plot_rangeAxisList); + ArrayList list = new ArrayList(); + list.add(axis); + if(axisList == null) { + axisList = ListUtils.create(graph, list); + graph.claim(plot, jfree.Plot_rangeAxisList, axisList); + } else { + ListUtils.insertBack(graph, axisList, list); + } + } + + return axis; + + } + + /** + * Create a XYDataset and map it to axis + * @param graph WriteGraph + * @param plot Plot resource containing the dataset + * @param domainAxis Mapped domain axis for the dataset + * @param rangeAxis Mapped range axis for the dataset + * @return created dataset or null if not successful + * @throws DatabaseException + */ + public static Resource createXYDataset(WriteGraph graph, Resource plot, Resource domainAxis, Resource rangeAxis) throws DatabaseException { + if(plot == null || domainAxis == null || rangeAxis == null) + return null; + + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + + // Create a dataset for the axis + Resource dataset = GraphUtils.create2(graph, jfree.XYDataset, + l0.HasName, "XYDataset" + UUID.randomUUID().toString(), + jfree.Dataset_mapToDomainAxis, domainAxis, + jfree.Dataset_mapToRangeAxis, rangeAxis, + jfree.Dataset_renderer, GraphUtils.create2(graph, jfree.XYLineRenderer), + l0.PartOf, plot); + + return dataset; + } + + /** + * Creates a new series to a dataset + * @param graph WriteGraph + * @param dataset Dataset for the new series + * @return created series or null if unsuccessful + * @throws DatabaseException + */ + public static Resource createSeries(WriteGraph graph, Resource dataset, String rvi) throws DatabaseException { + if(dataset == null) return null; + + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + // Create series + Resource series = GraphUtils.create2(graph, jfree.Series, + l0.HasName, "Series" + UUID.randomUUID().toString(), + jfree.variableRVI, rvi == null ? " Set variable" : rvi, + l0.PartOf, dataset); + + // Add series to the dataset's series list + Resource seriesList = graph.getPossibleObject(dataset, jfree.Dataset_seriesList); + ArrayList list = new ArrayList(); + list.add(series); + if(seriesList == null) { + seriesList = ListUtils.create(graph, list); + graph.claim(dataset, jfree.Dataset_seriesList, seriesList); + } else { + ListUtils.insertBack(graph, seriesList, list); + } + + return series; + } + + /** + * Find the current realization uri + * + * @param graph ReadGraph + * @param chartComponent A resource from a chart (consistsOf relation in a chart) + * @return current realization uri + * @throws DatabaseException + */ + public static String getCurrentRealizationURI(ReadGraph graph, Resource chartComponent) throws DatabaseException { + // Find the model where the chart is located + Resource model = graph.syncRequest(new PossibleModel(chartComponent)); + if(model == null) + return null; + + // Find the variable realization of the current experiment + String realizationURI = null; + Resource realization = graph.syncRequest(new PossibleActiveExperiment(model)); + if (realization == null) { + Layer0X L0X = Layer0X.getInstance(graph); + realization = graph.getPossibleObject(model, L0X.HasBaseRealization); + } + if (realization != null) + realizationURI = graph.getURI(realization); + + return realizationURI; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ExtendedNumberAxis.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ExtendedNumberAxis.java new file mode 100644 index 00000000..329faadf --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ExtendedNumberAxis.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.data.Range; + +/** + * NumberAxis that supports adding only one bound, lower or upper. + * The standard NumberAxis disables auto adjusting if even one of the bounds is set + * + * @author Teemu Lempinen + * + */ +public class ExtendedNumberAxis extends org.jfree.chart.axis.NumberAxis { + private static final long serialVersionUID = 3066266986472919998L; + + private Double lower = null; + private Double upper = null; + /** + * Use own lower and upper bounds to support using only one of them + */ + protected void autoAdjustRange() { + super.autoAdjustRange(); + Range range = getRange(); + Double lower = this.lower == null ? range.getLowerBound() : this.lower; + Double upper = this.upper == null ? range.getUpperBound() : this.upper; + if(lower > upper) + upper = lower + 1; + if(upper - lower < getAutoRangeMinimumSize()) + upper = lower + getAutoRangeMinimumSize(); + + setRange(new Range(lower, upper), false, false); + + } + + public void setLower(Double lower) { + this.lower = lower; + } + + public void setUpper(Double upper) { + this.upper = upper; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IAxis.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IAxis.java new file mode 100644 index 00000000..a5449856 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IAxis.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.axis.Axis; +import org.simantics.db.exception.DatabaseException; + +/** + * Interface for JFreeChart.Axis type resource + * + * @author Teemu Lempinen + * + */ +public interface IAxis extends IJFreeChartComponent { + + /** + * Returns the axis + * + * @return + * @throws DatabaseException + */ + public Axis getAxis(); + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IDataset.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IDataset.java new file mode 100644 index 00000000..cf91dd71 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IDataset.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.renderer.AbstractRenderer; +import org.jfree.data.general.Dataset; +import org.simantics.db.Resource; + +/** + * Interface for JFreeChart.Dataset type resource + * @author Teemu Lempinen + * + */ +public interface IDataset extends IJFreeChartComponent { + + /** + * Returns the JFreeChart dataset represented by the associated resource + * + * @return JFreeChart dataset + */ + public Dataset getDataset(); + + + /** + * Returns the renderer for this dataset + * + * @return JFreeChart renderer + */ + public AbstractRenderer getRenderer(); + + /** + * Returns the resource of this dataset + * + * @return + */ + public Resource getResource(); +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IJFreeChart.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IJFreeChart.java new file mode 100644 index 00000000..9c702c4b --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IJFreeChart.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.JFreeChart; +import org.simantics.db.exception.DatabaseException; +/** + * Interface for JFreeChart.Chart type resource + * + * @author Teemu Lempinen + * + */ +public interface IJFreeChart extends IJFreeChartComponent { + + /** + * Returns the chart + * + * @return + * @throws DatabaseException + */ + public JFreeChart getChart(); + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IJFreeChartComponent.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IJFreeChartComponent.java new file mode 100644 index 00000000..39b42e2e --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IJFreeChartComponent.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +/** + * Interface for all components that are used to create JFreeCharts based on org.simantics.jfreechart ontology + * @author Teemu Lempinen + * + */ +public interface IJFreeChartComponent { + + /** + * Dispose this component. Disposing a component may be useful + * if the component contains listeners that need to be disposed. + */ + public void dispose(); + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IPlot.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IPlot.java new file mode 100644 index 00000000..ec8386ef --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IPlot.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.plot.Plot; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; + +/** + * Interface for JFreeChart.Plot type resource + * + * @author Teemu Lempinen + * + */ +public interface IPlot extends IJFreeChartComponent { + + /** + * Returns the plot + * + * @return Title + * @throws DatabaseException + */ + public Plot getPlot(); + + /** + * Returns the resource of this plot + * + * @return + */ + public Resource getResource(); + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IRenderer.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IRenderer.java new file mode 100644 index 00000000..df832a45 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IRenderer.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.renderer.AbstractRenderer; +import org.simantics.db.Resource; + +/** + * Interface for JFreeChart.Renderer type resource + * @author Teemu Lempinen + * + */ +public interface IRenderer extends IJFreeChartComponent { + + /** + * Returns the JFreeChart AbstractRenderer represented by the associated resource + * + * @return JFreeChart renderer + */ + public AbstractRenderer getRenderer(); + + /** + * Returns the resource of this renderer + * @return + */ + public Resource getResource(); + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ITitle.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ITitle.java new file mode 100644 index 00000000..07281547 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ITitle.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.title.Title; +import org.simantics.db.exception.DatabaseException; + +/** + * Interface for JFreeChart.Title type resource + * + * @author Teemu Lempinen + * + */ +public interface ITitle extends IJFreeChartComponent { + + /** + * Returns the title + * + * @return Title + * @throws DatabaseException + */ + public Title getTitle(); + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java new file mode 100644 index 00000000..8a2f79c0 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import java.awt.Color; +import java.awt.Font; +import java.util.Collection; + +import javax.swing.SwingUtilities; + +import org.jfree.chart.title.LegendTitle; +import org.jfree.chart.title.TextTitle; +import org.jfree.ui.RectangleInsets; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.Pair; + +/** + * Class representing a complete JFreeChart.Chart + * + * This class supports all types of charts. The details of the chart are + * defined in plots and other adapted classes. + * + * @author Teemu Lempinen + * + */ +public class JFreeChart implements IJFreeChart { + + private org.jfree.chart.JFreeChart jfreechart; + private IPlot plot; + private ITitle title; + private Resource chartResource; + + /** + * + * @param graph ReadGraph + * @param chartResource Resource of type JFreeChart.Chart + */ + public JFreeChart(ReadGraph graph, Resource chartResource) { + this.chartResource = chartResource; + + try { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Collection plotsCollection = graph.syncRequest(new ObjectsWithType(chartResource, l0.ConsistsOf, jfree.Plot)); + for(Resource plotResource : plotsCollection) { + this.plot = graph.adapt(plotResource, IPlot.class); + } + + } catch(DatabaseException e) { + e.printStackTrace(); + } + } + + + JFreeChartListener listener; + + /** + * Returns a new chart using the information collected in the constructor + */ + @Override + public org.jfree.chart.JFreeChart getChart() { + if(plot == null) + return null; + + if(jfreechart == null) + jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot()); + + if(listener == null) { + listener = new JFreeChartListener(); + SimanticsUI.getSession().asyncRequest(new Read>() { + + @Override + public Pair perform(ReadGraph graph) throws DatabaseException { + if(chartResource == null || !graph.hasStatement(chartResource)) + return null; + + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Resource titleResource = graph.syncRequest(new PossibleObjectWithType(chartResource, l0.ConsistsOf, jfree.Title)); + title = graph.adapt(titleResource, ITitle.class); + Boolean legendVisible = graph.getPossibleRelatedValue(chartResource, jfree.Chart_visibleLegend, Bindings.BOOLEAN); + return new Pair(title, legendVisible); + } + }, listener); + } + + return jfreechart; + } + + @Override + public void dispose() { + // Call dispose to title and plots to disable their possible listeners + if(title != null) + title.dispose(); + if(listener != null) + listener.dispose(); + if(plot != null) + plot.dispose(); + } + + + private class JFreeChartListener implements Listener> { + + private boolean disposed = false; + private LegendTitle legend; + + public void dispose() { + disposed = true; + } + + @Override + public void execute(final Pair result) { + if(result == null) + return; + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + if(jfreechart == null) + return; + + jfreechart.setBackgroundPaint(Color.WHITE); + + if(jfreechart.getLegend() != null && !jfreechart.getLegend().equals(legend)) { + legend = jfreechart.getLegend(); + legend.setBorder(0, 0, 0, 0); + int size = legend.getItemFont().getSize(); + legend.setItemFont(new Font("helvetica", Font.PLAIN, size)); + } + + if(Boolean.FALSE.equals(result.second)) { + jfreechart.removeLegend(); + } else if (jfreechart.getLegend() == null && legend != null){ + jfreechart.addLegend(legend); + } + + TextTitle t = (org.jfree.chart.title.TextTitle)result.first.getTitle(); + if(t.isVisible()) { + t.setFont(new Font("georgia", Font.BOLD, 13)); + t.setPadding(new RectangleInsets(4, 0, 0, 0)); + jfreechart.setTitle(t); + } else { + jfreechart.setTitle((TextTitle)null); + } + } + }); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return disposed; + } + + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/NumberAxis.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/NumberAxis.java new file mode 100644 index 00000000..eda694fe --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/NumberAxis.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.axis.Axis; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + +/** + * Class representing a JFreeChart.NumberAxis + * + * @author Teemu Lempinen + * + */ +public class NumberAxis extends AbstractAxis { + + /** + * + * @param graph ReadGraph + * @param axisResource resource of type JFreeChart.NumberAxis + */ + public NumberAxis(ReadGraph graph, Resource axisResource) { + super(graph, axisResource); + } + + + @Override + public Axis getAxis() { + axis = new ExtendedNumberAxis(); + ((ExtendedNumberAxis)axis).setLower(min); + ((ExtendedNumberAxis)axis).setUpper(max); + return super.getAxis(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java new file mode 100644 index 00000000..a9af624d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java @@ -0,0 +1,320 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import javax.swing.SwingUtilities; + +import org.jfree.chart.renderer.AbstractRenderer; +import org.jfree.data.general.Dataset; +import org.jfree.data.general.DefaultPieDataset; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.MissingVariableException; +import org.simantics.db.layer0.request.PossibleActiveExperiment; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.diagram.G2DUtils; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.operation.Layer0X; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.adapter.SysdynVariableProperties; +import org.simantics.sysdyn.adapter.VariableRVIUtils; +import org.simantics.sysdyn.manager.SysdynDataSet; +import org.simantics.ui.SimanticsUI; + +/** + * Class representing a PieDataset in JFreeChart ontology + * @author Teemu Lempinen + * + */ +public class PieDataset extends AbstractDataset { + + private List seriesList; + private String realizationURI; + private DefaultPieDataset dataset; + + private HashMap colorMap; + private HashMap explodedMap; + + public PieDataset(ReadGraph graph, Resource resource) { + super(graph, resource); + + try { + Layer0 l0 = Layer0.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + // Find the model where the chart is located + Resource model = resource; + do { + model = graph.getPossibleObject(model, l0.PartOf); + } while(model != null && !graph.isInstanceOf(model, mr.StructuralModel)); + + // Find the variable realization of the current experiment + realizationURI = null; + Resource realization = graph.syncRequest(new PossibleActiveExperiment(model)); + if (realization == null) { + Layer0X L0X = Layer0X.getInstance(graph); + realization = graph.getPossibleObject(model, L0X.HasBaseRealization); + } + if (realization != null) + realizationURI = graph.getURI(realization); + + if(realizationURI == null) + return; // No experiment -> No results + + Resource seriesList = graph.getPossibleObject(resource, jfree.Dataset_seriesList); + if(seriesList != null) { + this.seriesList = ListUtils.toList(graph, seriesList); + } + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + + /** + * Map of colors for different slices in a pie chart. Name + * indicates the key of the value. + * @return Map of colors for different slices in a pie chart + */ + public HashMap getColorMap() { + return colorMap; + } + + /** + * Map of exploded statuses for slices in a pie chart. Name + * indicates the key of the slice. + * @return + */ + public HashMap getExplodedMap() { + return explodedMap; + } + + @Override + public Dataset getDataset() { + if(seriesList == null || seriesList.isEmpty()) + return null; + + if(dataset == null) { + dataset = new DefaultPieDataset(); + } + + if(listener == null) { + listener = new DatasetListener(); + SimanticsUI.getSession().asyncRequest(new Read>() { + + @Override + public ArrayList perform(ReadGraph graph) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + ArrayList series = new ArrayList(); + // Get properties for all series + if(seriesList != null) { + + colorMap = new HashMap(); + explodedMap = new HashMap(); + + for(Resource r : seriesList) { + String label = graph.getPossibleRelatedValue(r, Layer0.getInstance(graph).HasLabel); + String rvi = graph.getPossibleRelatedValue(r, jfree.variableRVI); + if(rvi == null) + continue; + + try { + // Get visual properties + Resource c = graph.getPossibleObject(r, jfree.color); + Color color = c == null ? null : G2DUtils.getColor(graph, c); + Boolean exploded = graph.getPossibleRelatedValue(r, jfree.Series_exploded, Bindings.BOOLEAN); + + // Get a variable for the series + Variable v = Variables.getVariable(graph, realizationURI + rvi); + + // Get values + Object object = v.getPossiblePropertyValue(graph, SysdynVariableProperties.ACTIVE_DATASETS , Bindings.VARIANT); + if(object == null || !(object instanceof ArrayList)) + return series; + + ArrayList datasets = new ArrayList(); + + for(Object o : (ArrayList)object) { + if(o instanceof SysdynDataSet) + datasets.add((SysdynDataSet)o); + } + + String[] filter = graph.getPossibleRelatedValue(r, jfree.variableFilter); + if(filter != null) { + ArrayList result2 = VariableRVIUtils.getDataset(datasets, filter); + if(result2 != null) { + datasets = result2; + } + } + + // Find if a specific time is set for this chart + Double chartTime = null; + if(!datasets.isEmpty()) { + Layer0 l0 = Layer0.getInstance(graph); + Resource datasetResource = graph.getPossibleObject(r, l0.PartOf); + if(datasetResource != null) { + Resource plot = graph.getPossibleObject(datasetResource, l0.PartOf); + if(plot != null) { + Resource chart = graph.getPossibleObject(plot, l0.PartOf); + if(chart != null) + chartTime = graph.getPossibleRelatedValue(chart, jfree.Chart_time); + } + } + } + + for(SysdynDataSet dataset : datasets) { + double[] va = dataset.values; + + if(va == null || va.length == 0) + continue; + + /* + * Time + * + * 1. find time for the individual series. + * 2. find time for the whole chart + * 3. find simulation time + */ + Double time = graph.getPossibleRelatedValue(r, jfree.Series_time, Bindings.DOUBLE); + if(time == null) + time = chartTime; + if(time == null) + time = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME, Bindings.DOUBLE); + + // Value + Double value = null; + if(time == null) { + value = va[va.length - 1]; + } else { + double[] ta = dataset.times; + for(int i = 0; i < ta.length; i++) { + double t = ta[i]; + if(time <= t) { + value = va[i]; + break; + } + } + + if(value == null) + value = va[va.length - 1]; + } + + String name = label == null || label.isEmpty() ? dataset.name : label; + if(dataset.result != null) + name = name + " : " + dataset.result; + colorMap.put(name, color); + explodedMap.put(name, exploded); + series.add(new TempSeries(name, value)); + } + } catch (MissingVariableException e) { + // Do nothing, if variable was not found. Move on to the next series + } + } + } + return series; + } + + }, listener); + } + return dataset; + } + + private DatasetListener listener; + + private class DatasetListener implements Listener> { + + private boolean disposed = false; + + @Override + public void execute(final ArrayList series) { + // Modify series in AWT thread to avoid synchronization problems + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + // Remove all series + dataset.clear(); + + // Add found series + for(int i = 0; i < series.size(); i++) { + TempSeries s = series.get(i); + dataset.setValue(s.name, s.value); + } + } + }); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return disposed; + } + + public void dispose() { + disposed = true; + } + } + + @Override + public AbstractRenderer getRenderer() { + // No renderer for pie chart + return null; + } + + @Override + public void dispose() { + super.dispose(); + if(listener != null) { + listener.dispose(); + listener = null; + } + } + + + /** + * Auxiliary class containing all information needed to define a single series + * @author Teemu Lempinen + * + */ + private class TempSeries { + public String name; + public Double value; + + public TempSeries(String name, Double value) { + this.name = name; + this.value = value; + } + + @Override + public String toString() { + return "TempSeries: " + name + ", " + value; + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java new file mode 100644 index 00000000..126a0184 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import java.awt.Color; +import java.awt.Font; +import java.util.HashMap; + +import org.jfree.chart.labels.StandardPieSectionLabelGenerator; +import org.jfree.chart.labels.StandardPieToolTipGenerator; +import org.jfree.chart.plot.DefaultDrawingSupplier; +import org.jfree.chart.plot.Plot; +import org.jfree.data.general.Dataset; +import org.jfree.data.general.DatasetChangeEvent; +import org.jfree.data.general.DatasetChangeListener; +import org.jfree.ui.RectangleInsets; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Class representing a PiePlot in JFreeChart ontology + * + * @author Teemu Lempinen + * + */ +public class PiePlot extends AbstractPlot { + + private org.jfree.data.general.PieDataset pieDataset; + private DatasetChangeListener listener; + + public PiePlot(ReadGraph graph, Resource resource) { + super(graph, resource); + } + + /** + * Pie plot class with a stricter equals condition + * @author Teemu Lempinen + * + */ + private class MyPiePlot extends org.jfree.chart.plot.PiePlot { + + private static final long serialVersionUID = -5917620061541212934L; + + @Override + public boolean equals(Object obj) { + boolean result = super.equals(obj); + if(result == true) { + org.jfree.chart.plot.PiePlot that = (org.jfree.chart.plot.PiePlot) obj; + if (this.getDataset() != that.getDataset()) { + return false; // Normally plot does not check this. We need this to properly update the charts + } + } + + return result; + } + + } + + @Override + protected Plot newPlot() { + MyPiePlot plot = new MyPiePlot(); + plot.setToolTipGenerator(new StandardPieToolTipGenerator()); + return plot; + } + + @Override + protected void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException { + Boolean labelsVisible = graph.getPossibleRelatedValue(resource, JFreeChartResource.getInstance(graph).Plot_visibleLabels, Bindings.BOOLEAN); + properties.otherProperties.put("labelsVisible", labelsVisible); + } + + @Override + protected void setPlotProperties(PlotProperties properties) { + if(!(plot instanceof MyPiePlot)) + return; + + final MyPiePlot piePlot = (MyPiePlot)plot; + + if(!properties.datasets.isEmpty()) { + // We assume that a pie plot has only one dataset + final IDataset ds = properties.datasets.get(0); + Dataset dataset = ((PieDataset)ds).getDataset(); + + if(dataset == null) + return; + + if(pieDataset != null && listener != null) { + pieDataset.removeChangeListener(listener); + } + + pieDataset = (org.jfree.data.general.PieDataset)dataset; + piePlot.setDataset(pieDataset); + + Boolean labelsVisible = (Boolean)properties.otherProperties.get("labelsVisible"); + if(Boolean.FALSE.equals(labelsVisible)) + piePlot.setLabelGenerator(null); + else if(piePlot.getLabelGenerator() == null) + piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator()); + + listener = new DatasetChangeListener() { + + @Override + public void datasetChanged(DatasetChangeEvent event) { + HashMap colorMap = ((PieDataset)ds).getColorMap(); + HashMap explodedMap = ((PieDataset)ds).getExplodedMap(); + + for(Object o : piePlot.getDataset().getKeys()) { + if(o instanceof Comparable) { + Comparable key = (Comparable)o; + if(explodedMap.containsKey(key) && explodedMap.get(key)) { + piePlot.setExplodePercent(key, 0.3); + + } else { + piePlot.setExplodePercent(key, 0); + } + } + } + + for(String name : explodedMap.keySet()) { + Boolean exploded = explodedMap.get(name); + if(Boolean.TRUE.equals(exploded)) + piePlot.setExplodePercent(name, 0.3); + } + piePlot.clearSectionPaints(false); + piePlot.setDrawingSupplier(new DefaultDrawingSupplier()); + for(String name : colorMap.keySet()) + piePlot.setSectionPaint(name, colorMap.get(name)); + } + }; + + pieDataset.addChangeListener(listener); + } + + // Cleaner look: no outline borders + piePlot.setInsets(new RectangleInsets(0,0,0,0), false); + piePlot.setOutlineVisible(false); + piePlot.setLabelBackgroundPaint(Color.WHITE); + piePlot.setLabelFont(new Font("helvetica", Font.PLAIN, 11)); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/StackedBarRenderer.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/StackedBarRenderer.java new file mode 100644 index 00000000..cd7f4cbf --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/StackedBarRenderer.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.labels.StandardCategoryToolTipGenerator; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + +/** + * Stacked bar renderer + * @author Teemu Lempinen + * + */ +public class StackedBarRenderer extends AbstractRenderer { + + public StackedBarRenderer(ReadGraph graph, Resource resource) { + super(graph, resource); + } + + private org.jfree.chart.renderer.category.StackedBarRenderer renderer; + + @Override + public org.jfree.chart.renderer.AbstractRenderer getRenderer() { + if(renderer == null) { + renderer = new org.jfree.chart.renderer.category.StackedBarRenderer(); + renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); + } + return renderer; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/TextTitle.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/TextTitle.java new file mode 100644 index 00000000..7386a862 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/TextTitle.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.title.Title; +import org.jfree.ui.RectangleEdge; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Class representing a JFreeChart.TextTitle + * @author Teemu Lempinen + * + */ +public class TextTitle implements ITitle { + + private org.jfree.chart.title.TextTitle textTitle; + private RectangleEdge position; + private String text; + private Boolean visible; + + public TextTitle(ReadGraph graph, Resource titleResource) { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + try { + text = graph.getPossibleRelatedValue(titleResource, l0.HasLabel, Bindings.STRING); + Resource pos = graph.getPossibleObject(titleResource, jfree.Title_position); + position = getRectangleEdgePosition(graph, pos); + visible = graph.getPossibleRelatedValue(titleResource, jfree.visible, Bindings.BOOLEAN); + + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + /** + * Get the RectangleEdge representation for Resource position (JFreeChart.Position) + * @param graph ReadGraph + * @param position Resource of type JFreeChart.Position + * @return RectangleEdge representation for Resource position + */ + private RectangleEdge getRectangleEdgePosition(ReadGraph graph, Resource position) { + if(position == null) + return null; + + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + if(position.equals(jfree.Top)) + return RectangleEdge.TOP; + else if(position.equals(jfree.Bottom)) + return RectangleEdge.BOTTOM; + else if(position.equals(jfree.Left)) + return RectangleEdge.LEFT; + else if(position.equals(jfree.Right)) + return RectangleEdge.RIGHT; + else + return null; + + } + + @Override + public Title getTitle() { + textTitle = new org.jfree.chart.title.TextTitle(text); + if(position != null) + textTitle.setPosition(position); + if(visible != null) + textTitle.setVisible(visible); + return textTitle; + } + + @Override + public void dispose() { + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYAreaRenderer.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYAreaRenderer.java new file mode 100644 index 00000000..65337783 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYAreaRenderer.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.labels.StandardXYToolTipGenerator; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + +/** + * Renderer representing jfree chart renderer for xy areas + * @author Teemu Lempinen + * + */ +public class XYAreaRenderer extends AbstractRenderer { + + private org.jfree.chart.renderer.xy.XYAreaRenderer renderer; + + public XYAreaRenderer(ReadGraph graph, Resource resource) { + super(graph, resource); + } + + @Override + public org.jfree.chart.renderer.AbstractRenderer getRenderer() { + if(renderer == null) { + renderer = new org.jfree.chart.renderer.xy.XYAreaRenderer(); + renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); + } + return renderer; + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java new file mode 100644 index 00000000..35cf2eec --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java @@ -0,0 +1,464 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Paint; +import java.awt.Stroke; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.SwingUtilities; + +import org.jfree.chart.ChartColor; +import org.jfree.chart.labels.StandardXYToolTipGenerator; +import org.jfree.chart.plot.DefaultDrawingSupplier; +import org.jfree.chart.plot.ValueMarker; +import org.jfree.chart.renderer.AbstractRenderer; +import org.jfree.chart.renderer.xy.AbstractXYItemRenderer; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.jfree.data.general.Dataset; +import org.jfree.data.xy.DefaultXYDataset; +import org.jfree.ui.Layer; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.MissingVariableException; +import org.simantics.db.layer0.request.PossibleActiveExperiment; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.diagram.G2DUtils; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.operation.Layer0X; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.adapter.SysdynVariableProperties; +import org.simantics.sysdyn.adapter.VariableRVIUtils; +import org.simantics.sysdyn.manager.SysdynDataSet; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.Pair; + +/** + * Class representing a JFreeChart.XYDataset + * + * @author Teemu Lempinen + * + */ +public class XYDataset extends AbstractDataset { + + private IRenderer renderer; + + public XYDataset(ReadGraph graph, final Resource datasetResource) { + super(graph, datasetResource); + } + + private DefaultXYDataset dataset; + private DataSetListener datasetListener; + private TimeListener timeListener; + + @Override + public Dataset getDataset() { + if(dataset == null) { + dataset = new DefaultXYDataset(); + } + + if(datasetListener == null || datasetListener.isDisposed()) { + datasetListener = new DataSetListener(); + SimanticsUI.getSession().asyncRequest(new Read, IRenderer>>() { + + @Override + public Pair, IRenderer> perform(ReadGraph graph) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + // Renderer + IRenderer renderer = null; + Resource rendererResource = graph.getPossibleObject(resource, jfree.Dataset_renderer); + if(rendererResource != null) + renderer = graph.adapt(rendererResource, IRenderer.class); + + ArrayList series = new ArrayList(); + + String realizationURI = getRealizationURI(graph); + + if(realizationURI == null) + return new Pair, IRenderer>(series, renderer); // No experiment -> No results + + // Get a variable for the x-axis (if not time) + double[] domainValues = null; + Resource domainAxis = graph.getPossibleObject(resource, jfree.Dataset_mapToDomainAxis); + if(domainAxis != null) { + String rvi = graph.getPossibleRelatedValue(domainAxis, jfree.variableRVI); + if(rvi != null && !rvi.isEmpty()) { + try { + Variable domainVariable = Variables.getVariable(graph, realizationURI + rvi); + domainValues = domainVariable.getPossiblePropertyValue(graph, SysdynVariableProperties.VALUES , Bindings.DOUBLE_ARRAY); + } catch(MissingVariableException e) { + //Do nothing, use time as domain axis + } + } + } + + Resource seriesList = graph.getPossibleObject(resource, jfree.Dataset_seriesList); + + // Get properties for all series + if(seriesList != null) { + for(Resource r : ListUtils.toList(graph, seriesList)) { + String rvi = graph.getPossibleRelatedValue(r, jfree.variableRVI); + if(rvi == null) + continue; + + try { + // Get visual properties + Integer width = graph.getPossibleRelatedValue(r, jfree.Series_lineWidth, Bindings.INTEGER); + if(width == null) width = 1; + + Resource c = graph.getPossibleObject(r, jfree.color); + Color color = c == null ? null : G2DUtils.getColor(graph, c); + + // Get a variable for the series + Variable v = Variables.getVariable(graph, realizationURI + rvi); + + + // Get values + Object object = v.getPossiblePropertyValue(graph, SysdynVariableProperties.ACTIVE_DATASETS , Bindings.VARIANT); + if(object == null || !(object instanceof ArrayList)) + return new Pair, IRenderer>(series, renderer); + + ArrayList datasets = new ArrayList(); + + for(Object o : (ArrayList)object) { + if(o instanceof SysdynDataSet) + datasets.add((SysdynDataSet)o); + } + + + String[] filter = graph.getPossibleRelatedValue(r, jfree.variableFilter); + if(filter != null) { + ArrayList result2 = VariableRVIUtils.getDataset(datasets, filter); + if(result2 != null) { + datasets = result2; + } + } + + for(SysdynDataSet dataset : datasets) { + double[] va = dataset.values; + + // Get domain axis values (time OR other variable) + double[] ta; + if(domainValues != null) { + ta = domainValues; + + // If domainAxis is other than time, parameter values size is different. + if(domainValues.length > va.length) { + double value = va[0]; + va = new double[domainValues.length]; + for(int i = 0; i < domainValues.length; i++) + va[i] = value; + } + + // If domainAxis is a parameter, the domainValues array is too short + if(domainValues.length < va.length && domainValues.length == 2 && domainValues[0] == domainValues[1]) { + double value = domainValues[0]; + ta = new double[va.length]; + for(int i = 0; i < va.length; i++) + ta[i] = value; + } + + } else { + ta = dataset.times; + } + + if(ta!=null && va!=null && (va.length == ta.length)) { + // Add series if everything OK + String name = dataset.name; + if(dataset.result != null && !dataset.result.isEmpty()) + name = name + " : " + dataset.result; + series.add(new TempSeries(name, new double[][] {ta, va}, width, color)); + if(ta.length == 0 || va.length == 0) + System.out.println(dataset.name + " : " + dataset.result + ". Sizes: " + va.length + " and " + ta.length); + } + } + + } catch (MissingVariableException e) { + // Do nothing, if variable was not found. Move on to the next series + } + } + } + return new Pair, IRenderer>(series, renderer); + } + + }, datasetListener); + } + + if(timeListener == null || timeListener.isDisposed()) { + timeListener = new TimeListener(); + SimanticsUI.getSession().asyncRequest(new Read() { + @Override + public Double perform(ReadGraph graph) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + // Get properties for all series + Resource series = graph.getPossibleObject(resource, jfree.Dataset_seriesList); + if(series != null) { + List seriesList = ListUtils.toList(graph, series); + if(seriesList != null) { + String realizationURI = getRealizationURI(graph); + for(Resource r : seriesList) { + String rvi = graph.getPossibleRelatedValue(r, jfree.variableRVI); + if(rvi == null) + continue; + try { + // Get a variable for the series + Variable v = Variables.getVariable(graph, realizationURI + rvi); + Double time = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME , Bindings.DOUBLE); + return time; + } catch (MissingVariableException e) { + // Do nothing, if variable was not found. + } + } + } + } + return null; + } + + }, timeListener); + } + return dataset; + } + + /** + * Class for identifying a time marker in a plot + * @author Teemu Lempinen + * + */ + private class TimeMarker extends ValueMarker { + private static final long serialVersionUID = 2018755066561629172L; + + public TimeMarker(double value, Paint paint, Stroke stroke) { + super(value, paint, stroke); + } + } + + private class DataSetListener implements Listener, IRenderer>> { + + private boolean disposed = false; + + public void dispose() { + disposed = true; + } + + @Override + public boolean isDisposed() { + return disposed; + } + + @Override + public void execute(Pair, IRenderer> result) { + final ArrayList series = result.first; + renderer = result.second; + + // Modify series in AWT thread to avoid synchronization problems + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + org.jfree.chart.plot.XYPlot plot = ((AbstractXYItemRenderer)getRenderer()).getPlot(); + if(plot != null) { + /* + * Drawing supplier with a modified first yellow. The default first + * yellow is too light to be visible against a white background + */ + Paint[] paintSequence = ChartColor.createDefaultPaintArray(); + paintSequence[3] = new Color(0xFF, 0xDD, 0x00); + DefaultDrawingSupplier drawingsupplier = new DefaultDrawingSupplier( + paintSequence, + DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE, + DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, + DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, + DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, + DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE); + plot.setDrawingSupplier(drawingsupplier); + } + // Remove all series + for(int i = dataset.getSeriesCount() - 1; i >= 0; i-- ) { + dataset.removeSeries(dataset.getSeriesKey(i)); + } + + // Add found series + for(int i = 0; i < series.size(); i++) { + TempSeries s = series.get(i); + dataset.addSeries(s.name, s.values); + getRenderer().setSeriesStroke(i, new BasicStroke((float)s.width)); + getRenderer().setSeriesPaint(i, s.color); + } + } + }); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + } + + + /** + * Listener for updating the time indicator for XY plots + * @author Teemu Lempinen + * + */ + private class TimeListener implements Listener { + + private ValueMarker marker; + private boolean disposed = false; + private Stroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, + BasicStroke.JOIN_MITER, 10.0f, new float[] {5.0f, 3.0f, 1.0f, 3.0f}, 0.0f); + + public TimeListener() { + this.marker = new TimeMarker(0.0, Color.red, dashStroke); + } + + public void dispose() { + this.disposed = true; + if(marker != null) { + org.jfree.chart.plot.XYPlot plot = ((AbstractXYItemRenderer)getRenderer()).getPlot(); + if(plot != null) + plot.removeDomainMarker(marker); + } + } + + @Override + public boolean isDisposed() { + return disposed; + } + + @Override + public void execute(final Double time) { + // Modify in AWT thread to avoid synchronization problems + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + org.jfree.chart.plot.XYPlot plot = ((AbstractXYItemRenderer)getRenderer()).getPlot(); + + if(plot == null) + return; + + plot.removeDomainMarker(marker); + if(time != null) { + marker.setValue(time); + if(plot.getDomainMarkers(Layer.FOREGROUND) == null || !plot.getDomainMarkers(Layer.FOREGROUND).contains(marker)) { + int i = 0; + for(i = 0; i < plot.getDatasetCount(); i++) { + if(plot.getDataset(i) != null && plot.getDataset(i).equals(dataset)) + break; + } + plot.addDomainMarker(i, marker, Layer.FOREGROUND); + } + } + + } + }); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + } + + @Override + public void dispose() { + if(timeListener != null) { + timeListener.dispose(); + timeListener = null; + } + + if(datasetListener != null) { + datasetListener.dispose(); + datasetListener = null; + } + } + + + /** + * Auxiliary class containing all information needed to define a single series + * @author Teemu Lempinen + * + */ + private class TempSeries { + public double[][] values; + public String name; + public int width; + public Color color; + + public TempSeries(String name, double[][] values, int width, Color color) { + this.name = name; + this.values = values; + this.width = width; + this.color = color; + } + } + + @Override + public AbstractRenderer getRenderer() { + if(renderer == null) { + XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); + renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); + return renderer; + } else { + return renderer.getRenderer(); + } + } + + /** + * Get the realization uri of the current dataset resource + * @param graph ReadGraph + * @return realization uri for current dataset resource + * @throws DatabaseException + */ + private String getRealizationURI(ReadGraph graph) throws DatabaseException { + if(resource == null) + return null; + + Layer0 l0 = Layer0.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + + // Find the model where the chart is located + Resource model = resource; + do { + model = graph.getPossibleObject(model, l0.PartOf); + } while(model != null && !graph.isInstanceOf(model, mr.StructuralModel)); + + if(model == null) + return null; + + // Find the variable realization of the current experiment + String realizationURI = null; + Resource realization = graph.syncRequest(new PossibleActiveExperiment(model)); + if (realization == null) { + Layer0X L0X = Layer0X.getInstance(graph); + realization = graph.getPossibleObject(model, L0X.HasBaseRealization); + } + if (realization != null) + realizationURI = graph.getURI(realization); + + return realizationURI; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYLineRenderer.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYLineRenderer.java new file mode 100644 index 00000000..cb2a6d14 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYLineRenderer.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.labels.StandardXYToolTipGenerator; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + +/** + * Renderer representing jfree chart renderer for xy lines + * @author Teemu Lempinen + * + */ +public class XYLineRenderer extends AbstractRenderer { + + XYLineAndShapeRenderer renderer; + + public XYLineRenderer(ReadGraph graph, Resource resource) { + super(graph, resource); + } + + @Override + public org.jfree.chart.renderer.AbstractRenderer getRenderer() { + if(renderer == null) { + renderer = new XYLineAndShapeRenderer(true, false); + renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); + } + return renderer; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java new file mode 100644 index 00000000..bea1ce22 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.Plot; +import org.jfree.chart.renderer.xy.XYItemRenderer; +import org.jfree.data.xy.XYDataset; +import org.jfree.ui.RectangleInsets; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Class representing a JFreeChart.XYPlot + * + * @author Teemu Lempinen + * + */ +public class XYPlot extends AbstractPlot { + + public XYPlot(ReadGraph graph, Resource plotResource) { + super(graph, plotResource); + } + + @Override + protected Plot newPlot() { + return new org.jfree.chart.plot.XYPlot(null, null, null, null); + } + + @Override + protected void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Boolean visibleGrid = graph.getPossibleRelatedValue(resource, jfree.Plot_visibleGrid); + properties.otherProperties.put("visibleGrid", visibleGrid); + if(!properties.datasets.isEmpty()) { + IDataset idataset = properties.datasets.get(0); + Resource renderer = graph.getPossibleObject(idataset.getResource(), jfree.Dataset_renderer); + if(renderer != null) { + properties.otherProperties.put("renderer", graph.adapt(renderer, IRenderer.class)); + } + } + } + + @Override + protected void setPlotProperties(PlotProperties properties) { + if(!(plot instanceof org.jfree.chart.plot.XYPlot)) + return; + + org.jfree.chart.plot.XYPlot xyplot = (org.jfree.chart.plot.XYPlot)plot; + xyplot.clearDomainAxes(); + xyplot.clearRangeAxes(); + + for(int i = 0; i < properties.ranges.size(); i++) { + xyplot.setRangeAxis(i, (ValueAxis)properties.ranges.get(i).getAxis()); + } + + for(int i = 0; i < properties.domains.size(); i++) { + xyplot.setDomainAxis(i, (ValueAxis)properties.domains.get(i).getAxis()); + } + + IAxis axis; + for(int i = 0; i < properties.datasets.size(); i++) { + IDataset dataset = properties.datasets.get(i); + xyplot.setDataset(i, (XYDataset)dataset.getDataset()); + xyplot.setRenderer(i, (XYItemRenderer)dataset.getRenderer()); + axis = properties.rangeMappings.get(dataset); + if(axis != null && properties.ranges.contains(axis)) + xyplot.mapDatasetToRangeAxis(i, properties.ranges.indexOf(axis)); + axis = properties.domainMappings.get(dataset); + if(axis != null && properties.ranges.contains(axis)) + xyplot.mapDatasetToDomainAxis(i, properties.domains.indexOf(axis)); + } + + Boolean visibleGrid = (Boolean)properties.otherProperties.get("visibleGrid"); + if(visibleGrid == null) + visibleGrid = true; + + xyplot.setRangeGridlinesVisible(visibleGrid); + xyplot.setDomainGridlinesVisible(visibleGrid); + + // Cleaner look: no outline borders + xyplot.setInsets(new RectangleInsets(2,5,2,10), false); + xyplot.setOutlineVisible(false); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartBoundsOutline.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartBoundsOutline.java new file mode 100644 index 00000000..ef22ada6 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartBoundsOutline.java @@ -0,0 +1,37 @@ +package org.simantics.sysdyn.ui.trend.chart.element; + +import java.awt.geom.Rectangle2D; + +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementHints; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.LifeCycle; +import org.simantics.g2d.element.handler.impl.BoundsOutline; + +/** + * Outline with default bounds. Needed to avoid crashing when trying to rotate chart elements. + * @author Teemu Lempinen + * + */ +public class ChartBoundsOutline extends BoundsOutline implements LifeCycle { + private static final long serialVersionUID = -3819495313008722843L; + + Rectangle2D defaultBounds; + + public ChartBoundsOutline(Rectangle2D defaultBounds) { + this.defaultBounds = defaultBounds; + } + + @Override + public void onElementCreated(IElement e) { + e.setHint(ElementHints.KEY_BOUNDS, defaultBounds); + } + + @Override + public void onElementDestroyed(IElement e) {} + @Override + public void onElementActivated(IDiagram d, IElement e) {} + @Override + public void onElementDeactivated(IDiagram d, IElement e) {} + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementFactory.java new file mode 100644 index 00000000..0a153c93 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementFactory.java @@ -0,0 +1,184 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.element; + +import java.awt.BasicStroke; +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.Path2D; +import java.awt.geom.QuadCurve2D; +import java.awt.geom.Rectangle2D; + +import org.jfree.chart.JFreeChart; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.adapter.ElementFactory; +import org.simantics.diagram.adapter.ElementFactoryUtil; +import org.simantics.diagram.adapter.SyncElementFactory; +import org.simantics.diagram.elements.ElementPropertySetter; +import org.simantics.diagram.synchronization.CompositeHintSynchronizer; +import org.simantics.diagram.synchronization.IHintSynchronizer; +import org.simantics.diagram.synchronization.ISynchronizationContext; +import org.simantics.diagram.synchronization.SynchronizationHints; +import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; +import org.simantics.diagram.synchronization.graph.RemoveElement; +import org.simantics.diagram.synchronization.graph.TransformSynchronizer; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.LifeCycle; +import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.g2d.element.handler.impl.StaticSymbolImageInitializer; +import org.simantics.g2d.element.handler.impl.StaticSymbolImpl; +import org.simantics.g2d.image.Image; +import org.simantics.g2d.image.impl.ShapeImage; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.trend.chart.IJFreeChart; +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; + +/** + * Element factory for creating chart elements to diagrams + * + * @author Teemu Lempinen + * + */ +public class ChartElementFactory extends SyncElementFactory { + + private static final String CLASS_ID = "Chart"; + public static final ElementFactory INSTANCE = new ChartElementFactory(); + public static final Image STATIC_IMAGE = new ShapeImage(getChartShape(), null, new BasicStroke(1f), true); + public static final double SYMBOL_CHART_SIZE = 10.0; + public static final Key KEY_CHART_COMPONENT = new KeyOf(Resource.class, "CHART_COMPONENT"); + public static final Key KEY_CHART = new KeyOf(JFreeChart.class, "CHART"); + + static Shape getChartShape() { + + Path2D path = new Path2D.Double(); + // First create the axis for a chart symbol + path.moveTo(-SYMBOL_CHART_SIZE, -SYMBOL_CHART_SIZE); + path.lineTo(-SYMBOL_CHART_SIZE, SYMBOL_CHART_SIZE); + path.lineTo( SYMBOL_CHART_SIZE, SYMBOL_CHART_SIZE); + + // Then a curve to the chart + QuadCurve2D curve = new QuadCurve2D.Double( + -SYMBOL_CHART_SIZE + 1, SYMBOL_CHART_SIZE - 1, + SYMBOL_CHART_SIZE - 5, SYMBOL_CHART_SIZE - 5, + SYMBOL_CHART_SIZE - 1, -SYMBOL_CHART_SIZE + 3); + + // Connect shapes + path.append(curve, false); + return path; + } + + // Hint synchronizer for synchronizing transform and bounds + private static final IHintSynchronizer HINT_SYNCHRONIZER = new CompositeHintSynchronizer( + TransformSynchronizer.INSTANCE); + + public static ElementClass create(ReadGraph graph, Resource chart) throws DatabaseException { + return ElementClass.compile( + new ChartSceneGraph(), + new Initializer(chart), + new StaticObjectAdapter(JFreeChartResource.getInstance(graph).ChartElement), + DefaultTransform.INSTANCE, + StaticSymbolImageInitializer.INSTANCE, + new StaticSymbolImpl(STATIC_IMAGE), + new ChartBoundsOutline(new Rectangle2D.Double(-40, -40, 80, 80)), + new ElementPropertySetter(ChartSceneGraph.KEY_SG_NODE) + ).setId(CLASS_ID); + } + + public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType) throws DatabaseException { + return create(graph, null); + } + + @Override + public void load(ReadGraph g, ICanvasContext canvas, final IDiagram diagram, Resource element, final IElement e) throws DatabaseException { + + Resource chartResource; + ElementPropertySetter ps = e.getElementClass().getSingleItem(ElementPropertySetter.class); + ps.loadProperties(e, element, g); + + AffineTransform at = DiagramGraphUtil.getAffineTransform(g, element); + // Hack for disabling all rotations in chart elements + double x = at.getTranslateX(); + double y = at.getTranslateY(); + at.setToRotation(0); + at.setToTranslation(x, y); + ElementUtils.setTransform(e, at); // Set hint transform without rotations + ps.overrideProperty(e, "Transform", at); // Set property Transform without rotations + + e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, HINT_SYNCHRONIZER); + + + Object o = e.getHint(KEY_CHART_COMPONENT); + if(o == null || !(o instanceof Resource)) { + chartResource = g.getPossibleObject(element, JFreeChartResource.getInstance(g).ChartElement_component); + } else { + chartResource = (Resource)o; + } + + if(chartResource == null || !g.hasStatement(chartResource)) { + // Remove element if there is no chart resource for it + final ISynchronizationContext syncContext = ElementFactoryUtil.getContextChecked(diagram); + g.asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + new RemoveElement(syncContext, diagram, e).perform(graph); + } + }); + return; + } + + IJFreeChart ichart = g.adapt(chartResource, IJFreeChart.class); + + if(ichart != null) { + JFreeChart chart = ichart.getChart(); + e.setHint(KEY_CHART, chart); + } + + } + + + /** + * Initializer for setting a chart component for element + * @author Teemu Lempinen + * + */ + static class Initializer implements LifeCycle { + private static final long serialVersionUID = -5822080013184271204L; + Object component; + + Initializer(Object component) { + this.component = component; + } + + @Override + public void onElementCreated(IElement e) { + if(component != null) e.setHint(KEY_CHART_COMPONENT, component); + } + + @Override + public void onElementActivated(IDiagram d, IElement e) {} + @Override + public void onElementDeactivated(IDiagram d, IElement e) {} + @Override + public void onElementDestroyed(IElement e) {} + }; +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementWriter.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementWriter.java new file mode 100644 index 00000000..31ef8da5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementWriter.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.element; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.synchronization.graph.ElementWriter; +import org.simantics.g2d.element.IElement; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Element writer for chart elements. ChartElementWriter stores + * the reference to a chart definition into the element resource + * @author Teemu Lempinen + * + */ +public class ChartElementWriter implements ElementWriter { + + @Override + public void addToGraph(WriteGraph graph, IElement element, Resource elementResource) throws DatabaseException { + Resource chartComponent = element.getHint(ChartElementFactory.KEY_CHART_COMPONENT); + if (chartComponent == null) + throw new IllegalArgumentException("KEY_CHART_COMPONENT hint not set"); + + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + graph.claim(elementResource, jfree.ChartElement_component, chartComponent); + } + + @Override + public void removeFromGraph(WriteGraph graph, Resource elementResource) throws DatabaseException { + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartNode.java new file mode 100644 index 00000000..f0460938 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartNode.java @@ -0,0 +1,282 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.element; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Stroke; +import java.awt.geom.AffineTransform; +import java.awt.geom.Line2D; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +import javax.swing.JPanel; + +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.simantics.scenegraph.ISelectionPainterNode; +import org.simantics.scenegraph.g2d.events.EventTypes; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonReleasedEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent; +import org.simantics.scenegraph.swing.ComponentNode; +import org.simantics.scenegraph.utils.GeometryUtils; +import org.simantics.scenegraph.utils.NodeUtil; + +/** + * Chart node for displaying jfreechart charts in diagrams + * @author Teemu Lempinen + * + */ +public class ChartNode extends ComponentNode implements ISelectionPainterNode { + + private static final long serialVersionUID = 5013911689968911010L; + private boolean hover = false; + private boolean dragging = false; + + private ResizeListener resizeListener; + + protected transient JFreeChart chart = null; + + public boolean dragging() { + return dragging; + } + + public void setChart(JFreeChart chart) { + this.chart = chart; + } + + public void setResizeListener(ResizeListener listener) { + this.resizeListener = listener; + } + + @SyncField({"hover"}) + public void setHover(boolean hover) { + this.hover = hover; + repaint(); + } + + @Override + public void cleanup() { + removeEventHandler(this); + super.cleanup(); + } + + @Override + public void init() { + super.init(); + } + + public static void expand(Rectangle2D rectangle, double scaleX, double scaleY) { + GeometryUtils.expandRectangle(rectangle, + 5 * scaleY > 5 ? 5 * scaleY : 5, + 3 * scaleY > 3 ? 3 * scaleY : 3, + 3 * scaleX > 3 ? 3 * scaleX : 3, + 3 * scaleX > 3 ? 3 * scaleX : 3); + } + + @Override + public void render(Graphics2D g2d) { + if (component == null && chart != null) { + // Need the chart, so this cannot be done during initialization + component = new ChartPanel(chart, false); + ((ChartPanel)component).setRefreshBuffer(false); + component.setIgnoreRepaint(true); + component.setDoubleBuffered(false); + if(bounds != null) { + component.setBounds(0, 0, 0, 0); + } + super.init(); + addEventHandler(this); + } + + if (component != null) { + AffineTransform ot = g2d.getTransform(); + g2d.transform(transform); + double scaleX = g2d.getTransform().getScaleX(); + double scaleY = g2d.getTransform().getScaleY(); + + AffineTransform at = new AffineTransform(transform); + synchronized(transform) { + at.setToTranslation(bounds.getMinX(), bounds.getMinY()); + at.scale(1/scaleX, 1/scaleY); + } + g2d.transform(at); + int width = (int)(bounds.getWidth() * scaleX); + int height = (int)(bounds.getHeight() * scaleY); + + if(hover || dragging) { + // Borders + Color orig = g2d.getColor(); + BasicStroke oldStroke = (BasicStroke) g2d.getStroke(); + g2d.setColor(Color.LIGHT_GRAY); + Rectangle2D b = new Rectangle2D.Double(0, 0, width, height); + Rectangle2D r = b.getBounds2D(); + expand(r, 1 * scaleX, 1 * scaleY); + g2d.fill(r); + + // Lower right corner for dragging + double x = r.getMaxX() - (0.33 * scaleX); + double y = r.getMaxY() - (0.33 * scaleY); + + if(r.getMaxX() - x > 0.4) { + // if there is enough space, use decorated corner + BasicStroke hilightStroke = new BasicStroke(oldStroke.getLineWidth() * 3); + for(int i = 1; i < 4; i++) { + Line2D line = new Line2D.Double( + x - (i * scaleX), + y, + x, + y - (i * scaleY)); + + g2d.setStroke(hilightStroke); + g2d.setColor(Color.GRAY); + g2d.draw(line); + + g2d.setStroke(oldStroke); + g2d.setColor(Color.BLACK); + g2d.draw(line); + } + + + } else { + // not enough space, use a non-decorated corner + float f = 3; + Rectangle2D corner = new Rectangle2D.Double(r.getMaxX() - f, r.getMaxY() - f, f, f); + g2d.setColor(Color.DARK_GRAY); + g2d.fill(corner); + } + + g2d.setStroke(oldStroke); + g2d.setColor(orig); + } + + boolean selected = NodeUtil.isSelected(this, 1); + if (selected) { + Color orig = g2d.getColor(); + Stroke origStroke = g2d.getStroke(); + + g2d.setColor(Color.RED); + double s = GeometryUtils.getScale(g2d.getTransform()); + g2d.setStroke(new BasicStroke(1f * s < 1f ? 1f : 1f * (float)s)); + + Rectangle2D b = new Rectangle2D.Double(0, 0, width, height); + Rectangle2D r = b.getBounds2D(); + expand(r, scaleX, scaleY); + g2d.draw(r); + + g2d.setColor(orig); + g2d.setStroke(origStroke); + } + + synchronized(component) { + component.setLocation((int)g2d.getTransform().getTranslateX(), (int)g2d.getTransform().getTranslateY()); + if(component.getSize().getWidth() != width || component.getSize().getHeight() != height) { + component.setSize(width, height); + } + component.paint(g2d); + } + + g2d.setTransform(ot); + } else { + /* + * Component == null + * + * The related chart definition ha been removed. + */ + System.out.println("TÄÄLLÄ, TÄÄLLÄ"); + } + } + + @Override + protected boolean mouseButtonPressed(MouseButtonPressedEvent event) { + Point2D local = controlToLocal( event.controlPosition ); + local = parentToLocal(local); + Rectangle2D bounds = getBoundsInLocal().getBounds2D(); + expand(bounds, 1, 1); + double control = 3.0; + Rectangle2D corner = new Rectangle2D.Double(bounds.getMaxX() - control, bounds.getMaxY() - control, control, control); + if (hover && corner.contains(local)) { + dragging = true; + return true; + } + return super.mouseButtonPressed(event); + } + + + @Override + protected boolean mouseMoved(MouseMovedEvent e) { + if(dragging) { + Point2D local = controlToLocal( e.controlPosition ); + local = parentToLocal(local); + + Rectangle2D bounds = getBoundsInLocal().getBounds2D(); + + if(Math.abs(bounds.getMaxX() - local.getX()) > 3 || + Math.abs(bounds.getMaxY() - local.getY()) > 3) { + resize(local); + } + return true; + } + return false; + } + + public boolean hitCorner(Point2D point) { + Rectangle2D bounds = getBoundsInLocal().getBounds2D(); + expand(bounds, 1, 1); + double control = 3.0; + Rectangle2D corner = new Rectangle2D.Double(bounds.getMaxX() - control, bounds.getMaxY() - control, control, control); + return corner.contains(point); + } + + private void resize(Point2D local) { + Rectangle2D bounds = getBoundsInLocal().getBounds2D(); + double x = bounds.getX(); + double y = bounds.getY(); + double dx = local.getX() - bounds.getMaxX(); + double dy = local.getY() - bounds.getMaxY(); + double w = bounds.getWidth() + dx; + double h = bounds.getHeight() + dy; + bounds.setRect( + x, + y, + w > 20 ? w : 20, + h > 20 ? h : 20 + ); + setBounds(bounds); + } + + @Override + protected boolean mouseButtonReleased(MouseButtonReleasedEvent e) { + if(dragging) { + Point2D local = controlToLocal( e.controlPosition ); + local = parentToLocal(local); + if(Math.abs(bounds.getMaxX() - local.getX()) > 3 || + Math.abs(bounds.getMaxY() - local.getY()) > 3) { + resize(local); + } + dragging = false; + if(resizeListener != null) + resizeListener.elementResized(bounds); + } + return false; + } + + @Override + public int getEventMask() { + return EventTypes.MouseButtonPressedMask + | EventTypes.MouseMovedMask + | EventTypes.MouseButtonReleasedMask + ; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartSceneGraph.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartSceneGraph.java new file mode 100644 index 00000000..f8ea0c72 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartSceneGraph.java @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.element; + +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; + +import org.jfree.chart.JFreeChart; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.DiagramUtils; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementHints; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.SceneGraphNodeKey; +import org.simantics.g2d.element.handler.HandleMouseEvent; +import org.simantics.g2d.element.handler.InternalSize; +import org.simantics.g2d.element.handler.PropertySetter; +import org.simantics.g2d.element.handler.SceneGraph; +import org.simantics.scenegraph.Node; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.IG2DNode; +import org.simantics.scenegraph.g2d.events.MouseEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseEnterEvent; +import org.simantics.scenegraph.g2d.events.MouseEvent.MouseExitEvent; +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintListener; +import org.simantics.utils.datastructures.hints.IHintObservable; + +/** + * Chart scenegraph for chart elements in diagrams + * @author Teemu Lempinen + * + */ +public class ChartSceneGraph implements SceneGraph, HandleMouseEvent, InternalSize { + private static final long serialVersionUID = 1875762898776996989L; + + public static final Key KEY_SG_NODE = new SceneGraphNodeKey(Node.class, "CHART_SG_NODE"); + public static final Key KEY_SG_SELECTION_NODE = new SceneGraphNodeKey(Node.class, "CHART_SG_SELECTION_NODE"); + + protected IHintListener hoverHintListener; + + public ChartSceneGraph() { + } + + /** + * Expands bounds a little to allow selecting and grabbing a chart element + * from outside the chart graphics + */ + @Override + public Rectangle2D getBounds(IElement e, Rectangle2D s) { + if (s==null) s = new Rectangle2D.Double(); + + IG2DNode node = (IG2DNode)e.getHint(KEY_SG_NODE); + AffineTransform at = (AffineTransform)e.getHint(ElementHints.KEY_TRANSFORM); + if(at != null && node != null && node.getBoundsInLocal() != null) { + Shape shape = node.getBoundsInLocal(); + Rectangle2D r = shape.getBounds2D(); + double scaleX = at.getScaleX(); + double scaleY = at.getScaleY(); + ChartNode.expand(r, 1 * scaleX, 1 * scaleY); + shape = r; + s.setFrame(shape.getBounds2D()); + } else { + s.setFrame((Rectangle2D)e.getHint(ElementHints.KEY_BOUNDS)); + } + return s; + } + + @Override + public void cleanup(IElement e) { + if(hoverHintListener != null) + e.removeHintListener(hoverHintListener); + + Node node = e.removeHint(KEY_SG_NODE); + if (node != null) + node.remove(); + } + + @Override + public void init(final IElement e, G2DParentNode parent) { + ChartNode node = e.getHint(KEY_SG_NODE); + if(node == null) { + // Create a new chart node + node = parent.getOrCreateNode("chart_"+e.hashCode(), ChartNode.class); + + Rectangle2D bounds = (Rectangle2D)e.getHint(ElementHints.KEY_BOUNDS); + if(bounds == null) { + bounds = new Rectangle2D.Double(-40, -40, 80, 80); + e.setHint(ElementHints.KEY_BOUNDS, bounds); + } + node.setBounds(bounds); + + JFreeChart chart = e.getHint(ChartElementFactory.KEY_CHART); + if(chart != null) + node.setChart(chart); + + // Add a resize listener for updating bounds information to graph after resizing + node.setResizeListener(new ResizeListener() { + + @Override + public void elementResized(Rectangle2D newBounds) { + e.setHint(ElementHints.KEY_BOUNDS, newBounds); + IDiagram diagram = ElementUtils.getDiagram(e); + DiagramUtils.synchronizeHintsToBackend(diagram, e); + } + }); + + e.setHint(KEY_SG_NODE, node); + } + + // Hover listening + hoverHintListener = new IHintListener() { + @Override + public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { + + } + + @Override + public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { + if(key == ElementHints.KEY_HOVER) { + IElement e = (IElement)sender; + ChartNode name = (ChartNode) e.getHint(KEY_SG_NODE); + if (name != null) + name.setHover(Boolean.TRUE.equals(e.getHint(ElementHints.KEY_HOVER))); + } + } + }; + e.addHintListener(hoverHintListener); + + update(e); + } + + public void update(IElement e) { + PropertySetter setter = e.getElementClass().getSingleItem(PropertySetter.class); + setter.syncPropertiesToNode(e); + } + + + @Override + public boolean handleMouseEvent(IElement e, ICanvasContext ctx, MouseEvent me) { + if (me instanceof MouseEnterEvent) { + e.setHint(ElementHints.KEY_HOVER, true); + } else if (me instanceof MouseExitEvent) { + e.setHint(ElementHints.KEY_HOVER, false); + } + return false; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/PopulateChartDropParticipant.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/PopulateChartDropParticipant.java new file mode 100644 index 00000000..168c2a26 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/PopulateChartDropParticipant.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.element; + +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.awt.dnd.DnDConstants; +import java.awt.dnd.DropTargetDragEvent; +import java.awt.geom.AffineTransform; +import java.io.IOException; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.request.UnaryRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.adapter.GraphToDiagramSynchronizer; +import org.simantics.g2d.dnd.DnDHints; +import org.simantics.g2d.dnd.ElementClassDragItem; +import org.simantics.g2d.dnd.IDnDContext; +import org.simantics.g2d.dnd.IDropTargetParticipant; +import org.simantics.g2d.element.ElementHints; +import org.simantics.modeling.ui.diagramEditor.PopulateElementDropParticipant; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.ui.dnd.LocalObjectTransfer; +import org.simantics.ui.dnd.LocalObjectTransferable; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Drop participant for dropping chart definitions into diagrams + * @author Teemu Lempinen + * + */ +public class PopulateChartDropParticipant extends PopulateElementDropParticipant implements IDropTargetParticipant { + + public PopulateChartDropParticipant(GraphToDiagramSynchronizer synchronizer) { + super(synchronizer); + } + + @Override + public void dragEnter(DropTargetDragEvent dtde, final IDnDContext dp) { + Transferable tr = dtde.getTransferable(); + if (tr.isDataFlavorSupported(LocalObjectTransferable.FLAVOR)) { + + Session session = synchronizer.getSession(); + + Object obj = null; + + try { + obj = tr.getTransferData(LocalObjectTransferable.FLAVOR); + + // Create a structural selection from transfer data + if (!(obj instanceof IStructuredSelection)) { + obj = LocalObjectTransfer.getTransfer().getObject(); + } + + if (obj instanceof IStructuredSelection) { + + IStructuredSelection sel = (IStructuredSelection) obj; + + // Can drop only one chart at the time + if (sel.size() == 1) { + + // Get the chart definition + Resource chart = AdaptionUtils.adaptToSingle(sel, Resource.class); + if (chart == null) + return; + + ElementClassDragItem item = session.syncRequest(new UnaryRead(chart) { + + @Override + public ElementClassDragItem perform(ReadGraph graph) throws DatabaseException { + if(graph.isInstanceOf(parameter, JFreeChartResource.getInstance(graph).Chart)) { + ElementClassDragItem item = new ElementClassDragItem(ChartElementFactory.create(graph, parameter)); + AffineTransform initialTr = AffineTransform.getScaleInstance(1, 1); + item.getHintContext().setHint(ElementHints.KEY_TRANSFORM, initialTr); + return item; + } else { + return null; + } + + } + }); + + if(item != null) { + dp.add(item); + dp.getHints().setHint(DnDHints.KEY_DND_GRID_COLUMNS, Integer.valueOf(1)); + } + + } + + } + + } catch (UnsupportedFlavorException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + + dtde.acceptDrag(DnDConstants.ACTION_COPY); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ResizeListener.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ResizeListener.java new file mode 100644 index 00000000..6c4116b5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ResizeListener.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.element; + +import java.awt.geom.Rectangle2D; + +/** + * Interface for listeners listening resize events in chart nodes + * @author Teemu Lempinen + * + */ +public interface ResizeListener { + + /** + * Triggered when a node has been resized + * @param newBounds new bounds for the node + */ + public void elementResized(Rectangle2D newBounds); +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisChildRule.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisChildRule.java new file mode 100644 index 00000000..5b8c44a0 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisChildRule.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.graphexplorer; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.model.children.ChildRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * ChildRule for finding the axis of a JFreeChart + * + * @author Teemu Lempinen + * + */ +public class AxisChildRule implements ChildRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public Collection getChildren(ReadGraph graph, Object parent) throws DatabaseException { + ArrayList result = new ArrayList(); + if(!(parent instanceof Resource)) + return result; + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + /* + * 1. chart may have multiple plots + * 2. plot may have multiple axis + */ + for(Resource plot : graph.syncRequest(new ObjectsWithType((Resource)parent, l0.ConsistsOf, jfree.Plot))) { + Resource rangeAxisList = graph.getPossibleObject(plot, jfree.Plot_rangeAxisList); + if(rangeAxisList != null) + for(Resource axis : ListUtils.toList(graph, rangeAxisList)) { + result.add(axis); + } + } + return result; + + + } + + @Override + public Collection getParents(ReadGraph graph, Object child) throws DatabaseException { + return new ArrayList(); + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisDropAction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisDropAction.java new file mode 100644 index 00000000..e6590aa0 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisDropAction.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.graphexplorer; + +import java.util.List; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.DropActionFactory; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.trend.chart.properties.xyline.AxisAndVariablesExplorerComposite; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Action for dropping axis on top of other axis or series in {@link AxisAndVariablesExplorerComposite} + * @author Teemu Lempinen + * + */ +public class AxisDropAction implements DropActionFactory { + + @Override + public Runnable create(ReadGraph g, Object target, Object source) throws DatabaseException { + // Make sure that both target and source are resources + Resource t = AdaptionUtils.adaptToSingle(target, Resource.class); + Resource s = AdaptionUtils.adaptToSingle(source, Resource.class); + + if(t == null || s == null) + return null; + + // Make sure that source and target are of correct type + JFreeChartResource jfree = JFreeChartResource.getInstance(g); + if(!g.isInstanceOf(s, jfree.Axis)) + return null; + if(!g.isInstanceOf(t, jfree.Series) && !g.isInstanceOf(t, jfree.Axis)) + return null; + + return getRunnable(t, s); + } + + /** + * Get the runnable for doing the drop action + * + * @param t target resource + * @param s source resource + * @return Runnable + */ + private Runnable getRunnable(final Resource t, final Resource s) { + Runnable runnable = new Runnable() { + + @Override + public void run() { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if(t == null || s == null) return; + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource target = t; + Resource source = s; + + // Dragged axis always exists in the same list with target axis, so it is safe to get the target index + Resource plot = graph.getPossibleObject(source, l0.PartOf); + Resource axisListResource = graph.getPossibleObject(plot, jfree.Plot_rangeAxisList); + List axisList = ListUtils.toList(graph, axisListResource); + if(graph.isInstanceOf(target, jfree.Series)) { + // Dropped a axis over a series -> get the axis of the series + Resource dataset = graph.getPossibleObject(target, l0.PartOf); + target = graph.getPossibleObject(dataset, jfree.Dataset_mapToRangeAxis); + } + + // move axis to target position + int targetIndex = axisList.indexOf(target); + axisList.remove(source); + axisList.add(targetIndex, source); + + // Update the range axis list + graph.deny(plot, jfree.Plot_rangeAxisList); + axisListResource = ListUtils.create(graph, axisList); + graph.claim(plot, jfree.Plot_rangeAxisList, axisListResource); + } + + }); + } + }; + return runnable; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisLabelRule.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisLabelRule.java new file mode 100644 index 00000000..ee3d3636 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisLabelRule.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.graphexplorer; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.model.labels.LabelRule; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Label rule for range axis label + * @author Teemu Lempinen + * + */ +public class AxisLabelRule implements LabelRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + /** + * Range axis label + * + * Options: + * 1. Label + * 2. Default + */ + @Override + public Map getLabel(ReadGraph graph, Object content) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource resource = (Resource)content; + String label = graph.getPossibleRelatedValue(resource, l0.HasLabel, Bindings.STRING); + if(label == null || label.isEmpty()) { + label = "Range"; + Resource plot = graph.getPossibleObject(resource, l0.PartOf); + if(plot != null) { + Resource axisListResource = graph.getPossibleObject(plot, jfree.Plot_rangeAxisList); + if(axisListResource != null) { + List axisList = ListUtils.toList(graph, axisListResource); + if(axisList.contains(resource)) + label = label + " " + (axisList.indexOf(resource) + 1); + } + } + } + return Collections.singletonMap(ColumnKeys.SINGLE, label); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesChildRule.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesChildRule.java new file mode 100644 index 00000000..a12f844e --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesChildRule.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.graphexplorer; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.model.children.ChildRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Child rule for obtaining series in a chart. + * Assumes that the chart has only one plot and that plot has only one dataset + * @author Teemu Lempinen + * + */ +public class SeriesChildRule implements ChildRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public Collection getChildren(ReadGraph graph, Object parent) throws DatabaseException { + ArrayList result = new ArrayList(); + if(!(parent instanceof Resource)) + return result; + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + /* + * 1. we assume that there is only one plot + * 2. we assume that the only plot has only one dataset + */ + Resource plot = graph.syncRequest(new PossibleObjectWithType((Resource)parent, l0.ConsistsOf, jfree.Plot)); + + Resource dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.Dataset)); + + Resource seriesList = graph.getPossibleObject(dataset, jfree.Dataset_seriesList); + if(seriesList != null) + for(Resource series : ListUtils.toList(graph, seriesList)) { + result.add(series); + } + return result; + } + + @Override + public Collection getParents(ReadGraph graph, Object child) throws DatabaseException { + return new ArrayList(); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesDropAction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesDropAction.java new file mode 100644 index 00000000..241394bb --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesDropAction.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.graphexplorer; + +import java.util.Collections; +import java.util.List; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.DropActionFactory; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.trend.chart.properties.xyline.XYLineAxisAndVariablesTab; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Drop action for explorer in {@link XYLineAxisAndVariablesTab}. This action is used for dropping + * both series on axis or another sries + * + * @author Teemu Lempinen + * + */ +public class SeriesDropAction implements DropActionFactory { + + @Override + public Runnable create(ReadGraph g, Object target, Object source) throws DatabaseException { + // Make sure that both target and source are resources + Resource t = AdaptionUtils.adaptToSingle(target, Resource.class); + Resource s = AdaptionUtils.adaptToSingle(source, Resource.class); + + if(t == null || s == null) + return null; + + // Make sure that source and target are of correct type + JFreeChartResource jfree = JFreeChartResource.getInstance(g); + if(!g.isInstanceOf(s, jfree.Series)) + return null; + if(!g.isInstanceOf(t, jfree.Series) && !g.isInstanceOf(t, jfree.Axis)) + return null; + + return getRunnable(t, s); + } + + /** + * Get the runnable for doing the drop action + * + * @param t target resource + * @param s source resource + * @return Runnable + */ + private Runnable getRunnable(final Resource t, final Resource s) { + Runnable runnable = new Runnable() { + + @Override + public void run() { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if(t == null || s == null) return; + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource target = t; + Resource source = s; + Resource droppedOnSeries = null; + + // Dropped a series over a series -> get target dataset + if(graph.isInstanceOf(target, jfree.Series)) { + droppedOnSeries = target; + Resource dataset = graph.getPossibleObject(target, l0.PartOf); + if(dataset != null) + target = dataset; + } + + // Dropped a series over an axis -> get target dataset + if(graph.isInstanceOf(target, jfree.Axis)) { + Resource dataset = graph.syncRequest(new PossibleObjectWithType(target, jfree.Dataset_mapToRangeAxis_Inverse, jfree.Dataset)); + if(dataset != null) + target = dataset; + } + + // Move series to a dataset + if(graph.isInstanceOf(target, jfree.Dataset)) { + // Remove from old dataset if it was different than the new one + Resource sourceDataset = graph.getPossibleObject(source, l0.PartOf); + if(sourceDataset != null && !sourceDataset.equals(target)) { + Resource sourceSeriesList = graph.getPossibleObject(sourceDataset, jfree.Dataset_seriesList); + if(sourceSeriesList != null) + ListUtils.removeElement(graph, sourceSeriesList, source); + } + graph.deny(source, l0.PartOf); + + // Add to new dataset + Resource targetSeriesList = graph.getPossibleObject(target, jfree.Dataset_seriesList); + if(targetSeriesList == null) { + targetSeriesList = ListUtils.create(graph, Collections.emptyList()); + graph.claim(target, jfree.Dataset_seriesList, targetSeriesList); + } + + + // Series was dropped on another series. Move the dropped series to that place and recreate the list + if(droppedOnSeries != null) { + List list = ListUtils.toList(graph, targetSeriesList); + int targetIndex = list.indexOf(droppedOnSeries); + if(list.contains(source)) + list.remove(source); + list.add(targetIndex, source); + graph.deny(target, jfree.Dataset_seriesList); + targetSeriesList = ListUtils.create(graph, list); + graph.claim(target, jfree.Dataset_seriesList, targetSeriesList); + } else { + ListUtils.insertFront(graph, targetSeriesList, Collections.singleton(source)); + } + + graph.claim(target, l0.ConsistsOf, source); + } + } + }); + } + }; + return runnable; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelDecorationRule.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelDecorationRule.java new file mode 100644 index 00000000..1aebcdb7 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelDecorationRule.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.graphexplorer; + +import org.eclipse.jface.resource.FontDescriptor; +import org.simantics.browsing.ui.content.LabelDecorator; +import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.ui.utils.AdaptionUtils; + +public class SeriesLabelDecorationRule implements LabelDecorationRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException { + Resource resource = AdaptionUtils.adaptToSingle(content, Resource.class); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + + if (resource != null && graph.isInstanceOf(resource, jfree.Series)) { + final String[] filter = graph.getPossibleRelatedValue(resource, jfree.variableFilter, Bindings.STRING_ARRAY); + if(filter != null) { + return new LabelDecorator.Stub() { + @Override + public String decorateLabel(String label, String column, int itemIndex) { + label += " ["; + for(int i = 0; i < filter.length; i++) { + label += filter[i]; + if(i < filter.length - 1) + label += ", "; + } + label += "]"; + return label; + } + + @SuppressWarnings("unchecked") + @Override + public F decorateFont(F font, String column, int itemIndex) { + return (F) ((FontDescriptor) font); + } + }; + } + } + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelRule.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelRule.java new file mode 100644 index 00000000..d334765a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelRule.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.graphexplorer; + +import java.util.Collections; +import java.util.Map; + +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.model.labels.LabelRule; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Label rule for dataset series + * @author Teemu Lempinen + * + */ +public class SeriesLabelRule implements LabelRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + /** + * Options: + * 1. Label + * 2. Variable rvi + * 3. Default + */ + @Override + public Map getLabel(ReadGraph graph, Object content) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource resource = (Resource)content; + String label = graph.getPossibleRelatedValue(resource, l0.HasLabel, Bindings.STRING); + if(label == null || label.isEmpty()) { + label = graph.getPossibleRelatedValue(resource, jfree.variableRVI); + if(label != null && !label.isEmpty() && label.length() > 1) + label = label.substring(1).replace('/', '.'); + else + label = "Set variable"; + } + return Collections.singletonMap(ColumnKeys.SINGLE, label); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/VariableChildRule.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/VariableChildRule.java new file mode 100644 index 00000000..f2cf79f7 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/VariableChildRule.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.graphexplorer; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.model.children.ChildRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * ChildRule for finding the series of an axis + * + * @author Teemu Lempinen + * + */ +public class VariableChildRule implements ChildRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public Collection getChildren(ReadGraph graph, Object parent) throws DatabaseException { + ArrayList result = new ArrayList(); + if(!(parent instanceof Resource)) + return result; + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource axis = (Resource)parent; + /* + * 1. Axis belongs to a plot + * 2. Plot may have multiple datasets + * 3. Dataset is mapped to a single range axis + * 3. Dataset may have multiple seires + */ + Resource plot = graph.getPossibleObject(axis, jfree.Plot_rangeAxis_Inverse); + if(plot == null) + return result; + + for(Resource dataset : graph.syncRequest(new ObjectsWithType(plot, l0.ConsistsOf, jfree.Dataset))) { + if(graph.hasStatement(dataset, jfree.Dataset_mapToRangeAxis, axis)) { + Resource seriesList = graph.getPossibleObject(dataset, jfree.Dataset_seriesList); + if(seriesList != null) + for(Resource series : ListUtils.toList(graph, seriesList)) { + result.add(series); + } + } + } + return result; + } + + @Override + public Collection getParents(ReadGraph graph, Object child) throws DatabaseException { + return new ArrayList(); + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/AxisHidePropertyComposite.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/AxisHidePropertyComposite.java new file mode 100644 index 00000000..f8334c71 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/AxisHidePropertyComposite.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Class containing properties for hiding pars of an axis + * + * @author Teemu Lempinen + * + */ +public class AxisHidePropertyComposite extends Composite { + + public AxisHidePropertyComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) { + super(parent, style); + + GridLayoutFactory.fillDefaults().applyTo(this); + + Group hideGroup = new Group(this, SWT.NONE); + hideGroup.setText("Hide"); + GridDataFactory.fillDefaults().applyTo(hideGroup); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup); + + Button label = new Button(hideGroup, support, SWT.CHECK); + label.setText("Label"); + label.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Axis_visibleLabel, true)); + label.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Axis_visibleLabel)); + GridDataFactory.fillDefaults().applyTo(label.getWidget()); + + Button tmarks = new Button(hideGroup, support, SWT.CHECK); + tmarks.setText("Tick marks"); + tmarks.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Axis_visibleTickMarks, true)); + tmarks.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Axis_visibleTickMarks)); + GridDataFactory.fillDefaults().applyTo(tmarks.getWidget()); + + Button axisLine = new Button(hideGroup, support, SWT.CHECK); + axisLine.setText("Axis line"); + axisLine.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Axis_visibleAxisLine, true)); + axisLine.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Axis_visibleAxisLine)); + GridDataFactory.fillDefaults().applyTo(axisLine.getWidget()); + + Button tlabels = new Button(hideGroup, support, SWT.CHECK); + tlabels.setText("Tick labels"); + tlabels.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Axis_visibleTickLabels, true)); + tlabels.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Axis_visibleTickLabels)); + GridDataFactory.fillDefaults().applyTo(tlabels.getWidget()); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/BooleanPropertyFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/BooleanPropertyFactory.java new file mode 100644 index 00000000..00a09548 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/BooleanPropertyFactory.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.utils.datastructures.Quad; + +/** + * PropertyFactory for finding a boolean property. Supports also finding the + * property from a first occurrence of resource ConsistsOf type HasProperty + * + * @author Teemu Lempinen + * + */ +public class BooleanPropertyFactory extends ReadFactoryImpl { + + final private String propertyURI; + final private String typeURI; + final private Boolean inverse; + final private Boolean defaultValue; + + /** + * PropertyFactory for finding a boolean property with propertyURI + * + * @param propertyURI URI for the boolean property + */ + public BooleanPropertyFactory(String propertyURI) { + this(null, propertyURI, false); + } + + /** + * PropertyFactory for finding a boolean property with propertyURI. + * + * Supports inverting the result (e.g. if required information is IsHidden, but database contains IsVisible) + * + * @param propertyURI URI for the boolean property + * @param inverse Invert the result? + */ + public BooleanPropertyFactory(String propertyURI, boolean inverse) { + this(null, propertyURI, inverse); + } + + /** + * PropertyFactory for finding a boolean property with propertyURI. + * + * Finds the property for first ObjectWithType(resource, L0.ConsistsOf, type) + * + * Supports inverting the result (e.g. if required information is IsHidden, but database contains IsVisible) + * + * @param typeURI URI for a resource (resource ConsistsOf type) (null allowed) + * @param propertyURI URI for the boolean property + * @param inverse Invert the result? + */ + public BooleanPropertyFactory(String typeURI, String propertyURI, boolean inverse) { + this(typeURI, propertyURI, inverse, false); + } + + /** + * PropertyFactory for finding a boolean property with propertyURI. + * + * Finds the property for first ObjectWithType(resource, L0.ConsistsOf, type) + * + * Supports inverting the result (e.g. if required information is IsHidden, but database contains IsVisible) + * + * @param typeURI URI for a resource (resource ConsistsOf type) (null allowed -> not used) + * @param propertyURI URI for the boolean property + * @param inverse Invert the result? + * @param defaultValue default value + */ + public BooleanPropertyFactory(String typeURI, String propertyURI, boolean inverse, boolean defaultValue) { + this.propertyURI = propertyURI; + this.inverse = inverse; + this.typeURI = typeURI; + this.defaultValue = defaultValue; + } + + @Override + public Object getIdentity(Object inputContents) { + return new Quad((Resource) inputContents, propertyURI, getClass(), defaultValue); + } + + @Override + public Boolean perform(ReadGraph graph, Resource r) throws DatabaseException { + if(typeURI == null) { + // if no typeUri, use the default resource r + return getValue(graph, r); + } else { + // typeURI was defined, find the property for the first occurence of ConsistsOf type + Resource type = graph.getResource(typeURI); + for(Resource o : graph.syncRequest(new ObjectsWithType(r, Layer0.getInstance(graph).ConsistsOf, type))) { + // Returns the value for the first occurrence + return getValue(graph, o); + } + } + // if nothing was found with typeURI + return false; + } + + /** + * Return the value for a Boolean literal possibly inverted (or default if resource != Boolean literal) + * + * @param graph ReadGraph + * @param resource Literal Boolean resource + * @return value of the parameter (or default or inverted) + * @throws DatabaseException + */ + private Boolean getValue(ReadGraph graph, Resource resource) throws DatabaseException { + Boolean value = graph.getPossibleRelatedValue(resource, graph.getResource(propertyURI), Bindings.BOOLEAN); + if(value != null) { + return !inverse.equals(value); + } else { + return defaultValue; + } + } +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/BooleanSelectionListener.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/BooleanSelectionListener.java new file mode 100644 index 00000000..718b9b2a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/BooleanSelectionListener.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; + +/** + * Class for setting a boolean value when a selection occurs. (check box buttons) + * + * @author Teemu Lempinen + * + */ +public class BooleanSelectionListener extends SelectionListenerImpl { + + final private String propertyURI; + final private String typeUri; + + /** + * Boolean selection listener for property with propertyURI + * + * @param context ISessionContext + * @param propertyURI uri of the boolean property + */ + public BooleanSelectionListener(ISessionContext context, String propertyURI) { + this(context, null, propertyURI); + } + + /** + * Boolean selection listener for property with propertyURI + * Sets the property for all ObjectWithType(resource, L0.ConsistsOf, type) + * + * @param context ISessionContext + * @param typeUri URI for a resource (resource ConsistsOf type) (null allowed -> not used) + * @param propertyURI uri of the boolean property + */ + public BooleanSelectionListener(ISessionContext context, String typeUri, String propertyURI) { + super(context); + this.propertyURI = propertyURI; + this.typeUri = typeUri; + } + + @Override + public void apply(WriteGraph graph, Resource chart) throws DatabaseException { + if(typeUri == null) { + setValue(graph, chart); + } else { + Resource type = graph.getResource(typeUri); + for(Resource object : graph.syncRequest(new ObjectsWithType(chart, Layer0.getInstance(graph).ConsistsOf, type))) { + setValue(graph, object); + } + } + + } + + /** + * Set boolean value for Boolean literal resource (inverts the current value). + * @param graph ReadGraph + * @param resource Boolean literal resource + * @throws DatabaseException + */ + private void setValue(WriteGraph graph, Resource resource) throws DatabaseException { + Resource property = graph.getResource(propertyURI); + Boolean value = graph.getPossibleRelatedValue(resource, property, Bindings.BOOLEAN); + graph.claimLiteral(resource, property, Boolean.FALSE.equals(value)); + } +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ChartTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ChartTab.java new file mode 100644 index 00000000..179dbe92 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ChartTab.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.Resource; +import org.simantics.db.management.ISessionContext; +import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; +import org.simantics.sysdyn.ui.trend.chart.ChartComposite; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Tab for displaying a chart + * @author Teemu Lempinen + * + */ +public class ChartTab extends LabelPropertyTabContributor implements Widget { + + private Composite parent; + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + support.register(this); + this.parent = body; + } + + @Override + public void setInput(ISessionContext context, final Object input) { + Resource chart = AdaptionUtils.adaptToSingle(input, Resource.class); + new ChartComposite(parent, chart, SWT.BORDER); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ColorPicker.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ColorPicker.java new file mode 100644 index 00000000..33b1fe95 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ColorPicker.java @@ -0,0 +1,375 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Device; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.ColorDialog; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.RunnableWithObject; +import org.simantics.utils.datastructures.Triple; + +/** + * Composite for selecting a color for a chart component + * + * @author Teemu Lempinen + * + */ +public class ColorPicker extends Composite implements Widget { + + Button defaultColor, customColor, color; + + /** + * Create a composite containing radio buttons for default or custom color. Color chooser button is active + * when the custom radio button is selected. Color chooser uses {@link ColorDialog} to select a color + * + * @param parent Composite + * @param context ISessionContext + * @param support WidgetSupport + * @param style SWT style + */ + public ColorPicker(Composite parent, ISessionContext context, WidgetSupport support, int style) { + super(parent, style); + support.register(this); + + GridLayoutFactory.fillDefaults().numColumns(4).applyTo(this); + + defaultColor = new Button(this, support, SWT.RADIO); + defaultColor.setText("default"); + defaultColor.setSelectionFactory(new DefaultColorSelectionFactory(false)); + defaultColor.addSelectionListener(new DefaultColorSelectionListener(context)); + GridDataFactory.fillDefaults().applyTo(defaultColor.getWidget()); + + customColor = new Button(this, support, SWT.RADIO); + customColor.setText("custom"); + customColor.setSelectionFactory(new DefaultColorSelectionFactory(true)); + customColor.addSelectionListener(new DefaultColorSelectionListener(context)); + + GridDataFactory.fillDefaults().applyTo(customColor.getWidget()); + + color = new Button(this, support, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(color.getWidget()); + color.setImageFactory(new ColorImageFactoryFactory(color)); + color.addSelectionListener(new ColorSelectionListener(context)); + color.getWidget().setEnabled(false); + } + + /** + * Method for finding the resource for which the color is selected. + * + * @param graph ReadGraph + * @param input input from WidgetSupport + * @return + * @throws DatabaseException + */ + protected Resource getResource(ReadGraph graph, Resource input) throws DatabaseException { + return input; + } + + /** + * Method for getting the relation with which the g2d.Color is related to a resource + * + * @param graph ReadGraph + * @return Color relation + * @throws DatabaseException + */ + protected Resource getColorRelation(ReadGraph graph) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + return jfree.color; + } + + + @Override + public void setInput(ISessionContext context, Object input) { + final Resource resource = AdaptionUtils.adaptToSingle(input, Resource.class); + + // Create a listener to define the enabled state of the color chooser button + context.getSession().asyncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + // if there is a color definition, the color chooser is active + Boolean result = graph.hasStatement(getResource(graph, resource), getColorRelation(graph)); + return result; + } + + }, new Listener() { + + @Override + public void execute(Boolean result) { + if(!color.getWidget().isDisposed()) { + color.getWidget().getDisplay().asyncExec(new RunnableWithObject(result) { + @Override + public void run() { + if(!color.getWidget().isDisposed()) + color.getWidget().setEnabled((Boolean)getObject()); + } + }); + } + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return color.getWidget().isDisposed(); + } + }); + } + + /** + * Get a colored image to be displayed in the color chooser button + * + * @param device SWT Device + * @param red Red 0-255 + * @param green Green 0-255 + * @param blue Blue 0-255 + * @return + */ + private Image getColorPickerImage(Device device, int red, int green, int blue) { + Image image = new Image(device, 20, 20); + GC gc = new GC (image); + gc.setBackground (new Color(device, red, green, blue)); + gc.fillRectangle (image.getBounds ()); + gc.dispose (); + return image; + } + + /** + * ImageFactory returning an image for color button + * @author Teemu Lempinen + * + */ + private class ColorImageFactoryFactory extends ReadFactoryImpl { + + Button button; + + public ColorImageFactoryFactory(Button button) { + super(); + this.button = button; + } + + public Object getIdentity(Object inputContents) { + return new Triple, Button>(inputContents, getClass(), button); + } + + @Override + public Image perform(ReadGraph graph, Resource input) throws DatabaseException { + if(button.getWidget().isDisposed()) + return null; + Display device = button.getWidget().getDisplay(); + if(device == null) + return null; + RGB rgb = getColor(graph, getResource(graph, input)); + return getColorPickerImage(device, rgb.red, rgb.green, rgb.blue); + } + + } + + /** + * Get RGB from a color literal resource. If resource is not a color resource, return blue (RGB 0, 0, 255) + * @param graph ReadGraph + * @param input Color literal resource (float[4]) + * @return RGB color + * @throws DatabaseException + */ + private RGB getColor(ReadGraph graph, Resource input) throws DatabaseException{ + float[] colorComponents = graph.getPossibleRelatedValue(input, getColorRelation(graph)); + RGB rgb; + if(colorComponents == null) + rgb = new RGB(0, 0, 255); + else + rgb = new RGB((int)(colorComponents[0] * 255.0f), + (int)(colorComponents[1] * 255.0f), + (int)(colorComponents[2] * 255.0f)); + return rgb; + } + + + /** + * SelectionListener for color button. + * + * @author Teemu Lempinen + * + */ + private class ColorSelectionListener extends SelectionListenerImpl { + + private SelectionEvent e; + private RGB rgb; + + /** + * + * @param context ISessionContext + */ + public ColorSelectionListener(ISessionContext context) { + super(context); + } + + @Override + public void widgetSelected(SelectionEvent e) { + if(color.getWidget().isDisposed()) + return; + // Save the event for coordinates + this.e = e; + super.widgetSelected(e); + } + + @Override + public void apply(WriteGraph graph, Resource input) throws DatabaseException { + if(color.getWidget().isDisposed()) + return; + + final Resource resource = getResource(graph, input); + final Display display = color.getWidget().getDisplay(); + final RGB oldRGB = getColor(graph, resource); + + display.asyncExec(new RunnableWithObject(oldRGB) { + public void run() { + // Use color dialog to select a color + Shell shell = new Shell(display); + ColorDialog cd = new ColorDialog(shell); + Point point = color.getWidget().toDisplay(e.x - 150, e.y - 150); + cd.getParent().setLocation(point.x, point.y); + cd.setText("Select color"); + cd.setRGB((RGB)getObject()); + rgb = cd.open(); + if(rgb == null) + return; + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + G2DResource g2d = G2DResource.getInstance(graph); + float[] components = new float[] {(float)rgb.red / 255.0f, (float)rgb.green / 255.0f, (float)rgb.blue / 255.0f, 1.0f}; + graph.claimLiteral(resource, getColorRelation(graph), g2d.Color, components); + } + }); + + } + }); + + + + } + + } + + /** + * SelectionFactory for default and custom color radio buttons + * @author Teemu Lempinen + * + */ + private class DefaultColorSelectionFactory extends ReadFactoryImpl { + + private Boolean isCustom; + + /** + * + * @param isCustom Is this custom button? + */ + public DefaultColorSelectionFactory(Boolean isCustom) { + super(); + this.isCustom = isCustom; + } + + @Override + public Object getIdentity(Object inputContents) { + return new Triple((Resource) inputContents, getClass(), isCustom); + } + + @Override + public Boolean perform(ReadGraph graph, Resource input) throws DatabaseException { + Resource r = graph.getPossibleObject(getResource(graph, input), getColorRelation(graph)); + boolean result = false; // Default == not selected + if(r == null && !isCustom) { + // No color definition and default-button -> selected + result = true; + } else if(r != null && isCustom) { + // color definition and custom button -> selected + result = true; + } + return result; + } + + } + + /** + * SelectionListener for default and custom radio buttons + * + * @author Teemu Lempinen + * + */ + private class DefaultColorSelectionListener extends SelectionListenerImpl { + + private SelectionEvent e; + + public DefaultColorSelectionListener(ISessionContext context) { + super(context); + } + + @Override + public void widgetSelected(SelectionEvent e) { + this.e = e; + super.widgetSelected(e); + } + + @Override + public void apply(WriteGraph graph, Resource input) throws DatabaseException { + Resource resource = getResource(graph, input); + if(customColor.getWidget().equals(e.widget)) { + // Custom selected. If there is no color already, create a default Blue color + G2DResource g2d = G2DResource.getInstance(graph); + if(graph.getPossibleObject(resource, getColorRelation(graph)) == null) { + float[] components = java.awt.Color.BLUE.getColorComponents(new float[4]); + components[3] = 1.0f; + graph.claimLiteral(resource, getColorRelation(graph), g2d.Color, components); + } + } else { + // Default selected, remove color definition + graph.deny(resource, getColorRelation(graph)); + } + } + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java new file mode 100644 index 00000000..74b984bd --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import org.eclipse.jface.dialogs.IInputValidator; + +/** + * Validator for validating that an input is double. + * + * Can allow empty strings. + * + * @author Teemu Lempinen + * + */ +public class DoubleValidator implements IInputValidator { + + boolean allowEmpty; + + /** + * New double validator. Does not allow empty strings + */ + public DoubleValidator() { + this(false); + } + + /** + * New double validator. + * @param allowEmpty Are empty strings allowed + */ + public DoubleValidator(boolean allowEmpty) { + this.allowEmpty = allowEmpty; + } + + @Override + public String isValid(String newText) { + if (allowEmpty && newText.trim().isEmpty()) + return null; + try { + Double.parseDouble(newText); + return null; + } catch (NumberFormatException e) { + return e.getMessage(); + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/JFreeChartPropertyColorProvider.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/JFreeChartPropertyColorProvider.java new file mode 100644 index 00000000..d8dea9be --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/JFreeChartPropertyColorProvider.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import org.eclipse.jface.resource.ColorDescriptor; +import org.eclipse.jface.resource.ResourceManager; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.simantics.browsing.ui.swt.widgets.impl.ITrackedColorProvider; + +/** + * ColorProvider providing coloring scheme for chart tab text widgets + * + * @author Teemu Lempinen + * + */ +public class JFreeChartPropertyColorProvider implements ITrackedColorProvider { + + private final ResourceManager resourceManager; + + private final ColorDescriptor highlightColor = ColorDescriptor.createFrom(new RGB(254, 255, 197)); + private final ColorDescriptor inactiveColor = ColorDescriptor.createFrom(new RGB(255, 255, 255)); + private final ColorDescriptor invalidInputColor = ColorDescriptor.createFrom(new RGB(255, 128, 128)); + + public JFreeChartPropertyColorProvider(ResourceManager resourceManager) { + this.resourceManager = resourceManager; + } + + @Override + public Color getEditingBackground() { + return null; + } + + @Override + public Color getHoverBackground() { + return resourceManager.createColor(highlightColor); + } + + @Override + public Color getInactiveBackground() { + return resourceManager.createColor(inactiveColor); + } + + @Override + public Color getInvalidBackground() { + return resourceManager.createColor(invalidInputColor); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIFactory.java new file mode 100644 index 00000000..d029827b --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIFactory.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Class for providing RVI content to a text field with all '/' characters changed to '.' + * @author Teemu Lempinen + * + */ +public class RVIFactory extends ReadFactoryImpl { + + @Override + public String perform(ReadGraph graph, Resource input) throws DatabaseException { + String value = graph.getPossibleRelatedValue(input, JFreeChartResource.getInstance(graph).variableRVI); + return value != null ? value = value.substring(1).replace('/', '.') : ""; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIModifier.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIModifier.java new file mode 100644 index 00000000..9a667b8e --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIModifier.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import org.eclipse.jface.bindings.keys.KeyStroke; +import org.eclipse.jface.bindings.keys.ParseException; +import org.eclipse.jface.fieldassist.ContentProposalAdapter; +import org.eclipse.jface.fieldassist.IContentProposal; +import org.eclipse.jface.fieldassist.IContentProposalListener; +import org.eclipse.jface.fieldassist.IContentProposalListener2; +import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; +import org.eclipse.jface.fieldassist.TextContentAdapter; +import org.eclipse.swt.widgets.Control; +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Class for modifying variable name to rvi and saving it to database. + * + * Modifier also adds content proposal support to the control it is added to. + * @author Teemu Lempinen + * + */ +public class RVIModifier extends TextModifyListenerImpl { + + private boolean active; + private Control control; + + private char[] alphaNumericCharacters = { + 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','Ã¥','ä','ö', + 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Ã…','Ä','Ö', + '1','2','3','4','5','6','7','8','9','0','.'}; + + /** + * Create a new RVIModifier and attach a content proposal support to control + * @param control + * @param support + */ + public RVIModifier(Control control, WidgetSupport support) { + this.control = control; + this.active = true; + + KeyStroke keyStroke = null; + try { + keyStroke = KeyStroke.getInstance("Ctrl+Space"); + } catch (ParseException e1) { + e1.printStackTrace(); + } + + SimpleContentProposalProvider scpp = new VariableProposalProvider(control, support); + scpp.setFiltering(true); + + ContentProposalAdapter adapter = new ContentProposalAdapter( + control, new TextContentAdapter(), scpp, keyStroke, alphaNumericCharacters); + adapter.setAutoActivationDelay(0); + adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); + adapter.addContentProposalListener(new IContentProposalListener2() { + + @Override + public void proposalPopupOpened(ContentProposalAdapter adapter) { + if(RVIModifier.this != null) + RVIModifier.this.deactivate(); + } + + @Override + public void proposalPopupClosed(ContentProposalAdapter adapter) { + if(RVIModifier.this != null) + RVIModifier.this.activate(); + } + }); + + adapter.addContentProposalListener(new IContentProposalListener() { + + @Override + public void proposalAccepted(IContentProposal proposal) { + if(RVIModifier.this.control != null && !RVIModifier.this.control.isDisposed()) + RVIModifier.this.modifyText(new TrackedModifyEvent(RVIModifier.this.control, proposal.getContent())); + } + }); + + + } + + + @Override + public void applyText(WriteGraph graph, Resource resource, String text) throws DatabaseException { + if(active) { + text = "/" + text.replace('.', '/'); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + graph.claimLiteral(resource, jfree.variableRVI, text, Bindings.STRING); + graph.deny(resource, jfree.variableFilter); + } + } + + public void deactivate() { + active = false; + } + + public void activate() { + active = true; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RangeComposite.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RangeComposite.java new file mode 100644 index 00000000..40cbadef --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RangeComposite.java @@ -0,0 +1,320 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.simantics.browsing.ui.swt.widgets.TrackedCombo; +import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.trend.chart.ChartUtils; +import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.RunnableWithObject; +import org.simantics.utils.datastructures.Quad; +import org.simantics.utils.datastructures.Triple; + +/** + * Composite for range controls in chart series properties + * @author Teemu Lempinen + * + */ +public class RangeComposite extends Composite implements Widget { + + private Composite composite; + + public RangeComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) { + super(parent, style); + support.register(this); + GridLayoutFactory.fillDefaults().spacing(3, 0).margins(3, 3).applyTo(this); + GridDataFactory.fillDefaults().grab(true, false).applyTo(this); + composite = this; + } + + @Override + public void setInput(final ISessionContext context, final Object input) { + if(composite == null || composite.isDisposed()) + return; + + final Resource series = AdaptionUtils.adaptToSingle(input, Resource.class); + + /* + * Listen to the enumerations assigned to the variable in this series. + * Listener is needed because the user can change the variableRVI for the series + * and that changes the options for range + */ + context.getSession().asyncRequest(new Read>() { + + @Override + public LinkedHashMap perform(ReadGraph graph) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + + String realizationURI = ChartUtils.getCurrentRealizationURI(graph, series); + String rvi = graph.getPossibleRelatedValue(series, jfree.variableRVI); + if(rvi == null) + return null; + + try { + // Find the variable for the current variableRVI + Variable v = Variables.getVariable(graph, realizationURI + rvi.trim()); + Resource variable = v.getRepresents(graph); + + // Return the enumerations assigned to that variable + Resource arrayIndexes = graph.getPossibleObject(variable, sr.HasArrayIndexes); + if(arrayIndexes != null) { + LinkedHashMap result = new LinkedHashMap(); + for(Resource enumeration : OrderedSetUtils.toList(graph, arrayIndexes)) { + String enumerationName = NameUtils.getSafeName(graph, enumeration); + result.put(enumerationName, enumeration); + } + return result; + } + } catch (DatabaseException e) { + // No variable was found, return null + } + return null; + } + + }, new Listener>() { + + @Override + public void execute(LinkedHashMap result) { + if(isDisposed()) + return; + + // Always modify the composite, even with null result + composite.getDisplay().asyncExec(new RunnableWithObject(result) { + @Override + public void run() { + if(composite == null || composite.isDisposed()) + return; + + // Remove all content (even with null result) + for(Control child : composite.getChildren()) + child.dispose(); + + if(getObject() == null) + return; + + // New widgetSupport for the combos + WidgetSupportImpl support = new WidgetSupportImpl(); + + Label label; + TrackedCombo combo; + LinkedHashMap result = (LinkedHashMap)getObject(); + Iterator iterator = result.keySet().iterator(); + + // For each array index (enumeration), create a label and a combo + int index = 0; + while(iterator.hasNext()) { + Object key = iterator.next(); + Composite c = new Composite(composite, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(c); + GridLayoutFactory.fillDefaults().applyTo(c); + + label = new Label(c, SWT.NONE); + label.setText((String)key); + GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.END).applyTo(label); + + combo = new TrackedCombo(c, support, SWT.READ_ONLY); + combo.setItemFactory(new RangeItemFactory(index, (Resource)result.get(key))); + combo.setSelectionFactory(new RangeSelectionFactory(index)); + combo.addModifyListener(new RangeModifyListener(index, result.size())); + GridDataFactory.fillDefaults().applyTo(combo.getWidget()); + index++; + } + + // Set the width of the combo + GridLayout gl = (GridLayout)composite.getLayout(); + gl.numColumns = index; + + // Set input for the combos + support.fireInput(context, input); + + /* + * Find out if this composite is located in a scrolled composite. + * If it is, resize the scrolled composite + */ + Composite previousParent = composite.getParent(); + for(int i = 0; i < 5; i++) { + if(previousParent.getParent() instanceof ScrolledComposite) { + previousParent.layout(); + ScrolledComposite sc = (ScrolledComposite) previousParent.getParent(); + Point size = previousParent.computeSize(SWT.DEFAULT, SWT.DEFAULT); + sc.setMinSize(size); + break; + } + previousParent = previousParent.getParent(); + } + } + }); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return composite == null || composite.isDisposed(); + } + }); + } + + /** + * + * @author Teemu Lempinen + * + */ + private class RangeSelectionFactory extends ReadFactoryImpl { + + int index; + + /** + * + * @param index Index of the enumeration in the variable + */ + public RangeSelectionFactory(int index) { + this.index = index; + } + + public Object getIdentity(Object inputContents) { + return new Triple>(inputContents, index, getClass()); + } + + @Override + public String perform(ReadGraph graph, Resource series) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + String[] filter = graph.getPossibleRelatedValue(series, jfree.variableFilter, Bindings.STRING_ARRAY); + + /* + * If no filter was found or the index is not applicable, return "All" + */ + if(filter == null) + return "All"; + else if(filter.length < index) + return "All"; + else + return filter[index]; + } + + } + + /** + * RangeItemFactory finds all inexes of a given enumeration + * and adds "Sum" and "All" to the returned indexes + * @author Teemu Lempinen + * + */ + private class RangeItemFactory extends ReadFactoryImpl> { + + private int index; + private Resource enumeration; + + /** + * + * @param index Index of the enumeration in the variable + * @param enumeration The enumeration + */ + public RangeItemFactory(int index, Resource enumeration) { + this.index = index; + this.enumeration = enumeration; + } + + public Object getIdentity(Object inputContents) { + return new Quad>(inputContents, index, enumeration, getClass()); + } + @Override + public Map perform(ReadGraph graph, Resource series) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + LinkedHashMap result = new LinkedHashMap(); + Resource enumerationIndexes = graph.getPossibleObject(enumeration, sr.HasEnumerationIndexes); + List indexes = OrderedSetUtils.toList(graph, enumerationIndexes); + // First add "All" and "Sum", then all of the enumeration indexes in order + result.put("All", "All"); + result.put("Sum", "Sum"); + for(Resource index : indexes) { + String name = NameUtils.getSafeName(graph, index); + result.put(name, name); + } + return result; + } + } + + /** + * RangeModifyListener for modifying a range filter in chart series + * @author Teemu Lempinen + * + */ + private class RangeModifyListener extends ComboModifyListenerImpl { + + private int index, size; + + /** + * + * @param index Index of the modified range filter + * @param size Size of the whole filter (for situations where there is no filter) + */ + public RangeModifyListener(int index, int size) { + this.index = index; + this.size = size; + } + + @Override + public void applyText(WriteGraph graph, Resource series, String text) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + String[] filter = graph.getPossibleRelatedValue(series, jfree.variableFilter, Bindings.STRING_ARRAY); + + // If there is no filter, create a default filter with all indexes "All" + if(filter == null) { + filter = new String[size]; + for(int i = 0; i < filter.length; i++) { + filter[i] = "All"; + } + } + + // Modify the filter index + filter[index] = text; + graph.claimLiteral(series, jfree.variableFilter, filter, Bindings.STRING_ARRAY); + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TitleFactory.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TitleFactory.java new file mode 100644 index 00000000..d9a081f8 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TitleFactory.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * TextFactory for chart title + * @author Teemu Lempinen + * + */ +public class TitleFactory extends ReadFactoryImpl { + @Override + public String perform(ReadGraph graph, Resource chart) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Resource title = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.TextTitle)); + if(title == null) + return ""; + else { + String label = graph.getPossibleRelatedValue(title, l0.HasLabel, Bindings.STRING); + return label == null ? "" : label; + } + } +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TitleModifier.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TitleModifier.java new file mode 100644 index 00000000..d47fbcdd --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TitleModifier.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * TitleModifier for chart title + * @author Teemu Lempinen + * + */ +public class TitleModifier extends TextModifyListenerImpl { + + @Override + public void applyText(WriteGraph graph, Resource chart, String text) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Resource title = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.TextTitle)); + if(title == null) { + title = GraphUtils.create2(graph, jfree.TextTitle, + jfree.Title_position, jfree.Top); + } + graph.claimLiteral(title, l0.HasLabel, text); + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TrackedSpinner.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TrackedSpinner.java new file mode 100644 index 00000000..b27ecd04 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TrackedSpinner.java @@ -0,0 +1,179 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Spinner; +import org.simantics.browsing.ui.common.ErrorLogger; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactory; +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener; +import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.Listener; +import org.simantics.utils.ui.SWTUtils; + +/** + * Class for implementing Widget behavior for SWT Spinner in Simantics. + * + * @author Teemu Lempinen + * + */ +public class TrackedSpinner implements Widget { + + private Spinner spinner; + private ListenerList modifyListeners; + private ReadFactory selectionFactory; + + + public TrackedSpinner(Composite parent, WidgetSupport support, int style) { + spinner = new Spinner(parent, style); + support.register(this); + + // Add a ModifyListener that uses all listeners in modifyListeners -list + spinner.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + if (modifyListeners != null) { + TrackedModifyEvent event = new TrackedModifyEvent(spinner, spinner.getText()); + for (Object o : modifyListeners.getListeners()) { + ((TextModifyListener) o).modifyText(event); + } + } + } + }); + } + + @Override + public void setInput(ISessionContext context, Object input) { + + // Update all modifyListeners + if (modifyListeners != null) { + for (Object o : modifyListeners.getListeners()) { + if(o instanceof Widget) { + ((Widget) o).setInput(context, input); + } + } + } + + if (selectionFactory != null) { + // Get a value for the spinner + selectionFactory.listen(context, input, new Listener() { + @Override + public void exception(Throwable t) { + ErrorLogger.defaultLogError(t); + } + @Override + public void execute(final Integer selection) { + SWTUtils.asyncExec(spinner, new Runnable() { + @Override + public void run() { + if(isDisposed()) return; + spinner.setSelection(selection); + } + }); + } + @Override + public boolean isDisposed() { + return spinner.isDisposed(); + } + }); + } + + } + + /** + * Set a selection factory for the spinner + * + * @param selectionFactory ReadFactory SelectionFactory + */ + public void setSelectionFactory(ReadFactory selectionFactory) { + this.selectionFactory = selectionFactory; + } + + /** + * Add a modifyListener for the spinner + * @param listener TextModifyListener + */ + public synchronized void addModifyListener(TextModifyListener listener) { + if (modifyListeners == null) { + modifyListeners = new ListenerList(ListenerList.IDENTITY); + } + modifyListeners.add(listener); + } + + /** + * Remove modifyListener from the spinner + * + * @param listener TextModifyListener + */ + public synchronized void removeModifyListener(TextModifyListener listener) { + if (modifyListeners == null) + return; + modifyListeners.remove(listener); + } + + /** + * Get the SWT Spinner of this TrackedSpinner widget + * @return + */ + public Spinner getWidget() { + return spinner; + } + + /** + * Set minimum value + * @param value int minimum value + */ + public void setMinimum(int value) { + spinner.setMinimum(value); + } + + /** + * Set maximum value + * @param value int maximum value + */ + public void setMaximum(int value) { + spinner.setMaximum(value); + } + + /** + * Sets the receiver's selection, minimum value, maximum value, digits, increment and page increment all at once. + * + * @param selection the new selection value + * @param minimum the new minimum value + * @param maximum the new maximum value + * @param digits the new digits value + * @param increment the new increment value + * @param pageIncrement the new pageIncrement value + */ + public void setValues(int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) { + spinner.setValues(selection, minimum, maximum, digits, increment, pageIncrement); + } + + /** + * Sets the selection, which is the receiver's position, to the argument. + * If the argument is not within the range specified by minimum and maximum, + * it will be adjusted to fall within this range. + * + * @param value + */ + public void setSelection(int value) { + spinner.setSelection(value); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableProposalProvider.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableProposalProvider.java new file mode 100644 index 00000000..f4382101 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableProposalProvider.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; +import org.eclipse.swt.widgets.Control; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.strings.AlphanumComparator; + +/** + * Provides all variables a model contains + * + * @author Teemu Lempinen + * + */ +public class VariableProposalProvider extends SimpleContentProposalProvider implements Widget { + + /** + * Provides all variables a model contains. Given resource needs to be + * part of a model (i.e. using PartOf leads eventually to a SysdynModel). + * + * @param control Control that is using this provider + * @param resource A resource that is part of a model + */ + public VariableProposalProvider(final Control control, WidgetSupport support) { + super(new String [] {}); + support.register(this); + this.control = control; + } + + private Resource resource; + private Control control; + + @Override + public void setInput(ISessionContext context, Object input) { + + final Resource resource = AdaptionUtils.adaptToSingle(input, Resource.class); + if(resource == null) + return; + this.resource = resource; + + SimanticsUI.getSession().asyncRequest(new Read() { + + @Override + public String[] perform(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SimulationResource simu = SimulationResource.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + + // Find the model of this resource + Resource model = resource; + while(model != null && !graph.isInstanceOf(model, sr.SysdynModel)) + model = graph.getPossibleObject(model, l0.PartOf); + + if(model == null) + return new String[0]; + + // Find the models configuration + Resource conf = graph.getSingleObject(model, simu.HasConfiguration); + List items = new ArrayList(); + + // Recursively read all configurations and add items + ReadConfiguration(graph, conf, "", items); + + // Finally sort the results + Collections.sort(items, AlphanumComparator.CASE_INSENSITIVE_COMPARATOR); + return items.toArray(new String[items.size()]); + } + + }, new Listener() { + + @Override + public void execute(String[] result) { + setProposals(result); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return control == null || + control.isDisposed() || + !resource.equals(VariableProposalProvider.this.resource); + } + + }); + + } + + /** + * Read components in a configuration and recursively all module configurations + * + * @param graph ReadGraph + * @param configuration Resource to be read + * @param path Current path from base realization + * @param items Found variables + * @throws DatabaseException + */ + private void ReadConfiguration(ReadGraph graph, Resource configuration, String path, Collection items) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + + String name; + for(Resource resource : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.IndependentVariable))) { + name = path + NameUtils.getSafeName(graph, resource); + items.add(name); + } + + for(Resource resource : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Input))) { + name = path + NameUtils.getSafeName(graph, resource); + items.add(name); + } + + for(Resource module : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Module))) { + Resource instanceOf = graph.getPossibleObject(module, l0.InstanceOf); + Resource conf = graph.getPossibleObject(instanceOf, sr2.IsDefinedBy); + if(conf != null) { + String p = path + NameUtils.getSafeName(graph, module) + "."; + ReadConfiguration(graph, conf, p, items); + } + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java new file mode 100644 index 00000000..c17e6939 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java @@ -0,0 +1,292 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties.bar; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener; +import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ui.chart.property.DoublePropertyFactory; +import org.simantics.modeling.ui.chart.property.DoublePropertyModifier; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; +import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite; +import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; +import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; +import org.simantics.sysdyn.ui.trend.chart.properties.TrackedSpinner; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Tab for bar chart axis properties + * @author Teemu Lempinen + * + */ +public class BarAxisTab extends LabelPropertyTabContributor implements Widget { + + private TrackedSpinner angle; + private Integer angleInt = null; + private WidgetSupportImpl domainAxisSupport = new WidgetSupportImpl(); + private WidgetSupportImpl rangeAxisSupport = new WidgetSupportImpl(); + private TrackedText rangelabel, rangemin, rangemax; + private ScrolledComposite sc; + private Composite composite; + + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + support.register(this); + + // Scrolled composite containing all of the properties in this tab + sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL); + GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(sc); + sc.setExpandHorizontal(true); + sc.setExpandVertical(true); + + composite = new Composite(sc, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); + + // Domain Axis properties + Group domainGroup = new Group(composite, SWT.NONE); + GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(domainGroup); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(domainGroup); + domainGroup.setText("Domain axis"); + + // Label for x-axis + Label label = new Label(domainGroup, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Label:"); + + rangelabel = new TrackedText(domainGroup, domainAxisSupport, SWT.BORDER); + rangelabel.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); + rangelabel.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); + rangelabel.setColorProvider(new JFreeChartPropertyColorProvider(rangelabel.getResourceManager())); + GridDataFactory.fillDefaults().grab(true, false).applyTo(rangelabel.getWidget()); + + Composite axisHide = new AxisHidePropertyComposite(domainGroup, context, domainAxisSupport, SWT.NONE); + GridDataFactory.fillDefaults().span(1, 3).applyTo(axisHide); + + Label angleLabel = new Label(domainGroup, SWT.NONE); + angleLabel.setText("Label angle:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(angleLabel); + + Composite angleComposite = new Composite(domainGroup, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(angleComposite); + GridLayoutFactory.fillDefaults().applyTo(angleComposite); + angle = new TrackedSpinner(angleComposite, domainAxisSupport, SWT.BORDER); + angle.setSelectionFactory(new AngleSelectionFactory()); + angle.addModifyListener(new AngleModifyListener()); + angle.setMinimum(0); + angle.setMaximum(90); + angle.getWidget().setIncrement(5); + GridDataFactory.fillDefaults().applyTo(angle.getWidget()); + + // Domain Color + label = new Label(domainGroup, SWT.NONE); + label.setText("Color:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + Composite colorPicker = new ColorPicker(domainGroup, context, domainAxisSupport, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker); + + domainGroup.layout(); + + // Range Axis properties + Group rangeGroup = new Group(composite, SWT.NONE); + GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(rangeGroup); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(rangeGroup); + rangeGroup.setText("Range axis"); + + // Label for range axis + label = new Label(rangeGroup, SWT.NONE); + label.setText("Label:"); + label.setAlignment(SWT.RIGHT); + GridDataFactory.fillDefaults().hint(angleLabel.getBounds().width, SWT.DEFAULT).align(SWT.END, SWT.CENTER).applyTo(label); + + rangelabel = new TrackedText(rangeGroup, rangeAxisSupport, SWT.BORDER); + rangelabel.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); + rangelabel.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); + rangelabel.setColorProvider(new JFreeChartPropertyColorProvider(rangelabel.getResourceManager())); + GridDataFactory.fillDefaults().grab(true, false).applyTo(rangelabel.getWidget()); + + axisHide = new AxisHidePropertyComposite(rangeGroup, context, rangeAxisSupport, SWT.NONE); + GridDataFactory.fillDefaults().span(1, 4).applyTo(axisHide); + + // Min and max values for range axis + label = new Label(rangeGroup, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Min:"); + + Composite minmax = new Composite(rangeGroup, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(minmax); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(minmax); + rangemin = new TrackedText(minmax, rangeAxisSupport, SWT.BORDER); + rangemin.setColorProvider(new JFreeChartPropertyColorProvider(rangemin.getResourceManager())); + rangemin.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min)); + rangemin.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min)); + rangemin.setInputValidator(new DoubleValidator(true)); + + label = new Label(minmax, SWT.NONE); + label.setText("Max:"); + rangemax = new TrackedText(minmax, rangeAxisSupport, SWT.BORDER); + rangemax.setColorProvider(new JFreeChartPropertyColorProvider(rangemax.getResourceManager())); + rangemax.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max)); + rangemax.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max)); + rangemax.setInputValidator(new DoubleValidator(true)); + + // Range Color + label = new Label(rangeGroup, SWT.NONE); + label.setText("Color:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + colorPicker = new ColorPicker(rangeGroup, context, rangeAxisSupport, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker); + + // Resize scrolled composite + sc.setContent(composite); + Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); + sc.setMinSize(size); + } + + /** + * ModifyListener for the angle {@link TrackedSpinner} + * + * @author Teemu Lempinen + * + */ + private class AngleModifyListener implements TextModifyListener, Widget { + + private ISessionContext context; + private Object lastInput = null; + + @Override + public void modifyText(TrackedModifyEvent e) { + if(context == null) + return; + + // Get the text value from spinner and associated resource (input) + Spinner spinner = (Spinner)e.getWidget(); + final String textValue = spinner.getText(); + final Object input = lastInput; + + try { + context.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Resource domainAxis = AdaptionUtils.adaptToSingle(input, Resource.class); + try { + // usually reliable, since the spinner does all the checks + Double value = Double.parseDouble(textValue); + Double oldValue = graph.getPossibleRelatedValue(domainAxis, jfree.Axis_rotateLabelDegrees, Bindings.DOUBLE); + if(oldValue == null || !oldValue.equals(value)) { + graph.claimLiteral(domainAxis, jfree.Axis_rotateLabelDegrees, value, Bindings.DOUBLE); + angleInt = value.intValue(); + } + } catch (NumberFormatException e) { + graph.claimLiteral(domainAxis, jfree.Axis_rotateLabelDegrees, 0.0, Bindings.DOUBLE); + angleInt = 0; + } + } + + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + } + + @Override + public void setInput(ISessionContext context, Object parameter) { + this.context = context; + lastInput = parameter; + } + + } + + /** + * Class for setting the value for angle {@link TrackedSpinner} + * @author Teemu Lempinen + * + */ + private class AngleSelectionFactory extends ReadFactoryImpl { + + @Override + public Integer perform(ReadGraph graph, Resource domainAxis) throws DatabaseException { + if(angleInt == null) { + Double angle = 0.0; + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + if(domainAxis != null) { + Double value = graph.getPossibleRelatedValue(domainAxis, jfree.Axis_rotateLabelDegrees); + if(value != null) + angle = value; + } + return angle.intValue(); + } else { + return angleInt; + } + } + + } + + @Override + public void setInput(final ISessionContext context, Object input) { + final Resource chart = AdaptionUtils.adaptToSingle(input, Resource.class); + if(chart == null) + return; + + context.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.Plot)); + if(plot == null) return; + Resource rangeAxis = graph.getPossibleObject(plot, jfree.Plot_rangeAxis); + if(rangeAxis == null) return; + rangeAxisSupport.fireInput(context, new StructuredSelection(rangeAxis)); + + Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis); + if(domainAxis == null) return; + domainAxisSupport.fireInput(context, new StructuredSelection(domainAxis)); + } + }); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java new file mode 100644 index 00000000..be09d06a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java @@ -0,0 +1,252 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties.bar; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.layout.LayoutConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedCombo; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; +import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; +import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; +import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; +import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory; +import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier; + + +/** + * General properties of a bar chart + * @author Teemu Lempinen + * + */ +public class BarGeneralPropertiesTab extends LabelPropertyTabContributor { + + private ScrolledComposite sc; + private Composite composite; + private Button hgrid, htitle, hlegend; + private TrackedText name, title, time; + private TrackedCombo type; + + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + // Scrolled composite containing all of the properties in this tab + sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL); + GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); + GridLayoutFactory.fillDefaults().applyTo(sc); + sc.setExpandHorizontal(true); + sc.setExpandVertical(true); + + composite = new Composite(sc, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); + + // General properties + Group general = new Group(composite, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(general); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(general); + general.setText("General"); + + // first column: labels + Composite labelColumn1 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1); + GridLayoutFactory.fillDefaults().applyTo(labelColumn1); + + // second column: name and title + Composite propertyColumn1 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyColumn1); + GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(propertyColumn1); + + // third column: labels + Composite labelColumn2 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn2); + GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(labelColumn2); + + // fourth column: type and time + Composite propertyColumn2 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2); + GridLayoutFactory.fillDefaults().applyTo(propertyColumn2); + + // Name + Label label = new Label(labelColumn1, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Name:"); + + name = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget()); + name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel)); + name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); + name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); + + // Type + label = new Label(labelColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Type:"); + + type = new TrackedCombo(propertyColumn2, support, SWT.BORDER | SWT.READ_ONLY); + type.addModifyListener(new TypeModifyListener()); + type.setItemFactory(new TypeItemFactory()); + type.setSelectionFactory(new TypeSelectionFactory()); + GridDataFactory.fillDefaults().applyTo(type.getWidget()); + + // Title (Which is different than name) + label = new Label(labelColumn1, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Title:"); + + title = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget()); + title.setTextFactory(new TitleFactory()); + title.addModifyListener(new TitleModifier()); + title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); + + // Time + label = new Label(labelColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Time:"); + + time = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn2, support, SWT.BORDER); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget()); + time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Chart_time)); + time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Chart_time)); + time.setInputValidator(new DoubleValidator(true)); + time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); + + // Group for hide options + Group hideGroup = new Group(composite, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(hideGroup); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup); + hideGroup.setText("Hide"); + + hgrid = new Button(hideGroup, support, SWT.CHECK); + hgrid.setText("Grid"); + hgrid.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleGrid, true)); + hgrid.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleGrid)); + htitle = new Button(hideGroup, support, SWT.CHECK); + htitle.setText("Title"); + htitle.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible, true)); + htitle.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible)); + hlegend = new Button(hideGroup, support, SWT.CHECK); + hlegend.setText("Legend"); + hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true)); + hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend)); + + + + // Resize scrolled composite + sc.setContent(composite); + Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); + sc.setMinSize(size); + } + + /** + * + * @author Teemu Lempinen + * + */ + private class TypeSelectionFactory extends ReadFactoryImpl { + @Override + public String perform(ReadGraph graph, Resource chart) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.CategoryPlot)); + if(plot != null) { + Resource dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.CategoryDataset)); + + if(dataset != null) { + Resource renderer = graph.syncRequest(new PossibleObjectWithType(dataset, jfree.Dataset_renderer, jfree.Renderer)); + + if(renderer != null && graph.isInstanceOf(renderer, jfree.StackedBarRenderer)) + return "Stacked"; + } + } + return "Normal"; + } + } + + /** + * RangeItemFactory finds all inexes of a given enumeration + * and adds "Sum" and "All" to the returned indexes + * @author Teemu Lempinen + * + */ + private class TypeItemFactory extends ReadFactoryImpl> { + @Override + public Map perform(ReadGraph graph, Resource series) throws DatabaseException { + LinkedHashMap result = new LinkedHashMap(); + result.put("Normal", "Normal"); + result.put("Stacked", "Stacked"); + return result; + } + } + + /** + * TypeModifyListener for modifying the type of a bar chart + * @author Teemu Lempinen + * + */ + private class TypeModifyListener extends ComboModifyListenerImpl { + @Override + public void applyText(WriteGraph graph, Resource chart, String text) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.CategoryPlot)); + if(plot == null) + return; + + Resource dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.CategoryDataset)); + if(dataset == null) + return; + + graph.deny(dataset, jfree.Dataset_renderer); + + Resource renderer; + if(text.equals("Stacked")) + renderer = GraphUtils.create2(graph, jfree.StackedBarRenderer); + else + renderer = GraphUtils.create2(graph, jfree.BarRenderer); + + graph.claim(dataset, jfree.Dataset_renderer, renderer); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java new file mode 100644 index 00000000..c7597ac0 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties.bar; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; +import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; +import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory; +import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier; +import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite; + +/** + * Composite for modifying properties of a series in a bar chart + * @author Teemu Lempinen + * + */ +public class BarSeriesPropertyComposite extends Composite { + + private TrackedText variable, label, time; + + public BarSeriesPropertyComposite(Composite parent, final ISessionContext context, WidgetSupport support, int style) { + super(parent, style); + + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this); + + // Variable for the series + Label label = new Label(this, SWT.NONE); + label.setText("Variable:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + + variable = new TrackedText(this, support, SWT.BORDER); + variable.setTextFactory(new RVIFactory()); + variable.addModifyListener(new RVIModifier(variable.getWidget(), support)); + variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager())); + GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget()); + + // Range + label = new Label(this, SWT.NONE); + label.setText("Range:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + RangeComposite rangeComposite = new RangeComposite(this, context, support, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeComposite); + + + // Label to be displayed in chart for this series + label = new Label(this, SWT.NONE); + label.setText("Label:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + + this.label = new TrackedText(this, support, SWT.BORDER); + this.label.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); + this.label.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); + this.label.setColorProvider(new JFreeChartPropertyColorProvider(this.label.getResourceManager())); + GridDataFactory.fillDefaults().grab(true, false).applyTo(this.label.getWidget()); + + // Time + label = new Label(this, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + label.setText("Time:"); + + Composite composite = new Composite(this, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(composite); + GridLayoutFactory.fillDefaults().applyTo(composite); + + time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER); + time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time)); + time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time)); + time.setInputValidator(new DoubleValidator(true)); + time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); + GridDataFactory.fillDefaults().applyTo(time.getWidget()); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesTab.java new file mode 100644 index 00000000..6196c353 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesTab.java @@ -0,0 +1,213 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties.bar; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.SingleSelectionInputSource; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; +import org.simantics.sysdyn.ui.trend.chart.ChartUtils; +import org.simantics.sysdyn.ui.trend.chart.properties.xyline.AxisAndVariablesExplorerComposite; +import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.datastructures.ArrayMap; + +/** + * Tab containing the series of a bar chart + * @author Teemu Lempinen + * + */ +public class BarSeriesTab extends LabelPropertyTabContributor implements Widget { + + private GraphExplorerComposite explorer; + private ScrolledComposite propertyContainer; + private WidgetSupportImpl additionalSupport; + private Button add, remove; + private Resource chartResource; + private BarSeriesPropertyComposite spc; + + + public BarSeriesTab() { + additionalSupport = new WidgetSupportImpl(); + } + + @Override + public void createControls(Composite body, IWorkbenchSite site, final ISessionContext context, WidgetSupport support) { + support.register(this); + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); + + // (Ontology-based) GraphExplorer displaying variables in a bar chart + explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), site, composite, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE); + explorer.setBrowseContexts(SysdynResource.URIs.BarSeriesBrowseContext); + explorer.setInputSource(new SingleSelectionInputSource( + Resource.class)); + explorer.getExplorer().setAutoExpandLevel(2); // Expand everything in the beginning + explorer.finish(); + + ((Tree)explorer.getExplorerControl()).addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + updateSelection(context); + } + }); + GridDataFactory.fillDefaults().hint(250, SWT.DEFAULT).grab(false, true).applyTo(explorer); + + // Scrolled composite for displaying properties of a selection in explorer + propertyContainer = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL); + GridDataFactory.fillDefaults().span(1, 2).grab(true, true).applyTo(propertyContainer); + GridLayoutFactory.fillDefaults().applyTo(propertyContainer); + propertyContainer.setExpandHorizontal(true); + propertyContainer.setExpandVertical(true); + + // Buttons for adding and removing variables from a pie plot + Composite buttonComposite = new Composite(composite, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(buttonComposite); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite); + + add = new Button(buttonComposite, additionalSupport, SWT.NONE); + add.setText("Add"); + add.addSelectionListener(new NewVariableListener(context)); + + remove = new Button(buttonComposite, additionalSupport, SWT.NONE); + remove.setText("Remove"); + remove.addSelectionListener(new RemoveListener(context)); + } + + /** + * Updates the content of propertyContainer + * @param context + */ + private void updateSelection(ISessionContext context) { + ISelectionProvider selectionProvider = (ISelectionProvider)explorer.getAdapter(ISelectionProvider.class); + IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection(); + final Resource resource = AdaptionUtils.adaptToSingle(selection, Resource.class); + if(resource == null) + return; + + for(Control child : propertyContainer.getChildren()) { + child.dispose(); + } + spc = new BarSeriesPropertyComposite(propertyContainer, context, additionalSupport, SWT.NONE); + + additionalSupport.fireInput(context, selection); + + propertyContainer.setContent(spc); + Point size = spc.computeSize(SWT.DEFAULT, SWT.DEFAULT); + propertyContainer.setMinSize(size); + } + + /** + * SelectionListener for adding a new variable to a plot + * @author Teemu Lempinen + * + */ + private class NewVariableListener extends SelectionListenerImpl { + + public NewVariableListener(ISessionContext context) { + super(context); + } + + @Override + public void apply(WriteGraph graph, Resource input) throws DatabaseException { + Resource dataset = null; + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + if(input == null) { + if(chartResource != null) { + Resource plot = graph.syncRequest(new PossibleObjectWithType(chartResource, l0.ConsistsOf, jfree.Plot)); + if(plot != null) + dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.Dataset)); + } + } else { + if(graph.isInstanceOf(input, jfree.Series)) { + dataset = graph.getPossibleObject(input, l0.PartOf); + } + } + + if(dataset != null) { + // Create series with no rvi + ChartUtils.createSeries(graph, dataset, null); + } + } + } + + /** + * SelectionListener for remove button + * @author Teemu Lempinen + * + */ + private class RemoveListener extends SelectionListenerImpl { + + public RemoveListener(ISessionContext context) { + super(context); + } + + /** + * Removes selected resource from explorer + */ + @Override + public void apply(WriteGraph graph, Resource input) throws DatabaseException { + if(input == null) + return; + + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource list = null; + if(graph.isInstanceOf(input, jfree.Series)) { + // Remove series from dataset and seriesList + Resource dataset = graph.getPossibleObject(input, l0.PartOf); + if(dataset != null) + list = graph.getPossibleObject(dataset, jfree.Dataset_seriesList); + + if(list != null) + ListUtils.removeElement(graph, list, input); + RemoverUtil.remove(graph, input); + } + } + } + + @Override + public void setInput(ISessionContext context, Object input) { + chartResource = AdaptionUtils.adaptToSingle(input, Resource.class); + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java new file mode 100644 index 00000000..10b034aa --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties.pie; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.layout.LayoutConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; +import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; +import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; +import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; +import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory; +import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier; + +/** + * General properties of a pie chart + * @author Teemu Lempinen + * + */ +public class PieGeneralPropertiesTab extends LabelPropertyTabContributor { + + private ScrolledComposite sc; + private Composite composite; + private Button htitle, hlegend, hlabels; + private TrackedText name, title, time; + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + // Scrolled composite containing all of the properties in this tab + sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL); + GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); + GridLayoutFactory.fillDefaults().applyTo(sc); + sc.setExpandHorizontal(true); + sc.setExpandVertical(true); + + composite = new Composite(sc, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); + + // General properties + Group general = new Group(composite, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(general); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(general); + general.setText("General"); + + // first column: labels + Composite labelColumn1 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1); + GridLayoutFactory.fillDefaults().applyTo(labelColumn1); + + // first column: name and title + Composite propertyColumn1 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyColumn1); + GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(propertyColumn1); + + // first column: labels + Composite labelColumn2 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn2); + GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(labelColumn2); + + // first column: type and time + Composite propertyColumn2 = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2); + GridLayoutFactory.fillDefaults().applyTo(propertyColumn2); + + // Name + Label label = new Label(labelColumn1, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Name:"); + + name = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget()); + name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel)); + name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); + name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); + + // Dummy data for now. Waiting for different pie chart types + label = new Label(labelColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(label); + label.setText(""); + + label = new Label(propertyColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(label); + label.setText(""); + + // Title (Which is different than name) + label = new Label(labelColumn1, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Title:"); + + title = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget()); + title.setTextFactory(new TitleFactory()); + title.addModifyListener(new TitleModifier()); + title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); + + // Time + label = new Label(labelColumn2, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Time:"); + + time = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn2, support, SWT.BORDER); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget()); + time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Chart_time)); + time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Chart_time)); + time.setInputValidator(new DoubleValidator(true)); + time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); + + // Group for hide options + Group hideGroup = new Group(composite, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(hideGroup); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup); + hideGroup.setText("Hide"); + + htitle = new Button(hideGroup, support, SWT.CHECK); + htitle.setText("Title"); + htitle.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible, true)); + htitle.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible)); + hlegend = new Button(hideGroup, support, SWT.CHECK); + hlegend.setText("Legend"); + hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true)); + hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend)); + hlabels = new Button(hideGroup, support, SWT.CHECK); + hlabels.setText("Section labels"); + hlabels.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels, true)); + hlabels.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels)); + + sc.setContent(composite); + Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); + sc.setMinSize(size); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java new file mode 100644 index 00000000..dad20d4a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties.pie; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; +import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; +import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; +import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; +import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; +import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; +import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory; +import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier; +import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite; + +/** + * Composite containing the properties of a series + * @author Teemu Lempinen + * + */ +public class PieSeriesPropertyComposite extends Composite { + + private TrackedText variable, label, time; + + public PieSeriesPropertyComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) { + super(parent, style); + + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this); + + // Variable for the series + Label label = new Label(this, SWT.NONE); + label.setText("Variable:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + + variable = new TrackedText(this, support, SWT.BORDER); + variable.setTextFactory(new RVIFactory()); + variable.addModifyListener(new RVIModifier(variable.getWidget(), support)); + variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager())); + GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget()); + + // Range + label = new Label(this, SWT.NONE); + label.setText("Range:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + RangeComposite rangeComposite = new RangeComposite(this, context, support, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeComposite); + + + // Label to be displayed in chart for this series + label = new Label(this, SWT.NONE); + label.setText("Label:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + + this.label = new TrackedText(this, support, SWT.BORDER); + this.label.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); + this.label.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); + this.label.setColorProvider(new JFreeChartPropertyColorProvider(this.label.getResourceManager())); + GridDataFactory.fillDefaults().grab(true, false).applyTo(this.label.getWidget()); + + // Color + label = new Label(this, SWT.NONE); + label.setText("Color:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + Composite colorPicker = new ColorPicker(this, context, support, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker); + + // Time + label = new Label(this, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + label.setText("Time:"); + + Composite composite = new Composite(this, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(composite); + GridLayoutFactory.fillDefaults().applyTo(composite); + + time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER); + time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time)); + time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time)); + time.setInputValidator(new DoubleValidator(true)); + time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); + GridDataFactory.fillDefaults().applyTo(time.getWidget()); + + // Exploded + label = new Label(this, SWT.NONE); + label.setText(""); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + + Button exploded = new Button(this, support, SWT.CHECK); + exploded.setText("Exploded"); + exploded.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Series_exploded)); + exploded.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Series_exploded)); + GridDataFactory.fillDefaults().applyTo(exploded.getWidget()); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesTab.java new file mode 100644 index 00000000..d05e5d28 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesTab.java @@ -0,0 +1,211 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties.pie; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.SingleSelectionInputSource; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; +import org.simantics.sysdyn.ui.trend.chart.ChartUtils; +import org.simantics.sysdyn.ui.trend.chart.properties.xyline.AxisAndVariablesExplorerComposite; +import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.datastructures.ArrayMap; + +/** + * Tab for modifying series in a pie chart configuration + * @author Teemu Lempinen + * + */ +public class PieSeriesTab extends LabelPropertyTabContributor implements Widget { + + private GraphExplorerComposite explorer; + private ScrolledComposite propertyContainer; + private WidgetSupportImpl additionalSupport; + private Button add, remove; + private Resource chartResource; + + public PieSeriesTab() { + additionalSupport = new WidgetSupportImpl(); + } + + @Override + public void createControls(Composite body, IWorkbenchSite site, final ISessionContext context, WidgetSupport support) { + support.register(this); + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); + + // (Ontology-based) GraphExplorer displaying variables of a pie chart + explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), site, composite, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE); + explorer.setBrowseContexts(SysdynResource.URIs.PieSeriesBrowseContext); + explorer.setInputSource(new SingleSelectionInputSource( + Resource.class)); + explorer.getExplorer().setAutoExpandLevel(2); // Expand everything in the beginning + explorer.finish(); + + ((Tree)explorer.getExplorerControl()).addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + updateSelection(context); + } + }); + GridDataFactory.fillDefaults().hint(250, SWT.DEFAULT).grab(false, true).applyTo(explorer); + + // Scrolled composite for displaying properties of a selection in explorer + propertyContainer = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL); + GridDataFactory.fillDefaults().span(1, 2).grab(true, true).applyTo(propertyContainer); + GridLayoutFactory.fillDefaults().applyTo(propertyContainer); + propertyContainer.setExpandHorizontal(true); + propertyContainer.setExpandVertical(true); + + + // Buttons for adding and removing variables from a pie plot + Composite buttonComposite = new Composite(composite, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(buttonComposite); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite); + + add = new Button(buttonComposite, additionalSupport, SWT.NONE); + add.setText("Add"); + add.addSelectionListener(new NewVariableListener(context)); + + remove = new Button(buttonComposite, additionalSupport, SWT.NONE); + remove.setText("Remove"); + remove.addSelectionListener(new RemoveListener(context)); + } + + /** + * Updates the content of propertyContainer + * @param context + */ + private void updateSelection(ISessionContext context) { + ISelectionProvider selectionProvider = (ISelectionProvider)explorer.getAdapter(ISelectionProvider.class); + IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection(); + final Resource resource = AdaptionUtils.adaptToSingle(selection, Resource.class); + if(resource == null) + return; + + for(Control child : propertyContainer.getChildren()) { + child.dispose(); + } + + PieSeriesPropertyComposite spc = new PieSeriesPropertyComposite(propertyContainer, context, additionalSupport, SWT.NONE); + propertyContainer.setContent(spc); + Point size = spc.computeSize(SWT.DEFAULT, SWT.DEFAULT); + propertyContainer.setMinSize(size); + + additionalSupport.fireInput(context, selection); + } + + + /** + * SelectionListener for adding a new variable to a plot + * @author Teemu Lempinen + * + */ + private class NewVariableListener extends SelectionListenerImpl { + + public NewVariableListener(ISessionContext context) { + super(context); + } + + @Override + public void apply(WriteGraph graph, Resource input) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource dataset = null; + if(input == null) { + if(chartResource != null) { + Resource plot = graph.syncRequest(new PossibleObjectWithType(chartResource, l0.ConsistsOf, jfree.Plot)); + if(plot != null) + dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.Dataset)); + } + } else { + if(graph.isInstanceOf(input, jfree.Series)) { + dataset = graph.getPossibleObject(input, l0.PartOf); + } + } + if(dataset != null) { + // Create series with no rvi + Resource series = ChartUtils.createSeries(graph, dataset, null); + graph.claimLiteral(series, jfree.Series_exploded, false); + } + } + } + + /** + * SelectionListener for remove button + * @author Teemu Lempinen + * + */ + private class RemoveListener extends SelectionListenerImpl { + + public RemoveListener(ISessionContext context) { + super(context); + } + + /** + * Removes selected resource from explorer + */ + @Override + public void apply(WriteGraph graph, Resource input) throws DatabaseException { + if(input == null) + return; + + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource list = null; + if(graph.isInstanceOf(input, jfree.Series)) { + // Remove series from dataset and seriesList + Resource dataset = graph.getPossibleObject(input, l0.PartOf); + if(dataset != null) + list = graph.getPossibleObject(dataset, jfree.Dataset_seriesList); + + if(list != null) + ListUtils.removeElement(graph, list, input); + RemoverUtil.remove(graph, input); + } + } + } + + @Override + public void setInput(ISessionContext context, Object input) { + chartResource = AdaptionUtils.adaptToSingle(input, Resource.class); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisAndVariablesExplorerComposite.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisAndVariablesExplorerComposite.java new file mode 100644 index 00000000..a3ee7e6a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisAndVariablesExplorerComposite.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties.xyline; + +import java.util.ArrayList; +import java.util.Map; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.common.ErrorLogger; +import org.simantics.browsing.ui.model.InvalidContribution; +import org.simantics.browsing.ui.model.dnd.DndBrowseContext; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.Read; +import org.simantics.structural.ui.modelBrowser.ModelBrowser2; +import org.simantics.ui.SimanticsUI; + +/** + * ExplorerComposite allowing ontology-based DnD definitions. DnD Copied from {@link ModelBrowser2} + * + * @author Teemu Lempinen + * + */ +public class AxisAndVariablesExplorerComposite extends GraphExplorerComposite { + + volatile DndBrowseContext dndBrowseContext; + + public AxisAndVariablesExplorerComposite(Map args, IWorkbenchSite site, Composite parent, + WidgetSupport support, int style) { + super(args, site, parent, support, style); + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + ArrayList browseContexts = new ArrayList(); + for (String uri : getBrowseContexts()) { + Resource browseContext = graph.getPossibleResource(uri); + if (browseContext != null) + browseContexts.add(browseContext); + } + try { + dndBrowseContext = DndBrowseContext.create(graph, browseContexts); + } catch (InvalidContribution e) { + ErrorLogger.defaultLogError(e); + } + } + }); + } + + @Override + protected void handleDrop(final Object data, final NodeContext target) { + if (target == null) + return; + + SimanticsUI.getSession().asyncRequest(new Read() { + @Override + public Runnable perform(ReadGraph graph) throws DatabaseException { + if (dndBrowseContext == null) + return null; + return dndBrowseContext.getAction(graph, target, data); + } + }, new Procedure() { + @Override + public void execute(Runnable result) { + if (result != null) + result.run(); + } + + @Override + public void exception(Throwable t) { + ErrorLogger.defaultLogError(t); + } + }); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java new file mode 100644 index 00000000..22228fde --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties.xyline; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ui.chart.property.DoublePropertyFactory; +import org.simantics.modeling.ui.chart.property.DoublePropertyModifier; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite; +import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; +import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; + +/** + * Composite for displaying axis properties in {@link XYLineAxisAndVariablesTab} + * + * @author Teemu Lempinen + * + */ +public class AxisPropertyComposite extends Composite { + + TrackedText name, units, min, max; + Button tlabels, tmarks; + + public AxisPropertyComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) { + super(parent, style); + + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this); + + // Label (units) + Label label = new Label(this, SWT.NONE); + label.setText("Label: "); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + + units = new TrackedText(this, support, SWT.BORDER); + units.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); // FIXME: Units + units.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); // FIXME: Units + units.setColorProvider(new JFreeChartPropertyColorProvider(units.getResourceManager())); + GridDataFactory.fillDefaults().grab(true, false).applyTo(units.getWidget()); + + + // Minimum and maximum values + label = new Label(this, SWT.NONE); + label.setText("Min:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + Composite minmax = new Composite(this, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(minmax); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(minmax); + min = new TrackedText(minmax, support, SWT.BORDER); + min.setColorProvider(new JFreeChartPropertyColorProvider(min.getResourceManager())); + min.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min)); + min.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min)); + min.setInputValidator(new DoubleValidator(true)); + + label = new Label(minmax, SWT.NONE); + label.setText("Max:"); + max = new TrackedText(minmax, support, SWT.BORDER); + max.setColorProvider(new JFreeChartPropertyColorProvider(max.getResourceManager())); + max.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max)); + max.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max)); + max.setInputValidator(new DoubleValidator(true)); + + + // Color + label = new Label(this, SWT.NONE); + label.setText("Color:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + Composite colorPicker = new ColorPicker(this, context, support, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker); + + // Tick and label visibility + Composite c = new Composite(this, SWT.NONE); + GridDataFactory.fillDefaults().span(2, 1).applyTo(c); + GridLayoutFactory.fillDefaults().applyTo(c); + Composite axisHide = new AxisHidePropertyComposite(c, context, support, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(axisHide); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/SeriesPropertyComposite.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/SeriesPropertyComposite.java new file mode 100644 index 00000000..f0568510 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/SeriesPropertyComposite.java @@ -0,0 +1,183 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties.xyline; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener; +import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker; +import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; +import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory; +import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier; +import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite; +import org.simantics.sysdyn.ui.trend.chart.properties.TrackedSpinner; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * Composite for displaying series properties in {@link XYLineAxisAndVariablesTab} + * + * @author Teemu Lempinen + * + */ +public class SeriesPropertyComposite extends Composite { + + private TrackedText variable, label; + private TrackedSpinner width; + + public SeriesPropertyComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) { + super(parent, style); + + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this); + + // Variable for the series + Label label = new Label(this, SWT.NONE); + label.setText("Variable:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + + variable = new TrackedText(this, support, SWT.BORDER); + variable.setTextFactory(new RVIFactory()); + variable.addModifyListener(new RVIModifier(variable.getWidget(), support)); + variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager())); + GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget()); + + // Range + label = new Label(this, SWT.NONE); + label.setText("Range:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + RangeComposite rangeComposite = new RangeComposite(this, context, support, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeComposite); + + // Label to be displayed in chart for this series + label = new Label(this, SWT.NONE); + label.setText("Label:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + + this.label = new TrackedText(this, support, SWT.BORDER); + this.label.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); + this.label.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); + this.label.setColorProvider(new JFreeChartPropertyColorProvider(this.label.getResourceManager())); + GridDataFactory.fillDefaults().grab(true, false).applyTo(this.label.getWidget()); + + // Color + label = new Label(this, SWT.NONE); + label.setText("Color:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + + Composite colorPicker = new ColorPicker(this, context, support, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker); + + // Line width + label = new Label(this, SWT.NONE); + label.setText("Line width:"); + GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); + + width = new TrackedSpinner(this, support, SWT.BORDER); + width.setSelectionFactory(new WidthSelectionFactory()); + width.addModifyListener(new WidthModifyListener()); + width.setMinimum(1); + width.setMaximum(10); + + } + + + /** + * ModifyListener for the width {@link TrackedSpinner} + * + * @author Teemu Lempinen + * + */ + private class WidthModifyListener implements TextModifyListener, Widget { + + private ISessionContext context; + private Object lastInput = null; + + @Override + public void modifyText(TrackedModifyEvent e) { + if(context == null) + return; + + // Get the text value from spinner and associated resource (input) + Spinner spinner = (Spinner)e.getWidget(); + final String textValue = spinner.getText(); + final Object input = lastInput; + + try { + context.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + // Apply with (textValue) to the series (input) + Resource series = AdaptionUtils.adaptToSingle(input, Resource.class); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + try { + // usually reliable, since the spinner does all the checks + Integer value = Integer.parseInt(textValue); + graph.claimLiteral(series, jfree.Series_lineWidth, value, Bindings.INTEGER); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + } + + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + } + + @Override + public void setInput(ISessionContext context, Object parameter) { + this.context = context; + lastInput = parameter; + } + + } + + /** + * Class for setting the value for width {@link TrackedSpinner} + * @author Teemu Lempinen + * + */ + private class WidthSelectionFactory extends ReadFactoryImpl { + + @Override + public Integer perform(ReadGraph graph, Resource axis) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Integer width = graph.getPossibleRelatedValue(axis, jfree.Series_lineWidth); + if(width == null) + // Default width == 1 + width = 1; + return width; + } + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineAxisAndVariablesTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineAxisAndVariablesTab.java new file mode 100644 index 00000000..530d611a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineAxisAndVariablesTab.java @@ -0,0 +1,283 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties.xyline; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.SingleSelectionInputSource; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; +import org.simantics.sysdyn.ui.trend.chart.ChartUtils; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.datastructures.ArrayMap; + +/** + * PropertyTab displaying properties of axis and variables of a chart + * + * @author Teemu Lempinen + * + */ +public class XYLineAxisAndVariablesTab extends LabelPropertyTabContributor { + + private GraphExplorerComposite explorer; + private ScrolledComposite propertyContainer; + private Button addAxis, addVariable, remove; + private WidgetSupportImpl additionalSupport; + + public XYLineAxisAndVariablesTab() { + additionalSupport = new WidgetSupportImpl(); + } + + @Override + public void createControls(Composite body, IWorkbenchSite site, final ISessionContext context, WidgetSupport support) { + Composite composite = new Composite(body, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); + + // (Ontology-based) GraphExplorer displaying range axis and variables mapped to those axis + explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), site, composite, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE); + explorer.setBrowseContexts(SysdynResource.URIs.ChartAxisAndVariablesBrowseContext); + explorer.setInputSource(new SingleSelectionInputSource( + Resource.class)); + explorer.getExplorer().setAutoExpandLevel(2); // Expand everything in the beginning + explorer.finish(); + + ((Tree)explorer.getExplorerControl()).addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + updateSelection(context); + } + }); + GridDataFactory.fillDefaults().hint(250, SWT.DEFAULT).grab(false, true).applyTo(explorer); + + // Scrolled composite for displaying properties of a selection in explorer + propertyContainer = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL); + GridDataFactory.fillDefaults().span(1, 2).grab(true, true).applyTo(propertyContainer); + GridLayoutFactory.fillDefaults().applyTo(propertyContainer); + propertyContainer.setExpandHorizontal(true); + propertyContainer.setExpandVertical(true); + + // Buttons for adding axis and variables and removing selected items from explorer + Composite buttonComposite = new Composite(composite, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(buttonComposite); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite); + + addAxis = new Button(buttonComposite, support, SWT.NONE); + addAxis.setText("Add axis"); + addAxis.addSelectionListener(new NewAxisListener(context)); + + addVariable = new Button(buttonComposite, additionalSupport, SWT.NONE); + addVariable.setText("Add variable"); + addVariable.addSelectionListener(new NewVariableListener(context)); + + remove = new Button(buttonComposite, additionalSupport, SWT.NONE); + remove.setText("Remove"); + remove.addSelectionListener(new RemoveListener(context)); + } + + /** + * Updates the content of propertyContainer + * @param context + */ + private void updateSelection(ISessionContext context) { + ISelectionProvider selectionProvider = (ISelectionProvider)explorer.getAdapter(ISelectionProvider.class); + IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection(); + final Resource resource = AdaptionUtils.adaptToSingle(selection, Resource.class); + if(resource == null) + return; + + // Get the type of the selected node (axis or series) + String typeUri = null; + try { + typeUri = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + if(graph.isInstanceOf(resource, jfree.Axis)) + return graph.getURI(jfree.Axis); + else if (graph.isInstanceOf(resource, jfree.Series)) + return graph.getURI(jfree.Series); + return null; + } + + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + // Create a PropertyComposite for the selected node + if(typeUri != null) { + + for(Control child : propertyContainer.getChildren()) { + child.dispose(); + } + + if(typeUri.equals(JFreeChartResource.URIs.Axis)) { + AxisPropertyComposite apc = new AxisPropertyComposite(propertyContainer, context, additionalSupport, SWT.NONE); + propertyContainer.setContent(apc); + Point size = apc.computeSize(SWT.DEFAULT, SWT.DEFAULT); + propertyContainer.setMinSize(size); + } else if(typeUri.equals(JFreeChartResource.URIs.Series)) { + SeriesPropertyComposite spc = new SeriesPropertyComposite(propertyContainer, context, additionalSupport, SWT.NONE); + propertyContainer.setContent(spc); + Point size = spc.computeSize(SWT.DEFAULT, SWT.DEFAULT); + propertyContainer.setMinSize(size); + } + } + + additionalSupport.fireInput(context, selection); + } + + /** + * SelectionListener for adding a new range axis to a plot + * @author Teemu Lempinen + * + */ + private class NewAxisListener extends SelectionListenerImpl { + + public NewAxisListener(ISessionContext context) { + super(context); + } + + @Override + public void apply(WriteGraph graph, Resource chart) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.Plot)); + if(plot != null) { + Resource rangeAxis = ChartUtils.createNumberRangeAxis(graph, plot); + if(rangeAxis != null) { + Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis); + ChartUtils.createXYDataset(graph, plot, domainAxis, rangeAxis); + } + } + } + } + + + /** + * SelectionListener for adding a new variable to a plot + * @author Teemu Lempinen + * + */ + private class NewVariableListener extends SelectionListenerImpl { + + public NewVariableListener(ISessionContext context) { + super(context); + } + + @Override + public void apply(WriteGraph graph, Resource input) throws DatabaseException { + if(input == null) + return; + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource dataset; + if(graph.isInstanceOf(input, jfree.Series)) { + // Selected resource is series. Add to same dataset + dataset = graph.getPossibleObject(input, l0.PartOf); + } else { + // Selected resource is axis. Find the dataset it is mapped to or create dataset if not created already + dataset = graph.getPossibleObject(input, jfree.Dataset_mapToRangeAxis_Inverse); + if(dataset == null) { + Resource plot = graph.getPossibleObject(input, l0.PartOf); + if(plot == null) return; + Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis); + if(domainAxis == null) return; + ChartUtils.createXYDataset(graph, plot, domainAxis, input); + } + } + + if(dataset != null) { + // Create series with no rvi + ChartUtils.createSeries(graph, dataset, null); + } + } + } + + + /** + * SelectionListener for remove button + * @author Teemu Lempinen + * + */ + private class RemoveListener extends SelectionListenerImpl { + + public RemoveListener(ISessionContext context) { + super(context); + } + + /** + * Removes selected resource from explorer + */ + @Override + public void apply(WriteGraph graph, Resource input) throws DatabaseException { + if(input == null) + return; + + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource list = null; + if(graph.isInstanceOf(input, jfree.Series)) { + // Remove series from dataset and seriesList + Resource dataset = graph.getPossibleObject(input, l0.PartOf); + if(dataset != null) + list = graph.getPossibleObject(dataset, jfree.Dataset_seriesList); + } else { + // Remove associated dataset + Resource dataset = graph.getPossibleObject(input, jfree.Dataset_mapToRangeAxis_Inverse); + if(dataset != null) { + graph.deny(dataset, jfree.Dataset_mapToDomainAxis); + graph.deny(dataset, jfree.Dataset_mapToRangeAxis); + RemoverUtil.remove(graph, dataset); + } + + // Remove axis from plot and rangeAxisList + Resource plot = graph.getPossibleObject(input, l0.PartOf); + if(plot != null) + list = graph.getPossibleObject(plot, jfree.Plot_rangeAxisList); + } + if(list != null) + ListUtils.removeElement(graph, list, input); + RemoverUtil.remove(graph, input); + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java new file mode 100644 index 00000000..c4e730da --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java @@ -0,0 +1,316 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.properties.xyline; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; +import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedCombo; +import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.PossibleObjectWithType; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ui.chart.property.DoublePropertyFactory; +import org.simantics.modeling.ui.chart.property.DoublePropertyModifier; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; +import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite; +import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; +import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; +import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; +import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; +import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory; +import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier; +import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory; +import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier; +import org.simantics.ui.utils.AdaptionUtils; + +/** + * PropertyTab displaying general properties and x-axis properties of a chart + * + * @author Teemu Lempinen + * + */ +public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor implements Widget { + + private ScrolledComposite sc; + private Composite composite; + private TrackedText name, title, xlabel, xvariable, xmin, xmax; + private TrackedCombo type; + private Button hgrid, htitle, hlegend; + private WidgetSupportImpl domainAxisSupport = new WidgetSupportImpl(); + + @Override + public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { + support.register(this); + + // Scrolled composite containing all of the properties in this tab + sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL); + GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); + GridLayoutFactory.fillDefaults().applyTo(sc); + sc.setExpandHorizontal(true); + sc.setExpandVertical(true); + + composite = new Composite(sc, SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); + + // General properties + Group general = new Group(composite, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(general); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(general); + general.setText("General"); + + // Name + Label nameLabel = new Label(general, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(nameLabel); + nameLabel.setText("Name:"); + nameLabel.setAlignment(SWT.RIGHT); + + Composite c = new Composite(general, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(c); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(c); + + name = new org.simantics.browsing.ui.swt.widgets.TrackedText(c, support, SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget()); + name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel)); + name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); + name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); + + // Type + Label label = new Label(c, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Type:"); + + type = new TrackedCombo(c, support, SWT.BORDER | SWT.READ_ONLY); + type.addModifyListener(new TypeModifyListener()); + type.setItemFactory(new TypeItemFactory()); + type.setSelectionFactory(new TypeSelectionFactory()); + GridDataFactory.fillDefaults().applyTo(type.getWidget()); + + // Title (Which is different than name) + label = new Label(general, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Title:"); + + title = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget()); + title.setTextFactory(new TitleFactory()); + title.addModifyListener(new TitleModifier()); + title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); + + // Group for hide options + Group hideGroup = new Group(composite, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(hideGroup); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup); + hideGroup.setText("Hide"); + + hgrid = new Button(hideGroup, support, SWT.CHECK); + hgrid.setText("Grid"); + hgrid.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleGrid, true)); + hgrid.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleGrid)); + htitle = new Button(hideGroup, support, SWT.CHECK); + htitle.setText("Title"); + htitle.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible, true)); + htitle.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible)); + hlegend = new Button(hideGroup, support, SWT.CHECK); + hlegend.setText("Legend"); + hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true)); + hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend)); + + + // X-Axis properties + Group xgroup = new Group(composite, SWT.NONE); + GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(xgroup); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(xgroup); + xgroup.setText("X-axis"); + + // Variable for x-axis (default: empty == time) + Label xVariableLabel = new Label(xgroup, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(xVariableLabel); + xVariableLabel.setText("Variable:"); + + xvariable = new TrackedText(xgroup, domainAxisSupport, SWT.BORDER); + xvariable.setTextFactory(new RVIFactory()); + xvariable.addModifyListener(new RVIModifier(xvariable.getWidget(), domainAxisSupport)); + xvariable.setColorProvider(new JFreeChartPropertyColorProvider(xvariable.getResourceManager())); + GridDataFactory.fillDefaults().grab(true, false).applyTo(xvariable.getWidget()); + + Composite axisHide = new AxisHidePropertyComposite(xgroup, context, domainAxisSupport, SWT.NONE); + GridDataFactory.fillDefaults().span(1, 3).applyTo(axisHide); + + // Label for x-axis + label = new Label(xgroup, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Label:"); + + xlabel = new TrackedText(xgroup, domainAxisSupport, SWT.BORDER); + xlabel.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); + xlabel.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); + xlabel.setColorProvider(new JFreeChartPropertyColorProvider(xlabel.getResourceManager())); + GridDataFactory.fillDefaults().grab(true, false).applyTo(xlabel.getWidget()); + + // Min and max values for x-axis + label = new Label(xgroup, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); + label.setText("Min:"); + + Composite minmax = new Composite(xgroup, SWT.NONE); + GridDataFactory.fillDefaults().applyTo(minmax); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(minmax); + xmin = new TrackedText(minmax, domainAxisSupport, SWT.BORDER); + xmin.setColorProvider(new JFreeChartPropertyColorProvider(xmin.getResourceManager())); + xmin.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min)); + xmin.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min)); + xmin.setInputValidator(new DoubleValidator(true)); + + label = new Label(minmax, SWT.NONE); + label.setText("Max:"); + xmax = new TrackedText(minmax, domainAxisSupport, SWT.BORDER); + xmax.setColorProvider(new JFreeChartPropertyColorProvider(xmax.getResourceManager())); + xmax.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max)); + xmax.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max)); + xmax.setInputValidator(new DoubleValidator(true)); + + // Set the same width to both label rows + composite.layout(); + GridDataFactory.fillDefaults().hint(xVariableLabel.getBounds().width, SWT.DEFAULT).align(SWT.END, SWT.CENTER).applyTo(nameLabel); + + sc.setContent(composite); + Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); + sc.setMinSize(size); + } + + @Override + public void setInput(final ISessionContext context, Object input) { + final Resource chart = AdaptionUtils.adaptToSingle(input, Resource.class); + if(chart == null) + return; + + context.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.Plot)); + if(plot == null) return; + Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis); + if(domainAxis == null) return; + domainAxisSupport.fireInput(context, new StructuredSelection(domainAxis)); + } + }); + } + + /** + * + * @author Teemu Lempinen + * + */ + private class TypeSelectionFactory extends ReadFactoryImpl { + @Override + public String perform(ReadGraph graph, Resource chart) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.XYPlot)); + if(plot != null) { + Collection datasets = graph.syncRequest(new ObjectsWithType(plot, l0.ConsistsOf, jfree.XYDataset)); + if(!datasets.isEmpty()) { + Resource dataset = datasets.iterator().next(); + if(dataset != null) { + Resource renderer = graph.syncRequest(new PossibleObjectWithType(dataset, jfree.Dataset_renderer, jfree.Renderer)); + if(renderer != null && graph.isInstanceOf(renderer, jfree.XYAreaRenderer)) + return "Area"; + } + } + } + return "Line"; + } + } + + /** + * RangeItemFactory finds all inexes of a given enumeration + * and adds "Sum" and "All" to the returned indexes + * @author Teemu Lempinen + * + */ + private class TypeItemFactory extends ReadFactoryImpl> { + @Override + public Map perform(ReadGraph graph, Resource series) throws DatabaseException { + LinkedHashMap result = new LinkedHashMap(); + result.put("Line", "Line"); + result.put("Area", "Area"); +// result.put("Stacked Area", "Stacked Area"); + return result; + } + } + + /** + * TypeModifyListener for modifying the type of a bar chart + * @author Teemu Lempinen + * + */ + private class TypeModifyListener extends ComboModifyListenerImpl { + @Override + public void applyText(WriteGraph graph, Resource chart, String text) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.XYPlot)); + if(plot == null) + return; + + Collection datasets = graph.syncRequest(new ObjectsWithType(plot, l0.ConsistsOf, jfree.XYDataset)); + if(datasets == null || datasets.isEmpty()) + return; + + for(Resource dataset : datasets) { + graph.deny(dataset, jfree.Dataset_renderer); + + Resource renderer; + if(text.equals("Area")) + renderer = GraphUtils.create2(graph, jfree.XYAreaRenderer); + else + renderer = GraphUtils.create2(graph, jfree.XYLineRenderer); + + graph.claim(dataset, jfree.Dataset_renderer, renderer); + } + } + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java new file mode 100644 index 00000000..574f71b8 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java @@ -0,0 +1,113 @@ +package org.simantics.sysdyn.ui.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.manager.SysdynModel; +import org.simantics.sysdyn.representation.Enumeration; +import org.simantics.sysdyn.representation.EnumerationIndex; +import org.simantics.sysdyn.representation.IElement; +import org.simantics.sysdyn.representation.Variable; + +public class ArrayVariableUtils { + + + /** + * Checks if the given range elements can be applied to the given variable. + * + * @param graph ReadGraph + * @param variable Resource of the variable + * @param range Range elements in the correct order. Elements are separated in range definition by ',' + * @return true if range is valid, false if not + * @throws DatabaseException + */ + public static Map isRangeValid(ReadGraph graph, Variable variable, String[] elements) throws DatabaseException { + if(variable == null) + return null; + Map result = new HashMap(); + // Not an array variable + if(variable.getArrayIndexes() == null || + variable.getArrayIndexes().getEnumerations() == null || + variable.getArrayIndexes().getEnumerations().size() == 0) { + for(int i = 0; i < elements.length ; i++) + result.put(i, "Variable is not an array variable"); + return result; + } + ArrayList enumerations = variable.getArrayIndexes().getEnumerations(); + // Too many elements + if(elements.length > enumerations.size()) { + result.put( enumerations.size(), "Too many elements"); + } else if(elements.length < enumerations.size()) { + result.put( elements.length > 0 ? elements.length - 1 : 0, "Too few elements"); + } + + + for(int i = 0; i < elements.length && i < enumerations.size(); i++) { + if(elements[i].trim().equals(":")) + continue; + if(elements[i].indexOf(":") != elements[i].lastIndexOf(":")) { + result.put( i, "Too many ':' elements"); + continue; + } + + String[] rangeComponents = elements[i].split(":"); + if(rangeComponents.length > 2){ + result.put( i, "Too many ':' elements"); + continue; + } + // Single range component, equals to the enumeration at that index + if(rangeComponents.length == 1 && rangeComponents[0].trim().equals(enumerations.get(i).getName())) + continue; + // one or two range components, they all equal to individual indexes in the enumeration + for(String r : rangeComponents) { + r = r.trim(); + boolean componentIsValid = false; + for(EnumerationIndex ei : enumerations.get(i).getEnumerationIndexes()) { + if(ei.getName().equals(r)) { + componentIsValid = true; + break; + } + } + if(!componentIsValid) + result.put( i, "Invalid range"); + } + } + if(result.isEmpty()) + return null; + else + return result; + } + + /** + * Checks if the given range can be applied to the given variable. + * + * @param graph ReadGraph + * @param variable Resource of the variable + * @param range Range WITHOUT [ and ] brackets + * @return true if range is valid, false if not + * @throws DatabaseException + */ + public static boolean isRangeValid(ReadGraph graph, Resource variable, String range) throws DatabaseException { + if(variable == null) + return true; + String[] elements = range.split(","); + SysdynModel model = ModelUtils.getModel(graph, variable); + if(model == null) + return false; + IElement e = model.getElement(variable); + if(e != null && e instanceof Variable) { + Variable v = (Variable) e; + Map result = isRangeValid(graph, v, elements); + if(result == null) + return true; + else + return false; + } else { + return false; + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java new file mode 100644 index 00000000..6abe38f2 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java @@ -0,0 +1,461 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.utils; + +import java.io.StringReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.jface.text.Position; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.expressionParser.ExpressionParser; +import org.simantics.sysdyn.expressionParser.ParseException; +import org.simantics.sysdyn.expressionParser.Token; +import org.simantics.sysdyn.expressionParser.TokenMgrError; +import org.simantics.sysdyn.manager.SysdynModel; +import org.simantics.sysdyn.manager.SysdynModelManager; +import org.simantics.sysdyn.representation.Configuration; +import org.simantics.sysdyn.representation.Enumeration; +import org.simantics.sysdyn.representation.EnumerationIndex; +import org.simantics.sysdyn.representation.IElement; +import org.simantics.sysdyn.representation.Module; +import org.simantics.sysdyn.representation.Sheet; +import org.simantics.sysdyn.representation.Variable; +import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionField; +import org.simantics.sysdyn.ui.properties.widgets.expressions.IExpression; +import org.simantics.sysdyn.ui.properties.widgets.expressions.StockExpression; +import org.simantics.ui.SimanticsUI; + +public class ExpressionUtils { + + /** + * Determines if the given expression is a parameter expression. Parameters are numbers. + * If the expression contains anything other than numbers, it is not a parameter. + * + * @param expression The expression to be checked + * @return is the expression a parameter + */ + static public boolean isParameter(String expression) { + try { + /* + StringTokenizer st = new StringTokenizer(expression, "{}[],;"); + while(st.hasMoreTokens()) { + Double.parseDouble(st.nextToken().trim()); + } + */ + Double.parseDouble(expression.trim()); + return true; + } catch (NumberFormatException e) { + return false; + } + } + + /** + * Validates the expressionfield of a given IExpression + * + * @param expression The expression whose fields are validated + * @param connectedVariables Table items from the shortcut widget. (Items needed so that they can be coloured) + * @param configuration configuration where the variable is located + */ + static public void validateExpressionFields(final Resource variable, IExpression expression, Table variableTable) { + + Resource configuration = null; + try { + configuration = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource configuration = variable; + while (configuration != null) { + configuration = graph.getPossibleObject(configuration, Layer0.getInstance(graph).PartOf); + + if(configuration == null || graph.isInstanceOf(configuration, sr.Configuration)) { + break; + } + } + return configuration; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + return; + } + + if(configuration == null) + return; + + ExpressionParser parser = new ExpressionParser(new StringReader("")); + Set variables = new HashSet(); + HashMap>> references = new HashMap>>(); + final HashMap>>> ranges = new HashMap>>>(); + HashMap>> forIndices = new HashMap>>(); + HashMap>> enumerationReferences = new HashMap>>(); + HashMap>> functionReferences = new HashMap>>(); + + // Build references and variable array + for(ExpressionField ef : expression.getExpressionFields()) { + ef.resetAnnotations(); + String textString = ef.getExpression(); + parser.ReInit(new StringReader(textString)); + try { + parser.expr(); + HashMap> refs = parser.getReferences(); + references.put(ef, refs); + variables.addAll(refs.keySet()); + + ranges.put(ef, parser.getRanges()); + + forIndices.put(ef, parser.getForIndices()); + + enumerationReferences.put(ef, parser.getEnumerationReferences()); + + functionReferences.put(ef, parser.getFunctionCallReferences()); + + } catch (ParseException e1) { + ef.setSyntaxError(e1.currentToken, "Syntax Error"); + } catch (TokenMgrError err) { + ef.setSyntaxError(0, textString.length(), ExpressionField.SYNTAX_ERROR, "Expression contains unsupported characters"); + } + } + + + final HashMap modelVariables = new HashMap(); + HashSet ignoreVariables = new HashSet(); + + if(!variables.isEmpty() || !functionReferences.isEmpty()) { + Set noSuchVariables = new HashSet(); + SysdynModelManager sdm = SysdynModelManager.getInstance(SimanticsUI.getSession()); + SysdynModel model = sdm.getModel(configuration); + try { + model.update(); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + + Configuration conf = model.getConfiguration(); + ArrayList elements = conf.getElements(); + for(IElement e : elements) { + if(e instanceof Variable) { + Variable v = (Variable) e; + modelVariables.put(v.getName(), v); + } else if(e instanceof Module) { + ignoreVariables.add(((Module)e).getName()); + } + } + + // VARIABLE NAMES + + if(variables.contains("time")) + variables.remove("time"); + + // Examine sheets + for(ExpressionField ef : functionReferences.keySet()) { + for(String key : functionReferences.get(ef).keySet()) { + String[] parts = key.split("\\."); + Object current = conf; + for(int i = 0; i < parts.length && current != null; i++) { + current = getElement(current, parts[i]); + } + if(current != null && current instanceof Sheet) { + Sheet sheet = (Sheet) current; + String e = ef.getExpression(); + int start = 0, end = 0, call = 0; + String cellOrRange = null; + while((call = e.indexOf(key, end)) >= 0) { + start = e.indexOf("(", call) +1; + end = e.indexOf(")", start); + if(start < 0 || end < 0 || end < start) { + break; + } + Pattern p = Pattern.compile("[-\\+\\*\\/\\(\\)\\{\\}\\[\\],\\.\\t\\n\\r\\f]"); + cellOrRange = e.substring(start, end); + Matcher m = p.matcher(cellOrRange); + if (m.find() || cellOrRange.split(":").length > 2) { + ef.setSyntaxError(start, end - start, ExpressionField.SYNTAX_ERROR, "Not a valid cell or range"); + } + } + + List tokens = functionReferences.get(ef).get(key); + for(Token cell : tokens) { + List refs = references.get(ef).get(cell.image); + if(refs != null) + refs.remove(cell); + if(!sheet.getCells().containsKey(cell.image)) + ef.setSyntaxError(cell.image, "Invalid cell", cell.beginLine, cell.beginColumn, cell.endLine, cell.endColumn); + } + + } + } + } + + for(String v : variables) { + + if(modelVariables.get(v) instanceof Enumeration || modelVariables.get(v) instanceof Sheet) { + ignoreVariables.add(v); + } + + // Reference to some other module, spreadsheet or enumeration + if(v.contains(".")) { + String[] parts = v.split("\\."); + Object parent = conf; + for(int i = 0; i < parts.length && parent != null; i++) { + parent = getElement(parent, parts[i]); + } + if(parent == null) { + noSuchVariables.add(v); + } else { + ignoreVariables.add(v); + } + } else if(!modelVariables.keySet().contains(v)) { + noSuchVariables.add(v); + } + } + + if(!noSuchVariables.isEmpty()) { + noSuchVariables.removeAll(ignoreVariables); + // remove no such variables from variable list + for(String s : noSuchVariables) + variables.remove(s); + // create annotations + HashMap> positions = getPositionsForVariables(references, noSuchVariables); + for(ExpressionField ef : positions.keySet()) { + ef.setNoSuchVariableAnnotations(positions.get(ef)); + } + } + } + + // Check that the variables that exist have connections and the connected variables have references in the expressions + if(!(expression instanceof StockExpression)) { + + if(variableTable != null && !variableTable.isDisposed()) { + TableItem[] connectedVariables = variableTable.getItems(); + for(TableItem ti : connectedVariables) { + if(!variables.contains(ti.getText())) { + ti.setForeground(new Color(ti.getDisplay(), 255,125,0)); + } else { + ti.setForeground(new Color(ti.getDisplay(), 0, 0, 0)); + variables.remove(ti.getText()); + } + } + } + + // Remove all enumerations and sheets, they cannot have connections + variables.removeAll(ignoreVariables); + + if(!variables.isEmpty()) { + HashMap> positions = getPositionsForVariables(references, variables); + for(ExpressionField ef : positions.keySet()) { + ef.setMissingLinkAnnotations(positions.get(ef)); + } + + } + } + + + + HashMap> errors = new HashMap>(); + HashMap result = null; + + for(final ExpressionField ef : ranges.keySet()) { + + // RANGES + try { + result = SimanticsUI.getSession().syncRequest(new Read>() { + + @Override + public HashMap perform(ReadGraph graph) throws DatabaseException { + HashMap result = new HashMap(); + for(String s : ranges.get(ef).keySet()) { + if(ranges.get(ef).containsKey(s)) { + for(List l : ranges.get(ef).get(s)) { + String[] ss = new String[l.size()]; + for(int i = 0; i < l.size(); i++) { + ss[i] = l.get(i).image; + } + Map invalidRanges = ArrayVariableUtils.isRangeValid(graph, modelVariables.get(s), ss); + if(invalidRanges != null && !invalidRanges.isEmpty()) { + for(Integer i : invalidRanges.keySet()) { + result.put(l.get(i), invalidRanges.get(i)); + } + } + } + } + } + return result; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + // FOR-INDICES + + HashMap> indexList = forIndices.get(ef); + for(Token t : indexList.keySet()) { + boolean isFound = false; + for(Token rt : indexList.get(t)) { + if(rt.image.equals(t.image)) { + isFound = true; + // remove range token from invalid ranges + result.remove(rt); + break; + } + } + if(!isFound) { + result.put(t, "Invalid index"); + } + } + + // ENUMERATION REFERENCES IN FOR-LOOPS + HashMap> enumRefList = enumerationReferences.get(ef); + for(String enumeration : enumRefList.keySet()) { + for(Token et : enumRefList.get(enumeration)) { + Variable v = modelVariables.get(enumeration); + if(v != null && v instanceof Enumeration) { + boolean isFound = false; + Enumeration e = (Enumeration)v; + + if(enumeration.equals(et.image) || + "size".equals(et.image) || + "elements".equals(et.image)){ + // The full enumeration + isFound = true; + } else { + for(EnumerationIndex ei : e.getEnumerationIndexes()) { + if(ei.getName().equals(et.image)) { + isFound = true; + break; + } + } + } + + if(!isFound) { + StringBuilder sb = new StringBuilder(); + sb.append("Enumeration "); + sb.append(enumeration); + sb.append(" has no such index.\nAvailable indexes are: "); + Iterator iterator = e.getEnumerationIndexes().iterator(); + while(iterator.hasNext()) { + sb.append(iterator.next().getName()); + if(iterator.hasNext()) + sb.append(", "); + } + result.put(et, sb.toString()); + } + + + } else { + result.put(et, "No such enumeration (" + enumeration + ")"); + } + } + } + + errors.put(ef, result); + + + } + + for(ExpressionField ef : ranges.keySet()) { + HashMap tokens = errors.get(ef); + if(tokens == null || tokens.isEmpty()) continue; + for(Token t : tokens.keySet()) { + ef.setSyntaxError(t, tokens.get(t)); + } + } + + } + + static private Object getElement(Object parent, String name) { + Configuration c = null; + if(parent instanceof Module) { + Module m = (Module)parent; + c = m.getType().getConfiguration(); + } else if (parent instanceof Configuration) { + c = (Configuration)parent; + } + + if(c != null) { + for(IElement e : c.getElements()) { + if(e instanceof Variable && ((Variable)e).getName().equals(name)) { + return e; + } else if(e instanceof Module && ((Module)e).getName().equals(name)) { + return e; + } + } + } else if(parent instanceof Sheet) { + Sheet s = (Sheet)parent; + for(String key : s.getCells().keySet()) { + if(key.equals(name)) { + return Boolean.TRUE; + } + } + + } else if(parent instanceof Enumeration) { + Enumeration e = (Enumeration)parent; + if(name.equals("size") || name.equals("elements")) + return Boolean.TRUE; + + for(EnumerationIndex ei : e.getEnumerationIndexes()) { + if(ei.getName().equals(name)) { + return Boolean.TRUE; + } + } + + } + + return null; + } + + @SuppressWarnings("unchecked") + static private HashMap> getPositionsForVariables(HashMap>> references, Set variables) { + HashMap> result = new HashMap>(); + for(String s : variables) { + List tlist = new ArrayList(); + for(ExpressionField ef : references.keySet()) { + ArrayList positions = new ArrayList(); + tlist = references.get(ef).get(s); + if(tlist != null) + for(Token t : tlist) { + StyledText st = ef.getSourceViewer().getTextWidget(); + int start = st.getOffsetAtLine(t.beginLine - 1) + t.beginColumn - 1; + int offset = st.getOffsetAtLine(t.endLine - 1) + t.endColumn - start; + positions.add(new Position( + start, + offset)); + } + if(result.keySet().contains(ef)) { + result.get(ef).addAll((ArrayList)positions.clone()); + } else { + result.put(ef, (ArrayList)positions.clone()); + } + } + } + return result; + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java new file mode 100644 index 00000000..1412dade --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java @@ -0,0 +1,159 @@ +package org.simantics.sysdyn.ui.utils; + +import java.util.UUID; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.Template; +import org.simantics.document.DocumentResource; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.modeling.ModelingUtils; +import org.simantics.operation.Layer0X; +import org.simantics.project.ontology.ProjectResource; +import org.simantics.spreadsheet.resource.SpreadsheetResource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.SysdynModel; +import org.simantics.sysdyn.manager.SysdynModelManager; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.ArrayMap; + +public class ModelUtils { + + /** + * Returns the SysdynModel where the given variable is located + * + * @param graph ReadGraph + * @param variable Variable whose model is wanted + * @return SysdynModel where variable is located + * @throws DatabaseException + */ + public static SysdynModel getModel(ReadGraph graph, Resource variable) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + Resource configuration = graph.getPossibleObject(variable, l0.PartOf); + if(configuration == null) + return null; + SysdynModelManager sdm = SysdynModelManager.getInstance(SimanticsUI.getSession()); + SysdynModel model = sdm.getModel(graph, configuration); + try { + model.update(graph); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + return model; + } + + public static void createModel(WriteGraph graph) { + createModelAt(graph, SimanticsUI.getProject().get()); + } + + public static void createModelAt(WriteGraph g, Resource library) { + try { + Layer0 l0 = Layer0.getInstance(g); + Layer0X L0X = Layer0X.getInstance(g); + SysdynResource sr = SysdynResource.getInstance(g); + SpreadsheetResource SHEET = SpreadsheetResource.getInstance(g); + ModelingUtils mu = new ModelingUtils(g); + DocumentResource DOC = DocumentResource.getInstance(g); + + String modelName = NameUtils.findFreshName(g, "Model", library, l0.ConsistsOf, "%s%d"); + + Resource project = SimanticsUI.getProject().get(); + Resource model = GraphUtils.create2(g, + sr.SysdynModel, + l0.PartOf, project, + l0.HasName, modelName, + l0.HasLabel, modelName, + L0X.IsActivatedBy, project + ); + + GraphUtils.create2(g, + sr.Validations_Dependencies_MissingDependencyConnectionsIssueSource, + L0X.IsActivatedBy, model, + l0.PartOf, model + ); + + GraphUtils.create2(g, + sr.Validations_Dependencies_DependencyConnectionsIssueSource, + L0X.IsActivatedBy, model, + l0.PartOf, model + ); + + GraphUtils.create2(g, + sr.Validations_Expressions_ExpressionIssueSource, + L0X.IsActivatedBy, model, + l0.PartOf, model + ); + + Resource conf = GraphUtils.create2(g, + sr.Configuration, + l0.PartOf, model, + L0X.IsBaseRealizationOf, model, + l0.HasName, modelName + ); + + Resource diagram = g.newResource(); + g.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(g, + ArrayMap + .keys("", "diagram", "name") + .values(conf, diagram, "Diagrammi") + ); + + g.claim(model, mu.SIMU.HasConfiguration, conf); + + Resource book = g.newResource(); + g.claim(book, l0.InstanceOf, null, SHEET.Book); + g.addLiteral(book, l0.HasName, l0.NameOf, l0.String, "Book" + UUID.randomUUID().toString(), Bindings.STRING); + g.claim(conf, l0.ConsistsOf, l0.PartOf, book); + + SheetUtils.createSheet(g, book, "Sheet1", new String[] { }, new int[] { 50 }); + + + + ModelingResources mr = ModelingResources.getInstance(g); + // Remove default mapping and add sysdyn mapping + for(Resource trigger : g.getObjects(diagram, L0X.HasTrigger)) { + if(g.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) { + g.deny(diagram, L0X.HasTrigger, trigger); + } + } + Resource mapping = g.newResource(); + g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); + g.claim(diagram, L0X.HasTrigger, mapping); + + Resource report = GraphUtils.create2(g, DOC.Report, DOC.HasDocumentation, "===Report==="); + + GraphUtils.create2(g, sr.BasicExperiment, + l0.HasName, "Experiment", + l0.HasLabel, "Experiment", + DOC.HasReportFactory, report, + l0.PartOf, model); + + ProjectResource PROJ = ProjectResource.getInstance(g); + for(Resource dep : g.getObjects(library, l0.IsLinkedTo)) { + if(g.isInstanceOf(dep, PROJ.NamespaceRequirement)) { + for(Resource req : g.getObjects(dep, PROJ.RequiresNamespace)) { + String uri = g.getPossibleValue(req, Bindings.STRING); + if(uri != null) { + Resource target = g.getResource(uri); + if(target != null) { + g.claim(model, l0.IsLinkedTo, null, target); + } + } + } + } + } + + ProfileEntries.createStandardProfiles(g, model); + + + } catch (DatabaseException e ) { + + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/OldTransferableGraph1.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/OldTransferableGraph1.java new file mode 100644 index 00000000..558f5a33 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/OldTransferableGraph1.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.utils; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.serialization.Serializer; +import org.simantics.graph.representation.External; +import org.simantics.graph.representation.Identity; +import org.simantics.graph.representation.Internal; +import org.simantics.graph.representation.Root; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.graph.representation.Value; + + +/** + * Transferable graph datatype. + * See specification. + * @author Hannu Niemistö + */ +public class OldTransferableGraph1 { + public static Binding BINDING = Bindings.getBindingUnchecked(TransferableGraph1.class); + public static Serializer SERIALIZER = Bindings.getSerializerUnchecked(BINDING); + + public int resourceCount; + public Identity[] identities; + public int[] statements; + public Value[] values; + + public OldTransferableGraph1() { + } + + public OldTransferableGraph1(int resourceCount, Identity[] identities, + int[] statements, Value[] values) { + this.resourceCount = resourceCount; + this.identities = identities; + this.statements = statements; + this.values = values; + } + + public void print() { + System.out.println("Identities"); + for(Identity id : identities) { + System.out.print(" " + id.resource + " = "); + if(id.definition instanceof Root) { + Root def = (Root)id.definition; + System.out.println("ROOT(" + def.name + ")"); + } + else if(id.definition instanceof External) { + External def = (External)id.definition; + System.out.println("EXTERNAL(" + def.parent + ", " + def.name + ")"); + } + else if(id.definition instanceof Internal) { + Internal def = (Internal)id.definition; + System.out.println("INTERNAL(" + def.parent + ", " + def.name + ")"); + } + } + System.out.println("Statements:"); + for(int i=0;i expressionList = OrderedSetUtils.toList(graph, expressions); + for(Resource s : expressionList) { + for(Resource p : graph.getPredicates(s)) { + Resource o = graph.getPossibleObject(s, p); + if(o != null && graph.isInstanceOf(o, l0.String) && !p.equals(sr.HasArrayRange)) { + String string = graph.getRelatedValue(s, p); + String replaced = replaceAllWords(string, originalName, newName); + graph.claimLiteral(s, p, replaced); + } + } + } + } + } + } + + private static String replaceAllWords(String original, String find, String replacement) { + if(!original.contains(find)) return original; + StringBuilder result = new StringBuilder(original.length()); + String delimiters = "+-*/(){}[],.: \t\n\r\f"; + StringTokenizer st = new StringTokenizer(original, delimiters, true); + while (st.hasMoreTokens()) { + String w = st.nextToken(); + if (w.equals(find)) { + result.append(replacement); + } else { + result.append(w); + } + } + return result.toString(); + } + + + private static boolean nameIsTaken(ReadGraph graph, Resource variable, String name) throws DatabaseException { + if(variable == null) + return false; + SysdynModel model = ModelUtils.getModel(graph, variable); + if(model == null) + return true; + Configuration configuration = model.getConfiguration(); + if(configuration == null) + return true; + IElement current = model.getElement(variable); + for(IElement e : configuration.getElements()) { + if(e instanceof Variable) { + Variable v = (Variable) e; + if(!v.equals(current) && v.getName().equals(name)) { + return true; + } + } + } + return false; + } + + /** + * Checks that the syntax of the given name is valid and there + * are no other variables that have the same name in the configuration + * + * @param graph ReadGraph + * @param variable The variable that is being renamed + * @param name The new name of the variable + * @return + * @throws DatabaseException + */ + public static boolean isValid(ReadGraph graph, Resource variable, String name, boolean hasRange) throws DatabaseException { + if(name.length() < 1) + return false; + if(hasRange) { + String range = null; + if(name.contains("[")) { + StringTokenizer st = new StringTokenizer(name, "[]", true); + if(st.countTokens() != 4) + return false; + name = st.nextToken(); + if(!st.nextToken().equals("[")) return false; + range = st.nextToken(); + if(!st.nextToken().equals("]")) return false; + } + if(range != null && !ArrayVariableUtils.isRangeValid(graph, variable, range)) return false; + } + if(nameIsTaken(graph, variable, name)) return false; + if(!isValid(name)) return false; + return true; + } + + + /** + * Checks that the syntax of the given name is valid and there + * are no other variables that have the same name in the configuration + * + * @param variable The variable that is being renamed + * @param name The new name of the variable + * @return + * @throws DatabaseException + */ + public static boolean isValid(final Resource variable, final String name, final boolean hasRange) { + boolean result = false; + try { + result = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + return isValid(graph, variable, name, hasRange); + } + + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + return result; + } + + /** + * Checks that the syntax of the given name is valid + * and that it is not a keyword in Modelica. + * + * @param name + * @return + */ + public static boolean isValid(String name) { + String lowerCase = name.toLowerCase(); + Pattern p = Pattern.compile("[a-zA-Z0-9]++"); + Matcher m = p.matcher(lowerCase); + if (!m.matches() || keywords.contains(name)) + return false; + else + return true; + } + + public static final Set keywords = new HashSet(); + + static { + keywords.add("algorithm"); + keywords.add("discrete"); + keywords.add("false"); + keywords.add("model"); + keywords.add("redeclare"); + keywords.add("and"); + keywords.add("each"); + keywords.add("final"); + keywords.add("not"); + keywords.add("replaceable"); + keywords.add("annotation"); + keywords.add("else"); + keywords.add("flow"); + keywords.add("operator"); + keywords.add("return"); + keywords.add("assert"); + keywords.add("elseif"); + keywords.add("for"); + keywords.add("or"); + keywords.add("stream"); + keywords.add("block"); + keywords.add("elsewhen"); + keywords.add("function"); + keywords.add("outer"); + keywords.add("then"); + keywords.add("break"); + keywords.add("encapsulated"); + keywords.add("if"); + keywords.add("output"); + keywords.add("true"); + keywords.add("class"); + keywords.add("end"); + keywords.add("import"); + keywords.add("package"); + keywords.add("type"); + keywords.add("connect"); + keywords.add("enumeration"); + keywords.add("in"); + keywords.add("parameter"); + keywords.add("when"); + keywords.add("connector"); + keywords.add("equation"); + keywords.add("initial"); + keywords.add("partial"); + keywords.add("while"); + keywords.add("constant"); + keywords.add("expandable"); + keywords.add("inner"); + keywords.add("protected"); + keywords.add("within"); + keywords.add("constrainedby"); + keywords.add("extends"); + keywords.add("input"); + keywords.add("public"); + keywords.add("der"); + keywords.add("external"); + keywords.add("loop"); + keywords.add("record"); + keywords.add("time"); + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyFunction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyFunction.java new file mode 100644 index 00000000..dbad2a45 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyFunction.java @@ -0,0 +1,250 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.validation; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.issues.common.Issue; +import org.simantics.issues.common.IssueUtils; +import org.simantics.issues.common.StandardIssue; +import org.simantics.layer0.Layer0; +import org.simantics.scl.reflection.annotations.SCLValue; +import org.simantics.sysdyn.SysdynResource; + +/** + * Evaluates issues related to Dependencies (arrows) + * + * @author Teemu Lempinen + * + */ +public class DependencyFunction { + + /** + * Evaluates dependency-related issues for a component. + * + * Issues include: Unused dependency + * + * @param graph ReadGraph + * @param component Evaluated component (Variable) + * @return list of issues related to component + * @throws DatabaseException + */ + @SCLValue(type = "ReadGraph -> Resource -> [Issue]") + public static List dependencyValidator(ReadGraph graph, Resource component) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + if (!graph.isInstanceOf(component, sr.IndependentVariable)) + return Collections.emptyList(); + + if (!graph.hasStatement(component) || !graph.hasStatement(component, l0.PartOf)) + return Collections.emptyList(); + + // Find all variables that are linked to component with arrows + Set dependencies = ValidationUtils.getDependencies(graph, component); + Set references = null; + + ArrayList result = new ArrayList(); + + + // Find all references in equations of component + try { + references = ValidationUtils.getReferences(graph, component); + } catch (Exception e) { + return result; + } + + // Check that all arrow dependencies are used in equations + if (dependencies != null) { + for (String dependency : dependencies) { + if (references == null || !references.contains(dependency)) { + Resource variable = ValidationUtils.reach(graph, component, dependency); + result.add(new StandardIssue(sr.Validations_UnusedDependencyIssue, component, variable)); + } + } + } + + return result; + } + + /** + * Evaluates dependency-related issues for a component. + * + * Issues include: Missing link No such variable + * + * @param graph ReadGraph + * @param component Evaluated component (Variable) + * @return list of issues related to component + * @throws DatabaseException + */ + @SCLValue(type = "ReadGraph -> Resource -> [Issue]") + public static List missingDependencyValidator(ReadGraph graph, Resource component) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + if (!graph.isInstanceOf(component, sr.IndependentVariable)) + return Collections.emptyList(); + + if (!graph.hasStatement(component) || !graph.hasStatement(component, l0.PartOf)) + return Collections.emptyList(); + + // Find all variables that are linked to component with arrows + Set dependencies = ValidationUtils.getDependencies(graph, component); + Set references = null; + + // Find all references in equations of component + try { + references = ValidationUtils.getReferences(graph, component); + } catch (SyntaxErrorException e) { + } catch (UnsupportedCharactersException e) { + } catch (UndefinedExpressionException e) { + } + + ArrayList result = new ArrayList(); + + StandardIssue noSuchVariableIssue = null; + // Check that all references have corresponding arrows + if (references != null && dependencies != null) { + for (String reference : references) { + if (!dependencies.contains(reference)) { + Resource variable = null; + if ((variable = ValidationUtils.reach(graph, component, reference)) != null) { + result.add(new StandardIssue(sr.Validations_MissingLinkIssue, component, variable)); + } else { + if (noSuchVariableIssue == null) { + noSuchVariableIssue = new StandardIssue(sr.Validations_NoSuchVariableIssue, component); + result.add(noSuchVariableIssue); + } + } + } + } + } + + return result; + + } + + /** + * Missing link description + * + * @param graph ReadGraph + * @param converter + * @param issue Issue + * @return issue description + * @throws DatabaseException + */ + @SCLValue(type = "ReadGraph -> Resource -> Variable -> String") + public static String missingLinkIssueDescription(ReadGraph graph, Resource converter, Variable property) + throws DatabaseException { + + List contexts = IssueUtils.getContextsForProperty(graph, property); + String result = "Missing a link to "; + if (contexts.size() > 0) { + Resource component = contexts.get(1); + String name = NameUtils.getSafeName(graph, component); + result = result + name; + } + return result; + + } + + /** + * Unused dependency description + * + * @param graph ReadGraph + * @param converter + * @param issue Issue + * @return issue description + * @throws DatabaseException + */ + @SCLValue(type = "ReadGraph -> Resource -> Variable -> String") + public static String unusedDependencyIssueDescription(ReadGraph graph, Resource converter, Variable property) + throws DatabaseException { + + List contexts = IssueUtils.getContextsForProperty(graph, property); + String result = "Unused dependency: "; + if (contexts.size() > 0) { + Resource component = contexts.get(1); + String name = NameUtils.getSafeName(graph, component); + result = result + name; + } + return result; + } + + /** + * No such variable description. Finds all variables that the component + * refers to and adds their names to the issue description. + * + * @param graph ReadGraph + * @param converter + * @param issue Issue + * @return issue description + * @throws DatabaseException + */ + @SCLValue(type = "ReadGraph -> Resource -> Variable -> String") + public static String noSuchVariableIssueDescription(ReadGraph graph, Resource converter, Variable property) + throws DatabaseException { + + List contexts = IssueUtils.getContextsForProperty(graph, property); + Resource component = contexts.get(0); + + // Find all variables that are linked to component with arrows + Set dependencies = ValidationUtils.getDependencies(graph, component); + Set references = null; + + // Find all references in equations of component + try { + references = ValidationUtils.getReferences(graph, component); + } catch (SyntaxErrorException e) { + } catch (UnsupportedCharactersException e) { + } catch (UndefinedExpressionException e) { + } + + ArrayList result = new ArrayList(); + // Loop all references + if (references != null && dependencies != null) { + for (String reference : references) { + // If dependencies does not contain reference and the reference +// is not reachable from component, add the name + if (!dependencies.contains(reference) && ValidationUtils.reach(graph, component, reference) == null) { + result.add(reference); + } + } + } + if (result.size() == 0) { + return "Missing link"; + } else if (result.size() == 1) { + return "Refers to unexisting variable " + result.get(0); + } else { + StringBuilder sb = new StringBuilder(); + sb.append("Refers to unexisting variables "); + Iterator iterator = result.iterator(); + String reference; + while (iterator.hasNext()) { + reference = iterator.next(); + sb.append(reference); + if (iterator.hasNext()) + sb.append(", "); + } + return sb.toString(); + } + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ExpressionIssueFunction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ExpressionIssueFunction.java new file mode 100644 index 00000000..e21926a6 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ExpressionIssueFunction.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.validation; + +import java.util.Collections; +import java.util.List; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.issues.common.Issue; +import org.simantics.issues.common.IssueUtils; +import org.simantics.issues.common.StandardIssue; +import org.simantics.scl.reflection.annotations.SCLValue; +import org.simantics.sysdyn.SysdynResource; + +/** + * Detects syntax errors, unsupported characters and undefined expressions from variables. + * + * @author tlteemu + * + */ +public class ExpressionIssueFunction { + + private static String SYNTAX_ERROR = "Syntax error"; + private static String UNSUPPORTED_CHARACTERS = "Unsupported characters"; + private static String UNDEFINED_EXPRESSION = "Undefined expression"; + + @SCLValue(type = "ReadGraph -> Resource -> [Issue]") + public static List expressionValidator(ReadGraph graph, Resource component) throws DatabaseException { + + SysdynResource sr = SysdynResource.getInstance(graph); + + if(!graph.isInstanceOf(component, sr.IndependentVariable)) { + return Collections.emptyList(); + } + + // Try if there are any errors while parsing the expressions + try { + ValidationUtils.getReferences(graph, component); + } catch (Exception e) { + return Collections.singletonList(new StandardIssue(sr.Validations_ExpressionIssue, component)); + } + return Collections.emptyList(); + } + + @SCLValue(type = "ReadGraph -> Resource -> Variable -> String") + public static String expressionIssueDescription(ReadGraph graph, Resource converter, Variable property) throws DatabaseException { + + List contexts = IssueUtils.getContextsForProperty(graph, property); + Resource component = contexts.get(0); + + // There should be an error + try { + ValidationUtils.getReferences(graph, component); + } catch (SyntaxErrorException e) { + return SYNTAX_ERROR; + } catch (UnsupportedCharactersException e) { + return UNSUPPORTED_CHARACTERS; + } catch (UndefinedExpressionException e) { + return UNDEFINED_EXPRESSION; + } + return "Erroneus error"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/Functions.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/Functions.java new file mode 100644 index 00000000..78128ff2 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/Functions.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.validation; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.scl.reflection.annotations.SCLValue; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; + +/** + * Generic functions for validations + * + * @author Teemu Lempinen + * + */ +public class Functions { + + @SCLValue(type = "ReadGraph -> Resource -> Resource") + public static Resource baseRealizationFunction(ReadGraph graph, Resource model) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.isInstanceOf(model, sr.SysdynModel)) + return graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration); + else if (graph.isInheritedFrom(model, sr.Module)) + return graph.getSingleObject(model, StructuralResource2.getInstance(graph).IsDefinedBy); + else return null; + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/NoSuchVariableException.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/NoSuchVariableException.java new file mode 100644 index 00000000..4ec11767 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/NoSuchVariableException.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.validation; + +public class NoSuchVariableException extends RuntimeException { + private static final long serialVersionUID = -5766352512554068379L; + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/SyntaxErrorException.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/SyntaxErrorException.java new file mode 100644 index 00000000..0592a5d7 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/SyntaxErrorException.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.validation; + +public class SyntaxErrorException extends RuntimeException { + private static final long serialVersionUID = -6466653179001958636L; + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UndefinedExpressionException.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UndefinedExpressionException.java new file mode 100644 index 00000000..1c53cd87 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UndefinedExpressionException.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.validation; + +public class UndefinedExpressionException extends RuntimeException { + private static final long serialVersionUID = 7352486116119189105L; + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnsupportedCharactersException.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnsupportedCharactersException.java new file mode 100644 index 00000000..b2aa82f4 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnsupportedCharactersException.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.validation; + +public class UnsupportedCharactersException extends RuntimeException { + private static final long serialVersionUID = 8210873686720503188L; + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ValidationUtils.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ValidationUtils.java new file mode 100644 index 00000000..5ad0123a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ValidationUtils.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.validation; + +import java.io.StringReader; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.expressionParser.ExpressionParser; +import org.simantics.sysdyn.expressionParser.ParseException; +import org.simantics.sysdyn.expressionParser.TokenMgrError; + +/** + * + * @author Teemu Lempinen + * + */ +public class ValidationUtils { + + /** + * Find all variables that are referred to in the expressions of variable r + * @param graph ReadGraph + * @param r Variable resource + * @return All names of the variables that are referred to in the expressions of r + * @throws DatabaseException + * @throws SyntaxErrorException + * @throws UnsupportedCharactersException + * @throws UndefinedExpressionException + */ + public static HashSet getReferences(ReadGraph graph, Resource r) throws DatabaseException, SyntaxErrorException, UnsupportedCharactersException, UndefinedExpressionException { + HashSet references = new HashSet(); + ExpressionParser parser = new ExpressionParser(new StringReader("")); + + SysdynResource sr = SysdynResource.getInstance(graph); + List expressionList = getExpressions(graph, r); + if(expressionList == null || expressionList.isEmpty()) + throw new UndefinedExpressionException(); + for(Resource expression : expressionList) { + Collection statements = graph.getStatements(expression, sr.HasEquation); + if(statements.isEmpty()) + throw new UndefinedExpressionException(); + + for(Statement statement : statements) { + Object v = graph.getValue(statement.getObject()); + String value = v.toString(); + + if(value.length() == 0) { + // Empty might be allowed + if(graph.isSubrelationOf(statement.getPredicate(), sr.HasEquationOrEmpty)) + return references; + else + throw new UndefinedExpressionException(); + } + + parser.ReInit(new StringReader(value)); + try { + parser.expr(); + references.addAll(parser.getReferences().keySet()); + } catch (ParseException e1) { + throw new SyntaxErrorException(); + } catch (TokenMgrError err) { + throw new UnsupportedCharactersException(); + } + } + } + return references; + } + + /** + * Get all expressions of a variable r + * @param graph ReadGraph + * @param r Variable with expressions + * @return List of expression (resources) + * @throws DatabaseException + */ + private static List getExpressions(ReadGraph graph, Resource r) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource hasExpressions = graph.getPossibleObject(r, sr.HasExpressions); + if(hasExpressions != null) + return OrderedSetUtils.toList(graph, hasExpressions); + else + return null; + } + + + /** + * Returns the names of the related variables (dependencies) + * + * @param graph + * @param r + * @return + * @throws DatabaseException + */ + public static HashSet getDependencies(ReadGraph graph, Resource r) throws DatabaseException { + HashSet variables = new HashSet(); + if(graph != null && r != null) { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Collection dependencies = graph.getObjects(r, sr.IsHeadOf); + + for(Resource d : dependencies) { + if(graph.isInstanceOf(d, sr.Dependency)) { + Resource tail = graph.getPossibleObject(d, sr.HasTail); + if(tail != null) { + Object name = graph.getPossibleRelatedValue(tail, l0.HasName); + if(name != null) + variables.add((String)name); + } + } + } + } + return variables; + } + + /** + * Is reference reachable from variable + * + * @param graph + * @param variable + * @param reference + * @return + * @throws DatabaseException + */ + public static boolean isReachable(ReadGraph graph, Resource variable, String reference) throws DatabaseException { + if(reach(graph, variable, reference) != null) + return true; + else + return false; + } + + /** + * Find a resource starting from variable and using reference path + * + * @param graph ReadGraph + * @param variable starting point + * @param reference path to another variable + * @return found variable or null + * @throws DatabaseException + */ + public static Resource reach(ReadGraph graph, Resource variable, String reference) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + Resource configuration = graph.getSingleObject(variable, l0.PartOf); + String varName; + for(Resource var : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Variable))) { + varName = graph.getRelatedValue(var, l0.HasName, Bindings.STRING); + if(varName != null && reference.equals(varName)) + return var; + } + return null; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/values/ValueView.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/values/ValueView.java new file mode 100644 index 00000000..5cfca79e --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/values/ValueView.java @@ -0,0 +1,346 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.values; + +import java.util.ArrayList; +import java.util.Collection; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.part.ViewPart; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.sysdyn.manager.SysdynDataSet; +import org.simantics.sysdyn.ui.viewUtils.SysdynDatasetSelectionListener; + +/** + * A view that shows the values of currently selected variables in a table. + * One column (first by default) is always time values. + * + * @author Teemu Lempinen + * + */ +public class ValueView extends ViewPart { + + private boolean disposed; + private Composite baseComposite; + private ISelectionListener selectionListener; + private Table table; + + @Override + public void createPartControl(Composite parent) { + + disposed = false; + GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(parent); + baseComposite = new Composite(parent, + SWT.NO_BACKGROUND | SWT.EMBEDDED); + GridLayoutFactory.fillDefaults().applyTo(baseComposite); + GridDataFactory.fillDefaults().grab(true, true).applyTo(baseComposite); + + // Result table + table = new Table (baseComposite, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION); + GridDataFactory.fillDefaults().grab(true, true).applyTo(table); + table.setLinesVisible (true); + table.setHeaderVisible (true); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.heightHint = 200; + table.setLayoutData(data); + + + // Add selectionListener for updating the table + selectionListener = new SysdynDatasetSelectionListener() { + + @Override + protected void selectionChanged(final Collection activeDatasets) { + if(disposed) return; + table.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + updateTable(activeDatasets); + } + }); + } + + @Override + protected void selectionChanged(ReadGraph graph, Resource resource) { + // Do nothing + } + + }; + getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener); + + // Refreshes the table. There might be a selection already before the table is shown. + ISelection selection = getSite().getWorkbenchWindow().getSelectionService().getSelection(); + if(selection != null) + selectionListener.selectionChanged(getSite().getPart(), selection); + + + /* + * A primitive copy paste to support exporting data from table to excel + * + * columnName\tcolumnName\tcolumnName\n + * value\tvalue\tvalue\n + * ... + * value\tvalue\tvalue\n + * + */ + KeyListener kl = new KeyListener() { + + @Override + public void keyReleased(KeyEvent e) { + + } + + @Override + public void keyPressed(KeyEvent e) { + if (e.stateMask == SWT.CTRL && e.keyCode == 99) + { + + Clipboard cb = new Clipboard(e.display); + + TextTransfer textTransfer = TextTransfer.getInstance(); + + // Add names of the columns first. Selection is always full, print all columns + StringBuilder sb = new StringBuilder(); + int columnCount = table.getColumnCount(); + for(int i = 0; i < columnCount; i++) { + TableColumn tc = table.getColumn(i); + sb.append(tc.getText()); + if(i < columnCount - 1) + sb.append("\t"); + else + sb.append("\n"); + } + + // Print all selected rows. + for(TableItem ti : table.getSelection()) + for(int i = 0; i < columnCount; i++) { + sb.append(ti.getText(i)); + if(i < columnCount - 1) + sb.append("\t"); + else + sb.append("\n"); + } + + cb.setContents(new Object[]{sb.toString()}, new Transfer[]{textTransfer}); + } + } + }; + + table.addKeyListener(kl); + + + } + + /** + * Updates the table after selection has been changed + * + * @param activeDatasets + */ + private void updateTable(Collection activeDatasets) { + + if(activeDatasets.isEmpty() || !(activeDatasets instanceof ArrayList)) return; + + // Clear the old table + table.removeAll(); + if(table.getColumnCount() > 0) { + for(int i = table.getColumnCount() - 1; i>=0; i--) { + table.getColumn(i).dispose(); + } + } + + // Create new columns + ArrayList datasets = (ArrayList) activeDatasets; + + ArrayList titleList = new ArrayList(); + titleList.add("Time"); + double[] times = new double[0]; + for (int i=0; i times.length) { + times = datasets.get(i).times; + } + } + + + Listener sortListener = new Listener() { + public void handleEvent(Event e) { + TableItem[] items = table.getItems(); + TableColumn column = (TableColumn)e.widget; + + TableColumn sortColumn = table.getSortColumn(); + int dir = table.getSortDirection(); + if (sortColumn == column) { + dir = dir == SWT.UP ? SWT.DOWN : SWT.UP; + } else { + table.setSortColumn(column); + dir = SWT.UP; + } + + int index = 0; + while(index < table.getColumnCount()) { + if(table.getColumn(index) == column) + break; + index++; + } + for (int i = 1; i < items.length; i++) { + String v1 = items[i].getText(index); + if(v1.contains("*")) + v1 = v1.substring(0, v1.indexOf("*")); + Double value1; + try { + value1 = Double.parseDouble(v1); + } catch(NumberFormatException ne) { + continue; + } + for (int j = 0; j < i; j++){ + String v2 = items[j].getText(index); + if(v2.contains("*")) + v2 = v2.substring(0, v2.indexOf("*")); + Double value2; + try { + value2 = Double.parseDouble(v2); + } catch(NumberFormatException ne) { + continue; + } + int result = value1.compareTo(value2); + if (dir == SWT.UP && result < 0 || dir == SWT.DOWN && result > 0) { + int columns = table.getColumnCount(); + String[] values = new String[columns]; + for(int k = 0; k < columns; k++) { + values[k] = items[i].getText(k); + } + items[i].dispose(); + TableItem item = new TableItem(table, SWT.NONE, j); + item.setText(values); + items = table.getItems(); + break; + } + } + } + table.setSortColumn(column); + table.setSortDirection(dir); + } + }; + + + + String[] titles = titleList.toArray(new String[titleList.size()]); + + for (int i=0; i dataset.times[dataset.times.length - 1] || + time < dataset.times[0]) { + return "---"; + } + + // Make sure the index is within times array + if(index >= dataset.times.length) + index = dataset.times.length - 1; + + // times match, no approximation needed + double t; + for(int i = 0; i < dataset.times.length; i++) { + t = dataset.times[i]; + if(t == time) + return String.valueOf(dataset.values[i]); + } + + // Search the position on datasets' timeline + int dir = table.getSortDirection(); + while(dataset.times[index] > time) { + index = dir == SWT.UP ? index - 1 : index + 1; + } + while(dataset.times[index] <= time) + index = dir == SWT.UP ? index + 1 : index - 1; + + int a = dir == SWT.UP ? index - 1 : index; + int b = dir == SWT.UP ? index : index - 1; + + // Calculate and return approximation + return dataset.values[a] + + (dataset.values[b] - dataset.values[a]) * + (time - dataset.times[a]) / + (dataset.times[b] - dataset.times[a]) + "*"; + } + + @Override + public void setFocus() { + + } + + @Override + public void dispose() { + super.dispose(); + getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(selectionListener); + disposed = true; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java new file mode 100644 index 00000000..5b356766 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java @@ -0,0 +1,305 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.viewUtils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchPart; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.SelectionHints; +import org.simantics.db.layer0.exception.MissingVariableException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.modeling.ModelingUtils; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.adapter.VariableRVIUtils; +import org.simantics.sysdyn.manager.SysdynDataSet; +import org.simantics.sysdyn.manager.SysdynModel; +import org.simantics.sysdyn.manager.SysdynModelManager; +import org.simantics.sysdyn.manager.SysdynResult; +import org.simantics.sysdyn.ui.trend.PinTrend; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ISelectionUtils; + +/** + * Selection listener for listening datasets of the selected variables. Selections can come + * from both diagram and model browser. Listener provides the active datasets + * of the selected variable(s) or the JFreeChart of a selected chart definition. + * + * @author Teemu Lempinen + * + */ +public abstract class SysdynDatasetSelectionListener implements ISelectionListener { + + /** + * Triggered after a variable is selected from diagram or model browser + * Subclasses implement. + * @param activeDatasets Active dataset(s) of the selected variable(s) + */ + protected abstract void selectionChanged(Collection activeDatasets); + + /** + * Triggered after a chart definition is selected from model browser + * Subclasses implement + * + * @param graph ReadGraph + * @param resource Chart definition resource + */ + protected abstract void selectionChanged(ReadGraph graph, Resource resource); + + HashMap resultListeners = new HashMap(); + + @Override + public void selectionChanged(IWorkbenchPart part, final ISelection selection) { + // Empty selection or pinned trend -> Do nothing + if(selection.isEmpty() || Boolean.TRUE.equals(PinTrend.getState())) + return; + + if(selection instanceof IStructuredSelection) { + // Remove all previously added result listeners from model + if(!resultListeners.isEmpty()) { + for(SysdynModel model : resultListeners.keySet()) + model.removeResultListener(resultListeners.get(model)); + resultListeners.clear(); + } + + Session session = SimanticsUI.peekSession(); + if (session == null) + return; + + session.asyncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + + // Model browser provides variables + Collection vars = ISelectionUtils.filterSetSelection(selection, Variable.class); + + if(vars.isEmpty()) { + // Selection did not contain variables + Set ress = ISelectionUtils.filterSetSelection(selection, Resource.class); + List runtimes = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_VARIABLE_RESOURCE, Resource.class); + if(!runtimes.isEmpty()) { + // Selection is most probably in a diagram + Resource runtime = runtimes.get(0); + + // Get variables for selected resources + for(Resource resource : ress) { + Variable variable = getVariable(graph, resource, runtime); + if(variable != null) + vars.add(variable); + } + + // If there is no vars and only one selection, it can be a chart + if(vars.isEmpty() && ress.size() == 1) { + Resource r = ress.iterator().next(); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + if(graph.isInstanceOf(r, jfree.ChartElement)) { + if(graph.hasStatement(r, jfree.ChartElement_component)) { + r = graph.getSingleObject(r, jfree.ChartElement_component); + selectionChanged(graph, r); + return; + } + } + } + + } else { + // Selection is a jfreechart + if(ress.size() == 1) { + Resource r = ress.iterator().next(); + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + if(graph.isInstanceOf(r, jfree.Chart)) { + selectionChanged(graph, r); + return; + } + } + } + } + + // Update datasets and add result listeners to models + updateDatasets(graph, vars); + addResultListeners(graph, vars); + } + }); + } + } + + + /** + * Adds result listeners to models. In model browser it is possible to select + * variables from different models. This method adds listeners to all of those. + * + * @param graph ReadGraph graph + * @param variables Selected variables + * @throws DatabaseException + */ + private void addResultListeners(ReadGraph graph, final Collection variables) throws DatabaseException { + if(variables.size() < 1) return; + + // Get models + HashSet models = new HashSet(); + for(Variable variable : variables) { + Resource model = Variables.getModel(graph, variable); + if(model != null) { + models.add(getSysdynModel(graph, model)); + } + } + + // Create a result listener + Runnable listener = new Runnable() { + @Override + public void run() { + Session session = SimanticsUI.peekSession(); + if (session == null) + return; + + session.asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + updateDatasets(graph, variables); + } + }); + } + }; + + // Add the result listener to all models and to resultListeners list + for(SysdynModel model : models) { + model.addResultListener(listener); + resultListeners.put(model, listener); + } + } + + /** + * Updates datasets for the selected variables + * @param graph ReadGraph + * @param variables Selected variables + * @throws DatabaseException + */ + private void updateDatasets(ReadGraph graph, Collection variables) throws DatabaseException { + + ArrayList datasets = new ArrayList(); + for(Variable variable : variables) { + // Get all active datasets for the variable and add them to the result + Collection activeDataSets = loadAllActive(graph, variable); + if(activeDataSets != null && !activeDataSets.isEmpty()) + datasets.addAll(activeDataSets); + } + + selectionChanged(datasets); + } + + + /** + * Get all active datasets for a variable (and all of its dimensions) + * @param g ReadGraph + * @param variable Selected variable + * @return Active datasets for the selected variable + * @throws DatabaseException + */ + protected Collection loadAllActive(ReadGraph g, Variable variable) throws DatabaseException { + ArrayList dataSets = new ArrayList(); + + // Get variable's rvi and change it to modelica format + String rvi; + try { + rvi = Variables.getRVI(g, variable).replace("/", "."); + } catch (DatabaseException e) { + return dataSets; + } + + // Remove the first '.' + if(rvi.length() > 1) + rvi = rvi.substring(1); + + + HashMap rvis = VariableRVIUtils.getActiveRVIs(g, variable); + + Resource modelResource = Variables.getModel(g, variable); + SysdynModel model = getSysdynModel(g, modelResource); + + if(model == null) + return dataSets; + + // Finally, find all active datasets for the found rvis + Collection activeResults = model.getActiveResults(); + for(SysdynResult sysdynResult : activeResults) { + for(String currvi : rvis.keySet()) { + if(currvi != null && currvi.length() > 0) { + SysdynDataSet sds = sysdynResult.getDataSet(currvi.substring(1).replace("/", ".")); + if(sds != null) { + try { + sds.name = rvis.get(currvi).substring(1).replace("/", "."); + } catch (NullPointerException e) { + e.printStackTrace(); + } + dataSets.add(sds); + } + } + } + } + return dataSets; + + } + + + /** + * Find a variable representing element + * + * @param g ReadGraph + * @param element Element resource + * @param runtime runtime resource + * @return Variable representing element + * @throws DatabaseException + */ + private Variable getVariable(ReadGraph g, Resource element, Resource runtime) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + DiagramResource dr = DiagramResource.getInstance(g); + if(runtime == null) return null; + Resource resource = ModelingUtils.getPossibleElementCorrespondendence(g, element); + if(resource == null || !g.isInstanceOf(resource, sr.Variable)) return null; + String variableURI = g.getPossibleRelatedValue(runtime, dr.RuntimeDiagram_HasVariable); + try { + Variable compositeVariable = Variables.getVariable(g, variableURI); + return compositeVariable.browsePossible(g, resource); + } catch (MissingVariableException e) { + return null; + } + } + + /** + * Get SysdynModel representing the model resource + * @param g ReadGraph + * @param model Model resource + * @return SysdynModel representing model + * @throws DatabaseException + */ + private SysdynModel getSysdynModel(ReadGraph g, Resource model) throws DatabaseException { + Resource configuration = g.getPossibleObject(model, SimulationResource.getInstance(g).HasConfiguration); + return SysdynModelManager.getInstance(g.getSession()).getModel(g, configuration); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/ExportWizardFunction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/ExportWizardFunction.java new file mode 100644 index 00000000..755282e1 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/ExportWizardFunction.java @@ -0,0 +1,53 @@ +package org.simantics.sysdyn.ui.wizards.functions; + + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; +import org.simantics.db.Resource; +import org.simantics.ui.utils.AdaptionUtils; + + +public class ExportWizardFunction extends Wizard implements IImportWizard { + + private WizardFunctionsExportPage mainPage; + private IStructuredSelection currentSelection = null; + private String initialPath = null; + public Resource selection; + + /** + * Constructor for ExternalProjectImportWizard. + */ + public ExportWizardFunction() { + this(null); + } + + /** + * Constructor for ExternalProjectImportWizard. + */ + public ExportWizardFunction(String initialPath) + { + super(); + this.initialPath = initialPath; + } + + public void init(IWorkbench workbench, IStructuredSelection currentSelection) { + setWindowTitle("Export"); + this.currentSelection = currentSelection; + selection = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class); + } + + public void addPages() { + super.addPages(); + mainPage = new WizardFunctionsExportPage( + "wizardFunctionsExportPage", initialPath, currentSelection); //$NON-NLS-1$ + addPage(mainPage); + } + + @Override + public boolean performFinish() { + return mainPage.createProjects(selection); + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeFunctionLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeFunctionLabeler.java new file mode 100644 index 00000000..37d85e05 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeFunctionLabeler.java @@ -0,0 +1,20 @@ +package org.simantics.sysdyn.ui.wizards.functions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode; + +public class FunctionTreeFunctionLabeler extends LabelerContributor>{ + + @Override + public String getLabel(ReadGraph graph, FunctionLibraryNode input) + throws DatabaseException { + String name = NameUtils.getSafeName(graph, input.data); + return name; + } + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeLibraries.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeLibraries.java new file mode 100644 index 00000000..f2344247 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeLibraries.java @@ -0,0 +1,37 @@ +package org.simantics.sysdyn.ui.wizards.functions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode; +import org.simantics.sysdyn.ui.browser.nodes.ModelNode; + +public class FunctionTreeLibraries extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, ModelNode model) + throws DatabaseException { + ArrayList> result = new ArrayList>(); + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + + for (Resource r : graph.syncRequest(new ObjectsWithType(model.data, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))){ + result.add(new FunctionLibraryNode(r)); + } + + return result; + } + + @Override + public String getViewpointId() { + return "Standard"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeModelLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeModelLabeler.java new file mode 100644 index 00000000..1a2003ab --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeModelLabeler.java @@ -0,0 +1,17 @@ +package org.simantics.sysdyn.ui.wizards.functions; + +import org.simantics.browsing.ui.graph.impl.contributor.labeler.LabelerContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.ModelNode; + +public class FunctionTreeModelLabeler extends LabelerContributorImpl{ + + @Override + public String getLabel(ReadGraph graph, ModelNode input) + throws DatabaseException { + return NameUtils.getSafeName(graph, input.data); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeModels.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeModels.java new file mode 100644 index 00000000..623f1a30 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeModels.java @@ -0,0 +1,43 @@ +package org.simantics.sysdyn.ui.wizards.functions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.ModelNode; + +public class FunctionTreeModels extends ViewpointContributorImpl { + + @Override + public Collection getContribution(ReadGraph graph, Resource input) + throws DatabaseException { + + + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + ArrayList> result = new ArrayList>(); + for(Resource r : graph.syncRequest(new ObjectsWithType(input, l0.ConsistsOf, sr.SysdynModel))) { + result.add(new ModelNode(r)); + } + Resource sharedlibrary = graph.getPossibleResource("http://SharedOntologies"); + if (sharedlibrary != null) + result.add(new SharedFunctionsFolderNode(sharedlibrary)); + + return result; + } + + @Override + public String getViewpointId() { + return "Function Library Import"; + } + + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedFolderLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedFolderLabeler.java new file mode 100644 index 00000000..17f53686 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedFolderLabeler.java @@ -0,0 +1,15 @@ +package org.simantics.sysdyn.ui.wizards.functions; + +import org.simantics.browsing.ui.graph.impl.contributor.labeler.LabelerContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; + +public class FunctionTreeSharedFolderLabeler extends LabelerContributorImpl{ + + @Override + public String getLabel(ReadGraph graph, SharedFunctionsFolderNode input) + throws DatabaseException { + return "Shared Functions"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedLibraries.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedLibraries.java new file mode 100644 index 00000000..e9003a1a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedLibraries.java @@ -0,0 +1,35 @@ +package org.simantics.sysdyn.ui.wizards.functions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode; + +public class FunctionTreeSharedLibraries extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, SharedFunctionsFolderNode folder) + throws DatabaseException { + ArrayList result = new ArrayList(); + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + Resource sharedlibrary = graph.getPossibleResource("http://SharedOntologies"); + for (Resource r : graph.syncRequest(new ObjectsWithType(sharedlibrary, l0.ConsistsOf, sr.SharedFunctionOntology))){ + result.add(new SharedFunctionLibraryNode(r)); + } + return result; + } + + @Override + public String getViewpointId() { + return "Standard"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedLibraryLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedLibraryLabeler.java new file mode 100644 index 00000000..e054cf60 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSharedLibraryLabeler.java @@ -0,0 +1,17 @@ +package org.simantics.sysdyn.ui.wizards.functions; + +import org.simantics.browsing.ui.graph.impl.contributor.labeler.LabelerContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode; + +public class FunctionTreeSharedLibraryLabeler extends LabelerContributorImpl{ + + @Override + public String getLabel(ReadGraph graph, SharedFunctionLibraryNode input) + throws DatabaseException { + return NameUtils.getSafeName(graph, input.data); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSubLibraries.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSubLibraries.java new file mode 100644 index 00000000..c88421a3 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/FunctionTreeSubLibraries.java @@ -0,0 +1,36 @@ +package org.simantics.sysdyn.ui.wizards.functions; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode; + +public class FunctionTreeSubLibraries extends ViewpointContributor> { + + @Override + public Collection getContribution(ReadGraph graph, FunctionLibraryNode library) + throws DatabaseException { + ArrayList> result = new ArrayList>(); + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + + for (Resource r : graph.syncRequest(new ObjectsWithType(library.data, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))){ + result.add(new FunctionLibraryNode(r)); + } + + return result; + } + + @Override + public String getViewpointId() { + return "Standard"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/ImportWizardFunction.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/ImportWizardFunction.java new file mode 100644 index 00000000..eb8b06f5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/ImportWizardFunction.java @@ -0,0 +1,54 @@ +package org.simantics.sysdyn.ui.wizards.functions; + + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; +import org.simantics.db.Resource; +import org.simantics.ui.utils.AdaptionUtils; + + +public class ImportWizardFunction extends Wizard implements IImportWizard { + + private WizardFunctionsImportPage mainPage; + private IStructuredSelection currentSelection = null; + private String initialPath = null; + public Resource selection; + + /** + * Constructor for ImportWizardFunction. + */ + public ImportWizardFunction() { + this(null); + } + + /** + * Constructor for ImportWizardFunction. + */ + public ImportWizardFunction(String initialPath) + { + super(); + this.initialPath = initialPath; + } + + public void init(IWorkbench workbench, IStructuredSelection currentSelection) { + setWindowTitle("Import"); + this.currentSelection = currentSelection; + selection = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class); + } + + public void addPages() { + super.addPages(); + mainPage = new WizardFunctionsImportPage( + "wizardFunctionsImportPage", initialPath, currentSelection); //$NON-NLS-1$ + addPage(mainPage); + } + + @Override + public boolean performFinish() { + return mainPage.createProjects(); + + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/SharedFunctionsFolderNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/SharedFunctionsFolderNode.java new file mode 100644 index 00000000..989c5cdb --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/SharedFunctionsFolderNode.java @@ -0,0 +1,65 @@ +package org.simantics.sysdyn.ui.wizards.functions; + +import org.simantics.browsing.ui.common.node.DeleteException; +import org.simantics.browsing.ui.common.node.IDropTargetNode; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; + +public class SharedFunctionsFolderNode extends FunctionLibraryNode implements IDropTargetNode { + + public SharedFunctionsFolderNode(Resource resource) { + super(resource); + } + + @Override + public void delete() throws DeleteException { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + + graph.deny(data, l0.PartOf); + graph.deny(data, l0.IsLinkedTo_Inverse); + + // TODO: remove file + } + }); + } + + @Override + public void drop(Object data) { + final Resource[] resources = ResourceAdaptionUtils.toResources(data); + final Resource library = this.data; + if(resources.length > 0) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + for(Resource tobeMoved : resources) { + if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) || + graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) { + Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf); + graph.deny(tobeMoved, l0.PartOf); + graph.claim(tobeMoved, l0.PartOf, library); + FunctionUtils.updateFunctionFileForLibrary(graph, oldLib); + FunctionUtils.updateFunctionFileForLibrary(graph, library); + } + } + + } + }); + } + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/WizardFunctionsExportPage.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/WizardFunctionsExportPage.java new file mode 100644 index 00000000..06b421f2 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/WizardFunctionsExportPage.java @@ -0,0 +1,366 @@ +package org.simantics.sysdyn.ui.wizards.functions; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.PixelConverter; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.simantics.browsing.ui.swt.AdaptableHintContext; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Files; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.primitiverequest.PossibleRelatedValue; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.TransferableGraphRequest2; +import org.simantics.db.request.Read; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.ArrayMap; +import org.simantics.utils.datastructures.Pair; + +public class WizardFunctionsExportPage extends WizardPage { + + // dialog store id constants + private Text filePathField; + + // Keep track of the archive that we browsed to last time + // the wizard was invoked. + private static String previouslyBrowsedFile = ""; + + private Button browseDirectoriesButton; + + //private IStructuredSelection currentSelection; + + GraphExplorerComposite functionLibraryExplorer; + + private boolean selectionMade = false; + + /** + * Creates a new project creation wizard page. + * + */ + public WizardFunctionsExportPage() { + this("wizardFunctionsExportPage", null, null); //$NON-NLS-1$ + } + + /** + * Create a new instance of the receiver. + * + * @param pageName + */ + public WizardFunctionsExportPage(String pageName) { + this(pageName,null, null); + } + + /** + * More (many more) parameters. + * + * @param pageName + * @param initialPath + * @param currentSelection + * @since 3.5 + */ + public WizardFunctionsExportPage(String pageName,String initialPath, + IStructuredSelection currentSelection) { + super(pageName); + //this.currentSelection = currentSelection; + setPageComplete(false); + setTitle("Export Function Library"); + setDescription("Choose the Function Library and the export location, then press Finish."); + } + + public void createControl(Composite parent) { + + initializeDialogUnits(parent); + + Composite workArea = new Composite(parent, SWT.NONE); + setControl(workArea); + + workArea.setLayout(new GridLayout()); + workArea.setLayoutData(new GridData(GridData.FILL_BOTH + | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); + + createProjectsRoot(workArea); + createTree(workArea); + + } + + private void createProjectsRoot(Composite workArea) { + + // set label for field + Label title = new Label(workArea, SWT.NONE); + title.setText("Select the export location for Function Library:"); + + Composite projectGroup = new Composite(workArea, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.makeColumnsEqualWidth = false; + layout.marginWidth = 0; + + projectGroup.setLayout(layout); + projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + // function library location entry field + this.filePathField = new Text(projectGroup, SWT.BORDER); + + GridData directoryPathData = new GridData(SWT.FILL, SWT.NONE, true, false); + directoryPathData.widthHint = new PixelConverter(filePathField).convertWidthInCharsToPixels(25); + filePathField.setLayoutData(directoryPathData); + + filePathField.addModifyListener(new ModifyListener(){ + @Override + public void modifyText(ModifyEvent e) { + previouslyBrowsedFile = filePathField.getText(); + } + }); + if (previouslyBrowsedFile != null){ + filePathField.setText(previouslyBrowsedFile); + validatePage(); + } + + // browse button + browseDirectoriesButton = new Button(projectGroup, SWT.PUSH); + browseDirectoriesButton.setText("Browse"); + setButtonLayoutData(browseDirectoriesButton); + + browseDirectoriesButton.addSelectionListener(new SelectionAdapter() { + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.SelectionAdapter#widgetS + * elected(org.eclipse.swt.events.SelectionEvent) + */ + public void widgetSelected(SelectionEvent e) { + handleLocationDirectoryButtonPressed(); + } + }); + + } + + private void createTree(Composite workArea){ + + //set label for tree + Label title = new Label(workArea, SWT.NONE); + title.setText("Select Function Library to export:"); + + try { + Resource input = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) + throws DatabaseException { + Resource model = SimanticsUI.getProject().get(); + return model; + } + + }); + + functionLibraryExplorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE); + + functionLibraryExplorer + .setBrowseContexts(SysdynResource.URIs.FunctionTree); + + functionLibraryExplorer.finish(); + + functionLibraryExplorer.setInput(null, input); + + GridDataFactory.fillDefaults().grab(true, true).applyTo( + functionLibraryExplorer); + + ((Tree)functionLibraryExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + setMessage(null); + selectionMade = true; + validatePage(); + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + setMessage(null); + selectionMade = true; + validatePage(); + } + }); + + } catch (DatabaseException e) { + e.printStackTrace(); + } + + + } + + //Set filePathField active + public void setVisible(boolean visible) { + super.setVisible(visible); + this.filePathField.setFocus(); + } + + + //Open dialog for choosing the file + protected void handleLocationDirectoryButtonPressed() { + + final Shell shell = filePathField.getShell(); + + FileDialog dialog = new FileDialog(shell, SWT.SAVE); + + String[] ext = {"*.tg"}; + dialog.setFilterExtensions(ext); + + dialog.setText("Export Function Library"); + + String dirName = filePathField.getText().trim(); + + File path = new File(dirName); + if (path.exists()) { + dialog.setFilterPath(new Path(dirName).toOSString()); + } + + String selectedFile = dialog.open(); + if (selectedFile != null) { + filePathField.setText(selectedFile); + validatePage(); + } + + } + + //Get selection from the tree + @SuppressWarnings("unchecked") + public static T getExplorerResource(GraphExplorerComposite explorer, + Class clazz) { + if(explorer == null) + return null; + ISelection selection = ((ISelectionProvider) explorer + .getAdapter(ISelectionProvider.class)).getSelection(); + if (selection == null) + return null; + IStructuredSelection iss = (IStructuredSelection) selection; + AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement(); + if (inc == null) + return null; + final T resource = (T) inc.getAdapter(clazz); + + return resource; + } + + public boolean createProjects(Resource selection) { + + final String selected = previouslyBrowsedFile; + if(selected == null) return false; + + final Resource functionLibrary = getExplorerResource(functionLibraryExplorer, Resource.class); + if(functionLibrary == null) return false; + + String name = null; + try { + name = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + if (!graph.hasStatement(functionLibrary, Layer0.getInstance(graph).PartOf)) + return null; + Layer0 l0 = Layer0.getInstance(graph); + String name = graph.syncRequest(new PossibleRelatedValue(functionLibrary, l0.HasName, Bindings.STRING )); + return name; + + } + + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + if(name == null) return false; + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + String name = graph.syncRequest(new PossibleRelatedValue(functionLibrary, l0.HasName, Bindings.STRING )); + ArrayList> roots = new ArrayList>(); + roots.add(Pair.make(functionLibrary, name)); + TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, functionLibrary)); + + try { + Files.createFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class), tg); + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + + } + }); + + return true; + } + + void validatePage() { + + if (previouslyBrowsedFile.isEmpty() || selectionMade == false){ + setPageComplete(false); + return; + } + + if (functionLibraryExplorer != null){ + final Resource selectedResource = getExplorerResource(functionLibraryExplorer, Resource.class); + + String root = null; + try { + root = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + Resource model = graph.getPossibleObject(selectedResource, l0.PartOf); + String rootName = NameUtils.getSafeName(graph, model); + + return rootName; + } + + }); + if (root != null && root.equalsIgnoreCase("Development Project")){ + setPageComplete(false); + setMessage("Select Function Library folder under the Model or from the Shared Functions folder."); + return; + } + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + setPageComplete(true); + + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/WizardFunctionsImportPage.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/WizardFunctionsImportPage.java new file mode 100644 index 00000000..86f10c2c --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/functions/WizardFunctionsImportPage.java @@ -0,0 +1,448 @@ +package org.simantics.sysdyn.ui.wizards.functions; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.PixelConverter; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.simantics.browsing.ui.swt.AdaptableHintContext; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Files; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.WriteOnlyGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; +import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; +import org.simantics.db.request.Read; +import org.simantics.graph.representation.Root; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.FunctionUtils; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.ArrayMap; + +public class WizardFunctionsImportPage extends WizardPage{ + + // dialog store id constants + private Text filePathField; + + // Keep track of the archive that we browsed to last time + // the wizard was invoked. + private static String previouslyBrowsedFile = ""; + + private Button browseDirectoriesButton; + + private Shell shell; + + //private IStructuredSelection currentSelection; + + private Resource selectedModel; + + GraphExplorerComposite functionLibraryExplorer; + + private String error = ""; + + private boolean selectionMade = false; + + /** + * Creates a new project creation wizard page. + * + */ + public WizardFunctionsImportPage() { + this("wizardFunctionsImportPage", null, null); //$NON-NLS-1$ + } + + /** + * Create a new instance of the receiver. + * + * @param pageName + */ + public WizardFunctionsImportPage(String pageName) { + this(pageName,null, null); + } + + /** + * More (many more) parameters. + * + * @param pageName + * @param initialPath + * @param currentSelection + * @since 3.5 + */ + public WizardFunctionsImportPage(String pageName,String initialPath, + IStructuredSelection currentSelection) { + super(pageName); + setPageComplete(false); + //this.currentSelection = currentSelection; + setTitle("Import Function Library"); + setDescription("Choose the Function Library file and the import location, then press Finish."); + } + + public void createControl(Composite parent) { + + initializeDialogUnits(parent); + + Composite workArea = new Composite(parent, SWT.NONE); + setControl(workArea); + + workArea.setLayout(new GridLayout()); + workArea.setLayoutData(new GridData(GridData.FILL_BOTH + | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); + + createProjectsRoot(workArea); + + createTree(workArea); + + + } + + private void createProjectsRoot(Composite workArea) { + + //set label for field + Label title = new Label(workArea, SWT.NONE); + title.setText("Select Function Library source:"); + + Composite projectGroup = new Composite(workArea, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.makeColumnsEqualWidth = false; + layout.marginWidth = 0; + + projectGroup.setLayout(layout); + projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + // module location entry field + this.filePathField = new Text(projectGroup, SWT.BORDER); + + GridData directoryPathData = new GridData(SWT.FILL, SWT.NONE, true, false); + directoryPathData.widthHint = new PixelConverter(filePathField).convertWidthInCharsToPixels(25); + filePathField.setLayoutData(directoryPathData); + + + filePathField.addModifyListener(new ModifyListener(){ + @Override + public void modifyText(ModifyEvent e) { + previouslyBrowsedFile = filePathField.getText(); + } + }); + if (previouslyBrowsedFile != null){ + filePathField.setText(previouslyBrowsedFile); + validatePage(); + } + + // browse button + browseDirectoriesButton = new Button(projectGroup, SWT.PUSH); + browseDirectoriesButton.setText("Browse"); + setButtonLayoutData(browseDirectoriesButton); + + browseDirectoriesButton.addSelectionListener(new SelectionAdapter() { + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.SelectionAdapter#widgetS + * elected(org.eclipse.swt.events.SelectionEvent) + */ + public void widgetSelected(SelectionEvent e) { + handleLocationDirectoryButtonPressed(); + } + }); + + } + + private void createTree(Composite workArea){ + + //set label for tree + Label title = new Label(workArea, SWT.NONE); + title.setText("Select import location:"); + + try { + Resource input = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) + throws DatabaseException { + Resource model = SimanticsUI.getProject().get(); + return model; + } + + }); + + functionLibraryExplorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE); + + functionLibraryExplorer + .setBrowseContexts(SysdynResource.URIs.FunctionTree); + + functionLibraryExplorer.finish(); + + functionLibraryExplorer.setInput(null, input); + + GridDataFactory.fillDefaults().grab(true, true).applyTo( + functionLibraryExplorer); + + ((Tree)functionLibraryExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + selectionMade = true; + validatePage(); + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + selectionMade = true; + validatePage(); + } + }); + + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + + //Set filePathField active + public void setVisible(boolean visible) { + super.setVisible(visible); + this.filePathField.setFocus(); + } + + //Open dialog for choosing the file + protected void handleLocationDirectoryButtonPressed() { + + shell = filePathField.getShell(); + + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + + String[] ext = {"*.tg"}; + dialog.setFilterExtensions(ext); + + dialog.setText("Import Function Library"); + + String dirName = filePathField.getText().trim(); + + File path = new File(dirName); + if (path.exists()) { + dialog.setFilterPath(new Path(dirName).toOSString()); + } + + String selectedFile = dialog.open(); + if (selectedFile != null) { + filePathField.setText(selectedFile); + validatePage(); + } + } + + //Get selection from the tree + @SuppressWarnings("unchecked") + public static T getExplorerResource(GraphExplorerComposite explorer, + Class clazz) { + + if(explorer == null) + return null; + ISelection selection = ((ISelectionProvider) explorer + .getAdapter(ISelectionProvider.class)).getSelection(); + if (selection == null) + return null; + IStructuredSelection iss = (IStructuredSelection) selection; + AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement(); + if (inc == null) + return null; + final T resource = (T) inc.getAdapter(clazz); + + return resource; + } + + //Create project after finish is pressed. + public boolean createProjects() { + + selectedModel= getExplorerResource(functionLibraryExplorer, Resource.class); + if(selectedModel == null){ + setErrorMessage("Error when retrieving resource"); + return false; + } + + String selected = previouslyBrowsedFile; + if(selected == null){ + setErrorMessage("No file selected"); + return false; + } + + TransferableGraph1 tg = null; + try { + tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class)); + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + return false; + } catch (IOException e) { + setErrorMessage("The imported file is not of type: Function Library"); + return false; + } + if(tg == null){ + setErrorMessage("The imported file is not of type: Function Library"); + return false; + } + + + try { + Boolean hasSharedOntologies; + hasSharedOntologies = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + try { + graph.getResource("http://SharedOntologies"); + } catch (ResourceNotFoundException e) { + return false; + } + return true; + } + }); + + if(!hasSharedOntologies) { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + GraphUtils.create2(graph, l0.Library, + l0.HasName, "SharedOntologies", + l0.PartOf, graph.getResource("http:/")); + } + }); + + } + } catch (DatabaseException e) { + e.printStackTrace(); + return false; + } + + + SysdynFunctionLibraryImportAdvisor ia = new SysdynFunctionLibraryImportAdvisor(selectedModel); + try { + DefaultPasteHandler.defaultExecute(tg, selectedModel, ia); + } catch (Exception e) { + e.printStackTrace(); + } + + final Resource root = ia.getRoot(); + + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + if(graph.isInstanceOf(root, SysdynResource.getInstance(graph).SharedFunctionOntology)) { + Resource library = graph.getResource("http://SharedOntologies"); + if(!graph.hasStatement(library, l0.ConsistsOf, root)) { + graph.claim(library, l0.ConsistsOf, root); + } + + SysdynResource sr = SysdynResource.getInstance(graph); + Resource model = selectedModel; + while(!graph.isInstanceOf(model, sr.SysdynModel) && graph.isInstanceOf(model, l0.Ontology)) + model = graph.getSingleObject(model, l0.PartOf); + if(graph.isInstanceOf(model, sr.SysdynModel)) { + graph.claim(model, l0.IsLinkedTo, l0.IsLinkedTo_Inverse, root); + } + + } else if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary)) { + Resource instanceOf = graph.getPossibleObject(root,l0.InstanceOf); + String type = "..."; + if(instanceOf != null) + type = NameUtils.getSafeName(graph, instanceOf); + else { + Resource inheritedFrom = graph.getPossibleObject(root, l0.Inherits); + if(inheritedFrom != null) + type = NameUtils.getSafeName(graph, inheritedFrom); + } + graph.deny(root, l0.PartOf); + error = type; + } else { + FunctionUtils.updateFunctionFileForLibrary(graph, selectedModel); + } + + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + if (!error.isEmpty()){ + setErrorMessage("The imported file is not of type: Function Library (" + error +")"); + error = ""; + return false; + } + return true; + } + + private class SysdynFunctionLibraryImportAdvisor extends DefaultPasteImportAdvisor { + + public SysdynFunctionLibraryImportAdvisor(Resource library) { + super(library); + } + + @Override + public void analyzeType(ReadGraph graph, Root root) throws DatabaseException { + if(root.type.equals(SysdynResource.URIs.SharedFunctionOntology)) { + try { + library = graph.getResource("http://SharedOntologies"); + } catch (ResourceNotFoundException e) { + e.printStackTrace(); + } + } + } + + @Override + public Resource createRoot(WriteOnlyGraph graph, Root root) throws DatabaseException { + Layer0 l0 = graph.getService(Layer0.class); + this.root = graph.newResource(); + graph.claim(library, l0.ConsistsOf, l0.PartOf, this.root); + String name = root.name; + String newName = nameMappings.get(name); + graph.addLiteral(this.root, l0.HasName, l0.NameOf, l0.String, newName, Bindings.STRING); + return this.root; + + } + + } + void validatePage() { + + if (previouslyBrowsedFile.isEmpty() || selectionMade == false){ + setPageComplete(false); + return; + } + setErrorMessage(null); + setPageComplete(true); + + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/ImportWizardMdl.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/ImportWizardMdl.java new file mode 100644 index 00000000..91422841 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/ImportWizardMdl.java @@ -0,0 +1,47 @@ +package org.simantics.sysdyn.ui.wizards.mdl; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; + +public class ImportWizardMdl extends Wizard implements IImportWizard { + + private WizardMdlImportPage mainPage; + private IStructuredSelection currentSelection = null; + private String initialPath = null; + + /** + * Constructor for ExternalProjectImportWizard. + */ + public ImportWizardMdl() { + this(null); + } + + /** + * Constructor for ExternalProjectImportWizard. + */ + public ImportWizardMdl(String initialPath) + { + super(); + this.initialPath = initialPath; + } + + public void addPages() { + super.addPages(); + mainPage = new WizardMdlImportPage( + "wizardMdlImportPage", initialPath, currentSelection); //$NON-NLS-1$ + addPage(mainPage); + } + + public void init(IWorkbench workbench, IStructuredSelection currentSelection) { + setWindowTitle("Import"); + this.currentSelection = currentSelection; + } + + @Override + public boolean performFinish() { + return mainPage.createProjects(); + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/WizardMdlImportPage.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/WizardMdlImportPage.java new file mode 100644 index 00000000..bf813ba6 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/mdl/WizardMdlImportPage.java @@ -0,0 +1,204 @@ +package org.simantics.sysdyn.ui.wizards.mdl; + +import java.io.File; + +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.layout.PixelConverter; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.mdlImport.MdlParser; +import org.simantics.sysdyn.mdlImport.mdlElements.Model; +import org.simantics.ui.SimanticsUI; + +public class WizardMdlImportPage extends WizardPage{ + + // dialog store id constants + private Text filePathField; + + // Keep track of the archive that we browsed to last time + // the wizard was invoked. + private static String previouslyBrowsedFile = ""; + + private Button browseDirectoriesButton; + + /** + * Creates a new project creation wizard page. + * + */ + public WizardMdlImportPage() { + this("wizardMdlImportPage", null, null); //$NON-NLS-1$ + } + + /** + * Create a new instance of the receiver. + * + * @param pageName + */ + public WizardMdlImportPage(String pageName) { + this(pageName,null, null); + } + + /** + * More (many more) parameters. + * + * @param pageName + * @param initialPath + * @param currentSelection + * @since 3.5 + */ + public WizardMdlImportPage(String pageName,String initialPath, + IStructuredSelection currentSelection) { + super(pageName); + setPageComplete(false); + setTitle("Import Vensim model"); + setDescription("Choose the Vensim model file (.mdl), then press Finish."); + } + + public void createControl(Composite parent) { + + initializeDialogUnits(parent); + + Composite workArea = new Composite(parent, SWT.NONE); + setControl(workArea); + + workArea.setLayout(new GridLayout()); + workArea.setLayoutData(new GridData(GridData.FILL_BOTH + | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); + + createProjectsRoot(workArea); + } + + private void createProjectsRoot(Composite workArea) { + + // set label for field + Label title = new Label(workArea, SWT.NONE); + title.setText("Select Vensim model source:"); + + Composite projectGroup = new Composite(workArea, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.makeColumnsEqualWidth = false; + layout.marginWidth = 0; + + projectGroup.setLayout(layout); + projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + // model location entry field + this.filePathField = new Text(projectGroup, SWT.BORDER); + + GridData directoryPathData = new GridData(SWT.FILL, SWT.NONE, true, false); + directoryPathData.widthHint = new PixelConverter(filePathField).convertWidthInCharsToPixels(25); + filePathField.setLayoutData(directoryPathData); + filePathField.addModifyListener(new ModifyListener(){ + @Override + public void modifyText(ModifyEvent e) { + previouslyBrowsedFile = filePathField.getText(); + } + }); + if (previouslyBrowsedFile != null){ + filePathField.setText(previouslyBrowsedFile); + validatePage(); + } + + // browse button + browseDirectoriesButton = new Button(projectGroup, SWT.PUSH); + browseDirectoriesButton.setText("Browse"); + setButtonLayoutData(browseDirectoriesButton); + + browseDirectoriesButton.addSelectionListener(new SelectionAdapter() { + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.SelectionAdapter#widgetS + * elected(org.eclipse.swt.events.SelectionEvent) + */ + public void widgetSelected(SelectionEvent e) { + handleLocationDirectoryButtonPressed(); + } + }); + + } + + //Set filePathField active + public void setVisible(boolean visible) { + super.setVisible(visible); + this.filePathField.setFocus(); + } + + //Open dialog for choosing the file + protected void handleLocationDirectoryButtonPressed() { + + final Shell shell = filePathField.getShell(); + + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + String[] ext = {"*.mdl"}; + dialog.setFilterExtensions(ext); + dialog.setText("Import Vensim model (.mdl)"); + + String dirName = filePathField.getText().trim(); + + File path = new File(dirName); + if (path.exists()) { + dialog.setFilterPath(new Path(dirName).toOSString()); + } + + String selectedFile = dialog.open(); + if (selectedFile != null) { + filePathField.setText(selectedFile); + validatePage(); + } + + } + + //Create project after finish is pressed. + public boolean createProjects() { + + final Resource project = SimanticsUI.getProject().get(); + if(project == null) return false; + + String selected = previouslyBrowsedFile; + if(selected == null) return false; + + File file = new File(selected); + + final Model model = MdlParser.parse(file); + + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + model.write(graph, project); + } + }); + + return true; + + } + void validatePage(){ + + if (previouslyBrowsedFile.isEmpty()){ + setPageComplete(false); + return; + } + + setPageComplete(true); + } +} + \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/ExportWizardModel.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/ExportWizardModel.java new file mode 100644 index 00000000..d68f341a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/ExportWizardModel.java @@ -0,0 +1,52 @@ +package org.simantics.sysdyn.ui.wizards.models; + + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; +import org.simantics.db.Resource; +import org.simantics.ui.utils.AdaptionUtils; + +public class ExportWizardModel extends Wizard implements IImportWizard { + + private WizardModelsExportPage mainPage; + private IStructuredSelection currentSelection = null; + private String initialPath = null; + public Resource selection; + + /** + * Constructor for ExternalProjectImportWizard. + */ + public ExportWizardModel() { + this(null); + } + + /** + * Constructor for ExternalProjectImportWizard. + */ + public ExportWizardModel(String initialPath) + { + super(); + this.initialPath = initialPath; + } + + public void init(IWorkbench workbench, IStructuredSelection currentSelection) { + setWindowTitle("Export"); + this.currentSelection = currentSelection; + selection = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class); + } + + public void addPages() { + super.addPages(); + mainPage = new WizardModelsExportPage( + "wizardModelsExportPage", initialPath, currentSelection); //$NON-NLS-1$ + addPage(mainPage); + } + + @Override + public boolean performFinish() { + return mainPage.createProjects(); + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/ImportWizardModel.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/ImportWizardModel.java new file mode 100644 index 00000000..e743d750 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/ImportWizardModel.java @@ -0,0 +1,48 @@ +package org.simantics.sysdyn.ui.wizards.models; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; + + +public class ImportWizardModel extends Wizard implements IImportWizard { + + private WizardModelsImportPage mainPage; + private IStructuredSelection currentSelection = null; + private String initialPath = null; + + /** + * Constructor for ExternalProjectImportWizard. + */ + public ImportWizardModel() { + this(null); + } + + /** + * Constructor for ExternalProjectImportWizard. + */ + public ImportWizardModel(String initialPath) + { + super(); + this.initialPath = initialPath; + } + + public void addPages() { + super.addPages(); + mainPage = new WizardModelsImportPage( + "wizardModelsImportPage", initialPath, currentSelection); //$NON-NLS-1$ + addPage(mainPage); + } + + public void init(IWorkbench workbench, IStructuredSelection currentSelection) { + setWindowTitle("Import"); + this.currentSelection = currentSelection; + } + + @Override + public boolean performFinish() { + return mainPage.createProjects(); + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsExportPage.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsExportPage.java new file mode 100644 index 00000000..a7194de6 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsExportPage.java @@ -0,0 +1,320 @@ +package org.simantics.sysdyn.ui.wizards.models; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.PixelConverter; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.simantics.browsing.ui.swt.AdaptableHintContext; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Files; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.primitiverequest.PossibleRelatedValue; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.TransferableGraphRequest2; +import org.simantics.db.request.Read; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.ArrayMap; +import org.simantics.utils.datastructures.Pair; + +public class WizardModelsExportPage extends WizardPage { + + // dialog store id constants + private Text filePathField; + + // Keep track of the archive that we browsed to last time + // the wizard was invoked. + + private static String previouslyBrowsedFile = ""; + + private Button browseDirectoriesButton; + + //private IStructuredSelection currentSelection; + + private Resource selectedModel; + + GraphExplorerComposite modelExplorer; + + private boolean selectionMade = false; + + + + /** + * Creates a new project creation wizard page. + * + */ + public WizardModelsExportPage() { + this("wizardModelsExportPage", null, null); //$NON-NLS-1$ + } + + /** + * Create a new instance of the receiver. + * + * @param pageName + */ + public WizardModelsExportPage(String pageName) { + this(pageName,null, null); + } + + /** + * More (many more) parameters. + * + * @param pageName + * @param initialPath + * @param currentSelection + * @since 3.5 + */ + public WizardModelsExportPage(String pageName,String initialPath, + IStructuredSelection currentSelection) { + super(pageName); + //this.currentSelection = currentSelection; + setPageComplete(false); + setTitle("Export Model"); + setDescription("Choose the Model and the export location, then press Finish."); + } + + public void createControl(Composite parent) { + + initializeDialogUnits(parent); + + Composite workArea = new Composite(parent, SWT.NONE); + setControl(workArea); + + workArea.setLayout(new GridLayout()); + workArea.setLayoutData(new GridData(GridData.FILL_BOTH + | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); + + createProjectsRoot(workArea); + createTree (workArea); + } + + private void createProjectsRoot(Composite workArea) { + + // set label for field + Label title = new Label(workArea, SWT.NONE); + title.setText("Select the export location for Model:"); + + Composite projectGroup = new Composite(workArea, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.makeColumnsEqualWidth = false; + layout.marginWidth = 0; + + projectGroup.setLayout(layout); + projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + // model location entry field + this.filePathField = new Text(projectGroup, SWT.BORDER); + + GridData directoryPathData = new GridData(SWT.FILL, SWT.NONE, true, false); + directoryPathData.widthHint = new PixelConverter(filePathField).convertWidthInCharsToPixels(25); + filePathField.setLayoutData(directoryPathData); + + filePathField.addModifyListener(new ModifyListener(){ + @Override + public void modifyText(ModifyEvent e) { + previouslyBrowsedFile = filePathField.getText(); + } + }); + if (previouslyBrowsedFile != null){ + filePathField.setText(previouslyBrowsedFile); + validatePage(); + } + + // browse button + browseDirectoriesButton = new Button(projectGroup, SWT.PUSH); + browseDirectoriesButton.setText("Browse"); + setButtonLayoutData(browseDirectoriesButton); + + browseDirectoriesButton.addSelectionListener(new SelectionAdapter() { + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.SelectionAdapter#widgetS + * elected(org.eclipse.swt.events.SelectionEvent) + */ + public void widgetSelected(SelectionEvent e) { + handleLocationDirectoryButtonPressed(); + } + }); + + } + + private void createTree(Composite workArea){ + + //set label for tree + Label title = new Label(workArea, SWT.NONE); + title.setText("Select Model to export:"); + + try { + Resource input = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) + throws DatabaseException { + Resource model = SimanticsUI.getProject().get(); + return model; + } + + }); + + modelExplorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE); + + modelExplorer + .setBrowseContexts(SysdynResource.URIs.ImportModuleTree); + + modelExplorer.finish(); + + modelExplorer.setInput(null, input); + + GridDataFactory.fillDefaults().grab(true, true).applyTo( + modelExplorer); + + ((Tree)modelExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + selectionMade = true; + validatePage(); + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + selectionMade = true; + validatePage(); + } + }); + + + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + + //Set filePathField active + public void setVisible(boolean visible) { + super.setVisible(visible); + this.filePathField.setFocus(); + } + + //Open dialog for choosing the file + protected void handleLocationDirectoryButtonPressed() { + final Shell shell = filePathField.getShell(); + + FileDialog dialog = new FileDialog(shell, SWT.SAVE); + + String[] ext = {"*.tg"}; + dialog.setFilterExtensions(ext); + + dialog.setText("Export Model"); + + String dirName = filePathField.getText().trim(); + + File path = new File(dirName); + if (path.exists()) { + dialog.setFilterPath(new Path(dirName).toOSString()); + } + + String selectedFile = dialog.open(); + if (selectedFile != null) { + filePathField.setText(selectedFile); + validatePage(); + } + + } + //Get selection from the tree + @SuppressWarnings("unchecked") + public static T getExplorerResource(GraphExplorerComposite explorer, + Class clazz) { + + if(explorer == null) + return null; + ISelection selection = ((ISelectionProvider) explorer + .getAdapter(ISelectionProvider.class)).getSelection(); + if (selection == null) + return null; + IStructuredSelection iss = (IStructuredSelection) selection; + AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement(); + if (inc == null) + return null; + final T resource = (T) inc.getAdapter(clazz); + + return resource; + } + + public boolean createProjects() { + + final String selected = previouslyBrowsedFile; + if(selected == null) return false; + + selectedModel= getExplorerResource(modelExplorer, Resource.class); + if(selectedModel == null) + return false; + + // FIXME: Model browser doesn't change its selection even if the selected object is removed, + // so you can try to export a removed model + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + String name = graph.syncRequest(new PossibleRelatedValue(selectedModel, l0.HasName, Bindings.STRING )); + ArrayList> roots = new ArrayList>(); + roots.add(Pair.make(selectedModel, name)); + TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, selectedModel)); + + try { + Files.createFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class), tg); + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + }); + + return true; + } + + void validatePage() { + + if (previouslyBrowsedFile.isEmpty() || selectionMade == false){ + setPageComplete(false); + return; + } + + setPageComplete(true); + + } +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsImportPage.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsImportPage.java new file mode 100644 index 00000000..39a6487f --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsImportPage.java @@ -0,0 +1,456 @@ +package org.simantics.sysdyn.ui.wizards.models; + +import java.io.File; +import java.io.IOException; +import java.util.HashSet; +import java.util.UUID; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.layout.PixelConverter; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Files; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; +import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.operation.Layer0X; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.spreadsheet.resource.SpreadsheetResource; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.handlers.imports.ImportModelHandler; +import org.simantics.sysdyn.ui.utils.OldTransferableGraph1; +import org.simantics.ui.SimanticsUI; + +public class WizardModelsImportPage extends WizardPage{ + + private Text filePathField; + + // Keep track of the archive that we browsed to last time + // the wizard was invoked. + private static String previouslyBrowsedFile = ""; + + private Button browseDirectoriesButton; + + private Shell shell; + + private String error = ""; + + /** + * Creates a new project creation wizard page. + * + */ + public WizardModelsImportPage() { + this("wizardModelsImportPage", null, null); //$NON-NLS-1$ + } + + /** + * Create a new instance of the receiver. + * + * @param pageName + */ + public WizardModelsImportPage(String pageName) { + this(pageName,null, null); + } + + /** + * More (many more) parameters. + * + * @param pageName + * @param initialPath + * @param currentSelection + * @since 3.5 + */ + public WizardModelsImportPage(String pageName,String initialPath, + IStructuredSelection currentSelection) { + super(pageName); + //this.initialPath = initialPath; + //this.currentSelection = currentSelection; + setPageComplete(false); + setTitle("Import Model"); + setDescription("Choose the Model file, then press Finish."); + } + + + public void createControl(Composite parent) { + + initializeDialogUnits(parent); + + Composite workArea = new Composite(parent, SWT.NONE); + setControl(workArea); + + workArea.setLayout(new GridLayout()); + workArea.setLayoutData(new GridData(GridData.FILL_BOTH + | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); + + createProjectsRoot(workArea); + } + + private void createProjectsRoot(Composite workArea) { + + // set label for field + Label title = new Label(workArea, SWT.NONE); + title.setText("Select Model source:"); + + Composite projectGroup = new Composite(workArea, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.makeColumnsEqualWidth = false; + layout.marginWidth = 0; + + projectGroup.setLayout(layout); + projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + // model location entry field + this.filePathField = new Text(projectGroup, SWT.BORDER); + + GridData directoryPathData = new GridData(SWT.FILL, SWT.NONE, true, false); + directoryPathData.widthHint = new PixelConverter(filePathField).convertWidthInCharsToPixels(25); + filePathField.setLayoutData(directoryPathData); + filePathField.addModifyListener(new ModifyListener(){ + @Override + public void modifyText(ModifyEvent e) { + previouslyBrowsedFile = filePathField.getText(); + } + }); + if (previouslyBrowsedFile != null){ + filePathField.setText(previouslyBrowsedFile); + validatePage(); + } + + // browse button + browseDirectoriesButton = new Button(projectGroup, SWT.PUSH); + browseDirectoriesButton.setText("Browse"); + setButtonLayoutData(browseDirectoriesButton); + + browseDirectoriesButton.addSelectionListener(new SelectionAdapter() { + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.SelectionAdapter#widgetS + * elected(org.eclipse.swt.events.SelectionEvent) + */ + public void widgetSelected(SelectionEvent e) { + setErrorMessage(null); + handleLocationDirectoryButtonPressed(); + } + }); + } + + + //Set filePathField active + public void setVisible(boolean visible) { + super.setVisible(visible); + this.filePathField.setFocus(); + } + + + //Open dialog for choosing the file + protected void handleLocationDirectoryButtonPressed() { + + shell = filePathField.getShell(); + + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + + String[] ext = {"*.tg"}; + dialog.setFilterExtensions(ext); + + dialog.setText("Import Model"); + + String path = Activator.getDefault().getPreferenceStore().getString(ImportModelHandler.IMPORTMODELTPATH); + if(path.isEmpty() || !(new File(path).exists())) + path = Platform.getLocation().toOSString(); + dialog.setFilterPath(path); + + String selectedFile = dialog.open(); + if (selectedFile != null) { + filePathField.setText(selectedFile); + validatePage(); + } + + } + + //Create project after finish is pressed. + public boolean createProjects() { + + Resource project = SimanticsUI.getProject().get(); + if(project == null){ + setErrorMessage("Error when retrieving resource"); + return false; + } + + String selected = previouslyBrowsedFile; + if(selected == null){ + setErrorMessage("No file selected"); + return false; + } + + TransferableGraph1 tg = null; + try { + tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class)); + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + } catch (IOException e) { + try { + OldTransferableGraph1 otg = (OldTransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(OldTransferableGraph1.class)); + tg = new TransferableGraph1(otg.resourceCount, otg.identities, otg.statements, otg.values); + } catch (RuntimeBindingConstructionException e1) { + e1.printStackTrace(); + } catch (IOException e1) { + setErrorMessage("The imported file is not of type: System Dynamics Model"); + return false; + } + } + if(tg == null){ + setErrorMessage("The imported file is not of type: System Dynamics Model"); + return false; + } + + try { + + DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(project); + DefaultPasteHandler.defaultExecute(tg, SimanticsUI.getProject().get(), ia); + + // Check that imported resource was actually a model + //and fix changes made to old ontology versions + final Resource root = ia.getRoot(); + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + if(!graph.isInstanceOf(root, SysdynResource.getInstance(graph).SysdynModel)) { + Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf); + String type = "..."; + if(instanceOf != null) + type = NameUtils.getSafeName(graph, instanceOf); + else { + Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits); + if(inheritedFrom != null) + type = NameUtils.getSafeName(graph, inheritedFrom); + } + graph.deny(root, Layer0.getInstance(graph).PartOf); + error = type; + } else { + updateOldConfigurationToBaseRealization(graph, root); + addDefaultOntologyLinks(graph, root); + addURIsToDiagrams(graph, root); + addSpreadSheetBook(graph, root); + } + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + + if (!error.isEmpty()){ + setErrorMessage("The imported file is not of type: System Dynamics Model (" + error +")"); + error = ""; + return false; + } + return true; + } + + /** + * In old versions base realization was separate. Newer versions use configuration as base realization. + * @param graph WriteGraph + * @param model Imported model + */ + private static void updateOldConfigurationToBaseRealization(WriteGraph graph, Resource model) { + Layer0X L0X = Layer0X.getInstance(graph); + try { + Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration); + if(configuration != null && !graph.hasStatement(configuration, L0X.IsBaseRealizationOf, model)) + graph.claim(configuration, L0X.IsBaseRealizationOf, model); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + + /** + * Links should be exported and imported automatically. If it has failed, the + * default ontology links sysdyn and layer0 are added. + * + * @param graph WriteGraph + * @param model Imported model + */ + + private static void addDefaultOntologyLinks(WriteGraph graph, Resource model) { + try { + Layer0 l0 = Layer0.getInstance(graph); + // The links should be exported and imported automatically + Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.1"); + Resource layer0 = graph.getResource("http://www.simantics.org/Layer0-1.0"); + if(!graph.hasStatement(model, l0.IsLinkedTo, sysdyn)) + graph.claim(model, l0.IsLinkedTo, sysdyn); + if(!graph.hasStatement(model, l0.IsLinkedTo, layer0)) + graph.claim(model, l0.IsLinkedTo, layer0); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + private static void addURIsToDiagrams(WriteGraph graph, Resource model) { + Layer0 l0 = Layer0.getInstance(graph); + SimulationResource simu = SimulationResource.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + try { + HashSet configurations = new HashSet(); + + Resource configuration = graph.getPossibleObject(model, simu.HasConfiguration); + if(configuration != null) + configurations.add(configuration); + + for(Resource r : graph.getObjects(model, l0.ConsistsOf)) { + if(graph.isInheritedFrom(r, sr.Module)) { + Resource moduleConfiguration = graph.getPossibleObject(r, sr2.IsDefinedBy); + if(moduleConfiguration != null) + configurations.add(moduleConfiguration); + } + } + + for(Resource conf : configurations) { + Resource configurationDiagram = graph.getPossibleObject(conf, mr.CompositeToDiagram); + if(configurationDiagram != null && !graph.hasStatement(configurationDiagram, l0.PartOf)) { + GraphUtils.create2(graph, l0.Library, + l0.HasName, "__CONTAINER__", + l0.PartOf, conf, + l0.ConsistsOf, configurationDiagram); + } + } + + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + + /** + * Add a missing spreadsheet book to the model + * + * @param graph + * @param model + */ + private static void addSpreadSheetBook(WriteGraph graph, Resource model) { + try { + Layer0 l0 = Layer0.getInstance(graph); + SpreadsheetResource ssr = SpreadsheetResource.getInstance(graph); + SimulationResource simu = SimulationResource.getInstance(graph); + Resource conf = graph.getPossibleObject(model, simu.HasConfiguration); + if(conf != null && graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, ssr.Book)).isEmpty()) { + Resource book = graph.newResource(); + graph.claim(book, l0.InstanceOf, null, ssr.Book); + graph.addLiteral(book, l0.HasName, l0.NameOf, l0.String, "Book" + UUID.randomUUID().toString(), Bindings.STRING); + graph.claim(conf, l0.ConsistsOf, l0.PartOf, book); + + createSheet(graph, book, "Sheet1", new String[] { }, new int[] { 50 }); + } + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + /** + * Create a sheet (Copied from SysdynProject) + * + * @param graph + * @param book + * @param name + * @param colNames + * @param colWidths + * @return + * @throws DatabaseException + */ + private static Resource createSheet(WriteGraph graph, Resource book, String name, String[] colNames, int[] colWidths) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + Layer0X L0X = Layer0X.getInstance(graph); + SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); + + Resource result = graph.newResource(); + graph.claim(result, L0.InstanceOf, null, sr.Spreadsheet); + + if(name == null) { + name = NameUtils.findFreshEscapedName(graph, "Sheet", book, sr.HasSheet); + } + graph.claimLiteral(result, L0.HasName, L0.NameOf, L0.String, name, Bindings.STRING); + graph.claim(book, L0.ConsistsOf, L0.PartOf, result); + + { + Resource newCell = graph.newResource(); + graph.claim(newCell, L0.InstanceOf, null, sr.Cell); + graph.claimLiteral(newCell, L0.HasName, L0.NameOf, L0.String, "Dimensions", Bindings.STRING); + graph.addLiteral(newCell, sr.FitColumns, sr.FitColumnsOf, L0.Boolean, false, Bindings.BOOLEAN); + graph.addLiteral(newCell, sr.FitRows, sr.FitRowsOf, L0.Boolean, false, Bindings.BOOLEAN); + graph.addLiteral(newCell, sr.ColumnCount, sr.ColumnCountOf, L0.Integer, 128, Bindings.INTEGER); + graph.addLiteral(newCell, sr.RowCount, sr.RowCountOf, L0.Integer, 256, Bindings.INTEGER); + graph.claim(result, L0.ConsistsOf, L0.PartOf, newCell); + } + + { + Resource newCell = graph.newResource(); + graph.claim(newCell, L0.InstanceOf, null, sr.Cell); + graph.claimLiteral(newCell, L0.HasName, L0.NameOf, L0.String, "Headers", Bindings.STRING); + graph.addLiteral(newCell, sr.ColumnLabels, sr.ColumnLabelsOf, L0.StringArray, colNames, Bindings.STRING_ARRAY); + graph.addLiteral(newCell, sr.ColumnWidths, sr.ColumnWidthsOf, L0.IntegerArray, colWidths, Bindings.INT_ARRAY); + graph.claim(result, L0.ConsistsOf, L0.PartOf, newCell); + } + + { + + double[] doubles = new double[10*2]; + for(int i=0;i<10*2;i++) doubles[i] = i; + + Resource newCell = graph.newResource(); + graph.claim(newCell, L0.InstanceOf, null, sr.DoubleArrayCell); + graph.addLiteral(newCell, sr.DoubleArrayCell_HasWidth, sr.DoubleArrayCell_HasWidth_Inverse, L0.Integer, 10, Bindings.INTEGER); + graph.addLiteral(newCell, sr.HasLocation, sr.HasLocation_Inverse, L0.String, "B2", Bindings.STRING); + graph.addLiteral(newCell, sr.DoubleArrayCell_HasDoubleArray, sr.DoubleArrayCell_HasDoubleArray_Inverse, L0.DoubleArray, doubles, Bindings.DOUBLE_ARRAY); + graph.claim(result, L0X.HasChildVariables, L0X.HasChildVariables_Inverse, newCell); + + } + + return result; + + } + + void validatePage(){ + + if (previouslyBrowsedFile.isEmpty()){ + setPageComplete(false); + return; + } + setErrorMessage(null); + setPageComplete(true); + } +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ExportWizardModule.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ExportWizardModule.java new file mode 100644 index 00000000..c3534403 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ExportWizardModule.java @@ -0,0 +1,54 @@ +package org.simantics.sysdyn.ui.wizards.modules; + + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; +import org.simantics.db.Resource; +import org.simantics.ui.utils.AdaptionUtils; + + +public class ExportWizardModule extends Wizard implements IImportWizard { + + private WizardModulesExportPage mainPage; + private IStructuredSelection currentSelection = null; + private String initialPath = null; + public Resource selection; + + /** + * Constructor for ExternalProjectImportWizard. + */ + public ExportWizardModule() { + this(null); + } + + /** + * Constructor for ExternalProjectImportWizard. + */ + public ExportWizardModule(String initialPath) + { + super(); + this.initialPath = initialPath; + } + + public void init(IWorkbench workbench, IStructuredSelection currentSelection) { + setWindowTitle("Export"); + this.currentSelection = currentSelection; + selection = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class); + } + + public void addPages() { + super.addPages(); + mainPage = new WizardModulesExportPage( + "wizardModulesExportPage", initialPath, currentSelection); //$NON-NLS-1$ + addPage(mainPage); + } + + @Override + public boolean performFinish() { + return mainPage.createProjects(); + + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ImportWizardModule.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ImportWizardModule.java new file mode 100644 index 00000000..b70d589a --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ImportWizardModule.java @@ -0,0 +1,54 @@ +package org.simantics.sysdyn.ui.wizards.modules; + + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; +import org.simantics.db.Resource; +import org.simantics.ui.utils.AdaptionUtils; + + +public class ImportWizardModule extends Wizard implements IImportWizard { + + private WizardModulesImportPage mainPage; + private IStructuredSelection currentSelection = null; + private String initialPath = null; + public Resource selection; + + /** + * Constructor for ExternalProjectImportWizard. + */ + public ImportWizardModule() { + this(null); + } + + /** + * Constructor for ExternalProjectImportWizard. + */ + public ImportWizardModule(String initialPath) + { + super(); + this.initialPath = initialPath; + } + + public void init(IWorkbench workbench, IStructuredSelection currentSelection) { + setWindowTitle("Import"); + this.currentSelection = currentSelection; + selection = (Resource)AdaptionUtils.adaptToSingle(currentSelection, org.simantics.db.Resource.class); + } + + public void addPages() { + super.addPages(); + mainPage = new WizardModulesImportPage( + "wizardModulesImportPage", initialPath, currentSelection); //$NON-NLS-1$ + addPage(mainPage); + } + + @Override + public boolean performFinish() { + return mainPage.createProjects(); + + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleComponentTypeNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleComponentTypeNode.java new file mode 100644 index 00000000..7b501811 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleComponentTypeNode.java @@ -0,0 +1,161 @@ +package org.simantics.sysdyn.ui.wizards.modules; + +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.DeleteException; +import org.simantics.browsing.ui.common.node.IDeletableNode; +import org.simantics.browsing.ui.common.node.IModifiableNode; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.browsing.ui.graph.impl.LabelModifier; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.layer0.adapter.PasteHandler; +import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.ui.SimanticsUI; + +public class ModuleComponentTypeNode extends AbstractNode implements IDeletableNode, IModifiableNode { + + + Listener configurationNameSynchronizer; + private boolean disposed = false; + private Resource configuration; + + public ModuleComponentTypeNode(Resource resource) { + super(resource); + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + configuration = graph.getPossibleObject(data, sr2.IsDefinedBy); + } + }); + + // Not the best solution for name sync + configurationNameSynchronizer = new Listener() { + + @Override + public void execute(final String result) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if(configuration != null) + graph.claimLiteral(configuration, Layer0.getInstance(graph).HasLabel, result); + } + }); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return disposed; + } + }; + + SimanticsUI.getSession().asyncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + return graph.getRelatedValue(data, l0.HasName); + } + + }, configurationNameSynchronizer); + + } + + @Override + public Modifier getModifier(String columnId) { + Modifier modifier = null; + try { + modifier = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Modifier perform(ReadGraph graph) throws ManyObjectsForFunctionalRelationException, ServiceException { + ModelingResources mr = ModelingResources.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource type = graph.getPossibleObject(data, mr.SymbolToComponentType); + + LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), type, l0.HasName) { + @Override + public String isValid(String label) { + if (label.isEmpty()) + return "Empty name not allowed"; + return null; + } + }; + + + return modifier; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + return modifier; + } + + @Override + public void delete() throws DeleteException { + disposed = true; + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + StructuralResource2 st = StructuralResource2.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + + Resource type = graph.getPossibleObject(data, mr.SymbolToComponentType); + Resource model = graph.getSingleObject(type, l0.PartOf); + Resource modelConfiguration = graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration); + if (!graph.syncRequest(new ObjectsWithType(modelConfiguration, l0.ConsistsOf, type)).isEmpty()) { + System.out.println("The module is used at the model configuration"); + return; + } + Collection moduleTypes = graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, st.ComponentType)); + for(Resource r : moduleTypes) { + Resource configuration = graph.getSingleObject(r, st.IsDefinedBy); + if(!graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, type)).isEmpty()) { + System.out.println("The module is used at another module: " + graph.getRelatedValue(r, l0.HasName)); + return; + } + } + graph.deny(model, l0.ConsistsOf, type); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if(PasteHandler.class == adapter && configuration != null) + return new DefaultPasteHandler(configuration); + return super.getAdapter(adapter); + } +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModels.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModels.java new file mode 100644 index 00000000..272a2af5 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModels.java @@ -0,0 +1,40 @@ +package org.simantics.sysdyn.ui.wizards.modules; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.browser.nodes.ModelNode; + +public class ModuleTreeModels extends ViewpointContributorImpl { + + @Override + public Collection getContribution(ReadGraph graph, Resource input) + throws DatabaseException { + + + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + ArrayList> result = new ArrayList>(); + for(Resource r : graph.syncRequest(new ObjectsWithType(input, l0.ConsistsOf, sr.SysdynModel))) { + result.add(new ModelNode(r)); + } + + return result; + } + + @Override + public String getViewpointId() { + return "Module Import"; + } + + + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModules.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModules.java new file mode 100644 index 00000000..76f76f85 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModules.java @@ -0,0 +1,35 @@ +package org.simantics.sysdyn.ui.wizards.modules; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.ui.browser.nodes.ModelNode; + +public class ModuleTreeModules extends ViewpointContributor { + + @Override + public Collection getContribution(ReadGraph graph, ModelNode model) + throws DatabaseException { + ArrayList result = new ArrayList(); + Layer0 l0 = Layer0.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + for (Resource r : graph.syncRequest(new ObjectsWithType(model.data, l0.ConsistsOf, sr2.ComponentType))){ + result.add(new ModuleComponentTypeNode(r)); + } + + return result; + } + + @Override + public String getViewpointId() { + return "Standard"; + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModulesLabeler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModulesLabeler.java new file mode 100644 index 00000000..0aa030a9 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/ModuleTreeModulesLabeler.java @@ -0,0 +1,16 @@ +package org.simantics.sysdyn.ui.wizards.modules; + +import org.simantics.browsing.ui.graph.impl.contributor.labeler.LabelerContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; + +public class ModuleTreeModulesLabeler extends LabelerContributorImpl{ + + @Override + public String getLabel(ReadGraph graph, ModuleComponentTypeNode input) + throws DatabaseException { + return NameUtils.getSafeName(graph, input.data); + } + +} diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/WizardModulesExportPage.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/WizardModulesExportPage.java new file mode 100644 index 00000000..1bfea7c3 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/WizardModulesExportPage.java @@ -0,0 +1,475 @@ +package org.simantics.sysdyn.ui.wizards.modules; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; + +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.PixelConverter; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.simantics.browsing.ui.swt.AdaptableHintContext; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Files; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.PossibleRelatedValue; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.TransferableGraphRequest2; +import org.simantics.db.request.Read; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.ArrayMap; +import org.simantics.utils.datastructures.Pair; + +public class WizardModulesExportPage extends WizardPage { + + // dialog store id constants + private Text filePathField; + + // Keep track of the archive that we browsed to last time + // the wizard was invoked. + private static String previouslyBrowsedFile = ""; + + private Button browseDirectoriesButton; + + private Resource selectedModule; + + GraphExplorerComposite modelExplorer; + + private boolean selectionMade = false; + + /** + * Creates a new project creation wizard page. + * + */ + public WizardModulesExportPage() { + this("wizardModulesExportPage", null, null); //$NON-NLS-1$ + } + + /** + * Create a new instance of the receiver. + * + * @param pageName + */ + public WizardModulesExportPage(String pageName) { + this(pageName,null, null); + } + + /** + * More (many more) parameters. + * + * @param pageName + * @param initialPath + * @param currentSelection + * @since 3.5 + */ + public WizardModulesExportPage(String pageName,String initialPath, + IStructuredSelection currentSelection) { + super(pageName); + //this.currentSelection = currentSelection; + setPageComplete(false); + setTitle("Export Module"); + setDescription("Choose the Module and the export location, then press Finish."); + } + + public void createControl(Composite parent) { + + initializeDialogUnits(parent); + + Composite workArea = new Composite(parent, SWT.NONE); + setControl(workArea); + + workArea.setLayout(new GridLayout()); + workArea.setLayoutData(new GridData(GridData.FILL_BOTH + | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); + + createProjectsRoot(workArea); + createTree(workArea); + } + + private void createProjectsRoot(Composite workArea) { + + // set label for field + Label title = new Label(workArea, SWT.NONE); + title.setText("Select the export location for Module:"); + + Composite projectGroup = new Composite(workArea, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.makeColumnsEqualWidth = false; + layout.marginWidth = 0; + + projectGroup.setLayout(layout); + projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + // module location entry field + this.filePathField = new Text(projectGroup, SWT.BORDER); + + GridData directoryPathData = new GridData(SWT.FILL, SWT.NONE, true, false); + directoryPathData.widthHint = new PixelConverter(filePathField).convertWidthInCharsToPixels(25); + filePathField.setLayoutData(directoryPathData); + + filePathField.addModifyListener(new ModifyListener(){ + @Override + public void modifyText(ModifyEvent e) { + previouslyBrowsedFile = filePathField.getText(); + } + }); + if (previouslyBrowsedFile != null){ + filePathField.setText(previouslyBrowsedFile); + validatePage(); + } + + // browse button + browseDirectoriesButton = new Button(projectGroup, SWT.PUSH); + browseDirectoriesButton.setText("Browse"); + setButtonLayoutData(browseDirectoriesButton); + + browseDirectoriesButton.addSelectionListener(new SelectionAdapter() { + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.SelectionAdapter#widgetS + * elected(org.eclipse.swt.events.SelectionEvent) + */ + public void widgetSelected(SelectionEvent e) { + handleLocationDirectoryButtonPressed(); + } + }); + + } + + private void createTree(Composite workArea){ + + //set label for tree + Label title = new Label(workArea, SWT.NONE); + title.setText("Select Module to export:"); + + try { + Resource input = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) + throws DatabaseException { + Resource model = SimanticsUI.getProject().get(); + return model; + } + + }); + + modelExplorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE); + + modelExplorer + .setBrowseContexts(SysdynResource.URIs.ExportModuleTree); + + modelExplorer.finish(); + + modelExplorer.setInput(null, input); + + GridDataFactory.fillDefaults().grab(true, true).applyTo( + modelExplorer); + + ((Tree)modelExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + setMessage(null); + selectionMade = true; + validatePage(); + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + setMessage(null); + selectionMade = true; + validatePage(); + } + }); + + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + + //Set filePathField active + public void setVisible(boolean visible) { + super.setVisible(visible); + this.filePathField.setFocus(); + } + + //Open dialog for choosing the file + protected void handleLocationDirectoryButtonPressed() { + + final Shell shell = filePathField.getShell(); + + FileDialog dialog = new FileDialog(shell, SWT.SAVE); + + String[] ext = {"*.tg"}; + dialog.setFilterExtensions(ext); + + dialog.setText("Export Module"); + + String dirName = filePathField.getText().trim(); + + File path = new File(dirName); + if (path.exists()) { + dialog.setFilterPath(new Path(dirName).toOSString()); + } + + String selectedFile = dialog.open(); + if (selectedFile != null) { + filePathField.setText(selectedFile); + validatePage(); + } + + } + + //Get selection from the tree + @SuppressWarnings("unchecked") + public static T getExplorerResource(GraphExplorerComposite explorer, + Class clazz) { + + if(explorer == null) + return null; + ISelection selection = ((ISelectionProvider) explorer + .getAdapter(ISelectionProvider.class)).getSelection(); + if (selection == null) + return null; + IStructuredSelection iss = (IStructuredSelection) selection; + AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement(); + if (inc == null) + return null; + final T resource = (T) inc.getAdapter(clazz); + + return resource; + } + + //Create export file when finish is pressed + public boolean createProjects() { + + final String selected = previouslyBrowsedFile; + if(selected == null) return false; + + selectedModule= getExplorerResource(modelExplorer, Resource.class); + if(selectedModule == null) + return false; + + String name = null; + try { + name = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Resource component = selectedModule; + if (component == null || !graph.hasStatement(component, Layer0.getInstance(graph).PartOf)) + return null; + + Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy); + if (configuration == null) + return null; + + ArrayList dependencies = null; + for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Module))) { + if(dependencies == null) + dependencies = new ArrayList(); + String name = NameUtils.getSafeName(graph, r); + String instanceOf = NameUtils.getSafeName(graph, graph.getSingleObject(r, l0.InstanceOf)); + dependencies.add(name + " : " + instanceOf); + } + if(dependencies != null && !dependencies.isEmpty()) + throw new ContainsDependenciesException(dependencies); + + String name = graph.getPossibleRelatedValue(component, l0.HasName, Bindings.STRING); + return name; + + } + + }); + } + catch (DatabaseException e1) { + e1.printStackTrace(); + } + if(name == null) return false; + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + + final Resource component = selectedModule; + //final Resource component = graph.getPossibleObject(modulesymbol, mr.SymbolToComponentType); + if (component == null || !graph.hasStatement(component, Layer0.getInstance(graph).PartOf)) + return; + String name = graph.syncRequest(new PossibleRelatedValue(component, l0.HasName, Bindings.STRING )); + final ArrayList> roots = new ArrayList>(); + roots.add(Pair.make(component, name)); + + graph.asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + final Resource modulesymbol = graph.getPossibleObject(component, mr.ComponentTypeToSymbol); + Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy); + if (!graph.hasStatement(configuration, l0.PartOf, component)&& + !graph.hasStatement(modulesymbol, l0.PartOf, component)) { + // Make sure that configuration and symbol are included. + // In old versions, they were attached to model, not to module. + Resource previousPartof = graph.getSingleObject(configuration, l0.PartOf); + + graph.deny(configuration, l0.PartOf); + graph.deny(modulesymbol, l0.PartOf); + graph.claim(configuration, l0.PartOf, l0.ConsistsOf, component); + graph.claim(modulesymbol, l0.PartOf, l0.ConsistsOf, component); + + export(graph, selected, roots, component); + + graph.deny(configuration, l0.PartOf); + graph.deny(modulesymbol, l0.PartOf); + graph.claim(configuration, l0.PartOf, l0.ConsistsOf, previousPartof); + graph.claim(modulesymbol, l0.PartOf, l0.ConsistsOf, previousPartof); + } else { + // Normal export + export(graph, selected, roots, component); + } + } + }); + + } + }); + + return true; + } + + private void export(WriteGraph graph, String path, ArrayList> roots, Resource component) { + + // FIXME: Enumeration replacement handling like this is not suitable. + try { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + + Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy); + ArrayList> replacements = new ArrayList>(); + + for(Resource enumeration : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) { + if(graph.hasStatement(enumeration, sr.ReplacedEnumeration_Inverse)) { + for(Resource replacement : graph.getObjects(enumeration, sr.ReplacedEnumeration_Inverse)) { + replacements.add(new Pair(enumeration, replacement)); + } + } + } + + for(Pair replacement : replacements) + graph.deny(replacement.first, sr.ReplacedEnumeration_Inverse, replacement.second); + + TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, component)); + Files.createFile(new File(path), Bindings.getBindingUnchecked(TransferableGraph1.class), tg); + + for(Pair replacement : replacements) + graph.claim(replacement.first, sr.ReplacedEnumeration_Inverse, replacement.second); + + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + class ContainsDependenciesException extends DatabaseException { + private static final long serialVersionUID = -1533706136673146020L; + + private Collection dependencies; + + ContainsDependenciesException(Collection dependencies) { + this.dependencies = dependencies; + } + + public Collection getDependencies() { + return this.dependencies; + } + + } + + void validatePage() { + + if (previouslyBrowsedFile.isEmpty() || selectionMade == false){ + setPageComplete(false); + return; + } + + if (modelExplorer != null){ + final Resource selectedResource = getExplorerResource(modelExplorer, Resource.class); + + String root = null; + try { + root = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + Resource model = graph.getPossibleObject(selectedResource, l0.PartOf); + String rootName = NameUtils.getSafeName(graph, model); + + return rootName; + } + + }); + if (root != null && root.equalsIgnoreCase("Development Project")){ + setPageComplete(false); + setMessage("Select Module under the Model."); + return; + } + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + setPageComplete(true); + + } + + + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/WizardModulesImportPage.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/WizardModulesImportPage.java new file mode 100644 index 00000000..9ec3377d --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/modules/WizardModulesImportPage.java @@ -0,0 +1,367 @@ +package org.simantics.sysdyn.ui.wizards.modules; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.PixelConverter; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.simantics.browsing.ui.swt.AdaptableHintContext; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Files; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; +import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; +import org.simantics.db.request.Read; +import org.simantics.graph.db.MissingDependencyException; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.ArrayMap; + + +public class WizardModulesImportPage extends WizardPage{ + + public static String IMPORTMODULETPATH = "IMPORT_MODULE_PATH"; + + // dialog store id constants + + private Text filePathField; + + // Keep track of the archive that we browsed to last time + // the wizard was invoked. + private static String previouslyBrowsedFile = ""; + + private Button browseDirectoriesButton; + + private Shell shell; + + //private IStructuredSelection currentSelection; + + private Resource selectedModel; + + GraphExplorerComposite modelExplorer; + + private boolean selectionMade = false; + + private String error = ""; + + /** + * Creates a new project creation wizard page. + * + */ + public WizardModulesImportPage() { + this("wizardModulesImportPage", null, null); //$NON-NLS-1$ + } + + /** + * Create a new instance of the receiver. + * + * @param pageName + */ + public WizardModulesImportPage(String pageName) { + this(pageName,null, null); + } + + /** + * More (many more) parameters. + * + * @param pageName + * @param initialPath + * @param currentSelection + * @since 3.5 + */ + public WizardModulesImportPage(String pageName,String initialPath, + IStructuredSelection currentSelection) { + super(pageName); + setPageComplete(false); + //this.currentSelection = currentSelection; + setTitle("Import Module"); + setDescription("Choose the Module file and the import location, then press Finish."); + } + + public void createControl(Composite parent) { + + initializeDialogUnits(parent); + + Composite workArea = new Composite(parent, SWT.NONE); + setControl(workArea); + + workArea.setLayout(new GridLayout()); + workArea.setLayoutData(new GridData(GridData.FILL_BOTH + | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); + + createProjectsRoot(workArea); + + createTree(workArea); + } + + private void createProjectsRoot(Composite workArea) { + + // set label for field + Label title = new Label(workArea, SWT.NONE); + title.setText("Select Module source:"); + + Composite projectGroup = new Composite(workArea, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.makeColumnsEqualWidth = false; + layout.marginWidth = 0; + + projectGroup.setLayout(layout); + projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + // module location entry field + this.filePathField = new Text(projectGroup, SWT.BORDER); + + GridData directoryPathData = new GridData(SWT.FILL, SWT.NONE, true, false); + directoryPathData.widthHint = new PixelConverter(filePathField).convertWidthInCharsToPixels(25); + filePathField.setLayoutData(directoryPathData); + + filePathField.addModifyListener(new ModifyListener(){ + @Override + public void modifyText(ModifyEvent e) { + previouslyBrowsedFile = filePathField.getText(); + } + }); + if (previouslyBrowsedFile != null){ + filePathField.setText(previouslyBrowsedFile); + validatePage(); + } + + // browse button + browseDirectoriesButton = new Button(projectGroup, SWT.PUSH); + browseDirectoriesButton.setText("Browse"); + setButtonLayoutData(browseDirectoriesButton); + + browseDirectoriesButton.addSelectionListener(new SelectionAdapter() { + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.SelectionAdapter#widgetS + * elected(org.eclipse.swt.events.SelectionEvent) + */ + public void widgetSelected(SelectionEvent e) { + handleLocationDirectoryButtonPressed(); + } + }); + + } + + private void createTree(Composite workArea){ + + //set label for tree + Label title = new Label(workArea, SWT.NONE); + title.setText("Select import location:"); + + try { + Resource input = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public Resource perform(ReadGraph graph) + throws DatabaseException { + Resource model = SimanticsUI.getProject().get(); + return model; + } + + }); + + modelExplorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), null, workArea, SWT.BORDER | SWT.SINGLE); + + modelExplorer + .setBrowseContexts(SysdynResource.URIs.ImportModuleTree); + + modelExplorer.finish(); + + modelExplorer.setInput(null, input); + + GridDataFactory.fillDefaults().grab(true, true).applyTo( + modelExplorer); + + ((Tree)modelExplorer.getExplorer().getControl()).addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + selectionMade = true; + validatePage(); + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + selectionMade = true; + validatePage(); + } + }); + + + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + + //Set filePathField active + public void setVisible(boolean visible) { + super.setVisible(visible); + this.filePathField.setFocus(); + } + + //Open dialog for choosing the file + protected void handleLocationDirectoryButtonPressed() { + + shell = filePathField.getShell(); + + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + + String[] ext = {"*.tg"}; + dialog.setFilterExtensions(ext); + + dialog.setText("Import Module"); + + String dirName = filePathField.getText().trim(); + + File path = new File(dirName); + if (path.exists()) { + dialog.setFilterPath(new Path(dirName).toOSString()); + } + + String selectedFile = dialog.open(); + if (selectedFile != null) { + filePathField.setText(selectedFile); + validatePage(); + } + } + + //Get selection from the tree + @SuppressWarnings("unchecked") + public static T getExplorerResource(GraphExplorerComposite explorer, + Class clazz) { + + if(explorer == null) + return null; + ISelection selection = ((ISelectionProvider) explorer + .getAdapter(ISelectionProvider.class)).getSelection(); + if (selection == null) + return null; + IStructuredSelection iss = (IStructuredSelection) selection; + AdaptableHintContext inc = (AdaptableHintContext) iss.getFirstElement(); + if (inc == null) + return null; + final T resource = (T) inc.getAdapter(clazz); + + return resource; + } + + //Create project after finish is pressed. + public boolean createProjects() { + + String selected = previouslyBrowsedFile; + if(selected == null){ + setErrorMessage("Error when retrieving resource"); + return false; + } + + selectedModel= getExplorerResource(modelExplorer, Resource.class); + if(selectedModel == null){ + setErrorMessage("No file selected"); + return false; + } + + TransferableGraph1 tg = null; + try { + tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class)); + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + } catch (IOException e) { + setErrorMessage("The imported file is not of type: Module Type"); + return false; + } + if(tg == null){ + setErrorMessage("The imported file is not of type: Module Type"); + return false; + } + + + DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(selectedModel); + try { + DefaultPasteHandler.defaultExecute(tg, selectedModel, ia); + } catch (MissingDependencyException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + + final Resource root = ia.getRoot(); + + try { + SimanticsUI.getSession().syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + if(!graph.isInheritedFrom(root, SysdynResource.getInstance(graph).Module)) { + Resource instanceOf = graph.getPossibleObject(root, Layer0.getInstance(graph).InstanceOf); + String type = "..."; + if(instanceOf != null) + type = NameUtils.getSafeName(graph, instanceOf); + else { + Resource inheritedFrom = graph.getPossibleObject(root, Layer0.getInstance(graph).Inherits); + if(inheritedFrom != null) + type = NameUtils.getSafeName(graph, inheritedFrom); + } + graph.deny(root, Layer0.getInstance(graph).PartOf); + error = type; + } + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + if (!error.isEmpty()){ + setErrorMessage("The imported file is not of type: Module Type (" + error +")"); + error = ""; + return false; + } + return true; + } + + void validatePage() { + + if (previouslyBrowsedFile.isEmpty() || selectionMade == false){ + setPageComplete(false); + return; + } + + setErrorMessage(null); + setPageComplete(true); + + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn.ui/sysdyn.product b/stable/org.simantics.sysdyn.ui/sysdyn.product new file mode 100644 index 00000000..03cbd945 --- /dev/null +++ b/stable/org.simantics.sysdyn.ui/sysdyn.product @@ -0,0 +1,116 @@ + + + + + + + + + + -fixerrors +--launcher.XXMaxPermSize +256m + -ea -Xmx768M -Xshare:off + -XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts + + + + + + + + + + + + + + org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6 + + + + http://www.eclipse.org/legal/epl-v10.html + + Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: +i) changes to the Program, and +ii) additions to the Program; +where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. + +"Program" means the Contributions distributed in accordance with this Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. + +2. GRANT OF RIGHTS + +a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. +b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. +c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. +d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: + +a) it complies with the terms and conditions of this Agreement; and +b) its license agreement: +i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; +ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; +iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and +iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. +When the Program is made available in source code form: + +a) it must be made available under this Agreement; and +b) a copy of this Agreement must be included with each copy of the Program. +Contributors may not remove or alter any copyright notices contained within the Program. + +Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. + + + + + + + + + + + + diff --git a/stable/org.simantics.sysdyn/.classpath b/stable/org.simantics.sysdyn/.classpath new file mode 100644 index 00000000..8a8f1668 --- /dev/null +++ b/stable/org.simantics.sysdyn/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/stable/org.simantics.sysdyn/.hgignore b/stable/org.simantics.sysdyn/.hgignore new file mode 100644 index 00000000..73df90f6 --- /dev/null +++ b/stable/org.simantics.sysdyn/.hgignore @@ -0,0 +1,5 @@ +syntax: regexp +^bin/ + +syntax: glob +*.svn/* \ No newline at end of file diff --git a/stable/org.simantics.sysdyn/.project b/stable/org.simantics.sysdyn/.project new file mode 100644 index 00000000..05d44396 --- /dev/null +++ b/stable/org.simantics.sysdyn/.project @@ -0,0 +1,28 @@ + + + org.simantics.sysdyn + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/stable/org.simantics.sysdyn/.settings/org.eclipse.jdt.core.prefs b/stable/org.simantics.sysdyn/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..785aae6f --- /dev/null +++ b/stable/org.simantics.sysdyn/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Mon Nov 16 15:37:44 EET 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/stable/org.simantics.sysdyn/META-INF/MANIFEST.MF b/stable/org.simantics.sysdyn/META-INF/MANIFEST.MF new file mode 100644 index 00000000..c83f7bdb --- /dev/null +++ b/stable/org.simantics.sysdyn/META-INF/MANIFEST.MF @@ -0,0 +1,43 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Simantics System Dynamics +Bundle-SymbolicName: org.simantics.sysdyn +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Require-Bundle: org.simantics.objmap;bundle-version="0.1.0", + org.simantics.db;bundle-version="0.6.2", + org.simantics.modelica;bundle-version="1.0.0", + org.simantics.db.common;bundle-version="0.8.0", + org.simantics.simulation;bundle-version="1.0.0", + org.eclipse.ui.console;bundle-version="3.4.0", + org.eclipse.core.runtime;bundle-version="3.5.0", + org.eclipse.jface;bundle-version="3.5.2", + org.simantics.project;bundle-version="1.0.0", + org.simantics.layer0.utils;bundle-version="0.8.0", + org.simantics.layer0;bundle-version="1.0.0", + org.simantics.structural.ontology;bundle-version="1.0.0", + org.simantics.sysdyn.ontology;bundle-version="1.0.0", + org.simantics.modeling;bundle-version="1.1.1", + org.simantics.diagram;bundle-version="1.1.1", + org.simantics.diagram.ontology;bundle-version="1.1.1", + org.simantics.scl.runtime;bundle-version="0.1.3", + org.simantics.db.layer0;bundle-version="1.1.0", + org.simantics.spreadsheet.common;bundle-version="1.1.0", + org.simantics.spreadsheet;bundle-version="1.1.0", + org.eclipse.jface.text;bundle-version="3.6.1" +Export-Package: org.simantics.sysdyn, + org.simantics.sysdyn.adapter, + org.simantics.sysdyn.expressionParser, + org.simantics.sysdyn.manager, + org.simantics.sysdyn.mdlImport, + org.simantics.sysdyn.mdlImport.mdlElements, + org.simantics.sysdyn.modelParser, + org.simantics.sysdyn.modelica, + org.simantics.sysdyn.representation, + org.simantics.sysdyn.representation.visitors, + org.simantics.sysdyn.simulation, + org.simantics.sysdyn.tableParser +Bundle-Activator: org.simantics.sysdyn.Activator +Bundle-ActivationPolicy: lazy +Import-Package: org.eclipse.ui +Bundle-Vendor: VTT Technical Reserarch Centre of Finland diff --git a/stable/org.simantics.sysdyn/adapters.xml b/stable/org.simantics.sysdyn/adapters.xml new file mode 100644 index 00000000..aa3f0ba4 --- /dev/null +++ b/stable/org.simantics.sysdyn/adapters.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/stable/org.simantics.sysdyn/build.properties b/stable/org.simantics.sysdyn/build.properties new file mode 100644 index 00000000..0b3e6894 --- /dev/null +++ b/stable/org.simantics.sysdyn/build.properties @@ -0,0 +1,16 @@ +############################################################################### +# Copyright (c) 2010 Association for Decentralized Information Management in +# Industry THTH ry. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# VTT Technical Research Centre of Finland - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + adapters.xml diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/Activator.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/Activator.java new file mode 100644 index 00000000..375e21b3 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/Activator.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn; + +import java.io.File; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + private static BundleContext bundleContext; + + @Override + public void start(BundleContext context) throws Exception { + bundleContext = context; + File modelsDir = Activator.getBundleContext().getDataFile("models"); + if (!modelsDir.exists()) { + modelsDir.mkdir(); + } + } + + @Override + public void stop(BundleContext context) throws Exception { + File modelsDir = Activator.getBundleContext().getDataFile("models"); + if (modelsDir.exists()) { + recursiveDelete(modelsDir); + } + } + + public static BundleContext getBundleContext() { + return bundleContext; + } + + private static boolean recursiveDelete(File fileOrDir) { + if(fileOrDir.isDirectory()) + for(File innerFile: fileOrDir.listFiles()) + if(!recursiveDelete(innerFile)) + return false; + return fileOrDir.delete(); + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariable.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariable.java new file mode 100644 index 00000000..a68c2eef --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariable.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.adapter; + +import java.util.List; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Datatypes; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.type.Datatype; +import org.simantics.databoard.util.ObjectUtils; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.AbstractChildVariable; +import org.simantics.db.layer0.variable.DatatypePropertyVariable; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.operation.Layer0X; +import org.simantics.sysdyn.SysdynResource; + +public class ChildVariable extends AbstractChildVariable { + + protected Variable parent; + protected Resource resource; + + public ChildVariable(Variable parent, Resource resource) { + this.parent = parent; + this.resource = resource; + } + + // FIXME: Support properties! This is just for the system to work like it used to. + @Override + public T getValue(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(this.resource == null) return null; + //FIXME: doesn't support multiple expressions + Resource expressions = graph.getPossibleObject(this.resource, sr.HasExpressions); + if(expressions == null) return null; + List expressionList = OrderedSetUtils.toList(graph, expressions); + Resource expression = expressionList.get(0); + if(expression == null) return null; + if(!graph.isInstanceOf(expression, sr.ParameterExpression)) return null; + String text = graph.getPossibleRelatedValue(expression, sr.HasEquation); + if(text == null) return null; + Double value = Double.parseDouble(text); + return (T)value; + } + + // FIXME: Support properties! This is just for the system to work like it used to. + @Override + public void setValue(WriteGraph graph, Object object, Binding binding) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(this.resource == null) return; + //FIXME: doesn't support multiple expressions + Resource expressions = graph.getPossibleObject(this.resource, sr.HasExpressions); + if(expressions == null) return; + List expressionList = OrderedSetUtils.toList(graph, expressions); + Resource expression = expressionList.get(0); + if(expression == null) return; + if(!graph.isInstanceOf(expression, sr.ParameterExpression)) return; + graph.claimLiteral(expression, sr.HasEquation, object.toString(), Bindings.STRING); + } + + // FIXME: Support properties! This is just for the system to work like it used to. + @Override + public T getInterface(ReadGraph graph, Class clazz) throws DatabaseException { + if(Datatype.class.equals(clazz)) { + return (T)Datatypes.DOUBLE; + } + return super.getInterface(graph, clazz); + } + + @Override + public Variable getPossibleExtraProperty(ReadGraph graph, String name) throws DatabaseException { + if(Variables.DATATYPE.equals(name)) { + return new DatatypePropertyVariable(this); + } + return super.getPossibleExtraProperty(graph, name); + } + /* + * + * + */ + + + @Override + public Variable getParent(ReadGraph graph) throws DatabaseException { + if(parent == null) + return null; // TODO is this correct thing to do? + else + return parent; + } + + @Override + public Resource getRepresents(ReadGraph graph) throws DatabaseException { + Layer0X L0X = Layer0X.getInstance(graph); + Resource represents = graph.getPossibleObject(resource, L0X.Represents); + if(represents != null) return represents; + else return resource; + } + + @Override + public String getName(ReadGraph graph) throws DatabaseException { + return graph.getRelatedValue(resource, graph.getService(Layer0.class).HasName, Bindings.STRING); + } + + + @Override + public String getSerialized(ReadGraph graph) throws DatabaseException { + return getURI(graph); + } + + @Override + public String getURI(ReadGraph graph) throws DatabaseException { + if(parent == null) + return getName(graph); + else + return parent.getURI(graph) + "/" + encodeString(getName(graph)); + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + resource.hashCode(); + result = prime * result + ObjectUtils.hashCode(parent); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ChildVariable other = (ChildVariable) obj; + if (!resource.equals(other.resource)) + return false; + return ObjectUtils.objectEquals(parent, other.parent); + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariableAdapter.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariableAdapter.java new file mode 100644 index 00000000..593c3b84 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariableAdapter.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.adapter; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.adaption.SimpleContextualAdapter; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.sysdyn.SysdynResource; + +public class ChildVariableAdapter extends SimpleContextualAdapter{ + + @Override + public Variable adapt(ReadGraph g, Resource source, Variable context) throws DatabaseException { + if(context instanceof HistoryVariable) { + return new HistoryVariable(context, source); + } else { + if(g.isInstanceOf(source, SysdynResource.getInstance(g).Module)) + return new ModuleVariable(context, source); + else + return new ChildVariable(context, source); + } + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java new file mode 100644 index 00000000..a1013322 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariable.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.adapter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.uri.UnescapedChildMapOfResource; +import org.simantics.db.exception.AdaptionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.StandardGraphChildVariable; +import org.simantics.db.layer0.variable.Variable; + +public class ConfigurationVariable extends StandardGraphChildVariable { + + public ConfigurationVariable(Variable parent, Resource resource) { + super(parent, resource); + } + +// @Override +// public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException { +// Map children = graph.syncRequest(new UnescapedChildMapOfResource(resource)); +// Resource child = children.get(name); +// if(child == null) { +// return getPossibleSpecialChild(graph, name); +// } +// else return graph.adaptContextual(child, this, Variable.class, Variable.class); +// } + + + @Override + public Collection browseChildren(ReadGraph graph) throws DatabaseException { + ArrayList result = new ArrayList(); + for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(resource)).values()) { + try { + result.add(graph.adaptContextual(child, this, Variable.class, Variable.class)); + } catch (AdaptionException e) { + } + } + collectSpecialChildren(graph, result); + return result; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariableAdapter.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariableAdapter.java new file mode 100644 index 00000000..53a54470 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ConfigurationVariableAdapter.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.adapter; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.adaption.SimpleContextualAdapter; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; + +public class ConfigurationVariableAdapter extends SimpleContextualAdapter{ + + @Override + public Variable adapt(ReadGraph g, Resource source, Variable context) throws DatabaseException { + return new ConfigurationVariable(context, source); + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/HistoryVariable.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/HistoryVariable.java new file mode 100644 index 00000000..c6f0b539 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/HistoryVariable.java @@ -0,0 +1,352 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.adapter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.simantics.databoard.Accessors; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Datatypes; +import org.simantics.databoard.accessor.Accessor; +import org.simantics.databoard.accessor.RecordAccessor; +import org.simantics.databoard.accessor.error.AccessorConstructionException; +import org.simantics.databoard.accessor.error.AccessorException; +import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ParametrizedPrimitiveRead; +import org.simantics.db.common.uri.UnescapedChildMapOfResource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.MissingVariableException; +import org.simantics.db.layer0.variable.ConstantPropertyVariable; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.ExternalRead; +import org.simantics.layer0.Layer0; +import org.simantics.modelica.data.DataSet; +import org.simantics.simulation.experiment.ExperimentState; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.SysdynDataSet; +import org.simantics.sysdyn.manager.SysdynExperiment; +import org.simantics.sysdyn.manager.SysdynModel; +import org.simantics.sysdyn.manager.SysdynModelManager; +import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; +import org.simantics.sysdyn.manager.SysdynResult; + +/** + * + * Variable implementation for Sysdyn variables. History + * variables are used when there is an active experiment. + * + * @author Teemu Lempinen + */ +public class HistoryVariable extends ChildVariable implements PropertyProvider { + + static Boolean DEBUG = false; + + private SysdynExperiment experiment; + private SysdynModel model = null; + private String rvi = null; + private HashMap rvis = null; + + /** + * Variable representing a variable with some history (active experiment) + * + * @param parent Parent variable + * @param resource Resource that the variable represents + */ + public HistoryVariable(Variable parent, Resource resource) { + super(parent, resource); + experiment = SysdynExperiment.INSTANCE; + } + + + @SuppressWarnings("unchecked") + @Override + public T getInterface(ReadGraph graph, Class clazz) throws DatabaseException { + /* + * Implementation for OperatingInterfaces (and Tacton integration?) + * Should get rid of this and use only properties. + */ + if(RecordAccessor.class.equals(clazz) || Accessor.class.equals(clazz)) { + SimulationResource SIMU = SimulationResource.getInstance(graph); + Resource model = Variables.getModel(graph, this); + Resource configuration = graph.getPossibleObject(model, SIMU.HasConfiguration); + final SysdynModel sm = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration); + SysdynResult sr = new SysdynResult(sm.getSimulationResult()); // TODO: copy or not to copy ... + + String tmp = Variables.getRVI(graph, this); + if(DEBUG) + System.out.println("HistoryVariable rvi='" + tmp + "'"); + final String rvi = tmp.substring(1).replace("/", "."); + SysdynDataSet ds = sr.getDataSet(rvi); + if(ds == null) ds = new SysdynDataSet("", "", new double[0], new double[0]); // We need a dataset, so if not set, create it + try { + final RecordAccessor ac = (RecordAccessor)Accessors.getAccessor(Bindings.getBindingUnchecked(SysdynDataSet.class), ds); + + sm.addResultListener(new Runnable() { // FIXME: remove listener at some point.. + @Override + public void run() { + if(HistoryVariable.this.experiment.getState().equals(ExperimentState.DISPOSED)) + return; + + SysdynResult sr = new SysdynResult(sm.getSimulationResult()); + SysdynDataSet ds = sr.getDataSet(rvi); + if(ds == null) return; + try { + if(ds.result == null) ds.result = ""; + ac.setValue(Bindings.getBindingUnchecked(SysdynDataSet.class), ds); + } catch (RuntimeBindingConstructionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (AccessorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + }}); + return (T)ac; + } catch (RuntimeBindingConstructionException e) { + e.printStackTrace(); + } catch (AccessorConstructionException e) { + e.printStackTrace(); + } + return null; + + } + return super.getInterface(graph, clazz); + } + + @Override + public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException { + try { + return getChild(graph, name); + } catch (DatabaseException e) { + return null; + } + } + + @Override + public Variable getChild(ReadGraph graph, String name) throws DatabaseException { + // If the variable represents a module, it may have children + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource instanceOf = graph.getSingleObject(this.resource, l0.InstanceOf); + if(graph.isInheritedFrom(instanceOf, sr.Module)) { + // Find the configuration of the module + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + if(instanceOf == null) + throw new MissingVariableException("No instanceof for resource " + NameUtils.getSafeName(graph, resource)); + Resource configuration = graph.getPossibleObject(instanceOf, sr2.IsDefinedBy); + if(configuration == null) + throw new MissingVariableException("No configuration for " + NameUtils.getSafeName(graph, instanceOf)); + // Get the components in the configuration and find the child + Map children = graph.syncRequest(new UnescapedChildMapOfResource(configuration)); + Resource child = children.get(name); + return graph.adaptContextual(child, this, Variable.class, Variable.class); + } else { + return super.getChild(graph, name); + } + } + + + @Override + public Collection browseChildren(ReadGraph graph) throws DatabaseException { + // If the variable represents a module, it may have children + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource instanceOf = graph.getPossibleObject(this.resource, l0.InstanceOf); + if(graph.isInheritedFrom(instanceOf, sr.Module)) { + ArrayList result = new ArrayList(); + if(instanceOf == null) + return result; + // Find the configuration of the model + Resource configuration = graph.getPossibleObject(instanceOf, sr2.IsDefinedBy); + if(configuration == null) + return result; + // Add all children to the result + for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(configuration)).values()) + result.add(graph.adaptContextual(child, this, Variable.class, Variable.class)); + return result; + } else { + return super.browseChildren(graph); + } + } + + @Override + public Variable getPossibleExtraProperty(ReadGraph graph, String name) throws DatabaseException { + if(SysdynVariableProperties.TIME.equals(name)) { + // Get current time + return graph.syncRequest(new PropertyRequest(this, name)); + } else if(SysdynVariableProperties.VALUES.equals(name) || SysdynVariableProperties.TIMES.equals(name) || + SysdynVariableProperties.ACTIVE_DATASETS.equals(name)) { + // For these requests, we need to make sure that model and rvi exist + if(model == null) { + SimulationResource SIMU = SimulationResource.getInstance(graph); + Resource modelResource = Variables.getModel(graph, this); + Resource configuration = graph.getPossibleObject(modelResource, SIMU.HasConfiguration); + model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration); + // Update active results + model.getActiveResults(); + } + if(rvi == null) { + rvi = Variables.getRVI(graph, this).substring(1).replace("/", "."); + } + + rvis = VariableRVIUtils.getActiveRVIs(graph, this); + + if(SysdynVariableProperties.TIMES.equals(name)) + // If times were requested, just return them without listening + return getProperty(name); + else + // Otherwise make a request and listen for changes in the result + return graph.syncRequest(new PropertyRequest(this, name)); + } + return super.getPossibleExtraProperty(graph, name); + } + + /** + * Register a property subscription + * + * @param request PropertyRequest + * @param procedure + * @param property Name of the requested property + * @return + */ + protected VariableValueSubscription registerSubscription(ExternalRead request, Listener procedure, String property) { + if(SysdynVariableProperties.TIME.equals(property)) { + // Current time is requested from experiment + VariableValueSubscription subscription = new VariableValueSubscription(request, this, property, procedure); + experiment.addVariableValueSubscription(subscription); + subscription.update(); + return subscription; + } else if(model != null && ( + SysdynVariableProperties.VALUES.equals(property) || + SysdynVariableProperties.TIMES.equals(property) || + SysdynVariableProperties.ACTIVE_DATASETS.equals(property))) { + // Other properties are requested from model (they listen to new simulation results) + VariableValueSubscription subscription = new VariableValueSubscription(request, this, property, procedure); + model.addVariableValueSubscription(subscription); + subscription.update(); + return subscription; + } else { + return null; + } + } + + /** + * Unregisters a subscription + * @param subscription + */ + protected void unregisterSubscription(VariableValueSubscription subscription) { + subscription.setListener(null); + if(SysdynVariableProperties.TIME.equals(subscription.property)) + // Time was registered from experiment + experiment.removeVariableValueSubscription(subscription); + else if(SysdynVariableProperties.TIMES.equals(subscription.property) + || SysdynVariableProperties.VALUES.equals(subscription.property) + || SysdynVariableProperties.ACTIVE_DATASETS.equals(subscription.property)) + // Other properties were requested from model + model.removeVariableValueSubscription(subscription); + } + + @Override + public Variable getProperty(String name) { + if(SysdynVariableProperties.TIME.equals(name)){ + // Get current time from experiment + if(experiment instanceof SysdynPlaybackExperiment) { + SysdynPlaybackExperiment exp = (SysdynPlaybackExperiment) experiment; + return new ConstantPropertyVariable(this, name, exp.getTime(), Datatypes.DOUBLE); + } else { + // Experiment is not compatible, return time = 0 + return null; + } + } else if(SysdynVariableProperties.VALUES.equals(name)) { + // Get the values of this variable from the currently active experiment + SysdynResult sr = new SysdynResult(model.getSimulationResult()); + SysdynDataSet ds = sr.getDataSet(rvi); + if(ds == null) + return new ConstantPropertyVariable(this, name, new double[0], Datatypes.DOUBLE_ARRAY); + else + return new ConstantPropertyVariable(this, name, ds.values, Datatypes.DOUBLE_ARRAY); + } else if(SysdynVariableProperties.TIMES.equals(name)) { + // Get the times of this variable from the currently active experiment + SysdynResult sr = new SysdynResult(model.getSimulationResult()); + SysdynDataSet ds = sr.getDataSet(rvi); + if(ds == null) + return new ConstantPropertyVariable(this, name, new double[0], Datatypes.DOUBLE_ARRAY); + else + return new ConstantPropertyVariable(this, name, ds.times, Datatypes.DOUBLE_ARRAY); + } else if(SysdynVariableProperties.ACTIVE_DATASETS.equals(name)) { + // Get all active datasets for this variable (currentyl active experiment and all active saved results) + Collection activeResults = model.getActiveResults(); + ArrayList result = new ArrayList(); + for(SysdynResult sysdynResult : activeResults) { + for(String currvi : rvis.keySet()) { + SysdynDataSet sds = sysdynResult.getDataSet(currvi.substring(1).replace("/", ".")); + if(sds != null) { + sds.name = rvis.get(currvi).substring(1).replace("/", "."); + result.add(sds); + } + } + } + return new ConstantPropertyVariable(this, name, result, Datatypes.VARIANT); + } + return null; + } + + /** + * Class for supporting requests with different property parameters. Equals-method has been modified + * from ParametrizedPrivimiteRead to check also the property value. + * + * @author Teemu Lempinen + * + */ + class PropertyRequest extends ParametrizedPrimitiveRead { + + String property; + + public PropertyRequest(Variable parameter, String property) { + super(parameter); + this.property = property; + } + + VariableValueSubscription subscription; + + @Override + public void register(Listener procedure) { + subscription = registerSubscription(this, procedure, property); + } + @Override + public void unregistered() { + unregisterSubscription(subscription); + subscription = null; + } + + @Override + public boolean equals(Object object) { + if(object instanceof PropertyRequest && super.equals(object)) { + return this.property.equals(((PropertyRequest)object).property); + } else { + return super.equals(object); + } + } + + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ModuleVariable.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ModuleVariable.java new file mode 100644 index 00000000..bfc5120f --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ModuleVariable.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.adapter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.uri.UnescapedChildMapOfResource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.AdaptionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.MissingVariableException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.layer0.Layer0; +import org.simantics.structural.stubs.StructuralResource2; + +public class ModuleVariable extends ChildVariable { + + public ModuleVariable(Variable parent, Resource resource) { + super(parent, resource); + } + + @Override + public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + Resource instanceOf = graph.getPossibleObject(this.resource, l0.InstanceOf); + if(instanceOf == null) + throw new MissingVariableException("No instanceof for resource " + NameUtils.getSafeName(graph, resource)); + Resource configuration = graph.getPossibleObject(instanceOf, sr2.IsDefinedBy); + if(configuration == null) + throw new MissingVariableException("No configuration for " + NameUtils.getSafeName(graph, instanceOf)); + Map children = graph.syncRequest(new UnescapedChildMapOfResource(configuration)); + Resource child = children.get(name); + return graph.adaptContextual(child, this, Variable.class, Variable.class); + } + + + @Override + public Collection browseChildren(ReadGraph graph) throws DatabaseException { + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + ArrayList result = new ArrayList(); + + Resource instanceOf = graph.getPossibleObject(this.resource, l0.InstanceOf); + if(instanceOf == null) + return result; + Resource configuration = graph.getPossibleObject(instanceOf, sr2.IsDefinedBy); + if(configuration == null) + return result; + + for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(configuration)).values()) { + try { + result.add(graph.adaptContextual(child, this, Variable.class, Variable.class)); + } catch (AdaptionException e) { + } + } + + return result; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/PropertyProvider.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/PropertyProvider.java new file mode 100644 index 00000000..2a7bcd06 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/PropertyProvider.java @@ -0,0 +1,10 @@ +package org.simantics.sysdyn.adapter; + +import org.simantics.databoard.adapter.AdaptException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; + +public interface PropertyProvider { + + Variable getProperty(String name) throws DatabaseException, AdaptException; +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/RunVariable.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/RunVariable.java new file mode 100644 index 00000000..d3b817a8 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/RunVariable.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.adapter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.uri.UnescapedChildMapOfResource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.StandardGraphChildVariable; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.layer0.Layer0; +import org.simantics.operation.Layer0X; + +public class RunVariable extends StandardGraphChildVariable { + + public RunVariable(Variable parent, Resource resource) { + super(parent, resource); + } + + @Override + public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException { + Resource config = getConfiguration(graph); + Map children = graph.syncRequest(new UnescapedChildMapOfResource(config)); + Resource child = children.get(name); + if(child == null) { + return getPossibleSpecialChild(graph, name); + } + else return new HistoryVariable(this, child); + } + + + @Override + public Collection browseChildren(ReadGraph graph) throws DatabaseException { + ArrayList result = new ArrayList(); + Resource config = getConfiguration(graph); + for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(config)).values()) + result.add(new HistoryVariable(this, child)); + collectSpecialChildren(graph, result); + return result; + } + + Resource getConfiguration(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Layer0X L0X = Layer0X.getInstance(graph); + Resource experiment = graph.getPossibleObject(resource, L0.PartOf); + Resource model = graph.getPossibleObject(experiment, L0.PartOf); + return graph.getPossibleObject(model, L0X.HasBaseRealization); + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/RunVariableAdapter.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/RunVariableAdapter.java new file mode 100644 index 00000000..64529ca9 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/RunVariableAdapter.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.adapter; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.adaption.SimpleContextualAdapter; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.sysdyn.SysdynResource; + +public class RunVariableAdapter extends SimpleContextualAdapter{ + + @Override + public Variable adapt(ReadGraph g, Resource source, Variable context) throws DatabaseException { + return new RunVariable(context, source); + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/SysdynVariableProperties.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/SysdynVariableProperties.java new file mode 100644 index 00000000..84dae6e2 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/SysdynVariableProperties.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.adapter; + +/** + * Properties that can be requested from Sysdyn variables + * @author Teemu Lempinen + * + */ +public class SysdynVariableProperties { + + final public static String VALUES = "VALUES"; + final public static String TIME = "TIME"; + final public static String TIMES = "TIMES"; + final public static String ACTIVE_DATASETS = "ACTIVE_DATASETS"; + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableRVIUtils.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableRVIUtils.java new file mode 100644 index 00000000..c5f05085 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableRVIUtils.java @@ -0,0 +1,337 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.adapter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.SysdynDataSet; + +/** + * Utils for finding all active rvis for a single variable. A variable can have multiple + * rvis, if it is an array variable. Active rvis can be limited using a boolean value sr.ShowEnumerationIndexInCharts + * + * Example rvis for a variable with two enumerations (/ModuleInstance1/ModuleInstance2/Variable[Enumeration, Enumeration2]): + * + * /ModuleInstance1/ModuleInstance2/Variable[index1, index1] + * /ModuleInstance1/ModuleInstance2/Variable[index1, index2] + * /ModuleInstance1/ModuleInstance2/Variable[index2, index1] + * /ModuleInstance1/ModuleInstance2/Variable[index2, index2] + * + * + * + * @author Teemu Lempinen + * + */ +public class VariableRVIUtils { + + /** + * Recursive function for finding number format and label for the set of rvis. (rvis.put("Variable[1]", "Variable[index1]"); + * At the end of the recursive calls, rvis contains all possible combinations of enumeration indexes that are + * set to be shown in charts + * + * @param g ReadGraph + * @param rvi RVI of the variable + * @param rvis RVI map containing the full rvi with enumerations. Key contains numerical + * value of the enumeration and value contains the name of the enumeration (e.g. ["Variable[1]", "Variable[index1]"]) + * @param arrayIndexes ArrayIndex resources, Enumerations. + * @throws DatabaseException + */ + private static void traverseIndexes(ReadGraph g, String rvi, HashMap rvis, List arrayIndexes) throws DatabaseException { + traverseIndexes(g, rvi, rvis, arrayIndexes, arrayIndexes.get(0), "", ""); + } + + /** + * Recursive function for finding number format and label for the set of rvis. (rvis.put("Variable[1]", "Variable[index1]"); + * At the end of the recursive calls, rvis contains all possible combinations of enumeration indexes that are + * set to be shown in charts + * + * @param g ReadGraph + * @param rvi RVI of the variable + * @param rvis RVI map containing the full rvi with enumerations. Key contains numerical + * @param arrayIndexes ArrayIndex resources, Enumerations. + * @param currentEnumeration Currently evaluated enumeration index (in arrayIndexes list) + * @param indexesSoFar String representation of the indexes so far in numerical format + * @param indexNamesSoFar String representation of the indexes so far in name format + * @throws DatabaseException + */ + private static void traverseIndexes(ReadGraph g, String rvi, HashMap rvis, List arrayIndexes, Resource currentEnumeration, String indexesSoFar, String indexNamesSoFar) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(g); + // Enumeration indexes of the current enumeration (e.g. the first EnumIndexes in Var[EnumIndexes, EnumIndexes, EnumIndexes]) + Resource enumerationIndexes = g.getPossibleObject(currentEnumeration, sr.HasEnumerationIndexes); + if(enumerationIndexes == null) + return; + List indexes = OrderedSetUtils.toList(g, enumerationIndexes); + for(int i = 0; i < indexes.size(); i++) { + Boolean b = g.getPossibleRelatedValue(indexes.get(i), sr.ShowEnumerationIndexInCharts, Bindings.BOOLEAN); + // If this index is not wanted to be shown in charts, the recursion does not go any further and rvis.put() is not called for this enumeration + if(Boolean.TRUE.equals(b)) { + int arrayIndex = arrayIndexes.indexOf(currentEnumeration); + // Get the name of the index + String name = g.getRelatedValue(indexes.get(i), Layer0.getInstance(g).HasName); + if(arrayIndex < arrayIndexes.size() - 1) + // If there are still more EnumIndexes, recursively call the function and add current index to indexesSoFar and indexNamesSoFar + traverseIndexes(g, rvi, rvis, arrayIndexes, arrayIndexes.get(arrayIndex + 1), + indexesSoFar + (i + 1) +",", indexNamesSoFar + (name) +","); + else { + // The last enumeration. Add [rvi[1, 1, 1] = rvi[index1, index1, index1]}and so on to the rvis map + rvis.put( + rvi + "[" + indexesSoFar + (i + 1) + "]", + rvi + "[" + indexNamesSoFar + (name) + "]"); + } + } + } + } + + /** + * Resolves and replaces all overridden enumerations in enumerations -list + * + * @param graph ReadGraph + * @param variable Selected variable + * @param enumerations List of array indexes of the variable + * @return + */ + private static List resolveActiveArrayIndexes(ReadGraph graph, Variable variable, List enumerations) { + try { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + String uri = variable.getURI(graph); + uri = uri.substring(0, uri.lastIndexOf("/")); + // The parent configuration or module + Variable v = Variables.getPossibleVariable(graph, uri); + if(v != null) { + Variable rp = (Variable)v.getProperty(graph, Variables.REPRESENTS); + Resource module = rp.getValue(graph); + if(module != null && graph.isInheritedFrom(graph.getSingleObject(module, l0.InstanceOf), sr.Module)) { + // If the variable is located in a module, it might have overridden (redeclared) enumerations + boolean somethingIsReplaced = false; + // Find all redeclarations + for(Resource redeclaration : graph.syncRequest(new ObjectsWithType(module, sr.HasRedeclaration, sr.Redeclaration))) { + Resource replaced = graph.getSingleObject(redeclaration, sr.ReplacedEnumeration); + if(enumerations.contains(replaced)) { + // Replace the redelcared enumeration in enumerations -list with the replacing enumeration + enumerations.add(enumerations.indexOf(replaced), graph.getSingleObject(redeclaration, sr.ReplacingEnumeration)); + enumerations.remove(replaced); + somethingIsReplaced = true; + } + } + + if(somethingIsReplaced) { + // If something was replaced, do the same again for the parent configuration. The + // enumerations may be replaced throughout the whole model hierarchy + resolveActiveArrayIndexes(graph, v, enumerations); + } + } + } + } catch (DatabaseException e) { + e.printStackTrace(); + + } + return enumerations; + } + + + /** + * Returns rvis in a map in format /ModuleInstance/Variable[1] = /ModuleInstance/Variable[index1] + * @param graph ReadGraph + * @param variable Variable for the rvis + * @return rvis in a map. Keys are numerical formatted array indexes and values are textual. + * @throws DatabaseException + */ + public static HashMap getActiveRVIs(ReadGraph graph, Variable variable) throws DatabaseException { + HashMap rvis = new LinkedHashMap(); + + SysdynResource sr = SysdynResource.getInstance(graph); + + String rvi = Variables.getRVI(graph, variable); + + Resource r = variable.getPropertyValue(graph, Variables.REPRESENTS); + + Resource arrayIndexes = graph.getPossibleObject(r, sr.HasArrayIndexes); + if(arrayIndexes == null) { + // If variable is single-dimensional, use the same rvi + rvis.put(rvi, rvi); + } else { + // If variable is multidimensional, get all indexes that are active and add them to rvis-map + List arrayIndexList= OrderedSetUtils.toList(graph, arrayIndexes); + resolveActiveArrayIndexes(graph, variable, arrayIndexList); + + if(arrayIndexList.size() > 0) + traverseIndexes(graph, rvi, rvis, arrayIndexList); + else + rvis.put(rvi, rvi); + } + + return rvis; + } + + + /** + * Filters a list of datasets of a single variable with a given filter. Filter should contain + * as many entries as the variable has enumerations. If the variable is Var[Enum1, Enum2, Enum3] + * the filter length should be 3. + * + * Allowed filter entries are All, Sum and a name of an index. + * + * Example filtering for variable Var[Enum1, Enum2, Enum3] where all enumerations have indexes {1, 2} + * + * filter: {All, Sum, 1} + * + * Filters are applied from back to front + * + * 1 1 1 + * 1 1 2 + * 1 2 1 1 1 1 + * 1 2 2 => 1 2 1 => 1 SUM(1 1, 2 1) + * 2 1 1 2 1 1 2 SUM(1 1, 2 1) + * 2 1 2 2 2 1 + * 2 2 1 + * 2 2 2 + * + * @param datasets List of SysdynDatasets for a single multidimensional variable + * @param filter filter for the datasets + * @return filtered list of SysdynDatasets + */ + public static ArrayList getDataset(ArrayList datasets, String[] filter) { + // If all filters are "All", no filtering is required. + boolean doFiltering = false; + for(String f : filter) { + if(!f.equalsIgnoreCase("All")) { + // One of the filters is not All -> do filtering + doFiltering = true; + break; + } + } + + if(doFiltering == false) + return datasets; + + // Start filtering with the complete set of datasets + ArrayList result = datasets; + + // Go through the filter from end to start + for(int i = filter.length - 1; i >= 0; i--) { + // Get the current filter + String currentFilter = filter[i].trim(); + + ArrayList tempResult = new ArrayList(); + HashMap sums = new HashMap(); + for(SysdynDataSet dataset : result) { + String tempIndexes = dataset.name.substring(dataset.name.indexOf('[') + 1, dataset.name.indexOf(']')); + String[] indexes = tempIndexes.split(","); + if(currentFilter.equals("All")) { + /* + * If the filter is "All", all datasets + * are kept for the next filtering + */ + tempResult.add(dataset); + } else if(currentFilter.equals(indexes[i].trim())) { + /* + * If the filter equals the index of the dataset + * at the same location, the dataset is kept for the next filtering + * + * e.g. + * dataset = Var[index3, index1, index2] + * filter = {All, index1, ALL} + * i = 1 (from 0 to 2) + * + * dataset's index and filter match at location 1 (the middle index) + */ + tempResult.add(dataset); + } else if(currentFilter.equals("Sum")) { + /* + * Whenever Sum is used as the filter, all datasets having the + * same indexes before the sum filter location are summed. + * + * e.g. + * filter = {1, 1, SUM} + * 1, 1, 1 + * 1, 1, 2 => 1, 1, SUM(1, 1, 1; 1, 1, 2) + * 1, 2, 1 1, 2, SUM(1, 2, 1; 1, 2, 2) + * 1, 2, 2 + */ + + // Find the preceding range (e.g. index1index2index2) + String rangeBefore = ""; + for(int j = 0; j < i; j++) + rangeBefore += indexes[j].trim(); + + // Find if there are any datasets for that preceding range in sums + SysdynDataSet sum = sums.get(rangeBefore); + if(sum != null) { + // A sum dataset was found. Add values from this dataset to the sum dataset + for(int j = 0; j < sum.values.length; j++) + sum.values[j] = sum.values[j] + dataset.values[j]; + } else { + // The first occurence of this preceding range, create a new dataset for the sum + + // Copy times and values + double[] times = new double[dataset.times.length]; + for(int j = 0; j < dataset.times.length; j++) + times[j] = dataset.times[j]; + double[] values = new double[dataset.values.length]; + for(int j = 0; j < dataset.values.length; j++) + values[j] = dataset.values[j]; + + // Create the dataset and add it to both tempResult and sums map + SysdynDataSet newDataset = new SysdynDataSet(dataset.name, dataset.result, times, values); + tempResult.add(newDataset); + sums.put(rangeBefore, newDataset); + + // Modify the name of the dataset by adding "Sum" to the current index location. + String name = newDataset.name.substring(0, newDataset.name.indexOf('[') + 1); + for(int j = 0; j < indexes.length; j++) { + if(j < i) + // Indexes before "Sum" stay the same + name += indexes[j].trim(); + else if(j >= i) + // Current "Sum" index and indexes after "Sum" are copied from filter + name += filter[j].trim(); + + if(j < indexes.length - 1) + name += ", "; + } + name += "]"; + + // Replace the sum dataset's name + newDataset.name = name; + } + + } else { + // Discard the series + } + } + + /* + * Replace result list with the filtered results and move on to next + * filter index or return the list + */ + result.clear(); + for(SysdynDataSet dataset : tempResult) + result.add(dataset); + } + return result; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableValueSubscription.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableValueSubscription.java new file mode 100644 index 00000000..75a561c1 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableValueSubscription.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.adapter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.simantics.databoard.adapter.AdaptException; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.ExternalRead; +import org.simantics.db.service.QueryControl; +import org.simantics.utils.datastructures.Callback; + +public class VariableValueSubscription { + + public static final long SUBSCRIPTION_COLLECTION_INTERVAL = 2000L; + + protected ExternalRead request; + protected PropertyProvider provider; + protected String property; + protected Listener listener; + + /** + * To protect against invoking listener.exception multiple times which is + * forbidden. + */ + protected AtomicBoolean excepted = new AtomicBoolean(false); + + public VariableValueSubscription(ExternalRead request, PropertyProvider variable, String property, Listener listener) { + this.request = request; + this.provider = variable; + this.property = property; + this.listener = listener; + } + + public ExternalRead getRequest() { + return request; + } + + public void update() { + update(property); + } + + public void update(String property) { + try { + Variable value = provider.getProperty(property); + fireValue(value); + } catch (DatabaseException e) { + fireException(e); + } catch (AdaptException e) { + fireException(e); + } + } + + void fireValue(Variable value) { + if (listener != null) + listener.execute(value); + } + + void fireException(Throwable t) { + if (listener != null && excepted.compareAndSet(false, true)) + listener.exception(t); + } + + public void setListener(Listener listener) { + this.listener = listener; + } + + /** + * This makes sure that subscriptions regarding performed DB external reads + * are abolished from DB client caches when no longer needed. + * + * @param session + * @param subscriptions + */ + public static void collectSubscriptions(Session session, final VariableValueSubscription[] subscriptions, final ExternalRead... extraReads) { + if (subscriptions.length == 0 && extraReads.length == 0) + return; + + session.asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Collection> requests = new ArrayList>(subscriptions.length + extraReads.length); + for (VariableValueSubscription subscription : subscriptions) + requests.add(subscription.getRequest()); + for (ExternalRead read : extraReads) + requests.add(read); + graph.getService(QueryControl.class).gc(graph, requests); + } + }, new Callback() { + @Override + public void run(DatabaseException e) { + if (e != null) + e.printStackTrace(); + } + }); + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.java new file mode 100644 index 00000000..fc72235a --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.java @@ -0,0 +1,1181 @@ +/* Generated By:JavaCC: Do not edit this line. ExpressionParser.java */ +package org.simantics.sysdyn.expressionParser; + +import java.util.Set; +import java.util.HashSet; +import java.util.List; +import java.util.ArrayList; +import java.util.HashMap; + + +public class ExpressionParser implements ExpressionParserConstants { + + public class ForRange { + public Token start; + public Token end; + } + + boolean forIndex = false; + Token firstToken; + + public Token getFirstToken() { + return firstToken; + } + + List forRanges = new ArrayList(); + + public List getForRanges() { + return forRanges; + } + + HashMap> references = new HashMap>(); + + public HashMap> getReferences() { + return references; + } + + HashMap>> ranges = new HashMap>>(); + + public HashMap>> getRanges() { + return ranges; + } + + List currentRange = null; + + HashMap> forIndices = new HashMap>(); + + public HashMap> getForIndices() { + return forIndices; + } + + HashMap> enumerationReferences = new HashMap>(); + + public HashMap> getEnumerationReferences() { + return enumerationReferences; + } + +/* + Collect EACH function call and all references that are inside the call brackets. + These are later used to exclude spread sheet references out of the normal functions. +*/ + String functionCall = null; + HashMap> functionCallReferences = new HashMap>(); + + public HashMap> getFunctionCallReferences() { + return functionCallReferences; + } + +/*** Parser ********************************************************/ + +// https://javacc.dev.java.net/doc/javaccgrm.html +// add_op -> add_op() +// [ add_op ] -> ( add_op() )? +// { add_op term } -> ( add_op() term() )* + final public void expr() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 33: + case 35: + case 62: + case 64: + case 66: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + firstToken = token; + simple_expression(); + jj_consume_token(0); + break; + case 31: + firstToken = token; + jj_consume_token(31); + expression(); + jj_consume_token(28); + expression(); + label_1: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 20: + ; + break; + default: + jj_la1[0] = jj_gen; + break label_1; + } + jj_consume_token(20); + expression(); + jj_consume_token(28); + expression(); + } + jj_consume_token(15); + expression(); + jj_consume_token(0); + break; + default: + jj_la1[1] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void expression() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 33: + case 35: + case 62: + case 64: + case 66: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + simple_expression(); + break; + case 31: + jj_consume_token(31); + expression(); + jj_consume_token(28); + expression(); + label_2: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 20: + ; + break; + default: + jj_la1[2] = jj_gen; + break label_2; + } + jj_consume_token(20); + expression(); + jj_consume_token(28); + expression(); + } + jj_consume_token(15); + expression(); + break; + default: + jj_la1[3] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void simple_expression() throws ParseException { + logical_expression(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 69: + jj_consume_token(69); + logical_expression(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 69: + jj_consume_token(69); + logical_expression(); + break; + default: + jj_la1[4] = jj_gen; + ; + } + break; + default: + jj_la1[5] = jj_gen; + ; + } + } + + final public void logical_expression() throws ParseException { + logical_term(); + label_3: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 22: + ; + break; + default: + jj_la1[6] = jj_gen; + break label_3; + } + jj_consume_token(22); + logical_term(); + } + } + + final public void logical_term() throws ParseException { + logical_factor(); + label_4: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 9: + ; + break; + default: + jj_la1[7] = jj_gen; + break label_4; + } + jj_consume_token(9); + logical_factor(); + } + } + + final public void logical_factor() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 12: + jj_consume_token(12); + break; + default: + jj_la1[8] = jj_gen; + ; + } + relation(); + } + + final public void relation() throws ParseException { + arithmetic_expression(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 72: + case 73: + case 74: + case 75: + case 76: + case 77: + rel_op(); + arithmetic_expression(); + break; + default: + jj_la1[9] = jj_gen; + ; + } + } + + final public void rel_op() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 72: + jj_consume_token(72); + break; + case 73: + jj_consume_token(73); + break; + case 74: + jj_consume_token(74); + break; + case 75: + jj_consume_token(75); + break; + case 76: + jj_consume_token(76); + break; + case 77: + jj_consume_token(77); + break; + default: + jj_la1[10] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void arithmetic_expression() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 78: + case 79: + case 80: + case 81: + add_op(); + break; + default: + jj_la1[11] = jj_gen; + ; + } + term(); + label_5: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 78: + case 79: + case 80: + case 81: + ; + break; + default: + jj_la1[12] = jj_gen; + break label_5; + } + add_op(); + term(); + } + } + + final public void add_op() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 78: + jj_consume_token(78); + break; + case 79: + jj_consume_token(79); + break; + case 80: + jj_consume_token(80); + break; + case 81: + jj_consume_token(81); + break; + default: + jj_la1[13] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void term() throws ParseException { + factor(); + label_6: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 82: + case 83: + case 84: + case 85: + ; + break; + default: + jj_la1[14] = jj_gen; + break label_6; + } + mul_op(); + factor(); + } + } + + final public void factor() throws ParseException { + primary(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 86: + case 87: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 86: + jj_consume_token(86); + break; + case 87: + jj_consume_token(87); + primary(); + break; + default: + jj_la1[15] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[16] = jj_gen; + ; + } + } + + final public void mul_op() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 82: + jj_consume_token(82); + break; + case 83: + jj_consume_token(83); + break; + case 84: + jj_consume_token(84); + break; + case 85: + jj_consume_token(85); + break; + default: + jj_la1[17] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void primary() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case UNSIGNED_NUMBER: + jj_consume_token(UNSIGNED_NUMBER); + break; + case UNSIGNED_INTEGER: + jj_consume_token(UNSIGNED_INTEGER); + break; + case STRING: + jj_consume_token(STRING); + break; + case 6: + jj_consume_token(6); + break; + case 33: + jj_consume_token(33); + break; + default: + jj_la1[19] = jj_gen; + if (jj_2_1(2147483647)) { + functionCall = null; + name(); + function_call_args(); + functionCall = null; + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IDENT: + component_reference(null); + break; + case 62: + jj_consume_token(62); + output_expression_list(); + jj_consume_token(63); + break; + case 66: + jj_consume_token(66); + expression_list(); + label_7: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 70: + ; + break; + default: + jj_la1[18] = jj_gen; + break label_7; + } + jj_consume_token(70); + expression_list(); + } + jj_consume_token(67); + break; + case 64: + jj_consume_token(64); + function_arguments(); + jj_consume_token(65); + break; + case 35: + jj_consume_token(35); + break; + default: + jj_la1[20] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + } + + final public void name() throws ParseException { + jj_consume_token(IDENT); + if (functionCall == null) + functionCall = token.image; + else + functionCall += "." + token.image; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + jj_consume_token(68); + name(); + break; + default: + jj_la1[21] = jj_gen; + ; + } + } + + final public void component_reference(String prevToken) throws ParseException { + jj_consume_token(IDENT); + String name = token.image; + // forIndex == true and prevToken != null => this is the second part of an enumeration in for-index + if(forIndex == true) { + if(prevToken != null) { + if(enumerationReferences.get(prevToken) == null) { + enumerationReferences.put(prevToken, new ArrayList()); + } + List list = enumerationReferences.get(prevToken); + list.add(token); + + // forIndex == true and prevToken == null => this is the enumeration in for-index + } else { + if(enumerationReferences.get(name) == null) { + enumerationReferences.put(name, new ArrayList()); + } + List list = enumerationReferences.get(name); + list.add(token); + } + } else { + if(prevToken != null) + name = prevToken + "." + name; + if(references.get(name) == null) { + references.put(name, new ArrayList()); + } + List list = references.get(name); + list.add(token); + + if(functionCall != null) { + if(!functionCallReferences.containsKey(functionCall)) + functionCallReferences.put(functionCall, new ArrayList()); + List functionReferencelist = getFunctionCallReferences().get(functionCall); + functionReferencelist.add(token); + } + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 66: + array_subscripts(); + break; + default: + jj_la1[22] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + jj_consume_token(68); + component_reference(name); + break; + default: + jj_la1[23] = jj_gen; + ; + } + } + + final public void function_call_args() throws ParseException { + jj_consume_token(62); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 31: + case 33: + case 35: + case 62: + case 64: + case 66: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + function_arguments(); + break; + default: + jj_la1[24] = jj_gen; + ; + } + jj_consume_token(63); + } + + final public void function_arguments() throws ParseException { + if (jj_2_2(2)) { + named_argument(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + jj_consume_token(71); + function_arguments(); + break; + default: + jj_la1[25] = jj_gen; + ; + } + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 31: + case 33: + case 35: + case 62: + case 64: + case 66: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + expression(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 21: + case 71: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + jj_consume_token(71); + function_arguments(); + break; + case 21: + jj_consume_token(21); + for_indices(); + break; + default: + jj_la1[26] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[27] = jj_gen; + ; + } + break; + default: + jj_la1[28] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + + final public void for_indices() throws ParseException { + for_index(); + label_8: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + ; + break; + default: + jj_la1[29] = jj_gen; + break label_8; + } + jj_consume_token(71); + for_index(); + } + } + + final public void for_index() throws ParseException { + jj_consume_token(IDENT); + forIndices.put(token, currentRange); + forIndex = true; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 41: + jj_consume_token(41); + ForRange forRange = new ForRange(); + forRange.start = token; + expression(); + forRange.start = forRange.start.next; + forRange.end = token; + forRanges.add(forRange); + break; + default: + jj_la1[30] = jj_gen; + ; + } + forIndex = false; + } + +/* Removed by Teemu. Refactored in function_arguments) +void named_arguments() : { +} { + named_argument() ( "," named_arguments() )? +} +*/ + final public void named_argument() throws ParseException { + jj_consume_token(IDENT); + jj_consume_token(88); + expression(); + } + + final public void output_expression_list() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 31: + case 33: + case 35: + case 62: + case 64: + case 66: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + expression(); + break; + default: + jj_la1[31] = jj_gen; + ; + } + label_9: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + ; + break; + default: + jj_la1[32] = jj_gen; + break label_9; + } + jj_consume_token(71); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 31: + case 33: + case 35: + case 62: + case 64: + case 66: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + expression(); + break; + default: + jj_la1[33] = jj_gen; + ; + } + } + } + + final public void expression_list() throws ParseException { + expression(); + label_10: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + ; + break; + default: + jj_la1[34] = jj_gen; + break label_10; + } + jj_consume_token(71); + expression(); + } + } + + final public void array_subscripts() throws ParseException { + if(ranges.get(token.image) == null) { + ranges.put(token.image, new ArrayList>()); + } + List> rangesList = ranges.get(token.image); + currentRange = new ArrayList(); + jj_consume_token(66); + subscript(currentRange); + label_11: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + ; + break; + default: + jj_la1[35] = jj_gen; + break label_11; + } + jj_consume_token(71); + subscript(currentRange); + } + jj_consume_token(67); + rangesList.add(currentRange); + } + + final public void subscript(List currentRange) throws ParseException { + Token rangeToken = new Token(token.kind, ""); + rangeToken.beginColumn = token.beginColumn + 1; + rangeToken.beginLine = token.beginLine; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 69: + jj_consume_token(69); + currentRange.add(token); + break; + case IDENT: + case UNSIGNED_INTEGER: + rangeIndex(rangeToken, false); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 69: + jj_consume_token(69); + rangeIndex(rangeToken, true); + break; + default: + jj_la1[36] = jj_gen; + ; + } + rangeToken.endColumn = token.endColumn; + rangeToken.endLine = token.endLine; + currentRange.add(rangeToken); + break; + default: + jj_la1[37] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void rangeIndex(Token rangeToken, boolean second) throws ParseException { + if(second) + rangeToken.image = rangeToken.image + ":"; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case UNSIGNED_INTEGER: + jj_consume_token(UNSIGNED_INTEGER); + rangeToken.image = rangeToken.image + token.image; + break; + case IDENT: + jj_consume_token(IDENT); + rangeToken.image = rangeToken.image + token.image; + break; + default: + jj_la1[38] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + private boolean jj_2_1(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_1(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(0, xla); } + } + + private boolean jj_2_2(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_2(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(1, xla); } + } + + private boolean jj_3R_14() { + if (jj_scan_token(68)) return true; + if (jj_3R_12()) return true; + return false; + } + + private boolean jj_3R_13() { + if (jj_scan_token(IDENT)) return true; + if (jj_scan_token(88)) return true; + return false; + } + + private boolean jj_3_2() { + if (jj_3R_13()) return true; + return false; + } + + private boolean jj_3_1() { + if (jj_3R_12()) return true; + if (jj_scan_token(62)) return true; + return false; + } + + private boolean jj_3R_12() { + if (jj_scan_token(IDENT)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_14()) jj_scanpos = xsp; + return false; + } + + /** Generated Token Manager. */ + public ExpressionParserTokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private Token jj_scanpos, jj_lastpos; + private int jj_la; + private int jj_gen; + final private int[] jj_la1 = new int[39]; + static private int[] jj_la1_0; + static private int[] jj_la1_1; + static private int[] jj_la1_2; + static { + jj_la1_init_0(); + jj_la1_init_1(); + jj_la1_init_2(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x100000,0x80001040,0x100000,0x80001040,0x0,0x0,0x400000,0x200,0x1000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x80001040,0x0,0x200000,0x200000,0x80001040,0x0,0x0,0x80001040,0x0,0x80001040,0x0,0x0,0x0,0x0,0x0,}; + } + private static void jj_la1_init_1() { + jj_la1_1 = new int[] {0x0,0x4000000a,0x0,0x4000000a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x40000008,0x0,0x0,0x0,0x4000000a,0x0,0x0,0x0,0x4000000a,0x0,0x200,0x4000000a,0x0,0x4000000a,0x0,0x0,0x0,0x0,0x0,}; + } + private static void jj_la1_init_2() { + jj_la1_2 = new int[] {0x0,0x3c03c005,0x0,0x3c03c005,0x20,0x20,0x0,0x0,0x0,0x3f00,0x3f00,0x3c000,0x3c000,0x3c000,0x3c0000,0xc00000,0xc00000,0x3c0000,0x40,0x38000000,0x4000005,0x10,0x4,0x10,0x3c03c005,0x80,0x80,0x80,0x3c03c005,0x80,0x0,0x3c03c005,0x80,0x3c03c005,0x80,0x80,0x20,0x14000020,0x14000000,}; + } + final private JJCalls[] jj_2_rtns = new JJCalls[2]; + private boolean jj_rescan = false; + private int jj_gc = 0; + + /** Constructor with InputStream. */ + public ExpressionParser(java.io.InputStream stream) { + this(stream, null); + } + /** Constructor with InputStream and supplied encoding */ + public ExpressionParser(java.io.InputStream stream, String encoding) { + try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source = new ExpressionParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 39; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream) { + ReInit(stream, null); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream, String encoding) { + try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 39; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor. */ + public ExpressionParser(java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new ExpressionParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 39; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader stream) { + jj_input_stream.ReInit(stream, 1, 1); + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 39; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor with generated Token Manager. */ + public ExpressionParser(ExpressionParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 39; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(ExpressionParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 39; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + private Token jj_consume_token(int kind) throws ParseException { + Token oldToken; + if ((oldToken = token).next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + if (++jj_gc > 100) { + jj_gc = 0; + for (int i = 0; i < jj_2_rtns.length; i++) { + JJCalls c = jj_2_rtns[i]; + while (c != null) { + if (c.gen < jj_gen) c.first = null; + c = c.next; + } + } + } + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + static private final class LookaheadSuccess extends java.lang.Error { } + final private LookaheadSuccess jj_ls = new LookaheadSuccess(); + private boolean jj_scan_token(int kind) { + if (jj_scanpos == jj_lastpos) { + jj_la--; + if (jj_scanpos.next == null) { + jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); + } else { + jj_lastpos = jj_scanpos = jj_scanpos.next; + } + } else { + jj_scanpos = jj_scanpos.next; + } + if (jj_rescan) { + int i = 0; Token tok = token; + while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } + if (tok != null) jj_add_error_token(kind, i); + } + if (jj_scanpos.kind != kind) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; + return false; + } + + +/** Get the next Token. */ + final public Token getNextToken() { + if (token.next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + +/** Get the specific Token. */ + final public Token getToken(int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next != null) t = t.next; + else t = t.next = token_source.getNextToken(); + } + return t; + } + + private int jj_ntk() { + if ((jj_nt=token.next) == null) + return (jj_ntk = (token.next=token_source.getNextToken()).kind); + else + return (jj_ntk = jj_nt.kind); + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + private int[] jj_lasttokens = new int[100]; + private int jj_endpos; + + private void jj_add_error_token(int kind, int pos) { + if (pos >= 100) return; + if (pos == jj_endpos + 1) { + jj_lasttokens[jj_endpos++] = kind; + } else if (jj_endpos != 0) { + jj_expentry = new int[jj_endpos]; + for (int i = 0; i < jj_endpos; i++) { + jj_expentry[i] = jj_lasttokens[i]; + } + jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) { + int[] oldentry = (int[])(it.next()); + if (oldentry.length == jj_expentry.length) { + for (int i = 0; i < jj_expentry.length; i++) { + if (oldentry[i] != jj_expentry[i]) { + continue jj_entries_loop; + } + } + jj_expentries.add(jj_expentry); + break jj_entries_loop; + } + } + if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; + } + } + + /** Generate ParseException. */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[94]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 39; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1< jj_gen) { + jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; + switch (i) { + case 0: jj_3_1(); break; + case 1: jj_3_2(); break; + } + } + p = p.next; + } while (p != null); + } catch(LookaheadSuccess ls) { } + } + jj_rescan = false; + } + + private void jj_save(int index, int xla) { + JJCalls p = jj_2_rtns[index]; + while (p.gen > jj_gen) { + if (p.next == null) { p = p.next = new JJCalls(); break; } + p = p.next; + } + p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; + } + + static final class JJCalls { + int gen; + Token first; + int arg; + JJCalls next; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj new file mode 100644 index 00000000..df82b2c8 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj @@ -0,0 +1,358 @@ +options { + JDK_VERSION = "1.6"; + STATIC = false; +} + +PARSER_BEGIN(ExpressionParser) +package org.simantics.sysdyn.expressionParser; + +import java.util.Set; +import java.util.HashSet; +import java.util.List; +import java.util.ArrayList; +import java.util.HashMap; + + +public class ExpressionParser { + + public class ForRange { public Token start; + public Token end; + } + + boolean forIndex = false; + Token firstToken; + + public Token getFirstToken() { return firstToken; + } + List forRanges = new ArrayList(); + + public List getForRanges() { + return forRanges; + } + + HashMap> references = new HashMap>(); + + public HashMap> getReferences() { + return references; + } + + HashMap>> ranges = new HashMap>>(); + + public HashMap>> getRanges() { + return ranges; + } + + List currentRange = null; + + HashMap> forIndices = new HashMap>(); + + public HashMap> getForIndices() { + return forIndices; + } + + HashMap> enumerationReferences = new HashMap>(); + + public HashMap> getEnumerationReferences() { + return enumerationReferences; + } + +/* + Collect EACH function call and all references that are inside the call brackets. + These are later used to exclude spread sheet references out of the normal functions. +*/ + String functionCall = null; + HashMap> functionCallReferences = new HashMap>(); + + public HashMap> getFunctionCallReferences() { + return functionCallReferences; + } + + +} +PARSER_END(ExpressionParser) + +/*** Lexer *********************************************************/ + +SKIP: +{ +| +| +} + +TOKEN: +{ +"algorithm" | "discrete" | "false" | "model" | "redeclare" +| "and" | "each" | "final" | "not" | "replaceable" +| "annotation" | "else" | "flow" | "operator" | "return" +|"assert" | "elseif" | "for" | "or" | "stream" +| "block" | "elsewhen" | "function" | "outer" | "then" +| "break" | "encapsulated" | "if" | "output" | "true" +| "class" | "end" | "import" | "package" | "type" +| "connect" | "enumeration" | "in" | "parameter" | "when" +| "connector" | "equation" | "initial" | "partial" | "while" +| "constant" | "expandable" | "inner" | "protected" | "within" +| "constrainedby" | "extends" | "input" | "public" +| "der" | "external" | "loop" | "record" +| "(" | ")" | "{" | "}" | "[" | "]" | "." | ":" | ";" | "," +| "<" | "<=" | ">" | ">=" | "==" | "<>" +| "+" | "-" | ".+" | ".-" +| "*" | "/" | ".*" | "./" +| "^" | ".^" +| "=" | ":=" +| +| + { matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); } +| +| "." ()? (["e","E"] )? + | "." (["e","E"] )? + | ["e","E"] + ) > +} + +/*** Parser ********************************************************/ + +// https://javacc.dev.java.net/doc/javaccgrm.html +// add_op -> add_op() +// [ add_op ] -> ( add_op() )? +// { add_op term } -> ( add_op() term() )* + +void expr() : { +} { + { + firstToken = token; + } + simple_expression() + | + { + firstToken = token; + } + "if" expression() "then" expression() ( "elseif" expression() "then" expression() )* + "else" expression() +} + +void expression() : { +} { + simple_expression() + | "if" expression() "then" expression() ( "elseif" expression() "then" expression() )* + "else" expression() +} + +void simple_expression() : { +} { + logical_expression() ( ":" logical_expression() ( ":" logical_expression() )? )? +} + +void logical_expression() : { +} { + logical_term() ( "or" logical_term() )* +} + +void logical_term() : { +} { + logical_factor() ( "and" logical_factor() )* +} + +void logical_factor() : { +} { + ( "not" )? relation() +} + +void relation() : { +} { + arithmetic_expression() ( rel_op() arithmetic_expression() )? +} + +void rel_op() : { +} { + "<" | "<=" | ">" | ">=" | "==" | "<>" +} + +void arithmetic_expression() : { +} { + (add_op())? term() (add_op() term())* +} + +void add_op() : { +} { + "+" | "-" | ".+" | ".-" +} + +void term() : { +} { + factor() ( mul_op() factor() )* +} + +void factor() : { +} { + primary() ( "^" | ".^" primary() )? +} + +void mul_op() : { +} { + "*" | "/" | ".*" | "./" +} + +void primary() : { +} { + + | + | + | "false" + | "true" + | LOOKAHEAD( name() "(" ) { functionCall = null; + } + name() function_call_args() { functionCall = null; + } + | component_reference(null) + | "(" output_expression_list() ")" + | "[" expression_list() ( ";" expression_list() )* "]" + | "{" function_arguments() "}" + | "end" +} + +void name() : { +} { + { if (functionCall == null) + functionCall = token.image; + else + functionCall += "." + token.image; + } + ( "." name() )? +} + +void component_reference(String prevToken) : { +} { + //IDENT [ array_subscripts ] [ "." component_reference ] + { + String name = token.image; + // forIndex == true and prevToken != null => this is the second part of an enumeration in for-index + if(forIndex == true) { if(prevToken != null) { + if(enumerationReferences.get(prevToken) == null) { enumerationReferences.put(prevToken, new ArrayList()); + } + List list = enumerationReferences.get(prevToken); + list.add(token); + + // forIndex == true and prevToken == null => this is the enumeration in for-index + } else { + if(enumerationReferences.get(name) == null) { + enumerationReferences.put(name, new ArrayList()); + } + List list = enumerationReferences.get(name); + list.add(token); + } + } else { + if(prevToken != null) + name = prevToken + "." + name; if(references.get(name) == null) { + references.put(name, new ArrayList()); + } + List list = references.get(name); + list.add(token); + + if(functionCall != null) { + if(!functionCallReferences.containsKey(functionCall)) + functionCallReferences.put(functionCall, new ArrayList()); + List functionReferencelist = getFunctionCallReferences().get(functionCall); + functionReferencelist.add(token); } + } + + } + + ( array_subscripts() )? ( "." component_reference(name) )? +} + +void function_call_args() : { +} { + "(" ( function_arguments() )? ")" +} + +void function_arguments() : { +} { + //expression [ "," function_arguments | for for_indices ] + //| named_arguments + LOOKAHEAD(2) named_argument() ( "," function_arguments() )? + | expression() ( "," function_arguments() | "for" for_indices() )? + +} + +void for_indices() : { +} { + //for_index {"," for_index} + for_index() ("," for_index())* +} + +void for_index() : { +} { + //IDENT [ in expression ] + { + forIndices.put(token, currentRange); + forIndex = true; } + ( "in" { + ForRange forRange = new ForRange(); + forRange.start = token; } + expression() { + forRange.start = forRange.start.next; + forRange.end = token; + forRanges.add(forRange); } + )? + { forIndex = false; + } +} + +/* Removed by Teemu. Refactored in function_arguments) +void named_arguments() : { +} { + named_argument() ( "," named_arguments() )? +} +*/ + +void named_argument() : { +} { + "=" expression() +} + +void output_expression_list() : { +} { + ( expression() )? ( "," ( expression() )? )* +} + + +void expression_list() : { +} { + expression() ( "," expression() )* +} + +void array_subscripts() : { if(ranges.get(token.image) == null) { + ranges.put(token.image, new ArrayList>()); + } + List> rangesList = ranges.get(token.image); + currentRange = new ArrayList(); +} { + "[" subscript(currentRange) ( "," subscript(currentRange) )* "]" + { + rangesList.add(currentRange); + } +} + +void subscript(List currentRange) : { + Token rangeToken = new Token(token.kind, ""); + rangeToken.beginColumn = token.beginColumn + 1; + rangeToken.beginLine = token.beginLine; +} { ":" { currentRange.add(token); + } + | rangeIndex(rangeToken, false) ( ":" rangeIndex(rangeToken, true))? { + rangeToken.endColumn = token.endColumn; + rangeToken.endLine = token.endLine; + currentRange.add(rangeToken); + } +} + +void rangeIndex(Token rangeToken, boolean second) : { + if(second) + rangeToken.image = rangeToken.image + ":"; +} { { + rangeToken.image = rangeToken.image + token.image; } + | { rangeToken.image = rangeToken.image + token.image; + } +} + diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParserConstants.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParserConstants.java new file mode 100644 index 00000000..8af22486 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParserConstants.java @@ -0,0 +1,129 @@ +/* Generated By:JavaCC: Do not edit this line. ExpressionParserConstants.java */ +package org.simantics.sysdyn.expressionParser; + + +/** + * Token literal values and constants. + * Generated by org.javacc.parser.OtherFilesGen#start() + */ +public interface ExpressionParserConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int WHITESPACE = 1; + /** RegularExpression Id. */ + int COMMENT1 = 2; + /** RegularExpression Id. */ + int COMMENT2 = 3; + /** RegularExpression Id. */ + int IDENT = 90; + /** RegularExpression Id. */ + int STRING = 91; + /** RegularExpression Id. */ + int UNSIGNED_INTEGER = 92; + /** RegularExpression Id. */ + int UNSIGNED_NUMBER = 93; + + /** Lexical state. */ + int DEFAULT = 0; + + /** Literal token values. */ + String[] tokenImage = { + "", + "", + "", + "", + "\"algorithm\"", + "\"discrete\"", + "\"false\"", + "\"model\"", + "\"redeclare\"", + "\"and\"", + "\"each\"", + "\"final\"", + "\"not\"", + "\"replaceable\"", + "\"annotation\"", + "\"else\"", + "\"flow\"", + "\"operator\"", + "\"return\"", + "\"assert\"", + "\"elseif\"", + "\"for\"", + "\"or\"", + "\"stream\"", + "\"block\"", + "\"elsewhen\"", + "\"function\"", + "\"outer\"", + "\"then\"", + "\"break\"", + "\"encapsulated\"", + "\"if\"", + "\"output\"", + "\"true\"", + "\"class\"", + "\"end\"", + "\"import\"", + "\"package\"", + "\"type\"", + "\"connect\"", + "\"enumeration\"", + "\"in\"", + "\"parameter\"", + "\"when\"", + "\"connector\"", + "\"equation\"", + "\"initial\"", + "\"partial\"", + "\"while\"", + "\"constant\"", + "\"expandable\"", + "\"inner\"", + "\"protected\"", + "\"within\"", + "\"constrainedby\"", + "\"extends\"", + "\"input\"", + "\"public\"", + "\"der\"", + "\"external\"", + "\"loop\"", + "\"record\"", + "\"(\"", + "\")\"", + "\"{\"", + "\"}\"", + "\"[\"", + "\"]\"", + "\".\"", + "\":\"", + "\";\"", + "\",\"", + "\"<\"", + "\"<=\"", + "\">\"", + "\">=\"", + "\"==\"", + "\"<>\"", + "\"+\"", + "\"-\"", + "\".+\"", + "\".-\"", + "\"*\"", + "\"/\"", + "\".*\"", + "\"./\"", + "\"^\"", + "\".^\"", + "\"=\"", + "\":=\"", + "", + "", + "", + "", + }; + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParserTokenManager.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParserTokenManager.java new file mode 100644 index 00000000..2ca8a9d6 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParserTokenManager.java @@ -0,0 +1,1334 @@ +/* Generated By:JavaCC: Do not edit this line. ExpressionParserTokenManager.java */ +package org.simantics.sysdyn.expressionParser; +import java.util.Set; +import java.util.HashSet; +import java.util.List; +import java.util.ArrayList; +import java.util.HashMap; + +/** Token Manager. */ +public class ExpressionParserTokenManager implements ExpressionParserConstants +{ + + /** Debug output. */ + public java.io.PrintStream debugStream = System.out; + /** Set debug output. */ + public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } +private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1) +{ + switch (pos) + { + case 0: + if ((active0 & 0x3ffffffffffffff0L) != 0L) + { + jjmatchedKind = 90; + return 2; + } + if ((active1 & 0x80000L) != 0L) + return 13; + if ((active1 & 0xb30010L) != 0L) + return 9; + return -1; + case 1: + if ((active0 & 0x108420080400000L) != 0L) + return 2; + if ((active0 & 0x3ef7bdff7fbffff0L) != 0L) + { + if (jjmatchedPos != 1) + { + jjmatchedKind = 90; + jjmatchedPos = 1; + } + return 2; + } + return -1; + case 2: + if ((active0 & 0x400000800201200L) != 0L) + return 2; + if ((active0 & 0x3bfffdf77f9fedf0L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 2; + return 2; + } + return -1; + case 3: + if ((active0 & 0x1000084212118400L) != 0L) + return 2; + if ((active0 & 0x2bfff5b56d8e69f0L) != 0L) + { + if (jjmatchedPos != 3) + { + jjmatchedKind = 90; + jjmatchedPos = 3; + } + return 2; + } + return -1; + case 4: + if ((active0 & 0x1090004290008c0L) != 0L) + return 2; + if ((active0 & 0x2af6f5b1469e6130L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 4; + return 2; + } + return -1; + case 5: + if ((active0 & 0x22200011009c0000L) != 0L) + return 2; + if ((active0 & 0x8d6f5a046026130L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 5; + return 2; + } + return -1; + case 6: + if ((active0 & 0x80d0a000000000L) != 0L) + return 2; + if ((active0 & 0x856250046026130L) != 0L) + { + if (jjmatchedPos != 6) + { + jjmatchedKind = 90; + jjmatchedPos = 6; + } + return 2; + } + return -1; + case 7: + if ((active0 & 0x54150040006110L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 7; + return 2; + } + if ((active0 & 0x802200006020020L) != 0L) + return 2; + return -1; + case 8: + if ((active0 & 0x10140000000110L) != 0L) + return 2; + if ((active0 & 0x44010040006000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 8; + return 2; + } + return -1; + case 9: + if ((active0 & 0x40010040002000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 9; + return 2; + } + if ((active0 & 0x4000000004000L) != 0L) + return 2; + return -1; + case 10: + if ((active0 & 0x10000002000L) != 0L) + return 2; + if ((active0 & 0x40000040000000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 10; + return 2; + } + return -1; + case 11: + if ((active0 & 0x40000000L) != 0L) + return 2; + if ((active0 & 0x40000000000000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 11; + return 2; + } + return -1; + default : + return -1; + } +} +private final int jjStartNfa_0(int pos, long active0, long active1) +{ + return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0, active1), pos + 1); +} +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0() +{ + switch(curChar) + { + case 40: + return jjStopAtPos(0, 62); + case 41: + return jjStopAtPos(0, 63); + case 42: + return jjStopAtPos(0, 82); + case 43: + return jjStopAtPos(0, 78); + case 44: + return jjStopAtPos(0, 71); + case 45: + return jjStopAtPos(0, 79); + case 46: + jjmatchedKind = 68; + return jjMoveStringLiteralDfa1_0(0x0L, 0xb30000L); + case 47: + return jjStartNfaWithStates_0(0, 83, 13); + case 58: + jjmatchedKind = 69; + return jjMoveStringLiteralDfa1_0(0x0L, 0x2000000L); + case 59: + return jjStopAtPos(0, 70); + case 60: + jjmatchedKind = 72; + return jjMoveStringLiteralDfa1_0(0x0L, 0x2200L); + case 61: + jjmatchedKind = 88; + return jjMoveStringLiteralDfa1_0(0x0L, 0x1000L); + case 62: + jjmatchedKind = 74; + return jjMoveStringLiteralDfa1_0(0x0L, 0x800L); + case 91: + return jjStopAtPos(0, 66); + case 93: + return jjStopAtPos(0, 67); + case 94: + return jjStopAtPos(0, 86); + case 97: + return jjMoveStringLiteralDfa1_0(0x84210L, 0x0L); + case 98: + return jjMoveStringLiteralDfa1_0(0x21000000L, 0x0L); + case 99: + return jjMoveStringLiteralDfa1_0(0x42108400000000L, 0x0L); + case 100: + return jjMoveStringLiteralDfa1_0(0x400000000000020L, 0x0L); + case 101: + return jjMoveStringLiteralDfa1_0(0x884210842108400L, 0x0L); + case 102: + return jjMoveStringLiteralDfa1_0(0x4210840L, 0x0L); + case 105: + return jjMoveStringLiteralDfa1_0(0x108421080000000L, 0x0L); + case 108: + return jjMoveStringLiteralDfa1_0(0x1000000000000000L, 0x0L); + case 109: + return jjMoveStringLiteralDfa1_0(0x80L, 0x0L); + case 110: + return jjMoveStringLiteralDfa1_0(0x1000L, 0x0L); + case 111: + return jjMoveStringLiteralDfa1_0(0x108420000L, 0x0L); + case 112: + return jjMoveStringLiteralDfa1_0(0x210842000000000L, 0x0L); + case 114: + return jjMoveStringLiteralDfa1_0(0x2000000000042100L, 0x0L); + case 115: + return jjMoveStringLiteralDfa1_0(0x800000L, 0x0L); + case 116: + return jjMoveStringLiteralDfa1_0(0x4210000000L, 0x0L); + case 119: + return jjMoveStringLiteralDfa1_0(0x21080000000000L, 0x0L); + case 123: + return jjStopAtPos(0, 64); + case 125: + return jjStopAtPos(0, 65); + default : + return jjMoveNfa_0(0, 0); + } +} +private int jjMoveStringLiteralDfa1_0(long active0, long active1) +{ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(0, active0, active1); + return 1; + } + switch(curChar) + { + case 42: + if ((active1 & 0x100000L) != 0L) + return jjStopAtPos(1, 84); + break; + case 43: + if ((active1 & 0x10000L) != 0L) + return jjStopAtPos(1, 80); + break; + case 45: + if ((active1 & 0x20000L) != 0L) + return jjStopAtPos(1, 81); + break; + case 47: + if ((active1 & 0x200000L) != 0L) + return jjStopAtPos(1, 85); + break; + case 61: + if ((active1 & 0x200L) != 0L) + return jjStopAtPos(1, 73); + else if ((active1 & 0x800L) != 0L) + return jjStopAtPos(1, 75); + else if ((active1 & 0x1000L) != 0L) + return jjStopAtPos(1, 76); + else if ((active1 & 0x2000000L) != 0L) + return jjStopAtPos(1, 89); + break; + case 62: + if ((active1 & 0x2000L) != 0L) + return jjStopAtPos(1, 77); + break; + case 94: + if ((active1 & 0x800000L) != 0L) + return jjStopAtPos(1, 87); + break; + case 97: + return jjMoveStringLiteralDfa2_0(active0, 0x842000000440L, active1, 0L); + case 101: + return jjMoveStringLiteralDfa2_0(active0, 0x2400000000042100L, active1, 0L); + case 102: + if ((active0 & 0x80000000L) != 0L) + return jjStartNfaWithStates_0(1, 31, 2); + break; + case 104: + return jjMoveStringLiteralDfa2_0(active0, 0x1080010000000L, active1, 0L); + case 105: + return jjMoveStringLiteralDfa2_0(active0, 0x20000000000820L, active1, 0L); + case 108: + return jjMoveStringLiteralDfa2_0(active0, 0x403118010L, active1, 0L); + case 109: + return jjMoveStringLiteralDfa2_0(active0, 0x1000000000L, active1, 0L); + case 110: + if ((active0 & 0x20000000000L) != 0L) + { + jjmatchedKind = 41; + jjmatchedPos = 1; + } + return jjMoveStringLiteralDfa2_0(active0, 0x108410840004200L, active1, 0L); + case 111: + return jjMoveStringLiteralDfa2_0(active0, 0x1042108000201080L, active1, 0L); + case 112: + return jjMoveStringLiteralDfa2_0(active0, 0x20000L, active1, 0L); + case 113: + return jjMoveStringLiteralDfa2_0(active0, 0x200000000000L, active1, 0L); + case 114: + if ((active0 & 0x400000L) != 0L) + return jjStartNfaWithStates_0(1, 22, 2); + return jjMoveStringLiteralDfa2_0(active0, 0x10000220000000L, active1, 0L); + case 115: + return jjMoveStringLiteralDfa2_0(active0, 0x80000L, active1, 0L); + case 116: + return jjMoveStringLiteralDfa2_0(active0, 0x800000L, active1, 0L); + case 117: + return jjMoveStringLiteralDfa2_0(active0, 0x20000010c000000L, active1, 0L); + case 120: + return jjMoveStringLiteralDfa2_0(active0, 0x884000000000000L, active1, 0L); + case 121: + return jjMoveStringLiteralDfa2_0(active0, 0x4000000000L, active1, 0L); + default : + break; + } + return jjStartNfa_0(0, active0, active1); +} +private int jjMoveStringLiteralDfa2_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(0, old0, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(1, active0, 0L); + return 2; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa3_0(active0, 0x400000000L); + case 98: + return jjMoveStringLiteralDfa3_0(active0, 0x200000000000000L); + case 99: + return jjMoveStringLiteralDfa3_0(active0, 0x2000002040000400L); + case 100: + if ((active0 & 0x200L) != 0L) + return jjStartNfaWithStates_0(2, 9, 2); + else if ((active0 & 0x800000000L) != 0L) + return jjStartNfaWithStates_0(2, 35, 2); + return jjMoveStringLiteralDfa3_0(active0, 0x180L); + case 101: + return jjMoveStringLiteralDfa3_0(active0, 0x80030020000L); + case 103: + return jjMoveStringLiteralDfa3_0(active0, 0x10L); + case 105: + return jjMoveStringLiteralDfa3_0(active0, 0x1400000000000L); + case 108: + return jjMoveStringLiteralDfa3_0(active0, 0x40L); + case 110: + return jjMoveStringLiteralDfa3_0(active0, 0x4a108004004800L); + case 111: + return jjMoveStringLiteralDfa3_0(active0, 0x1010000001010000L); + case 112: + return jjMoveStringLiteralDfa3_0(active0, 0x104005000002000L); + case 114: + if ((active0 & 0x200000L) != 0L) + return jjStartNfaWithStates_0(2, 21, 2); + else if ((active0 & 0x400000000000000L) != 0L) + return jjStartNfaWithStates_0(2, 58, 2); + return jjMoveStringLiteralDfa3_0(active0, 0x840000800000L); + case 115: + return jjMoveStringLiteralDfa3_0(active0, 0x2188020L); + case 116: + if ((active0 & 0x1000L) != 0L) + return jjStartNfaWithStates_0(2, 12, 2); + return jjMoveStringLiteralDfa3_0(active0, 0x8a0000108040000L); + case 117: + return jjMoveStringLiteralDfa3_0(active0, 0x210200000000L); + default : + break; + } + return jjStartNfa_0(1, active0, 0L); +} +private int jjMoveStringLiteralDfa3_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(1, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(2, active0, 0L); + return 3; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa4_0(active0, 0x4240060000800L); + case 99: + return jjMoveStringLiteralDfa4_0(active0, 0x5000020L); + case 101: + if ((active0 & 0x8000L) != 0L) + { + jjmatchedKind = 15; + jjmatchedPos = 3; + } + else if ((active0 & 0x200000000L) != 0L) + return jjStartNfaWithStates_0(3, 33, 2); + else if ((active0 & 0x4000000000L) != 0L) + return jjStartNfaWithStates_0(3, 38, 2); + return jjMoveStringLiteralDfa4_0(active0, 0x88800000a980180L); + case 104: + if ((active0 & 0x400L) != 0L) + return jjStartNfaWithStates_0(3, 10, 2); + return jjMoveStringLiteralDfa4_0(active0, 0x20000000000000L); + case 107: + return jjMoveStringLiteralDfa4_0(active0, 0x2000000000L); + case 108: + return jjMoveStringLiteralDfa4_0(active0, 0x201000000002000L); + case 109: + return jjMoveStringLiteralDfa4_0(active0, 0x10000000000L); + case 110: + if ((active0 & 0x10000000L) != 0L) + return jjStartNfaWithStates_0(3, 28, 2); + else if ((active0 & 0x80000000000L) != 0L) + return jjStartNfaWithStates_0(3, 43, 2); + return jjMoveStringLiteralDfa4_0(active0, 0x108000000000L); + case 111: + return jjMoveStringLiteralDfa4_0(active0, 0x2000001000004010L); + case 112: + if ((active0 & 0x1000000000000000L) != 0L) + return jjStartNfaWithStates_0(3, 60, 2); + return jjMoveStringLiteralDfa4_0(active0, 0x100000000L); + case 114: + return jjMoveStringLiteralDfa4_0(active0, 0x20000L); + case 115: + return jjMoveStringLiteralDfa4_0(active0, 0x42000400000040L); + case 116: + return jjMoveStringLiteralDfa4_0(active0, 0x10c00000000000L); + case 117: + return jjMoveStringLiteralDfa4_0(active0, 0x100000000040000L); + case 119: + if ((active0 & 0x10000L) != 0L) + return jjStartNfaWithStates_0(3, 16, 2); + break; + default : + break; + } + return jjStartNfa_0(2, active0, 0L); +} +private int jjMoveStringLiteralDfa4_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(2, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(3, active0, 0L); + return 4; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa5_0(active0, 0x2000822000L); + case 99: + return jjMoveStringLiteralDfa5_0(active0, 0x100L); + case 101: + if ((active0 & 0x40L) != 0L) + return jjStartNfaWithStates_0(4, 6, 2); + else if ((active0 & 0x1000000000000L) != 0L) + return jjStartNfaWithStates_0(4, 48, 2); + return jjMoveStringLiteralDfa5_0(active0, 0x10118000000000L); + case 105: + return jjMoveStringLiteralDfa5_0(active0, 0x220c00000100000L); + case 107: + if ((active0 & 0x1000000L) != 0L) + return jjStartNfaWithStates_0(4, 24, 2); + else if ((active0 & 0x20000000L) != 0L) + return jjStartNfaWithStates_0(4, 29, 2); + break; + case 108: + if ((active0 & 0x80L) != 0L) + return jjStartNfaWithStates_0(4, 7, 2); + else if ((active0 & 0x800L) != 0L) + return jjStartNfaWithStates_0(4, 11, 2); + break; + case 109: + return jjMoveStringLiteralDfa5_0(active0, 0x40000000000L); + case 110: + return jjMoveStringLiteralDfa5_0(active0, 0x84000000000000L); + case 112: + return jjMoveStringLiteralDfa5_0(active0, 0x40000000L); + case 114: + if ((active0 & 0x8000000L) != 0L) + return jjStartNfaWithStates_0(4, 27, 2); + else if ((active0 & 0x8000000000000L) != 0L) + return jjStartNfaWithStates_0(4, 51, 2); + return jjMoveStringLiteralDfa5_0(active0, 0x28000010000c0030L); + case 115: + if ((active0 & 0x400000000L) != 0L) + return jjStartNfaWithStates_0(4, 34, 2); + break; + case 116: + if ((active0 & 0x100000000000000L) != 0L) + return jjStartNfaWithStates_0(4, 56, 2); + return jjMoveStringLiteralDfa5_0(active0, 0x42200004004000L); + case 117: + return jjMoveStringLiteralDfa5_0(active0, 0x100000000L); + case 119: + return jjMoveStringLiteralDfa5_0(active0, 0x2000000L); + default : + break; + } + return jjStartNfa_0(3, active0, 0L); +} +private int jjMoveStringLiteralDfa5_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(3, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(4, active0, 0L); + return 5; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa6_0(active0, 0x2c00000004000L); + case 99: + if ((active0 & 0x200000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 57, 2); + return jjMoveStringLiteralDfa6_0(active0, 0x10108000002000L); + case 100: + if ((active0 & 0x2000000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 61, 2); + return jjMoveStringLiteralDfa6_0(active0, 0x84000000000000L); + case 101: + return jjMoveStringLiteralDfa6_0(active0, 0x40000000020L); + case 102: + if ((active0 & 0x100000L) != 0L) + return jjStartNfaWithStates_0(5, 20, 2); + break; + case 103: + return jjMoveStringLiteralDfa6_0(active0, 0x2000000000L); + case 104: + return jjMoveStringLiteralDfa6_0(active0, 0x2000000L); + case 105: + return jjMoveStringLiteralDfa6_0(active0, 0x200004000010L); + case 108: + return jjMoveStringLiteralDfa6_0(active0, 0x100L); + case 109: + if ((active0 & 0x800000L) != 0L) + return jjStartNfaWithStates_0(5, 23, 2); + break; + case 110: + if ((active0 & 0x40000L) != 0L) + return jjStartNfaWithStates_0(5, 18, 2); + else if ((active0 & 0x20000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 53, 2); + return jjMoveStringLiteralDfa6_0(active0, 0x800000000000000L); + case 114: + return jjMoveStringLiteralDfa6_0(active0, 0x40010000000000L); + case 115: + return jjMoveStringLiteralDfa6_0(active0, 0x40000000L); + case 116: + if ((active0 & 0x80000L) != 0L) + return jjStartNfaWithStates_0(5, 19, 2); + else if ((active0 & 0x100000000L) != 0L) + return jjStartNfaWithStates_0(5, 32, 2); + else if ((active0 & 0x1000000000L) != 0L) + return jjStartNfaWithStates_0(5, 36, 2); + return jjMoveStringLiteralDfa6_0(active0, 0x20000L); + default : + break; + } + return jjStartNfa_0(4, active0, 0L); +} +private int jjMoveStringLiteralDfa6_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(4, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(5, active0, 0L); + return 6; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa7_0(active0, 0x844010000000100L); + case 101: + if ((active0 & 0x2000000000L) != 0L) + return jjStartNfaWithStates_0(6, 37, 2); + return jjMoveStringLiteralDfa7_0(active0, 0x2002000L); + case 108: + if ((active0 & 0x400000000000L) != 0L) + return jjStartNfaWithStates_0(6, 46, 2); + else if ((active0 & 0x800000000000L) != 0L) + return jjStartNfaWithStates_0(6, 47, 2); + break; + case 110: + return jjMoveStringLiteralDfa7_0(active0, 0x2000000000000L); + case 111: + return jjMoveStringLiteralDfa7_0(active0, 0x200004020000L); + case 115: + if ((active0 & 0x80000000000000L) != 0L) + return jjStartNfaWithStates_0(6, 55, 2); + break; + case 116: + if ((active0 & 0x8000000000L) != 0L) + { + jjmatchedKind = 39; + jjmatchedPos = 6; + } + return jjMoveStringLiteralDfa7_0(active0, 0x10140000004030L); + case 117: + return jjMoveStringLiteralDfa7_0(active0, 0x40000000L); + default : + break; + } + return jjStartNfa_0(5, active0, 0L); +} +private int jjMoveStringLiteralDfa7_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(5, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(6, active0, 0L); + return 7; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa8_0(active0, 0x2000L); + case 98: + return jjMoveStringLiteralDfa8_0(active0, 0x4000000000000L); + case 101: + if ((active0 & 0x20L) != 0L) + return jjStartNfaWithStates_0(7, 5, 2); + return jjMoveStringLiteralDfa8_0(active0, 0x10040000000000L); + case 104: + return jjMoveStringLiteralDfa8_0(active0, 0x10L); + case 105: + return jjMoveStringLiteralDfa8_0(active0, 0x40000000004000L); + case 108: + if ((active0 & 0x800000000000000L) != 0L) + return jjStartNfaWithStates_0(7, 59, 2); + return jjMoveStringLiteralDfa8_0(active0, 0x40000000L); + case 110: + if ((active0 & 0x2000000L) != 0L) + return jjStartNfaWithStates_0(7, 25, 2); + else if ((active0 & 0x4000000L) != 0L) + return jjStartNfaWithStates_0(7, 26, 2); + else if ((active0 & 0x200000000000L) != 0L) + return jjStartNfaWithStates_0(7, 45, 2); + break; + case 111: + return jjMoveStringLiteralDfa8_0(active0, 0x100000000000L); + case 114: + if ((active0 & 0x20000L) != 0L) + return jjStartNfaWithStates_0(7, 17, 2); + return jjMoveStringLiteralDfa8_0(active0, 0x100L); + case 116: + if ((active0 & 0x2000000000000L) != 0L) + return jjStartNfaWithStates_0(7, 49, 2); + return jjMoveStringLiteralDfa8_0(active0, 0x10000000000L); + default : + break; + } + return jjStartNfa_0(6, active0, 0L); +} +private int jjMoveStringLiteralDfa8_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(6, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(7, active0, 0L); + return 8; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa9_0(active0, 0x40000000L); + case 98: + return jjMoveStringLiteralDfa9_0(active0, 0x2000L); + case 100: + if ((active0 & 0x10000000000000L) != 0L) + return jjStartNfaWithStates_0(8, 52, 2); + break; + case 101: + if ((active0 & 0x100L) != 0L) + return jjStartNfaWithStates_0(8, 8, 2); + break; + case 105: + return jjMoveStringLiteralDfa9_0(active0, 0x10000000000L); + case 108: + return jjMoveStringLiteralDfa9_0(active0, 0x4000000000000L); + case 109: + if ((active0 & 0x10L) != 0L) + return jjStartNfaWithStates_0(8, 4, 2); + break; + case 110: + return jjMoveStringLiteralDfa9_0(active0, 0x40000000000000L); + case 111: + return jjMoveStringLiteralDfa9_0(active0, 0x4000L); + case 114: + if ((active0 & 0x40000000000L) != 0L) + return jjStartNfaWithStates_0(8, 42, 2); + else if ((active0 & 0x100000000000L) != 0L) + return jjStartNfaWithStates_0(8, 44, 2); + break; + default : + break; + } + return jjStartNfa_0(7, active0, 0L); +} +private int jjMoveStringLiteralDfa9_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(7, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(8, active0, 0L); + return 9; + } + switch(curChar) + { + case 101: + if ((active0 & 0x4000000000000L) != 0L) + return jjStartNfaWithStates_0(9, 50, 2); + return jjMoveStringLiteralDfa10_0(active0, 0x40000000000000L); + case 108: + return jjMoveStringLiteralDfa10_0(active0, 0x2000L); + case 110: + if ((active0 & 0x4000L) != 0L) + return jjStartNfaWithStates_0(9, 14, 2); + break; + case 111: + return jjMoveStringLiteralDfa10_0(active0, 0x10000000000L); + case 116: + return jjMoveStringLiteralDfa10_0(active0, 0x40000000L); + default : + break; + } + return jjStartNfa_0(8, active0, 0L); +} +private int jjMoveStringLiteralDfa10_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(8, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(9, active0, 0L); + return 10; + } + switch(curChar) + { + case 100: + return jjMoveStringLiteralDfa11_0(active0, 0x40000000000000L); + case 101: + if ((active0 & 0x2000L) != 0L) + return jjStartNfaWithStates_0(10, 13, 2); + return jjMoveStringLiteralDfa11_0(active0, 0x40000000L); + case 110: + if ((active0 & 0x10000000000L) != 0L) + return jjStartNfaWithStates_0(10, 40, 2); + break; + default : + break; + } + return jjStartNfa_0(9, active0, 0L); +} +private int jjMoveStringLiteralDfa11_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(9, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(10, active0, 0L); + return 11; + } + switch(curChar) + { + case 98: + return jjMoveStringLiteralDfa12_0(active0, 0x40000000000000L); + case 100: + if ((active0 & 0x40000000L) != 0L) + return jjStartNfaWithStates_0(11, 30, 2); + break; + default : + break; + } + return jjStartNfa_0(10, active0, 0L); +} +private int jjMoveStringLiteralDfa12_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(10, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(11, active0, 0L); + return 12; + } + switch(curChar) + { + case 121: + if ((active0 & 0x40000000000000L) != 0L) + return jjStartNfaWithStates_0(12, 54, 2); + break; + default : + break; + } + return jjStartNfa_0(11, active0, 0L); +} +private int jjStartNfaWithStates_0(int pos, int kind, int state) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return pos + 1; } + return jjMoveNfa_0(state, pos + 1); +} +static final long[] jjbitVec0 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +private int jjMoveNfa_0(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 31; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 13: + if (curChar == 47) + { + if (kind > 3) + kind = 3; + jjCheckNAdd(20); + } + else if (curChar == 42) + jjCheckNAddStates(0, 2); + break; + case 0: + if ((0x3ff000000000000L & l) != 0L) + { + if (kind > 92) + kind = 92; + jjCheckNAddStates(3, 7); + } + else if ((0x100002600L & l) != 0L) + { + if (kind > 1) + kind = 1; + } + else if (curChar == 47) + jjAddStates(8, 9); + else if (curChar == 46) + jjCheckNAdd(9); + else if (curChar == 34) + jjCheckNAddStates(10, 12); + break; + case 2: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 90) + kind = 90; + jjstateSet[jjnewStateCnt++] = 2; + break; + case 3: + if (curChar == 34) + jjCheckNAddStates(10, 12); + break; + case 4: + if ((0xfffffffbfffffbffL & l) != 0L) + jjCheckNAddStates(10, 12); + break; + case 6: + if ((0xfffffffffffffbffL & l) != 0L) + jjCheckNAddStates(10, 12); + break; + case 7: + if (curChar == 34 && kind > 91) + kind = 91; + break; + case 8: + if (curChar == 46) + jjCheckNAdd(9); + break; + case 9: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjCheckNAddTwoStates(9, 10); + break; + case 11: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjstateSet[jjnewStateCnt++] = 11; + break; + case 12: + if (curChar == 47) + jjAddStates(8, 9); + break; + case 14: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddStates(0, 2); + break; + case 15: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 16; + break; + case 16: + if ((0xffff7fffffffffffL & l) != 0L) + jjCheckNAddStates(0, 2); + break; + case 17: + if (curChar == 47 && kind > 2) + kind = 2; + break; + case 18: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 17; + break; + case 19: + if (curChar != 47) + break; + if (kind > 3) + kind = 3; + jjCheckNAdd(20); + break; + case 20: + if ((0xfffffffffffffbffL & l) == 0L) + break; + if (kind > 3) + kind = 3; + jjCheckNAdd(20); + break; + case 21: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 92) + kind = 92; + jjCheckNAddStates(3, 7); + break; + case 22: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 92) + kind = 92; + jjCheckNAdd(22); + break; + case 23: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(23, 24); + break; + case 24: + if (curChar != 46) + break; + if (kind > 93) + kind = 93; + jjCheckNAddTwoStates(25, 26); + break; + case 25: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjCheckNAddTwoStates(25, 26); + break; + case 27: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjstateSet[jjnewStateCnt++] = 27; + break; + case 28: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(28, 29); + break; + case 30: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjstateSet[jjnewStateCnt++] = 30; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 0: + case 2: + if ((0x7fffffe87fffffeL & l) == 0L) + break; + if (kind > 90) + kind = 90; + jjCheckNAdd(2); + break; + case 4: + if ((0xffffffffefffffffL & l) != 0L) + jjCheckNAddStates(10, 12); + break; + case 5: + if (curChar == 92) + jjstateSet[jjnewStateCnt++] = 6; + break; + case 6: + jjCheckNAddStates(10, 12); + break; + case 10: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 11; + break; + case 14: + case 16: + jjCheckNAddStates(0, 2); + break; + case 20: + if (kind > 3) + kind = 3; + jjstateSet[jjnewStateCnt++] = 20; + break; + case 26: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 27; + break; + case 29: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 30; + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 4: + case 6: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddStates(10, 12); + break; + case 14: + case 16: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddStates(0, 2); + break; + case 20: + if ((jjbitVec0[i2] & l2) == 0L) + break; + if (kind > 3) + kind = 3; + jjstateSet[jjnewStateCnt++] = 20; + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + if ((i = jjnewStateCnt) == (startsAt = 31 - (jjnewStateCnt = startsAt))) + return curPos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return curPos; } + } +} +static final int[] jjnextStates = { + 14, 15, 18, 22, 23, 24, 28, 29, 13, 19, 4, 5, 7, +}; + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, "\141\154\147\157\162\151\164\150\155", +"\144\151\163\143\162\145\164\145", "\146\141\154\163\145", "\155\157\144\145\154", +"\162\145\144\145\143\154\141\162\145", "\141\156\144", "\145\141\143\150", "\146\151\156\141\154", "\156\157\164", +"\162\145\160\154\141\143\145\141\142\154\145", "\141\156\156\157\164\141\164\151\157\156", "\145\154\163\145", +"\146\154\157\167", "\157\160\145\162\141\164\157\162", "\162\145\164\165\162\156", +"\141\163\163\145\162\164", "\145\154\163\145\151\146", "\146\157\162", "\157\162", +"\163\164\162\145\141\155", "\142\154\157\143\153", "\145\154\163\145\167\150\145\156", +"\146\165\156\143\164\151\157\156", "\157\165\164\145\162", "\164\150\145\156", "\142\162\145\141\153", +"\145\156\143\141\160\163\165\154\141\164\145\144", "\151\146", "\157\165\164\160\165\164", "\164\162\165\145", +"\143\154\141\163\163", "\145\156\144", "\151\155\160\157\162\164", "\160\141\143\153\141\147\145", +"\164\171\160\145", "\143\157\156\156\145\143\164", +"\145\156\165\155\145\162\141\164\151\157\156", "\151\156", "\160\141\162\141\155\145\164\145\162", "\167\150\145\156", +"\143\157\156\156\145\143\164\157\162", "\145\161\165\141\164\151\157\156", "\151\156\151\164\151\141\154", +"\160\141\162\164\151\141\154", "\167\150\151\154\145", "\143\157\156\163\164\141\156\164", +"\145\170\160\141\156\144\141\142\154\145", "\151\156\156\145\162", "\160\162\157\164\145\143\164\145\144", +"\167\151\164\150\151\156", "\143\157\156\163\164\162\141\151\156\145\144\142\171", +"\145\170\164\145\156\144\163", "\151\156\160\165\164", "\160\165\142\154\151\143", "\144\145\162", +"\145\170\164\145\162\156\141\154", "\154\157\157\160", "\162\145\143\157\162\144", "\50", "\51", "\173", "\175", +"\133", "\135", "\56", "\72", "\73", "\54", "\74", "\74\75", "\76", "\76\75", +"\75\75", "\74\76", "\53", "\55", "\56\53", "\56\55", "\52", "\57", "\56\52", "\56\57", +"\136", "\56\136", "\75", "\72\75", null, null, null, null, }; + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", +}; +static final long[] jjtoToken = { + 0xfffffffffffffff1L, 0x3fffffffL, +}; +static final long[] jjtoSkip = { + 0xeL, 0x0L, +}; +protected SimpleCharStream input_stream; +private final int[] jjrounds = new int[31]; +private final int[] jjstateSet = new int[62]; +private final StringBuilder jjimage = new StringBuilder(); +private StringBuilder image = jjimage; +private int jjimageLen; +private int lengthOfMatch; +protected char curChar; +/** Constructor. */ +public ExpressionParserTokenManager(SimpleCharStream stream){ + if (SimpleCharStream.staticFlag) + throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); + input_stream = stream; +} + +/** Constructor. */ +public ExpressionParserTokenManager(SimpleCharStream stream, int lexState){ + this(stream); + SwitchTo(lexState); +} + +/** Reinitialise parser. */ +public void ReInit(SimpleCharStream stream) +{ + jjmatchedPos = jjnewStateCnt = 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); +} +private void ReInitRounds() +{ + int i; + jjround = 0x80000001; + for (i = 31; i-- > 0;) + jjrounds[i] = 0x80000000; +} + +/** Reinitialise parser. */ +public void ReInit(SimpleCharStream stream, int lexState) +{ + ReInit(stream); + SwitchTo(lexState); +} + +/** Switch to specified lex state. */ +public void SwitchTo(int lexState) +{ + if (lexState >= 1 || lexState < 0) + throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); + else + curLexState = lexState; +} + +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = (im == null) ? input_stream.GetImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind); + t.kind = jjmatchedKind; + t.image = curTokenImage; + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop : + for (;;) + { + try + { + curChar = input_stream.BeginToken(); + } + catch(java.io.IOException e) + { + jjmatchedKind = 0; + matchedToken = jjFillToken(); + return matchedToken; + } + image = jjimage; + image.setLength(0); + jjimageLen = 0; + + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + TokenLexicalActions(matchedToken); + return matchedToken; + } + else + { + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { input_stream.readChar(); input_stream.backup(1); } + catch (java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + } + throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); + } +} + +void TokenLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + case 91 : + image.append(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))); + matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); + break; + default : + break; + } +} +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + +private void jjCheckNAddStates(int start, int end) +{ + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); +} + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ParseException.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ParseException.java new file mode 100644 index 00000000..c5c3b5f2 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ParseException.java @@ -0,0 +1,196 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.expressionParser; + +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(Token currentTokenVal, + int[][] expectedTokenSequencesVal, + String[] tokenImageVal + ) + { + super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String initialise(Token currentToken, + int[][] expectedTokenSequences, + String[] tokenImage) { + String eol = System.getProperty("line.separator", "\n"); + StringBuffer expected = new StringBuffer(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) { + maxSize = expectedTokenSequences[i].length; + } + for (int j = 0; j < expectedTokenSequences[i].length; j++) { + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + } + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { + expected.append("..."); + } + expected.append(eol).append(" "); + } + String retval = "Encountered \""; + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + if (i != 0) retval += " "; + if (tok.kind == 0) { + retval += tokenImage[0]; + break; + } + retval += " " + tokenImage[tok.kind]; + retval += " \""; + retval += add_escapes(tok.image); + retval += " \""; + tok = tok.next; + } + retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; + retval += "." + eol; + if (expectedTokenSequences.length == 1) { + retval += "Was expecting:" + eol + " "; + } else { + retval += "Was expecting one of:" + eol + " "; + } + retval += expected.toString(); + return retval; + } + + /** + * The end of line string for this machine. + */ + protected String eol = System.getProperty("line.separator", "\n"); + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + +} +/* JavaCC - OriginalChecksum=65dcbd31a9e7a053287ebf70e24f8b8f (do not edit this line) */ diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/SimpleCharStream.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/SimpleCharStream.java new file mode 100644 index 00000000..ae8e144a --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/SimpleCharStream.java @@ -0,0 +1,480 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.expressionParser; + +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public class SimpleCharStream +{ +/** Whether parser is static. */ + public static final boolean staticFlag = false; + int bufsize; + int available; + int tokenBegin; +/** Position in buffer. */ + public int bufpos = -1; + protected int bufline[]; + protected int bufcolumn[]; + + protected int column = 0; + protected int line = 1; + + protected boolean prevCharIsCR = false; + protected boolean prevCharIsLF = false; + + protected java.io.Reader inputStream; + + protected char[] buffer; + protected int maxNextCharInd = 0; + protected int inBuf = 0; + protected int tabSize = 8; + + protected void setTabSize(int i) { tabSize = i; } + protected int getTabSize(int i) { return tabSize; } + + + protected void ExpandBuff(boolean wrapAround) + { + char[] newbuffer = new char[bufsize + 2048]; + int newbufline[] = new int[bufsize + 2048]; + int newbufcolumn[] = new int[bufsize + 2048]; + + try + { + if (wrapAround) + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos += (bufsize - tokenBegin)); + } + else + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos -= tokenBegin); + } + } + catch (Throwable t) + { + throw new Error(t.getMessage()); + } + + + bufsize += 2048; + available = bufsize; + tokenBegin = 0; + } + + protected void FillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + { + if (available == bufsize) + { + if (tokenBegin > 2048) + { + bufpos = maxNextCharInd = 0; + available = tokenBegin; + } + else if (tokenBegin < 0) + bufpos = maxNextCharInd = 0; + else + ExpandBuff(false); + } + else if (available > tokenBegin) + available = bufsize; + else if ((tokenBegin - available) < 2048) + ExpandBuff(true); + else + available = tokenBegin; + } + + int i; + try { + if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) + { + inputStream.close(); + throw new java.io.IOException(); + } + else + maxNextCharInd += i; + return; + } + catch(java.io.IOException e) { + --bufpos; + backup(0); + if (tokenBegin == -1) + tokenBegin = bufpos; + throw e; + } + } + +/** Start. */ + public char BeginToken() throws java.io.IOException + { + tokenBegin = -1; + char c = readChar(); + tokenBegin = bufpos; + + return c; + } + + protected void UpdateLineColumn(char c) + { + column++; + + if (prevCharIsLF) + { + prevCharIsLF = false; + line += (column = 1); + } + else if (prevCharIsCR) + { + prevCharIsCR = false; + if (c == '\n') + { + prevCharIsLF = true; + } + else + line += (column = 1); + } + + switch (c) + { + case '\r' : + prevCharIsCR = true; + break; + case '\n' : + prevCharIsLF = true; + break; + case '\t' : + column--; + column += (tabSize - (column % tabSize)); + break; + default : + break; + } + + bufline[bufpos] = line; + bufcolumn[bufpos] = column; + } + +/** Read a character. */ + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + --inBuf; + + if (++bufpos == bufsize) + bufpos = 0; + + return buffer[bufpos]; + } + + if (++bufpos >= maxNextCharInd) + FillBuff(); + + char c = buffer[bufpos]; + + UpdateLineColumn(c); + return c; + } + + @Deprecated + /** + * @deprecated + * @see #getEndColumn + */ + + public int getColumn() { + return bufcolumn[bufpos]; + } + + @Deprecated + /** + * @deprecated + * @see #getEndLine + */ + + public int getLine() { + return bufline[bufpos]; + } + + /** Get token end column number. */ + public int getEndColumn() { + return bufcolumn[bufpos]; + } + + /** Get token end line number. */ + public int getEndLine() { + return bufline[bufpos]; + } + + /** Get token beginning column number. */ + public int getBeginColumn() { + return bufcolumn[tokenBegin]; + } + + /** Get token beginning line number. */ + public int getBeginLine() { + return bufline[tokenBegin]; + } + +/** Backup a number of characters. */ + public void backup(int amount) { + + inBuf += amount; + if ((bufpos -= amount) < 0) + bufpos += bufsize; + } + + /** Constructor. */ + public SimpleCharStream(java.io.Reader dstream, int startline, + int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } + + /** Constructor. */ + public SimpleCharStream(java.io.Reader dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.Reader dstream) + { + this(dstream, 1, 1, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader dstream, int startline, + int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + if (buffer == null || buffersize != buffer.length) + { + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } + prevCharIsLF = prevCharIsCR = false; + tokenBegin = inBuf = maxNextCharInd = 0; + bufpos = -1; + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader dstream) + { + ReInit(dstream, 1, 1, 4096); + } + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream) + { + this(dstream, 1, 1, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, 1, 1, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream) + { + ReInit(dstream, 1, 1, 4096); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, startline, startcolumn, 4096); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + /** Get token literal value. */ + public String GetImage() + { + if (bufpos >= tokenBegin) + return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); + else + return new String(buffer, tokenBegin, bufsize - tokenBegin) + + new String(buffer, 0, bufpos + 1); + } + + /** Get the suffix. */ + public char[] GetSuffix(int len) + { + char[] ret = new char[len]; + + if ((bufpos + 1) >= len) + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + else + { + System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, + len - bufpos - 1); + System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); + } + + return ret; + } + + /** Reset buffer when finished. */ + public void Done() + { + buffer = null; + bufline = null; + bufcolumn = null; + } + + /** + * Method to adjust line and column numbers for the start of a token. + */ + public void adjustBeginLineColumn(int newLine, int newCol) + { + int start = tokenBegin; + int len; + + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0, j = 0, k = 0; + int nextColDiff = 0, columnDiff = 0; + + while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) + { + bufline[j] = newLine; + nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; + bufcolumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + bufline[j] = newLine++; + bufcolumn[j] = newCol + columnDiff; + + while (i++ < len) + { + if (bufline[j = start % bufsize] != bufline[++start % bufsize]) + bufline[j] = newLine++; + else + bufline[j] = newLine; + } + } + + line = bufline[j]; + column = bufcolumn[j]; + } + +} +/* JavaCC - OriginalChecksum=c766a5138ab7879b8b98d46681a242b8 (do not edit this line) */ diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/TestExpressionParser.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/TestExpressionParser.java new file mode 100644 index 00000000..35225c26 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/TestExpressionParser.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.expressionParser; + +import java.io.StringReader; +import java.util.HashMap; +import java.util.List; + +public class TestExpressionParser { + + static private ExpressionParser parser; + + public static void parse(String string) { + parser.ReInit(new StringReader(string)); + try { + parser.expr(); + HashMap> references = parser.getReferences(); + for(String ref : references.keySet()) { + System.out.println(ref); + } + } catch (ParseException e) { + System.out.println("While parsing " + string + ":"); + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static void main(String[] args) { + parser = new ExpressionParser( + new StringReader("") + ); + parse("1 + m2ma"); + System.out.println("##"); + parse("ter2e + moro"); + System.out.println("##"); + parse("moro * sqr(4.0) + min(m2ma, moi)"); + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/Token.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/Token.java new file mode 100644 index 00000000..ed3a26a5 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/Token.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.expressionParser; + +/** + * Describes the input token stream. + */ + +public class Token implements java.io.Serializable { + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(int kind) + { + this(kind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(int kind, String image) + { + this.kind = kind; + this.image = image; + } + + /** + * Returns the image. + */ + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* JavaCC - OriginalChecksum=ed7a6d865f7fbc2c64e008e34bd824b0 (do not edit this line) */ diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/TokenMgrError.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/TokenMgrError.java new file mode 100644 index 00000000..db380412 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/TokenMgrError.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.expressionParser; + +/** Token Manager Error. */ +public class TokenMgrError extends Error +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + + /** No arg constructor. */ + public TokenMgrError() { + } + + /** Constructor with message and reason. */ + public TokenMgrError(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { + this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* JavaCC - OriginalChecksum=24b6b4792f62099f85bde9ed73a49451 (do not edit this line) */ diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java new file mode 100644 index 00000000..e3d02a2c --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java @@ -0,0 +1,294 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.manager; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Simantics; +import org.simantics.layer0.Layer0; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.Activator; +import org.simantics.sysdyn.SysdynResource; + +public class FunctionUtils { + + public static List getLibraryPathsForModelica(final SysdynModel model) { + final ArrayList paths = new ArrayList(); + + try { + Simantics.getSession().syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + SimulationResource simu = SimulationResource.getInstance(graph); + + Set parents = getParents(graph, model, true); + for(Resource parent : parents) { + if(graph.isInstanceOf(parent, sr.SysdynModel)) { + Resource configuration = graph.getPossibleObject(parent, simu.HasConfiguration); + if(configuration.equals(model.getConfigurationResource())) { + String parentName = NameUtils.getSafeName(graph, parent); + paths.add(parentName + "_functions.mo"); + } + } else { + String libraryname = NameUtils.getSafeName(graph, parent); + paths.add("..\\\\..\\\\libraries\\\\functions\\\\" + libraryname + ".mo"); + } + } + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + return paths; + } + + private static Set getParents(ReadGraph graph, SysdynModel model, boolean onlyWithContent) throws DatabaseException{ + HashSet parents = new HashSet(); + + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + SimulationResource simu = SimulationResource.getInstance(graph); + Resource modelResource = graph.getPossibleObject(model.getConfigurationResource(), simu.IsConfigurationOf); + if(modelResource == null) + return parents; + + parents.add(modelResource); + + for(Resource r : graph.getObjects(modelResource, l0.IsLinkedTo)) { + if(graph.isInstanceOf(r, sr.SharedFunctionOntology)) { + parents.add(r); + } else { + Collection libraries = graph.syncRequest(new ObjectsWithType( + r, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary)); + if(!libraries.isEmpty()) + parents.add(r); + } + } + + if(onlyWithContent) { + HashSet contentParents = new HashSet(); + for(Resource parent : parents) { + if(hasContent(graph, parent)) + contentParents.add(parent); + } + parents = contentParents; + } + + return parents; + + } + + private static boolean hasContent(ReadGraph graph, Resource library) { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + try { + if(!graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunction)).isEmpty()) + return true; + else { + for(Resource l : graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) { + boolean hasContent = hasContent(graph, l); + if(hasContent) + return true; + } + } + } catch (DatabaseException e) { + e.printStackTrace(); + } + return false; + } + + public static void updateFunctionFilesForModel(ReadGraph graph, SysdynModel model) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + + Set parents = getParents(graph, model, false); + + for(Resource parent : parents) { + if(graph.isInstanceOf(parent, sr.SysdynModel)) { + String parentName = NameUtils.getSafeName(graph, parent); + File scriptFile = new File(model.getSimulationDir(), parentName + "_functions.mo"); + updateFunctionFile(graph, parent, scriptFile, false); + } else { + updateFunctionFileForLibrary(graph, parent); + } + } + return; + } + + private static File getDir(ReadGraph graph, Resource resource) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Resource library = resource; + while(!graph.isInstanceOf(library, sr.SysdynModel) && !graph.isInstanceOf(library, l0.Ontology)) { + library = graph.getSingleObject(resource, l0.PartOf); + } + + File dir = null; + + if(graph.isInstanceOf(library, sr.SysdynModel)) { + SimulationResource simu = SimulationResource.getInstance(graph); + Resource configuration = graph.getSingleObject(library, simu.HasConfiguration); + SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession()); + SysdynModel model = smm.getModel(graph, configuration); + dir = model.getSimulationDir(); + } else { + File librariesDir = Activator.getBundleContext().getDataFile("libraries"); + if (!librariesDir.exists()) { + librariesDir.mkdir(); + } + dir = new File(librariesDir, "functions"); + if (!dir.exists()) { + dir.mkdir(); + } + } + return dir; + } + + public static void createExternalFunctionFile(ReadGraph graph, Resource externalFunction) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Resource function = graph.getSingleObject(externalFunction, l0.PartOf); + File dir = getDir(graph, function); + + try { + String name = NameUtils.getSafeName(graph, externalFunction); + if(name.endsWith(".o") || name.endsWith(".a")) { + FileOutputStream fos = new FileOutputStream(dir + "\\" + name); + byte[] fileBArray = graph.getPossibleRelatedValue(externalFunction, sr.HasExternalFile, Bindings.BYTE_ARRAY); + fos.write(fileBArray); + fos.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void removeExternalFunctionFile(ReadGraph graph, Resource externalFunction) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + + Resource function = graph.getSingleObject(externalFunction, l0.PartOf); + File dir = getDir(graph, function); + String name = NameUtils.getSafeName(graph, externalFunction); + File file = new File(dir, name); + file.delete(); + } + + + + public static void updateFunctionFileForLibrary(ReadGraph graph, Resource library) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + while(!graph.isInstanceOf(library, sr.SysdynModel) && !graph.isInstanceOf(library, l0.Ontology)) { + library = graph.getSingleObject(library, l0.PartOf); + } + + if(graph.isInstanceOf(library, sr.SysdynModel)) { + SimulationResource simu = SimulationResource.getInstance(graph); + Resource configuration = graph.getSingleObject(library, simu.HasConfiguration); + SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession()); + SysdynModel model = smm.getModel(graph, configuration); + updateFunctionFilesForModel(graph, model); + } else { + + File librariesDir = Activator.getBundleContext().getDataFile("libraries"); + if (!librariesDir.exists()) { + librariesDir.mkdir(); + } + File dir = new File(librariesDir, "functions"); + if (!dir.exists()) { + dir.mkdir(); + } + String parentName = NameUtils.getSafeName(graph, library); + File scriptFile = new File(dir, parentName + ".mo"); + + Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.1"); + + if(library.equals(sysdyn)) { + updateFunctionFile(graph, library, scriptFile, true); + } else { + updateFunctionFile(graph, library, scriptFile, false); + } + } + + + } + + private static void updateFunctionFile(ReadGraph graph, Resource library, File scriptFile, boolean builtIn) throws DatabaseException { + PrintStream s; + try { + s = new PrintStream(scriptFile); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return; + } + + SysdynResource sr = SysdynResource.getInstance(graph); + String name = NameUtils.getSafeName(graph, library); + if(!builtIn && !graph.isInstanceOf(library, sr.SysdynModel)) + s.println("package " + name); + writeLibrary(graph, library, s, builtIn); + if(!builtIn && !graph.isInstanceOf(library, sr.SysdynModel)) + s.println("end " + name + ";\n"); + + s.close(); + } + + private static void writeLibrary(ReadGraph graph, Resource library, PrintStream stream, boolean builtIn) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + writeLibraryFunctions(graph, library, stream); + for(Resource sublibrary : graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) { + String name = NameUtils.getSafeName(graph, sublibrary); + if(!builtIn) + stream.println("encapsulated package " + name); + writeLibrary(graph, sublibrary, stream, builtIn); + if(!builtIn) + stream.println("end " + name + ";\n"); + } + } + + private static void writeLibraryFunctions(ReadGraph graph, Resource library, PrintStream stream) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + for(Resource function : graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunction))) { + String name = NameUtils.getSafeName(graph, function); + String functionCode = graph.getRelatedValue(function, sr.HasModelicaFunctionCode); + stream.println("function " + name); + stream.println(functionCode); + stream.println("end " + name + ";\n"); + for(Resource externalFunction : graph.syncRequest(new ObjectsWithType(function, l0.ConsistsOf, sr.ExternalFunctionFile))) { + createExternalFunctionFile(graph, externalFunction); + } + } + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynDataSet.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynDataSet.java new file mode 100644 index 00000000..89e53db5 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynDataSet.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.manager; + +import org.simantics.modelica.data.DataSet; + +/** + * Extension for the basic Modelica result {@link DataSet} containing also an optional result name. + * + * @author Teemu Lempinen + * + */ +public class SysdynDataSet extends DataSet { + + public String result; // Name of the result file if this is not the result of the current simulation + + public SysdynDataSet(String name, String result, double[] times, double[] values) { + super(name, times, values); + this.result = result; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java new file mode 100644 index 00000000..2dbe53d5 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java @@ -0,0 +1,346 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.manager; + +import gnu.trove.set.hash.THashSet; + +import java.io.File; +import java.util.UUID; +import java.util.concurrent.locks.Lock; + +import org.eclipse.core.runtime.Platform; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.simulation.data.Datasource; +import org.simantics.simulation.experiment.Experiment; +import org.simantics.simulation.experiment.ExperimentState; +import org.simantics.simulation.experiment.IDynamicExperiment; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.adapter.VariableValueSubscription; +import org.simantics.sysdyn.simulation.SimulationScheduler; + +public class SysdynExperiment extends Experiment implements IDynamicExperiment { + + protected Session session; + protected Runnable modificationListener; + protected SysdynModel sysdynModel; + protected boolean toggled = false; + protected THashSet variableValueSubscriptions = new THashSet(); + protected volatile VariableValueSubscription[] variableValueSubscriptionsSnapshot = null; + + public static SysdynExperiment INSTANCE; + + public SysdynExperiment(Resource experiment, Resource model) { + super(experiment, model); + INSTANCE = this; + } + + public static SysdynExperiment getInstance() { + return INSTANCE; + } + + @Override + public void rewindTo(double time) { + // TODO Auto-generated method stub + System.out.println("rewindTo"); + } + + @Override + public void saveState() { + if(sysdynModel.getSysdynResult() == null) return; + + try { + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + Resource model = graph.getSingleObject(experiment, l0.PartOf); + Resource project = graph.getSingleObject(model, l0.PartOf); + String projectName = graph.getPossibleRelatedValue(project, l0.HasName); + File root = new File(Platform.getLocation().toOSString(), "www.simantics.org"); + if(!root.isDirectory()) root.mkdir(); + File projectRoot = new File(root, projectName); + if(!projectRoot.isDirectory()) projectRoot.mkdir(); + File file = new File( projectRoot, UUID.randomUUID().toString() + ".dbb"); + + String name = NameUtils.findFreshName(graph, "Result", model, l0.ConsistsOf, "%s%d"); + + SysdynResource sr = SysdynResource.getInstance(graph); + Resource res = GraphUtils.create2(graph, sr.Result, + l0.HasLabel, name, + l0.HasName, name, + l0.PartOf, model, + sr.HasResultFile, file.getAbsolutePath()); + graph.claim(experiment, sr.HasResult, res); + sysdynModel.getSysdynResult().saveToFile(file); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + + @Override + public void simulate(boolean enabled) { + if(enabled && sysdynModel != null) { + changeState(ExperimentState.RUNNING); + startSimulation(); + } else if (!toggled){ + changeState(ExperimentState.STOPPED); + } + } + + + protected void startSimulation() { + session.asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + SimulationScheduler.start(sysdynModel, SysdynExperiment.this); + } + }); + } + + public void toggleSimulation(boolean enabled) { + if(enabled) { + this.toggled = true; + changeState(ExperimentState.RUNNING); + if(modificationListener == null) { + + modificationListener = new Runnable() { + + @Override + public void run() { + session.asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + if(getState() == ExperimentState.RUNNING) { + SimulationScheduler.start(sysdynModel, SysdynExperiment.this); + } + + } + }); + + }; + }; + sysdynModel.addModificationListener(modificationListener); + } + } + else { + changeState(ExperimentState.STOPPED); + this.toggled = false; + } + + } + + @Override + public void simulateDuration(double duration) { + // TODO Auto-generated method stub + System.out.println("simulateDuartion"); + } + + @Override + public void refresh(Session session) { + session.asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + init(graph); + } + + }); + } + + public void init(ReadGraph g) { + this.session = g.getSession(); + changeState(ExperimentState.STOPPED); + + session.asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + final Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration); + sysdynModel = SysdynModelManager.getInstance(session).getModel(graph, configuration); + toggleActivation(graph, true); + } + }); + + } + + protected void localStateChange() { + final ExperimentState state = getState(); + session.asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + SimulationResource SR = SimulationResource.getInstance(graph); + graph.deny(model, SR.HasExperimentState); + Resource st = graph.newResource(); + switch(state) { + case INITIALIZING: + graph.claim(st, L0.InstanceOf, SR.ExperimentState_Initializing); + break; + case RUNNING: + graph.claim(st, L0.InstanceOf, SR.ExperimentState_Running); + break; + case STOPPED: + graph.claim(st, L0.InstanceOf, SR.ExperimentState_Stopped); + break; + case DISPOSED: + graph.claim(st, L0.InstanceOf, SR.ExperimentState_Disposed); + break; + } + + graph.claim(model, SR.HasExperimentState, st); + }}); + + switch(state) { + case DISPOSED: + System.out.println("disposed"); + session.asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + sysdynModel.cancelSimulation(); + sysdynModel.removeModificationListener(modificationListener); + modificationListener = null; + toggleActivation(graph, false); + } + }); + break; + } + + } + + + protected void toggleActivation(ReadGraph graph, final boolean activate) { + VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class); + final Session session = graph.getSession(); + session.asyncRequest(new WriteRequest(support.getWorkspacePersistent("experiments")) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + VirtualGraph runtime = graph.getService(VirtualGraph.class); + + session.asyncRequest(new WriteRequest(runtime) { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SimulationResource SIMU = SimulationResource.getInstance(graph); + if(activate) + graph.claim(experiment, SIMU.IsActive, experiment); + else + graph.denyStatement(experiment, SIMU.IsActive, experiment); + } + + }); + } + }); + } + + @Override + public Lock getDatasourceLock() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Datasource getDatasource() { + // TODO Auto-generated method stub + return null; + } + + /** + * Copy from AprosExperiment + * @param subscription + */ + public void addVariableValueSubscription(VariableValueSubscription subscription) { + assert subscription != null; + synchronized (variableValueSubscriptions) { + //System.out.println("ADD listener " + subscription); + variableValueSubscriptions.add(subscription); + variableValueSubscriptionsSnapshot = null; + } + } + + /** + * Copy from AprosExperiment + * @param subscription + */ + public void removeVariableValueSubscription(VariableValueSubscription subscription) { + assert subscription != null; + synchronized (variableValueSubscriptions) { + //System.out.println("REMOVE listener " + subscription); + variableValueSubscriptions.remove(subscription); + variableValueSubscriptionsSnapshot = null; + } + } + + /** + * Copy from AprosExperiment + * @return + */ + private VariableValueSubscription[] getListenerSnapshot() { + VariableValueSubscription[] snapshot = variableValueSubscriptionsSnapshot; + if (snapshot == null) { + synchronized (variableValueSubscriptions) { + snapshot = variableValueSubscriptionsSnapshot; + if (snapshot == null) { + snapshot = variableValueSubscriptionsSnapshot = variableValueSubscriptions.toArray(new VariableValueSubscription[variableValueSubscriptions.size()]); + } + } + //System.out.println("listener count: " + snapshot.length); + } + return snapshot; + } + + volatile long previousVariableUpdateTime = 0; + volatile boolean skippedVariableUpdate = true; + + + /** + * Modified copy from AprosExperiment + */ + public void fireValuesChanged() { + long time = System.nanoTime(); + if(time - previousVariableUpdateTime > 100000000) { + updateSubscriptions(); + previousVariableUpdateTime = time; + } + else + skippedVariableUpdate = true; + } + + /** + * Modified copy from AporsExperiment + */ + private void updateSubscriptions() { + for(VariableValueSubscription subscription : getListenerSnapshot()) + subscription.update(); + skippedVariableUpdate = false; + } + +} + diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java new file mode 100644 index 00000000..4ffb342b --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java @@ -0,0 +1,792 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.manager; + +import gnu.trove.set.hash.THashSet; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.modelica.IModelicaMonitor; +import org.simantics.modelica.ModelicaException; +import org.simantics.modelica.ModelicaManager; +import org.simantics.modelica.SimulationLocation; +import org.simantics.modelica.data.CSVSimulationResult; +import org.simantics.modelica.data.MatSimulationResult; +import org.simantics.modelica.data.SimulationResult; +import org.simantics.objmap.IMapping; +import org.simantics.objmap.IMappingListener; +import org.simantics.objmap.Mappings; +import org.simantics.simulation.experiment.Experiment; +import org.simantics.simulation.experiment.ExperimentState; +import org.simantics.simulation.experiment.IDynamicExperiment; +import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.model.IModel; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.simulation.project.ExperimentRuns; +import org.simantics.simulation.project.IExperimentActivationListener; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.Activator; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.adapter.VariableValueSubscription; +import org.simantics.sysdyn.modelica.ModelicaWriter; +import org.simantics.sysdyn.representation.Configuration; +import org.simantics.sysdyn.representation.IElement; +import org.simantics.sysdyn.representation.IndependentVariable; +import org.simantics.sysdyn.representation.Model; +import org.simantics.sysdyn.representation.Module; +import org.simantics.sysdyn.representation.SysdynSchema; +import org.simantics.sysdyn.representation.expressions.IExpression; +import org.simantics.sysdyn.representation.expressions.ParameterExpression; + +/** + * Maintains a Java representation of system dynamic model. + * @author Hannu Niemistö + */ +public class SysdynModel implements IMappingListener, IModel { + + private Session session; + + private IMapping mapping; + + private Resource configurationResource; + private Resource modelResource; + + private Configuration configuration; + + private Set modules = new HashSet(); + + private Process process; + private boolean canceled; + private SimulationResult result; + private SysdynResult sysdynResult; + private ArrayList activeResults; + + private CopyOnWriteArrayList modificationListeners = + new CopyOnWriteArrayList(); + private CopyOnWriteArrayList resultListeners = + new CopyOnWriteArrayList(); + + protected THashSet variableValueSubscriptions = new THashSet(); + protected volatile VariableValueSubscription[] variableValueSubscriptionsSnapshot = null; + + @SuppressWarnings("rawtypes") + private Map services = new HashMap(); + + private String previousModelStructure; + private HashMap previousImportantInits = new HashMap(); + + private File simulationDir; + + /** + * Recursively read all module configurations that are used in + * configResource and its components children + * + * @param graph ReadGraph + * @param configResource Configuration + * @param result set containing all encountered configurations + * @throws DatabaseException + */ + void readModules(ReadGraph graph, Resource configResource, Set result) throws DatabaseException { + + // if result does not contain this resource, add it to the result + if(!result.add(configResource)) return; + + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 str = StructuralResource2.getInstance(graph); + + for(Resource part : graph.getObjects(configResource, l0.ConsistsOf)) { + if(graph.isInstanceOf(part, sr.Module)) { + Resource type = graph.getPossibleType(part, sr.Module); + Resource config = graph.getPossibleObject(type, str.IsDefinedBy); + // Recursively readModules + readModules(graph, config, result); + } + } + + } + + /** + * Get all modules that have been used in configResource and its children + * @param graph ReadGraph + * @param configResource Configuration + * @return All modules (configuration resources) that have been used in configResource + * @throws DatabaseException + */ + Set readModules(ReadGraph graph, Resource configResource) throws DatabaseException { + HashSet result = new HashSet(); + readModules(graph, configResource, result); + return result; + } + + /** + * Create an ObjMapping + * @param g ReadGraph + * @throws DatabaseException + */ + private void createMapping(ReadGraph g) throws DatabaseException { + SysdynSchema schema = new SysdynSchema(g); + mapping = Mappings.createWithListening(schema); + mapping.addMappingListener(SysdynModel.this); + configuration = (Configuration)mapping.map(g, configurationResource); + for(Resource config : readModules(g, configurationResource)) { + modules.add((Configuration)mapping.map(g, config)); + } + } + + /** + * New Sysdyn model + * @param g ReadGraph + * @param configurationResource Configration resource of the model + */ + public SysdynModel(ReadGraph g, Resource configurationResource) { + this.session = g.getSession(); + this.configurationResource = configurationResource; + + try { + createMapping(g); + } catch(DatabaseException e) { + e.printStackTrace(); + } + + // initialize results + sysdynResult = new SysdynResult(); + sysdynResult.setResult(new SimulationResult()); + + previousModelStructure = ""; + + g.asyncRequest(new Read> () { + @Override + public ArrayList perform(ReadGraph graph) throws DatabaseException { + ArrayList activeResults = new ArrayList(); + // TODO: this can be done automatically with a listener + try { + // Find all active saved results + Layer0 l0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + SimulationResource SIMU = SimulationResource.getInstance(graph); + Resource model = graph.getSingleObject(getConfigurationResource(), SIMU.IsConfigurationOf); + Collection experiments = graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, sr.Experiment)); + for(Resource experiment : experiments) { + Collection experimentResults = graph.getObjects(experiment, sr.HasResult); + for(Resource result : experimentResults) { + if(graph.hasStatement(result, sr.ShowResult)) { + SysdynResult sysdynResult = new SysdynResult( + (String) graph.getPossibleRelatedValue(result, l0.HasLabel), + (String) graph.getPossibleRelatedValue(result, sr.HasResultFile)); + activeResults.add(sysdynResult); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + // Add the current result if there is one + if(getSysdynResult() != null) + activeResults.add(0, getSysdynResult() ); + + return activeResults; + } + + }, new Listener> () { + + @Override + public void execute(ArrayList result) { + activeResults = result; + resultChanged(); + } + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + } + + + /* + * a dummy(?) call for experiments + */ + public SysdynModel(Resource modelResource) { + this.modelResource = modelResource; + } + + /** + * Simulate this model + * @param monitor IModelicaMonitor + * @param progressMonitor IProgressMonitor + * @param experiment SysdynExperiment + * @throws IOException + */ + public synchronized void simulate(final IModelicaMonitor monitor, final IProgressMonitor progressMonitor, final Experiment experiment) throws IOException { + canceled = false; + progressMonitor.subTask("Write modelica classes"); + + // Write Modelica files + ModelicaWriter writer = new ModelicaWriter(); + try { + // Write all configurations once + for(Configuration c : modules) { + writer.write(c); + } + } catch (Exception e) { + // Stop experiment and show console + setExperimentStopped(experiment); + monitor.showConsole(); + monitor.message("Error when writing Modelica code."); + return; + } + String modelText = writer.toString(); + progressMonitor.worked(1); + + // Write initial files and add init-parameters + progressMonitor.subTask("Write initial files"); + HashMap inits = getInits(configuration, ""); + Model model = configuration.getModel(); + Double startTime = model.getStartTime(); + Double stopTime = model.getStopTime(); + Double numberOfIntervals = model.getOutputInterval(); + inits.put("start value", startTime.toString()); + inits.put("stop value", stopTime.toString()); + String outputFormat = "\"mat\""; + inits.put("outputFormat", outputFormat); + if(numberOfIntervals != null) { + inits.put("step value", numberOfIntervals.toString()); + } else { + inits.put("step value", "" + (stopTime - startTime) / 500); + } + String method = "\"" + model.getSolver() + "\""; + inits.put("method", method); + if(model.getTolerance() != null) + inits.put("tolerance", model.getTolerance().toString()); + + // add loadFile script to load all related functions and function libraries + StringBuilder functionscript = new StringBuilder(); + for(String path : FunctionUtils.getLibraryPathsForModelica(this)) { + functionscript.append("loadFile(\"" + path + "\");\n"); + } + + // Create simulation files + final SimulationLocation simulationLocation = ModelicaManager.createInputFiles( + getSimulationDir(), + configuration.getName(), + modelText, + inits, + functionscript.toString()); + + + progressMonitor.worked(1); + + // Build the model and store previous model structure and inits that affect the building + // If there is no exe file OR the model structure has not changed, no need to build + if (!simulationLocation.exeFile.isFile() || hasStructureChanged(modelText, inits)) { + progressMonitor.subTask("Build model"); + previousModelStructure = modelText; +// System.out.println("== Modelica == "); +// System.out.println(writer.toString()); +// System.out.println("== Modelica ends == "); + + try { + simulationLocation.exeFile.delete(); + ModelicaManager.buildModel(simulationLocation, monitor); + previousImportantInits.clear(); + previousImportantInits.put("start value", startTime.toString()); + previousImportantInits.put("stop value", stopTime.toString()); + previousImportantInits.put("method", method); + previousImportantInits.put("outputFormat", outputFormat); + } catch (ModelicaException e) { + if(e.getMessage() != null) + monitor.message(e.getMessage()); + monitor.showConsole(); + canceled = true; + previousModelStructure = ""; + } + } + + progressMonitor.worked(1); + + if(simulationLocation != null && !canceled) { + // Simulate the model + progressMonitor.subTask("Simulate model"); + process = ModelicaManager.runModelica( + simulationLocation, + monitor, + inits + ); + ModelicaManager.printProcessOutput(process, monitor); + + Thread resultThread = new Thread() { + @Override + public void run() { + try { + process.waitFor(); + + if(!canceled) { + // Get and store results + progressMonitor.worked(1); + progressMonitor.subTask("Read results"); + if(simulationLocation.outputFile.getName().endsWith(".csv")) + result = new CSVSimulationResult(); + else if(simulationLocation.outputFile.getName().endsWith(".plt")) + result = new SimulationResult(); + else + result = new MatSimulationResult(); // The latest format + result.read(simulationLocation.outputFile); + result.readInits(simulationLocation.initFile); + result.filter(); + sysdynResult.setResult(result); + progressMonitor.worked(1); + resultChanged(); + + setExperimentStopped(experiment); + + String errorString = result.getResultReadErrors(); + if(errorString != null && !errorString.isEmpty()) + monitor.message(errorString); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }; + resultThread.run(); + } + if(canceled) + setExperimentStopped(experiment); + process = null; + } + + /** + * Stop an experiment + * + * @param experiment Experiment to be stopped + */ + private void setExperimentStopped(Experiment experiment) { + if(experiment instanceof SysdynExperiment) { + SysdynExperiment e = (SysdynExperiment)experiment; + if(e.getState() != ExperimentState.DISPOSED) + e.simulate(false); + } + } + + /** + * Method that compares given modelText and inits to previous model and inits + * @param modelText Textual representation of a model (Modelica code) + * @param inits map of init parameters + * @return true if the model has changed, false otherwise + */ + private boolean hasStructureChanged(String modelText, Map inits) { + + // Compare inits first because it is faster + for(String key : previousImportantInits.keySet()) { + if(!inits.containsKey(key) || !previousImportantInits.get(key).equals(inits.get(key))) + return true; + } + + // Then compare the actual model structure + BufferedReader current = new BufferedReader( + new StringReader(modelText)); + BufferedReader previous = new BufferedReader( + new StringReader(previousModelStructure)); + + String c, p; + try { + // Read both current and previous model texts at the same time + c = current.readLine(); + p = previous.readLine(); + + while (c != null && p != null) { + // if the lines are the same, no need for further examination + if(!c.equals(p)) { + if(c.contains("parameter") && p.contains("parameter")) { + /* + * The line is a parameter definition. + * In this case only what is before '=' matters + * + * parameter Real Var = 1; + * is structurally same as + * parameter Real Var = 2; + */ + int i = c.indexOf("="); + if(!c.substring(0, i).equals(p.substring(0, i))) { + // different parameter definition + return true; + } + } else { + // other than a line containing parameters differs + return true; + } + } + c = current.readLine(); + p = previous.readLine(); + } + + if((c == null && p != null) || (c != null && p == null)) { + // different lengths + return true; + } + + } catch(IOException e) { + // Something went wrong in the comparison, it is safer to say that the structure has changed + return true; + } + return false; + } + + /** + * Cancel a possible ongoing simulation + */ + public void cancelSimulation() { + canceled = true; + if(process != null) { + process.destroy(); + } + } + + /** + * Update mapping. + * + * Use this if inside a transaction. + * + * @param graph ReadGraph + * @return has the range been modified + * @throws DatabaseException + */ + public synchronized boolean update(ReadGraph graph) throws DatabaseException { + if(mapping.isDomainModified()) { + mapping.updateRange(graph); + + // Remove all unnecessary module configurations from modules + Set configs = readModules(graph, configurationResource); + for(Resource config : configs) { + if(!modules.contains(config)) + modules.add((Configuration)mapping.map(graph, config)); + } + + HashSet toBeRemoved = null; + for(Configuration module : modules) { + if(!configs.contains(mapping.inverseGet(module))) { + if(toBeRemoved == null) + toBeRemoved = new HashSet(); + toBeRemoved.add(module); + } + } + if(toBeRemoved != null) + modules.removeAll(toBeRemoved); + return true; + } + else + return false; + } + + /** + * Update mapping. + * + * Use only if not inside a transaction + * @return has range been updated + * @throws DatabaseException + */ + public boolean update() throws DatabaseException { + return session.syncRequest(new Read() { + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + return update(graph); + } + }); + } + + public SimulationResult getSimulationResult() { + return result; + } + + public SysdynResult getSysdynResult() { + return sysdynResult; + } + + public void addResultListener(Runnable listener) { + synchronized(resultListeners) { + resultListeners.add(listener); + } + } + + public void removeResultListener(Runnable listener) { + synchronized(resultListeners) { + resultListeners.remove(listener); + } + } + + /** + * Fires an update to all result listeners and subscriptions + * after results have changed + */ + public void resultChanged() { + synchronized(resultListeners) { + for(Runnable listener : resultListeners) { + listener.run(); + } + } + + updateSubscriptions(); + } + + public void addModificationListener(Runnable listener) { + synchronized(modificationListeners) { + modificationListeners.add(listener); + } + } + + public void removeModificationListener(Runnable listener) { + synchronized(modificationListeners) { + modificationListeners.remove(listener); + } + } + + /** + * Fires all modification listeners after a change in the domain + */ + @Override + public void domainModified() { + synchronized(modificationListeners) { + for(Runnable listener : modificationListeners) + listener.run(); + } + } + + @Override + public void rangeModified() { + } + + public Configuration getConfiguration() { + return configuration; + } + + public Resource getConfigurationResource() { + return configurationResource; + } + + public IMapping getMapping() { + return mapping; + } + + public synchronized IElement getElement(Resource resource) { + return (IElement)mapping.get(resource); + } + + public T getService(Class clazz) { + synchronized(services) { + return clazz.cast(services.get(clazz)); + } + } + + public void addService(Class clazz, T service) { + synchronized(services) { + services.put(clazz, service); + } + } + + @Override + public IExperiment loadExperiment(ReadGraph g, Resource experiment, IExperimentActivationListener listener) { + + // Make sure that configurationResource exists + if(configurationResource == null && modelResource != null) { + SimulationResource simu = SimulationResource.getInstance(g); + try { + configurationResource = g.getPossibleObject(modelResource, simu.HasConfiguration); + } catch (ManyObjectsForFunctionalRelationException e) { + e.printStackTrace(); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + + try { + // Create a new experiment based on the experiment resource type + SysdynResource sr = SysdynResource.getInstance(g); + IDynamicExperiment exp; + if(g.isInstanceOf(experiment, sr.PlaybackExperiment)) { + exp = new SysdynPlaybackExperiment(experiment, modelResource); + } else if(g.isInstanceOf(experiment, sr.BasicExperiment)) { + exp = new SysdynExperiment(experiment, modelResource); + } else { + return null; + } + + ((SysdynExperiment)exp).init(g); + + ExperimentRuns.createRun(g.getSession(), experiment, exp, listener, null); + if(listener != null) + listener.onExperimentActivated(exp); + return exp; + } catch(Exception e) { + if(listener != null) + listener.onFailure(e); + return null; + } + } + + + /** + * Get active results. To update the active results, use getAndUpdateActiveResults() + * @param graph ReadGraph + * @return all active SysdynResults (last update with getAndUpdateActiveResults()) + */ + public Collection getActiveResults() { + if(activeResults == null) + return new ArrayList(); + else + return activeResults; + } + + /** + * Get all parameters for Configuration + * + * @param configuration Configuration + * @param prefix String prefix of configuration in this model (Module1.Module2...) + * @return + */ + private HashMap getInits(Configuration configuration, String prefix) { + HashMap inits = new HashMap(); + for (IElement element : configuration.getElements()) { + if (element instanceof Module) { + Module module = (Module) element; + Configuration conf = module.getType().getConfiguration(); + inits.putAll(getInits(conf, prefix + module.getName() + ".")); + } else if (element instanceof IndependentVariable) { + IndependentVariable variable = (IndependentVariable) element; + //FIXME: more general solution for finding out if the variable is a parameter + IExpression expression = variable.getExpressions().getExpressions().get(0); + if (expression instanceof ParameterExpression) { + Double value = ((ParameterExpression)expression).getValue(); + if(value != null) + inits.put(prefix + variable.getName(), "" + value); + } + } + } + return inits; + } + + /** + * Get a simulation directory for this model + * @return File directory + */ + public File getSimulationDir() { + if(simulationDir == null) { + File modelsDir = Activator.getBundleContext().getDataFile("models"); + String configName = configuration.getName(); + List files = Arrays.asList(modelsDir.list()); + if (files.contains(configName)) { + int i = 2; + while (files.contains(configName + "_" + i)){ + i++; + } + configName += "_" + i; + } + + simulationDir = Activator.getBundleContext().getDataFile("models/" + configName); + if (!simulationDir.exists()) { + simulationDir.mkdir(); + } + } + return simulationDir; + } + + + /** + * Copy from AprosExperiment + * @param subscription + */ + public void addVariableValueSubscription(VariableValueSubscription subscription) { + assert subscription != null; + synchronized (variableValueSubscriptions) { + //System.out.println("ADD listener " + subscription); + variableValueSubscriptions.add(subscription); + variableValueSubscriptionsSnapshot = null; + } + } + + /** + * Copy from AprosExperiment + * @param subscription + */ + public void removeVariableValueSubscription(VariableValueSubscription subscription) { + assert subscription != null; + synchronized (variableValueSubscriptions) { + //System.out.println("REMOVE listener " + subscription); + variableValueSubscriptions.remove(subscription); + variableValueSubscriptionsSnapshot = null; + } + } + + /** + * Copy from AprosExperiment + * @return + */ + private VariableValueSubscription[] getListenerSnapshot() { + VariableValueSubscription[] snapshot = variableValueSubscriptionsSnapshot; + if (snapshot == null) { + synchronized (variableValueSubscriptions) { + snapshot = variableValueSubscriptionsSnapshot; + if (snapshot == null) { + snapshot = variableValueSubscriptionsSnapshot = variableValueSubscriptions.toArray(new VariableValueSubscription[variableValueSubscriptions.size()]); + } + } + //System.out.println("listener count: " + snapshot.length); + } + return snapshot; + } + + /** + * Modified copy from AporsExperiment + */ + private void updateSubscriptions() { + VariableValueSubscription[] snapShot = getListenerSnapshot(); + for(VariableValueSubscription subscription : snapShot) + subscription.update(); + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModelManager.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModelManager.java new file mode 100644 index 00000000..efa5578c --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModelManager.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.manager; + +import java.util.WeakHashMap; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.simulation.ontology.SimulationResource; + +/** + * Manages system dynamic models. + * @author Hannu Niemistö + */ +public class SysdynModelManager { + WeakHashMap models = + new WeakHashMap(); // FIXME: Resources are weak, there is no guarantee that model exists in this map as long as needed. + // HashTable with a disposal procedure could be better solution.. + Session session; + + public SysdynModelManager(Session session) { + this.session = session; + } + + /** + * Use only if not inside a transaction + */ + public SysdynModel getModel(final Resource resource) { + synchronized(models) { + SysdynModel model = models.get(resource); + if(model == null) { + try { + session.syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + SysdynModel model = new SysdynModel(graph, resource); + models.put(resource, model); + FunctionUtils.updateFunctionFilesForModel(graph, model); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + + model = models.get(resource); + } + return model; + } + } + + /** + * Should be used if called inside a transaction + */ + public SysdynModel getModel(ReadGraph g, Resource resource) { + synchronized(models) { + SysdynModel model = models.get(resource); + if(model == null) { + model = new SysdynModel(g, resource); + models.put(resource, model); + try { + SimulationResource simu = SimulationResource.getInstance(g); + Resource modelResource = g.getPossibleObject(model.getConfigurationResource(), simu.IsConfigurationOf); + if(modelResource != null) + FunctionUtils.updateFunctionFilesForModel(g, model); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + return model; + } + } + + public synchronized static SysdynModelManager getInstance(Session session) { + SysdynModelManager manager = + session.peekService(SysdynModelManager.class); + if(manager == null) { + manager = new SysdynModelManager(session); + session.registerService(SysdynModelManager.class, manager); + } + return manager; + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynPlaybackExperiment.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynPlaybackExperiment.java new file mode 100644 index 00000000..814c0beb --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynPlaybackExperiment.java @@ -0,0 +1,287 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.manager; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Simantics; +import org.simantics.db.request.Read; +import org.simantics.simulation.experiment.ExperimentState; +import org.simantics.simulation.experiment.IDynamicExperiment; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.SysdynResource; + +public class SysdynPlaybackExperiment extends SysdynExperiment implements IDynamicExperiment { + + public static long DURATION_SLOW = 20000; + public static long DURATION_NORMAL = 10000; + public static long DURATION_FAST = 5000; + + double time, startTime, endTime; + public static final long VARIABLE_UPDATE_INTERVAL = 500000000; + private static final double UPDATES_PER_TIME_UNIT = 0.015; + private long playbackDuration = DURATION_NORMAL; + private Collection timeListeners = new ArrayList(); + + ScheduledExecutorService playbackExecutionService; + PlaybackConfiguration playbackConfiguration; + + public SysdynPlaybackExperiment(Resource experiment, Resource model) { + super(experiment, model); + this.time = 0; + } + + + /** + * Interrupts a possible ongoing playback + * + * @param time + */ + public void setTimeInterrupting(double time) { + stopPlayback(); + setTime(time); + } + + /** + * Sets a new time and continues playback from that point if + * playback was running + * @param time + */ + public void setTimeAndContinue(double time) { + if(isPlaybackRunning()) { + stopPlayback(); + setTime(time); + startPlayback(500); + } else { + setTime(time); + } + } + + private void setTime(double time) { + this.time = time; + fireValuesChanged(); + } + + public double getTime() { + return this.time; + } + + public double getStartTime() { + return this.startTime; + } + + public double getEndTime() { + return this.endTime; + } + + public void setPlaybackDuration(long duration) { + this.playbackDuration = duration; + if(isPlaybackRunning()) { + //Restart playback with different time settings + startPlayback(); + } + } + + public long getPlaybackDuration() { + return this.playbackDuration; + } + + @Override + public void init(ReadGraph g) { + this.session = g.getSession(); + session.asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + changeState(ExperimentState.RUNNING); + final Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration); + sysdynModel = SysdynModelManager.getInstance(session).getModel(graph, configuration); + toggleActivation(graph, true); + getPlaybackConfiguration(graph); + startSimulation(); + } + }); + } + + + // PLAYBACK CONTROLS + public void startPlayback() { + startPlayback(0); + } + public void startPlayback(long initialDelay) { + if(isPlaybackRunning()) { + stopPlayback(); + } + playbackConfiguration = getPlaybackConfiguration(); + playbackExecutionService = Executors.newScheduledThreadPool(1); + + if(time >= playbackConfiguration.endTime) { + setTime(playbackConfiguration.startTime); + playbackConfiguration = getPlaybackConfiguration(); + } + + Runnable playbackSimulationTask = new PlaybackSimulationTask(time, playbackConfiguration.simulationStepLength); + + long delay = (long) (playbackConfiguration.playbackDuration / playbackConfiguration.intervals); + ScheduledFuture stepper = playbackExecutionService.scheduleWithFixedDelay( + playbackSimulationTask, initialDelay, delay, TimeUnit.MILLISECONDS + ); + + Runnable stopSimulationTask = new StopSimulationTask(stepper, playbackConfiguration.endTime); + playbackExecutionService.schedule(stopSimulationTask, playbackConfiguration.playbackDuration + initialDelay, TimeUnit.MILLISECONDS); + + changeState(ExperimentState.RUNNING); + } + + public boolean isPlaybackRunning() { + return playbackExecutionService != null && !playbackExecutionService.isShutdown(); + } + + public void resetPlayback() { + double startTime = 0.0; + if(isPlaybackRunning() && playbackConfiguration != null) { + startTime = playbackConfiguration.startTime; + } else { + startTime = getPlaybackConfiguration().startTime; + } + setTimeInterrupting(startTime); + } + + public void stopPlayback() { + if(isPlaybackRunning()) { + playbackExecutionService.shutdownNow(); + playbackExecutionService.shutdown(); + if(playbackConfiguration != null) + playbackConfiguration = null; + changeState(ExperimentState.STOPPED); + } + } + + + private class PlaybackSimulationTask implements Runnable { + private int stepCount; + private double startTime, stepLength; + + public PlaybackSimulationTask(double startTime, double stepLength) { + this.startTime = startTime; + this.stepLength = stepLength; + } + + public void run() { + ++stepCount; + setTime(startTime + stepCount * stepLength); +// System.out.println("Playback step at time: " + (startTime + stepCount * stepLength) + " (step: " + stepCount + ")"); + } + } + + private class StopSimulationTask implements Runnable { + + private ScheduledFuture scheduledFuture; + private double endTime; + + public StopSimulationTask(ScheduledFuture aSchedFuture, double endTime){ + scheduledFuture = aSchedFuture; + this.endTime = endTime; + } + public void run() { +// System.out.println("Stopping playback"); + scheduledFuture.cancel(false); + stopPlayback(); + setTime(endTime); + } + + } + + private PlaybackConfiguration getPlaybackConfiguration() { + PlaybackConfiguration config = null; + try { + config = Simantics.getSession().syncRequest(new Read() { + + @Override + public PlaybackConfiguration perform(ReadGraph graph) throws DatabaseException { + return getPlaybackConfiguration(graph); + } + + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + return config; + } + private PlaybackConfiguration getPlaybackConfiguration(ReadGraph graph) throws DatabaseException { + Double[] numbers = new Double[3]; + Resource model = getModel(); + SysdynResource sr = SysdynResource.getInstance(graph); + numbers[0] = graph.getRelatedValue(model, sr.HasStartTime); + numbers[1] = graph.getRelatedValue(model, sr.HasStopTime); + numbers[2] = graph.getPossibleRelatedValue(model, sr.HasOutputInterval); + + PlaybackConfiguration config = new PlaybackConfiguration(); + config.simulationDuration = numbers[1] - numbers[0] - time; + config.playbackDuration = (long) (config.simulationDuration / (config.simulationDuration + time) * playbackDuration); + config.intervals = config.playbackDuration * UPDATES_PER_TIME_UNIT; + config.simulationStepLength = config.simulationDuration / config.intervals; + config.endTime = numbers[1]; + config.startTime = numbers[0]; + + this.startTime = config.startTime; + this.endTime = config.endTime; + return config; + } + + private class PlaybackConfiguration { + public double simulationDuration, simulationStepLength, intervals, endTime, startTime; + public long playbackDuration; + } + + protected void localStateChange() { + super.localStateChange(); + + ExperimentState state = getState(); + if(ExperimentState.DISPOSED.equals(state)) { + stopPlayback(); + } + } + + // TIME LISTENERS + public void addTimeListener(Runnable timeListener) { + if(!this.timeListeners.contains(timeListener)) + this.timeListeners.add(timeListener); + } + + public Collection getTimeListeners() { + return this.timeListeners; + } + + public void removeTimeListener(Runnable timeListener) { + this.timeListeners.remove(timeListener); + } + + @Override + public void fireValuesChanged() { + for(Runnable listener : timeListeners) { + listener.run(); + } + super.fireValuesChanged(); + + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java new file mode 100644 index 00000000..d0771f50 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java @@ -0,0 +1,245 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.manager; + + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.TreeMap; + +import org.simantics.databoard.Accessors; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Datatypes; +import org.simantics.databoard.Files; +import org.simantics.databoard.accessor.Accessor; +import org.simantics.databoard.accessor.MapAccessor; +import org.simantics.databoard.accessor.RecordAccessor; +import org.simantics.databoard.accessor.binary.BinaryRecord; +import org.simantics.databoard.accessor.binary.BinaryVariant; +import org.simantics.databoard.accessor.error.AccessorConstructionException; +import org.simantics.databoard.accessor.error.AccessorException; +import org.simantics.databoard.accessor.java.JavaRecord; +import org.simantics.databoard.accessor.reference.ChildReference; +import org.simantics.databoard.accessor.reference.ComponentReference; +import org.simantics.databoard.accessor.reference.IndexReference; +import org.simantics.databoard.accessor.reference.KeyReference; +import org.simantics.databoard.accessor.reference.NameReference; +import org.simantics.databoard.annotations.Arguments; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.RecordBinding; +import org.simantics.databoard.binding.error.BindingException; +import org.simantics.databoard.binding.mutable.Variant; +import org.simantics.databoard.type.Datatype; +import org.simantics.modelica.data.DataSet; +import org.simantics.modelica.data.SimulationResult; + +/** + * Class for containing the accessor for a sysdyn simulation result + * @author Teemu Lempinen + * + */ +public class SysdynResult { + + RecordAccessor accessor; + String resultName; + + /** + * Create an empty result + */ + public SysdynResult() { + + } + + /** + * Create a sysdynresult accessor using a {@link SimulationResult} + * @param result + */ + public SysdynResult(SimulationResult result) { + if(result != null) + setResult(result); + } + + /** + * Open result from a file + * + * @param result Name of the result (seen in visualization) + * @param path file path + */ + public SysdynResult(String result, String path) { + this.resultName = result; + File file = new File(path); + try { + BinaryVariant bv = (BinaryVariant)Accessors.openAccessor(file); + BinaryRecord br = bv.getContentAccessor(); + accessor = br; + } catch (AccessorConstructionException e) { + e.printStackTrace(); + } + } + + /** + * Get the {@link RecordAccessor} of this result + * @return {@link RecordAccessor} for this result + */ + public Accessor getAccessor() { + return accessor; + } + + /** + * Create a {@link RecordAccessor} for this result based on a {@link SimulationResult} + * @param result {@link SimulationResult} + */ + public void setResult(SimulationResult result) { + try { + // Create Memory Historian + Datatype recordingSessionType = Datatypes.getDatatype("RecordingSession"); + RecordBinding sessionBinding = (RecordBinding) Bindings.getBinding( recordingSessionType ); + RecordBinding recordingBinding = (RecordBinding) Bindings.getBinding( Recording.class ); + Object session = sessionBinding.createDefault(); + accessor = (JavaRecord) Accessors.getAccessor( sessionBinding, session ); + MapAccessor recordings = accessor.getFieldAccessor("recordings"); + + // There is a recording for each variable + List datasets = result.getVariableDataSets(); + + // Add variables + for(DataSet ds : datasets){ + // Add recording to session + Recording recording = createRecording(ds); + recordings.put(Bindings.VARIANT, recording.nodeId, Bindings.VARIANT, new Variant(recordingBinding, recording)); + } + + // Add initial values + for(DataSet ds : result.getInitialValueDataSets()){ + Variant nodeId = Variant.ofInstance( ds.name ); + if (recordings.containsKey(Bindings.VARIANT, nodeId)) continue; + // Add recording to session + Recording recording = createRecording(ds); + recordings.put(Bindings.VARIANT, recording.nodeId, Bindings.VARIANT, new Variant(recordingBinding, recording)); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Create a recording for a variable to this result's {@link RecordAccessor} + * @param ds {@link DataSet} for the variable + * @return {@link Recording} + * @throws BindingException + */ + @SuppressWarnings("unchecked") + Recording createRecording(DataSet ds) throws BindingException { + RecordBinding recordingBinding = (RecordBinding) Bindings.getBindingUnchecked( Recording.class ); + Recording recording = (Recording) recordingBinding.createDefault(); + recording.nodeId = Variant.ofInstance( ds.name ); + recording.labels.put("en", ds.name); + + // Create one segment + TreeMap segment = new TreeMap(); + recording.segments = new TreeMap[] { segment }; + + int length = ds.values.length; + for (int i=0; i labels; + public @Arguments({TreeMap.class, Double.class, Double.class}) TreeMap[] segments; + } + + /** + * Get dataset for a named variable + * @param variable The name of the variable + * @return {@link SysdynDataSet} + */ + public SysdynDataSet getDataSet(String variable) { + if(accessor != null) { + try { + ChildReference ref = ChildReference.compile( + new NameReference("recordings"), + new KeyReference( Bindings.VARIANT, Variant.ofInstance(variable) ), + new ComponentReference(), + new NameReference("segments"), + new IndexReference(0) + ); + + MapAccessor ma = accessor.getComponent( ref ); + int size = ma.size(); + Double[] times = new Double[size]; + Double[] values = new Double[size]; + + ma.getAll(Bindings.DOUBLE, Bindings.DOUBLE, times, values); + + double[] times_ = new double[size]; + double[] values_ = new double[size]; + for (int i=0; i variables = new ArrayList(); + private ArrayList controls = new ArrayList(); + private ArrayList sketchData = new ArrayList(); + private ArrayList otherData = new ArrayList(); + + + + public void addVariable(String variable) { + variables.add(variable); + } + + public ArrayList getVariables() { + return variables; + } + + public void addControl(String control) { + controls.add(control); + } + + public ArrayList getControls() { + return controls; + } + + public void addSketchData(String sketchRow) { + sketchData.add(sketchRow); + } + + public ArrayList getSketchData() { + return sketchData; + } + + public void addOtherData(String dataRow) { + otherData.add(dataRow); + } + + public ArrayList getOtherData() { + return otherData; + } + + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/MdlParser.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/MdlParser.java new file mode 100644 index 00000000..2f68f086 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/MdlParser.java @@ -0,0 +1,622 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport; + +import java.awt.geom.Point2D; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.ArrayList; +import java.util.HashMap; + +import org.simantics.sysdyn.mdlImport.mdlElements.Auxiliary; +import org.simantics.sysdyn.mdlImport.mdlElements.Cloud; +import org.simantics.sysdyn.mdlImport.mdlElements.Connection; +import org.simantics.sysdyn.mdlImport.mdlElements.Dependency; +import org.simantics.sysdyn.mdlImport.mdlElements.Element; +import org.simantics.sysdyn.mdlImport.mdlElements.EquivalenceSubscript; +import org.simantics.sysdyn.mdlImport.mdlElements.Expression; +import org.simantics.sysdyn.mdlImport.mdlElements.Flow; +import org.simantics.sysdyn.mdlImport.mdlElements.Function; +import org.simantics.sysdyn.mdlImport.mdlElements.Model; +import org.simantics.sysdyn.mdlImport.mdlElements.Stock; +import org.simantics.sysdyn.mdlImport.mdlElements.Subscript; +import org.simantics.sysdyn.mdlImport.mdlElements.Valve; +import org.simantics.sysdyn.mdlImport.mdlElements.Variable; +import org.simantics.sysdyn.mdlImport.mdlElements.View; + +public class MdlParser { + + public static Model parse(File file) { + + Model model = new Model(); + + String[] name = file.getName().split("\\.mdl"); + model.setName(name[0]); + + MdlFile mdlFile = getMdlContents(file); + + getVariableData(model, mdlFile.getVariables()); + + getSketchData(model, mdlFile.getSketchData()); + + getControlData(model, mdlFile.getControls()); + +// getOthertData(model, mdlFile.getOtherData()); + + setAllSubscripts(model); + + return model; + } + + + private static MdlFile getMdlContents(File aFile) { + MdlFile mdlFile = new MdlFile(); + + try { + BufferedReader input = new BufferedReader(new FileReader(aFile)); + + try { + String line = null; //not declared within while loop + + // See if the document is encoded with UTF-8. It will be marked with {UTF-8} on the first line + input.mark(30); + if (( line = input.readLine()) != null && + line.contains("{UTF-8}")){ + Reader in = new InputStreamReader(new FileInputStream(aFile), "UTF-8"); + input = new BufferedReader(in); + line = input.readLine(); + } else { + input.reset(); + } + + + boolean isControl = false; + + while (( line = input.readLine()) != null){ + // Build an element (combine the lines to one string) + StringBuilder elementBuilder = new StringBuilder(); + while(line != null && !line.contains("\\\\\\---///")) { + // Add a new line for the element + elementBuilder.append(line); + if(line.endsWith("|") && !line.endsWith("~~|")) { + //Element definition has ended + break; + } + line = input.readLine(); + } + + if(line.contains("\\\\\\---///")) + break; + + String variable = elementBuilder.toString(); + + if(variable.trim().matches("[\\*]{46}.+[\\*]{46}.+")) { + if(variable.contains(".Control")) { + isControl = true; + } else { + isControl = false; + } + continue; + } + + // Add element string to model + if(isControl) { + mdlFile.addControl(variable); + } else { + mdlFile.addVariable(variable); + } + } + + while (( line = input.readLine()) != null && !line.contains("///---\\\\\\")){ + mdlFile.addSketchData(line); + } + + while (( line = input.readLine()) != null){ + mdlFile.addOtherData(line); + } + } + finally { + input.close(); + } + } + catch (IOException ex){ + ex.printStackTrace(); + } + + return mdlFile; + } + + private static void getVariableData(Model model, ArrayList elements) { + ArrayList equivalenceSubscripts = new ArrayList(); + for(String elementString : elements) { + Variable v = createVariable(model, elementString); + if(v instanceof EquivalenceSubscript){ + equivalenceSubscripts.add((EquivalenceSubscript) v); + } + } + + // All variables are ready, determine subscript equivalences + for(EquivalenceSubscript es : equivalenceSubscripts) { + Element e = model.getElement(es.getEquivalentToName()); + if(e != null && e instanceof Subscript) { + es.setEquivalentTo((Subscript)e); + } + } + } + + + private static void getControlData(Model model, ArrayList controls) { + for(String controlString : controls) { + String[] nameAndData = controlString.split("="); + String[] expressionUnitsAndComments = nameAndData[1].split("[\\~|\\|]"); + + if(nameAndData[0].trim().equals("FINAL TIME")) { + model.setEndTime(Double.parseDouble(expressionUnitsAndComments[0])); + } else if(nameAndData[0].trim().equals("INITIAL TIME")) { + model.setStartTime(Double.parseDouble(expressionUnitsAndComments[0])); + } else if(nameAndData[0].trim().equals("TIME STEP")) { + model.setTimeStep(Double.parseDouble(expressionUnitsAndComments[0])); + } else if(nameAndData[0].trim().equals("SAVEPER")) { + model.setSaveper(expressionUnitsAndComments[0]); + model.setTimeUnit(expressionUnitsAndComments[1]); + } + } + + } + + private static Variable getVariable(Model model, String name) { + Element e = model.getElement(name); + Variable variable = null; + if(e != null && e instanceof Variable) + variable = (Variable)e; + return variable; + } + + private static String[] getNormalVariableNameDataAndRange(String element) { + String[] nameAndData = element.split("=", 2); + String[] nameAndRange = nameAndData[0].trim().split("[\\[|\\]]"); + if(nameAndData.length == 2) + return new String[] {nameAndRange[0], nameAndData[1], nameAndRange.length == 2 ? nameAndRange[1] : null}; + return null; + } + + private static String[] getSubscriptNameAndData(String element) { + String[] nameAndData = element.split(":"); + if(nameAndData.length == 2) + return nameAndData; + return null; + } + + private static String[] getEquivalenceSubscriptNameAndData(String element) { + String[] nameAndData = element.split("\\<\\-\\>"); + if(nameAndData.length == 2) + return nameAndData; + return null; + } + + private static String[] getTableNameDataAndRange(String element) { + String[] parts = element.split("\\~"); + if(!parts[0].contains("(") || !parts[0].contains(")")) + return null; + String name = element.substring(0, element.indexOf("(")); + String theRest = element.substring(element.indexOf("(")); + String[] nameAndData = {name, theRest}; + String[] nameAndRange = nameAndData[0].trim().split("[\\[|\\]]"); + if(nameAndData.length == 2) + return new String[] {nameAndRange[0], nameAndData[1], nameAndRange.length == 2 ? nameAndRange[1] : null}; + return nameAndData; + } + + private static String[] getDataVariableNameAndData(String element) { + String[] nameAndData = { + element.substring(0, element.indexOf("~")), + " " + element.substring(element.indexOf("~"))}; + return nameAndData; + } + + private static Variable createVariable(Model model, String elementString) { + + String[] elementExpressions = elementString.split("\\~\\~\\|"); + + Variable variable = null; + + for(String s : elementExpressions) { + // Skip these definitions at least for now + if(elementExpressions.length > 1 && s.contains("A FUNCTION OF")) + continue; + + Expression expression = new Expression(); + + String[] nameAndData = null; + String name; + + // Create the expression based on the expression string + if((nameAndData = getNormalVariableNameDataAndRange(s)) != null) { + + name = nameAndData[0].replace("\"", ""); + variable = getVariable(model, name); + if(variable == null) { + variable = new Auxiliary(); + variable.setName(name); + model.addElement(variable); + } + + if(!nameAndData[1].trim().endsWith("|")) { + // Multiple expressions + expression.setExpression(nameAndData[1].trim()); + } else { + String[] expressionUnitsAndComments = nameAndData[1].split("[\\~|\\|]"); + expression.setExpression(expressionUnitsAndComments[0].trim()); + } + + } else if((nameAndData = getSubscriptNameAndData(s)) != null) { + + name = nameAndData[0].replace("\"", ""); + variable = getVariable(model, name); + if(variable == null) { + variable = new Subscript(); + variable.setName(name); + model.addElement(variable); + } + + // No support for multidimensional variables. Don't know what that would mean + String[] expressionUnitsAndComments = nameAndData[1].split("[\\~|\\|]"); + expression.setExpression(expressionUnitsAndComments[0].trim()); + variable.setUnits(expressionUnitsAndComments[1].trim()); + variable.setComments(expressionUnitsAndComments[2].trim()); + + } else if((nameAndData = getEquivalenceSubscriptNameAndData(s)) != null) { + + name = nameAndData[0].replace("\"", ""); + variable = getVariable(model, name); + if(variable == null) { + variable = new EquivalenceSubscript(); + variable.setName(name); + model.addElement(variable); + } + + // No support for multidimensional variables. Don't know what that would mean + String[] expressionUnitsAndComments = nameAndData[1].split("[\\~|\\|]"); + expression.setExpression(expressionUnitsAndComments[0].trim()); + variable.setUnits(expressionUnitsAndComments[1].trim()); + variable.setComments(expressionUnitsAndComments[2].trim()); + + } else if((nameAndData = getTableNameDataAndRange(s)) != null) { + + name =(nameAndData[0].replace("\"", "")); + variable = getVariable(model, name); + if(variable == null) { + variable = new Function(); + variable.setName(name); + model.addElement(variable); + } + + String[] expressionUnitsAndComments = nameAndData[1].split("[\\~|\\|]"); + // ([(0,0)-(2,5)],(0,5),(0.5,3),(1,0.5),(2,0.5) => ( ; (0,0)-(2,5) ; ,(0,5),(0.5,3),(1,0.5),(2,0.5) + String table = expressionUnitsAndComments[0].trim().split("[\\[|\\]]")[2]; + // ,(0,5),(0.5,3),(1,0.5),(2,0.5) => (0,5),(0.5,3),(1,0.5),(2,0.5) + table = table.substring(table.indexOf(",") + 1, table.lastIndexOf(")")); + table = "{" + table + "}"; + table = table.replace("(", "{"); + table = table.replace(")", "}"); + expression.setExpression(table); + + + } else if((nameAndData = getDataVariableNameAndData(s)) != null) { + + name = nameAndData[0].replace("\"", ""); + variable = getVariable(model, name); + if(variable == null) { + variable = new Auxiliary(); + variable.setName(name); + model.addElement(variable); + } + + expression.setExpression(""); + } + + if(nameAndData == null || variable == null) + continue; + + // Set possible range for the expression + if(nameAndData.length == 3) + expression.setRange(nameAndData[2]); + + // Set units and comments for the variable + if(nameAndData[1].trim().endsWith("|")) { + String[] expressionUnitsAndComments = nameAndData[1].split("[\\~|\\|]"); + String units = expressionUnitsAndComments[1].trim(); + if(units.contains("[") && + units.contains("]") && + units.lastIndexOf("]") == units.length() - 1) { + // Range definitions are at the end + String range = units.substring( + units.lastIndexOf("[") + 1, + units.length() - 1); + String[] rangeParts = range.split(","); + + try { + variable.setRangeStart(Double.parseDouble(rangeParts[0])); + if(rangeParts.length >= 2) + variable.setRangeEnd(Double.parseDouble(rangeParts[1])); + if(rangeParts.length >= 3) + variable.setRangeStep(Double.parseDouble(rangeParts[2])); + } catch (NumberFormatException e) { + // Not a double + } + expressionUnitsAndComments[1] = units.substring(0, units.lastIndexOf("[")); + } + variable.setUnits(expressionUnitsAndComments[1].trim()); + variable.setComments(expressionUnitsAndComments[2].trim()); + } + + // Finally add the expression to element + variable.getExpressions().add(expression); + } + return variable; + } + + private static int SCALE = 4; + private static void getSketchData(Model model, ArrayList sketchData) { + + String line = null; + View view = null; + int i = 0; + while(i < sketchData.size()) { + line = sketchData.get(i); + if(line.startsWith("*")) { + view = new View(); + model.addView(view); + + view.setName(line.substring(1)); + + // STARTED A NEW VIEW + + HashMap elementNumbers = new HashMap(); + ArrayList ghostNumbers = new ArrayList(); + ArrayList connections = new ArrayList(); + HashMap emptyValves = new HashMap(); // map for valves that don't have an element + + + i++; + line = sketchData.get(i); + while(i < sketchData.size() && !sketchData.get(i).startsWith("*")) { + line = sketchData.get(i); + + if(line.startsWith("$")) { + view.setFontParameters(line); + i++; + continue; + } + + String[] data = line.split(","); + if(data[0].equals("1")) { + // Connections are handled after all elements + String[] connectionData = line.split(","); + connections.add(connectionData); + + } else if(data[0].equals("11")){ + // Valve + i = i + 1; + String elementLine = sketchData.get(i); + String[] elementData = elementLine.split(","); + // FIXME: Assumes that element is always attached to the valve + Element element = model.getElement(elementData[2].replace("\"", "")); + Valve valve = new Valve(); + if(element != null && element instanceof Variable) { + Variable v = (Variable) element; + valve.setName(v.getName()); + valve.setExpressions(v.getExpressions()); + valve.setUnits(v.getUnits()); + valve.setComments(v.getComments()); + valve.setX(Integer.parseInt(data[3]) / SCALE); + valve.setY(Integer.parseInt(data[4]) / SCALE); + + model.removeElement(element); + model.addElement(view, valve); + + // Add valve to the element list with both valve and variable symbol numbers + elementNumbers.put(elementData[1], valve); + elementNumbers.put(data[1], valve); + } else { + i = i - 1; + emptyValves.put(data[1], data); + } + } else if(data[0].equals("12")){ + // Cloud + Cloud cloud = new Cloud(); + cloud.setX(Integer.parseInt(data[3]) / SCALE); + cloud.setY(Integer.parseInt(data[4]) / SCALE); + elementNumbers.put(data[1], cloud); + model.addElement(view, cloud); + } else if(data[0].equals("10") && data.length <= 15){ + // Some variable + Element e = model.getElement(data[2].replace("\"", "").trim()); + if(e != null && e instanceof Variable) { + Variable v = (Variable) e; + if(v.getExpressions().get(0).getExpression().startsWith("INTEG (") && !(e instanceof Stock)) { + // Stock + Stock s = new Stock(); + s.setName(v.getName()); + s.setUnits(v.getUnits()); + s.setComments(v.getComments()); + s.setExpressions(v.getExpressions()); + model.removeElement(e); + e = s; + model.addElement(view, e); + } + } + + e.setX(Integer.parseInt(data[3]) / SCALE); + e.setY(Integer.parseInt(data[4]) / SCALE); + elementNumbers.put(data[1], e); + model.relocateElement(view, e); + } else if(data[0].equals("10") && data.length > 15){ + // TODO: Ghost + // for now, direct back to the original element + Element originalElement = model.getElement(data[2].replace("\"", "")); + if(originalElement != null) { + elementNumbers.put(data[1], originalElement); + ghostNumbers.add(data[1]); + } + } + + i++; + } + i--; + + // Find the first variable that is connected to an empty valve + for(String[] connectionData : connections) { + if(!connectionData[9].equals("64")) + continue; // not dependency + String[] end = emptyValves.get(connectionData[3]); + if(end != null && elementNumbers.get(connectionData[3]) == null) { + // Use the connected element to create a valve and give it a name + Element start = elementNumbers.get(connectionData[2]); + if(start == null) + continue; + + Valve valve = new Valve(); + valve.setName(start.getName() + " Rate"); + valve.setX(Integer.parseInt(end[3]) / SCALE); + valve.setY(Integer.parseInt(end[4]) / SCALE); + + model.addElement(view, valve); + elementNumbers.put(connectionData[3], valve); + valve.setUnits(""); + valve.setComments(""); + } + } + + + + for(String[] connectionData : connections) { + + Element start = elementNumbers.get(connectionData[2]); + Element end = elementNumbers.get(connectionData[3]); + // Discard connection if one of the ends is null + if(start == null || end == null) + continue; + + + Connection connection; + if(connectionData[9].equals("64")) { + // Dependency + Point2D startPoint = new Point2D.Double(start.getX(), start.getY()); + Point2D endPoint = new Point2D.Double(end.getX(), end.getY()); + String controlX = connectionData[13].substring(connectionData[13].indexOf("(") + 1); + String controlY = connectionData[14].substring(0, connectionData[14].indexOf(")")); + Point2D controlPoint = new Point2D.Double(Double.parseDouble(controlX) / SCALE, Double.parseDouble(controlY) / SCALE); + + if(ghostNumbers.contains(connectionData[2]) || + ghostNumbers.contains(connectionData[3])) { + connection = new Dependency(); + } else { + double angle = Dependency.angleOfArc( + startPoint.getX(), startPoint.getY(), + controlPoint.getX(), controlPoint.getY(), + endPoint.getX(), endPoint.getY()); + + connection = new Dependency(angle); + } + + } else { + // Flow + connection = new Flow(); + if(connectionData[4].equals("100")) { + // Flip the flow + Element temp = start; + start = end; + end = temp; + } + } + connection.setStart(start); + connection.setEnd(end); + model.addConnection(connection); + } + + + // Generate expressions for empty valves + for(String key : emptyValves.keySet()) { + Element e = elementNumbers.get(key); + if(e instanceof Valve && ((Valve)e).getExpressions().isEmpty()) { + Valve valve = (Valve)e; + // Find the stock + Stock stock = null; + for(Connection connection : valve.getConnections()) { + if(!(connection instanceof Flow)) + continue; + if(connection.getStart().equals(valve) && + connection.getEnd() instanceof Stock) { + stock = (Stock)connection.getEnd(); + break; + } + } + + // Create the expression. Use the expression of the stock, and undo the effect of other valves + if(stock != null && stock instanceof Stock) { + Expression expression = new Expression(); + + StringBuilder sb = new StringBuilder(); + sb.append(((Stock)stock).getIntegralParts(stock.getExpressions().get(0))[0]); + + for(Connection c : stock.getConnections()) { + if(c instanceof Flow) { + if(c.getStart().equals(stock) && !c.getEnd().equals(valve)) { + sb.append("+"); + sb.append(c.getEnd().getName()); + } else if(!c.getStart().equals(valve)){ + sb.append("-"); + sb.append(c.getStart().getName()); + } + } + } + expression.setExpression(sb.toString()); + ArrayList expressions = new ArrayList(); + expressions.add(expression); + valve.setExpressions(expressions); + } + } + } + } + i++; + } + + } + + private static void getOthertData(Model model, String otherData) { + + } + + private static void setAllSubscripts(Model model) { + + // Set subscripts for all elements + ArrayList elements = new ArrayList(); + elements.addAll(model.getUnlocatedElements()); + for(View view : model.getViews()) { + elements.addAll(view.getElements()); + } + + for(Element e : elements) { + if(!(e instanceof Variable)) + continue; + Variable v = (Variable)e; + v.initializeSubscripts(model); + } + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Auxiliary.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Auxiliary.java new file mode 100644 index 00000000..375878d2 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Auxiliary.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.mdlImport.ImportUtils; + +public class Auxiliary extends Variable { + + @Override + public Resource getExpression(WriteGraph graph, Expression expression) throws DatabaseException { + + SysdynResource sr = SysdynResource.getInstance(graph); + Resource e = GraphUtils.create2(graph, + sr.NormalExpression, + sr.HasEquation, ImportUtils.escapeExpression(expression.getExpression()).trim()); + return e; + } + + @Override + public void write(WriteGraph graph, Resource parent, double xOffset, + double yOffset) { + if(parent == null || graph == null) + return; + + try { + SysdynResource sr = SysdynResource.getInstance(graph); + if(!graph.isInstanceOf(parent, sr.Configuration)) + return; + createVariable(graph, parent, sr.Auxiliary, sr.AuxiliarySymbol, xOffset, yOffset); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Cloud.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Cloud.java new file mode 100644 index 00000000..95a83811 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Cloud.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.sysdyn.SysdynResource; + +public class Cloud extends Element { + + @Override + public void write(WriteGraph graph, Resource parent, double xOffset, + double yOffset) { + if(parent == null || graph == null) + return; + + try { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + DiagramResource dr = DiagramResource.getInstance(graph); + G2DResource g2d = G2DResource.getInstance(graph); + + if(!graph.isInstanceOf(parent, sr.Configuration)) + return; + + Resource diagram = graph.getSingleObject(parent, mr.CompositeToDiagram); + + if(diagram == null) + return; + + Resource cloud = GraphUtils.create2(graph, + sr.Cloud); + + graph.claim(parent, l0.ConsistsOf, cloud); + + + + Resource symbol = GraphUtils.create2(graph, + sr.CloudSymbol, + mr.ElementToComponent, cloud); + + double[] transform = {1.0, 0.0, 0.0, 1.0, getX() + xOffset, getY() + yOffset}; + graph.claimLiteral(symbol, dr.HasTransform, g2d.Transform, transform); + + OrderedSetUtils.add(graph, diagram, symbol); + + setResource(cloud); + + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Connection.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Connection.java new file mode 100644 index 00000000..d6c64469 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Connection.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; + +public abstract class Connection implements IWriteableMDLObject { + protected Element start, end; + + public Resource writeConnection(WriteGraph graph, Resource configuration, Resource connectionType, Resource connectionSymbol) throws DatabaseException { + if(configuration == null || graph == null + || start.getResource() == null || end.getResource() == null) { + return null; + } + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + DiagramResource dr = DiagramResource.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + + Resource diagram = graph.getPossibleObject(configuration, mr.CompositeToDiagram); + Resource startElement = graph.getPossibleObject(start.getResource(), mr.ComponentToElement); + Resource endElement = graph.getPossibleObject(end.getResource(), mr.ComponentToElement); + if(diagram == null || startElement == null || endElement == null) + return null; + + + if(connectionType == null) + connectionType = sr.Dependency; + + if(connectionSymbol == null) + connectionSymbol = sr.DependencyConnection; + + // Build the connection to configuration + Resource connection = GraphUtils.create2(graph, + connectionType, + sr.HasHead, end.getResource(), + sr.HasTail, start.getResource(), + l0.PartOf, configuration); + graph.claim(connection, mr.Mapped, connection); + + + // Build diagram connectors and connection + Resource tailConnector = GraphUtils.create2(graph, + dr.Connector, + sr.HasTailTerminal, startElement); + + Resource headConnector = GraphUtils.create2(graph, + dr.Connector, + sr.HasHeadTerminal, endElement, + dr.AreConnected, tailConnector); + + Resource diagramConnection = GraphUtils.create2(graph, + connectionSymbol, + sr2.HasConnectionType, sr.SysdynConnectionType, + mr.DiagramConnectionToConnection, connection, + dr.HasArrowConnector, headConnector, + dr.HasPlainConnector, tailConnector); + + OrderedSetUtils.add(graph, diagram, diagramConnection); + + return connection; + } + + public Element getStart() { + return start; + } + + public void setStart(Element start) { + this.start = start; + } + + public Element getEnd() { + return end; + } + + public void setEnd(Element end) { + this.end = end; + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Dependency.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Dependency.java new file mode 100644 index 00000000..65b4c60a --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Dependency.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.modeling.ModelingResources; +import org.simantics.sysdyn.SysdynResource; + +public class Dependency extends Connection { + + private double angle; + + public Dependency() { + this(-0.1); + } + + public Dependency(double angle) { + this.angle = angle; + } + + @Override + public void write(WriteGraph graph, Resource parent) { + if(parent == null || graph == null || start == null || end == null) + return; + try { + SysdynResource sr = SysdynResource.getInstance(graph); + Resource connection = writeConnection(graph, parent, sr.Dependency, sr.DependencyConnection); + + if(connection != null) { + ModelingResources mr = ModelingResources.getInstance(graph); + Resource diagramConnection = graph.getSingleObject(connection, mr.ConnectionToDiagramConnection); + graph.claimLiteral(diagramConnection, sr.angle, angle); + } + + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + + public double getAngle() { + return angle; + } + + public void setAngle(double angle) { + this.angle = angle; + } + + + + /** + * Returns an angle in radians between straight line from (x0,y0) to (x2,y2) + * and an arc from (x0,y0) to (x2,y2) thru (x1,y1). The angle + * is measured at (x0,y0) and is between -PI and PI. + */ + public static double angleOfArc( + double x0, double y0, + double x1, double y1, + double x2, double y2) { + double dx0 = x1-x0; + double dy0 = y1-y0; + double dx1 = x1-x2; + double dy1 = y1-y2; + double dx = x2-x0; + double dy = y2-y0; + // Length of cross product (p1-p0)x(p2-p0) + double dd = dx0*dy - dy0*dx; + + if(Math.abs(dd) < 1e-6) // Points are (almost) collinear + return 0.0; + else { + // (p1-p0)*(p1-p2) / dd + double offset = (dx0*dx1 + dy0*dy1) / dd; + double angle = Math.PI*0.5 - Math.atan(offset); + if(dd > 0.0) + angle = angle-Math.PI; + return angle; + + } + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Element.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Element.java new file mode 100644 index 00000000..fb233346 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Element.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import java.util.ArrayList; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; + +public abstract class Element implements IWriteableMDLElement { + + protected int x, y; + protected Resource resource; + protected String name; + protected ArrayList connections; + + protected Resource getExpression(WriteGraph graph, Expression expression) + throws DatabaseException { + return null; + } + + public int getX() { + return x; + } + + public void setX(int x) { + this.x = x; + } + + public int getY() { + return y; + } + + public void setY(int y) { + this.y = y; + } + + public String getName() { + if(name == null) + return "Name"; + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Resource getResource() { + return resource; + } + + public void setResource(Resource resource) { + this.resource = resource; + } + + public ArrayList getConnections() { + if(connections == null) + connections = new ArrayList(); + return connections; + } + + public void setConnections(ArrayList connections) { + this.connections = connections; + } + + public void addConnection(Connection connection) { + getConnections().add(connection); + } +} + diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/EquivalenceSubscript.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/EquivalenceSubscript.java new file mode 100644 index 00000000..74741b30 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/EquivalenceSubscript.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; + +public class EquivalenceSubscript extends Subscript { + + public String getEquivalentToName() { + String name = ""; + if(expressions != null && expressions.get(0) != null) { + name = expressions.get(0).getExpression().trim(); + } + return name; + } + + public void setEquivalentTo(Subscript equivalentTo) { + setExpressions(equivalentTo.getExpressions()); + } + + @Override + public void write(WriteGraph graph, Resource parent, double xOffset, + double yOffset) { + super.write(graph, parent, xOffset, yOffset); + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Expression.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Expression.java new file mode 100644 index 00000000..e36ca60a --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Expression.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + + +public class Expression { + private String range, expression; + + @Override + public String toString() { + return (range != null ? "[" + range + "]: " : "") + expression; + } + + public String getRange() { + return range; + } + + public void setRange(String range) { + this.range = range; + } + + public String getExpression() { + if(expression == null) + return ""; + return expression; + } + + public void setExpression(String expression) { + this.expression = expression; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Flow.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Flow.java new file mode 100644 index 00000000..b8e8e50f --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Flow.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; + +public class Flow extends Connection { + + @Override + public void write(WriteGraph graph, Resource parent) { + if(parent == null || graph == null) + return; + try { + SysdynResource sr = SysdynResource.getInstance(graph); + writeConnection(graph, parent, sr.Flow, sr.FlowConnection); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Function.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Function.java new file mode 100644 index 00000000..faadc02f --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Function.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.mdlImport.ImportUtils; + +public class Function extends Variable { + + @Override + public void write(WriteGraph graph, Resource parent, double xOffset, + double yOffset) { + if(parent == null || graph == null) + return; + + try { + SysdynResource sr = SysdynResource.getInstance(graph); + if(!graph.isInstanceOf(parent, sr.SysdynModel)) + return; + Layer0 l0 = Layer0.getInstance(graph); + + Resource function = GraphUtils.create2(graph, + sr.SysdynModelicaFunction, + l0.HasName, ImportUtils.escapeName(this.getName())); + + if(comments != null && comments.length() > 0) + graph.claimLiteral(function, l0.HasDescription, comments); + + if(expressions != null && expressions.get(0) != null) { + StringBuilder sb = new StringBuilder(); + sb.append(" input Real a;\n"); + sb.append(" output Real result;\n"); + sb.append("algorithm\n"); + sb.append(" result := interpolate(a, " + expressions.get(0).getExpression() + ");"); + graph.claimLiteral(function, sr.HasModelicaFunctionCode, sb.toString()); + } + + graph.claim(parent, l0.ConsistsOf, function); + resource = function; + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/IWriteableMDLElement.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/IWriteableMDLElement.java new file mode 100644 index 00000000..5f0a4250 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/IWriteableMDLElement.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; + +public interface IWriteableMDLElement { + + /** + * Writes an element with coordinates (variable, cloud) to the given resource. + * + * Offsets determine where the parent view is located in the combined diagram + * + * @param graph WriteGraph + * @param parent The resource where the object is located + * @param xOffset xOffset of the view in the diagram + * @param yOffset yOffset of the view in the diagram + */ + public void write(WriteGraph graph, Resource parent, double xOffset, double yOffset); +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/IWriteableMDLObject.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/IWriteableMDLObject.java new file mode 100644 index 00000000..a464cfb0 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/IWriteableMDLObject.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; + +public interface IWriteableMDLObject { + + /** + * Writes an object with no coordinates (connection, model, view) to the given resource + * + * @param graph WriteGraph + * @param parent The resource where the object is located + */ + public void write(WriteGraph graph, Resource parent); +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Model.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Model.java new file mode 100644 index 00000000..48cc1fce --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Model.java @@ -0,0 +1,328 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.Template; +import org.simantics.document.DocumentResource; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.operation.Layer0X; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.utils.datastructures.ArrayMap; + +public class Model implements IWriteableMDLObject { + + private String name, timeUnit, saveper; + private double startTime = 0, endTime = 10, timeStep = 1; + + private HashMap elementMap = new HashMap(); + private ArrayList subscripts = new ArrayList(); + private ArrayList functions = new ArrayList(); + private ArrayList connections = new ArrayList(); + private ArrayList views = new ArrayList(); + private ArrayList unlocatedElements = new ArrayList(); + + public void addElement(Element element) { + if(element instanceof Subscript) + addSubscript((Subscript)element); + else if(element instanceof Function) + addFunction((Function)element); + else + unlocatedElements.add(element); + if(element.getName() != null) + elementMap.put(element.getName(), element); + } + + public void addSubscript(Subscript subscript) { + subscripts.add(subscript); + } + + public void addFunction(Function function) { + functions.add(function); + } + + public void addElement(View view, Element element) { + if(element instanceof Subscript) + addSubscript((Subscript)element); + else { + if(unlocatedElements.contains(element)) + unlocatedElements.remove(element); + view.addElement(element); + } + if(element.getName() != null) + elementMap.put(element.getName(), element); + } + + public void relocateElement(View view, Element element) { + if(unlocatedElements.contains(element)) + unlocatedElements.remove(element); + for(View v : views) { + if(v.getElements().contains(element)) + v.getElements().remove(element); + } + view.addElement(element); + } + + public void removeElement(Element element) { + if(unlocatedElements.contains(element)) + unlocatedElements.remove(element); + + for(View view : views) { + if(view.getElements().contains(element)) { + view.getElements().remove(element); + } + } + + // just to be sure: loop the whole elementMap and don't trust the element's name + String toBeRemoved = null; + for(String key : elementMap.keySet()) { + if(element.equals(elementMap.get(key))) { + toBeRemoved = key; + break; + } + } + if(toBeRemoved != null) + elementMap.remove(toBeRemoved); + } + + public ArrayList getUnlocatedElements() { + return unlocatedElements; + } + + public Element getElement(String name) { + return elementMap.get(name); + } + + public void addConnection(Connection connection) { + connections.add(connection); + if(connection.getStart() != null && + !connection.getStart().getConnections().contains(connection)) { + connection.getStart().addConnection(connection); + } + if(connection.getEnd() != null && + !connection.getEnd().getConnections().contains(connection)) { + connection.getEnd().addConnection(connection); + } + } + + public ArrayList getConnections() { + return connections; + } + + public ArrayList getSubscripts() { + return subscripts; + } + + public String getName() { + if(name == null) + return "ModelName"; + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getTimeUnit() { + return timeUnit; + } + + public void setTimeUnit(String timeUnit) { + this.timeUnit = timeUnit; + } + + public String getSaveper() { + return saveper; + } + + public void setSaveper(String saveper) { + this.saveper = saveper; + } + + public double getStartTime() { + return startTime; + } + + public void setStartTime(double startTime) { + this.startTime = startTime; + } + + public double getEndTime() { + return endTime; + } + + public void setEndTime(double endTime) { + this.endTime = endTime; + } + + public double getTimeStep() { + return timeStep; + } + + public void setTimeStep(double timeStep) { + this.timeStep = timeStep; + } + + public HashMap getElementMap() { + return elementMap; + } + + public void setElementMap(HashMap elementMap) { + this.elementMap = elementMap; + } + + public void setSubscripts(ArrayList subscripts) { + this.subscripts = subscripts; + } + + public void setConnections(ArrayList connections) { + this.connections = connections; + } + + public void addView(View view) { + views.add(view); + } + + public ArrayList getViews() { + return views; + } + + /** + * Write the model to a project + * @param graph WriteGraph + * @param parent Project resource + */ + @Override + public void write(WriteGraph graph, Resource parent) { + if(parent == null || graph == null) + return; + + try { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Layer0X L0X = Layer0X.getInstance(graph); + SimulationResource simu = SimulationResource.getInstance(graph); + DocumentResource DOC = DocumentResource.getInstance(graph); + + // Diagram creation copied from SysdynProject. + // Could the same code be reused? + + Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.1"); + Resource layer0 = graph.getResource("http://www.simantics.org/Layer0-1.1"); + + Resource model = GraphUtils.create2( + graph, + sr.SysdynModel, + l0.PartOf, parent, + l0.HasName, NameUtils.findFreshName(graph, getName(), parent, l0.ConsistsOf, "%s%d"), + l0.HasLabel, getName(), + sr.HasStartTime, startTime, + sr.HasStopTime, endTime, + l0.IsLinkedTo, sysdyn, + l0.IsLinkedTo, layer0 + ); + + + Resource conf = GraphUtils.create2(graph, + sr.Configuration, + l0.PartOf, model, + l0.HasName, getName() + ); + + Resource diagram = graph.newResource(); + graph.adapt(sr.ConfigurationDiagramTemplate, Template.class).apply(graph, + ArrayMap + .keys("", "diagram", "name") + .values(conf, diagram, "Diagrammi") + ); + + + ModelingResources mr = ModelingResources.getInstance(graph); + // Remove default mapping and add sysdyn mapping + for(Resource trigger : graph.getObjects(diagram, L0X.HasTrigger)) { + if(graph.isInstanceOf(trigger, mr.DiagramToCompositeMapping)) { + graph.deny(diagram, L0X.HasTrigger, trigger); + } + } + Resource mapping = graph.newResource(); + graph.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); + graph.claim(diagram, L0X.HasTrigger, mapping); + + graph.claim(model, simu.HasConfiguration, conf); + graph.claim(model, L0X.HasBaseRealization, conf); + + Resource report = GraphUtils.create2(graph, DOC.Report, DOC.HasDocumentation, "===Report==="); + + GraphUtils.create2(graph, simu.Experiment, + l0.HasName, "Experiment", + l0.HasLabel, "Experiment", + DOC.HasReportFactory, report, + l0.PartOf, model); + + for(Subscript s : subscripts) { + s.write(graph, conf, 0, 0); + } + + // Create the grid n*n of views: + + double n = Math.sqrt(views.size()); + n = Math.ceil(n); + + int width = 0, height = 0; + for(View v : views) { + if(v.getWidth() > width) + width = v.getWidth(); + if(v.getHeight() > height) + height = v.getHeight(); + } + + for(int i = 0; i < n; i++) { + for(int j = 0; j < n; j++) { + int index = i * (int)n + j; + if(index < views.size()) { + View v = views.get(index); + v.setxOffset(width * j); + v.setyOffset(height * i); + v.write(graph, conf); + } + } + } + + for(Element e : unlocatedElements) { + e.write(graph, conf, 0, 0); + } + + for(Connection c : connections) { + c.write(graph, conf); + } + + for(Function f : functions) { + f.write(graph, model, 0, 0); + } + + + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/ModelControl.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/ModelControl.java new file mode 100644 index 00000000..8197c773 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/ModelControl.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; + +public class ModelControl extends Variable { + + + + @Override + public Resource getExpression(WriteGraph graph, Expression expression) + throws DatabaseException { + return null; + } + + @Override + public void write(WriteGraph graph, Resource parent, double xOffset, + double yOffset) { + // TODO Auto-generated method stub + + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Stock.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Stock.java new file mode 100644 index 00000000..e3437f38 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Stock.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.mdlImport.ImportUtils; + +public class Stock extends Variable { + + @Override + public Resource getExpression(WriteGraph graph, Expression expression) throws DatabaseException { + + String integralEquation = ImportUtils.escapeExpression(getIntegralParts(expression)[1]); + SysdynResource sr = SysdynResource.getInstance(graph); + Resource e = GraphUtils.create2(graph, + sr.StockExpression, + sr.HasInitialEquation, integralEquation); + + return e; + } + + public String[] getIntegralParts(Expression expression) { + // Does not work, if the integral has some other logic than +inflows -outflows! + + // Parsing the possible functions. Searching ',' that divides the INTEG -function + int parenthesiscount = 0; + int location = 0; + char[] charArray = expression.getExpression().toCharArray(); + for(int i = 0; i < charArray.length; i++) { + char c = charArray[i]; + if(c == '(') + parenthesiscount++; + else if(c == ')') + parenthesiscount--; + else if(c == ',' && parenthesiscount == 1) { + location = i + 1; + break; + } + } + + String exp = expression.getExpression(); + String initialEquation = exp.substring(location, exp.lastIndexOf(')')).trim(); + String integral = exp.substring(exp.indexOf("(") + 1, location - 1).trim(); + + + return new String[] {integral, initialEquation}; + } + + @Override + public void write(WriteGraph graph, Resource parent, double xOffset, + double yOffset) { + if(parent == null || graph == null) + return; + + try { + SysdynResource sr = SysdynResource.getInstance(graph); + if(!graph.isInstanceOf(parent, sr.Configuration)) + return; + createVariable(graph, parent, sr.Stock, sr.StockSymbol, xOffset, yOffset); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Subscript.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Subscript.java new file mode 100644 index 00000000..40ca4761 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Subscript.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; + +public class Subscript extends Variable { + + @Override + public Resource getExpression(WriteGraph graph, Expression expression) + throws DatabaseException { + return null; + } + + @Override + public void write(WriteGraph graph, Resource parent, double xOffset, + double yOffset) { + if(parent == null || graph == null) + return; + + try { + SysdynResource sr = SysdynResource.getInstance(graph); + if(!graph.isInstanceOf(parent, sr.Configuration)) + return; + Layer0 l0 = Layer0.getInstance(graph); + Resource enumerationIndexes = OrderedSetUtils.create(graph, sr.EnumerationIndexes); + + if(expressions != null && expressions.get(0) != null) { + String[] indexes = expressions.get(0).getExpression().split(","); + for(String s : indexes) { + Resource ei = GraphUtils.create2(graph, + sr.EnumerationIndex, + l0.HasName, s.trim()); + OrderedSetUtils.add(graph, enumerationIndexes, ei); + } + } + + Resource enumeration = GraphUtils.create2(graph, + sr.Enumeration, + l0.HasName, this.getName(), + sr.HasEnumerationIndexes, enumerationIndexes); + + graph.claim(parent, l0.ConsistsOf, enumeration); + + resource = enumeration; + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Valve.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Valve.java new file mode 100644 index 00000000..e3987d15 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Valve.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.mdlImport.ImportUtils; + +public class Valve extends Variable { + + @Override + public Resource getExpression(WriteGraph graph, Expression expression) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + String expressionString = ImportUtils.escapeExpression(expression.getExpression()); + Resource e = GraphUtils.create2(graph, + sr.NormalExpression, + sr.HasEquation, expressionString.trim()); + return e; + } + + @Override + public void write(WriteGraph graph, Resource parent, double xOffset, + double yOffset) { + try { + SysdynResource sr = SysdynResource.getInstance(graph); + if(!graph.isInstanceOf(parent, sr.Configuration)) + return; + createVariable(graph, parent, sr.Valve, sr.ValveSymbol, xOffset, yOffset); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Variable.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Variable.java new file mode 100644 index 00000000..126dd35e --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/Variable.java @@ -0,0 +1,213 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import java.util.ArrayList; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.mdlImport.ImportUtils; + +public abstract class Variable extends Element { + protected String units; + protected String comments; + protected ArrayList expressions; + protected ArrayList subscripts; + + private Double rangeStart, rangeEnd, rangeStep; + + protected void createVariable(WriteGraph graph, Resource configuration, Resource variableType, Resource symbolType, double xOffset, double yOffset) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + ModelingResources mr = ModelingResources.getInstance(graph); + DiagramResource dr = DiagramResource.getInstance(graph); + G2DResource g2d = G2DResource.getInstance(graph); + + Resource diagram = graph.getSingleObject(configuration, mr.CompositeToDiagram); + if(diagram == null) + return; + + Resource expressionList = OrderedSetUtils.create(graph, sr.Expressions); + + // Make sure at least one expression exist + if(getExpressions().isEmpty()) { + Expression e = new Expression(); + e.setExpression(""); + getExpressions().add(e); + } + + Resource arrayIndexList = OrderedSetUtils.create(graph, sr.ArrayIndexes); + + + Resource variable = GraphUtils.create2(graph, + variableType, + l0.HasName, ImportUtils.escapeName(name), + sr.HasExpressions, expressionList); + graph.claim(variable, mr.Mapped, variable); + + for(Expression e : getExpressions()) { + + // Get expression from the variable. They have different types + Resource expression = getExpression(graph, e); + + if(e.getRange() != null) { + graph.claimLiteral(expression, sr.HasArrayRange, "[" + e.getRange().trim() + "]"); + } + OrderedSetUtils.add(graph, expressionList, expression); + graph.claim(variable, l0.ConsistsOf, expression); + } + + if(subscripts != null) { + for(Subscript sub : subscripts) { + if(sub.getResource() != null) + OrderedSetUtils.add(graph, arrayIndexList, sub.getResource()); + } + graph.claim(variable, sr.HasArrayIndexes, arrayIndexList); + } + + if(units != null && units.length() > 0) + graph.claimLiteral(variable, sr.HasUnit, units); + if(comments != null && comments.length() > 0) + graph.claimLiteral(variable, l0.HasDescription, comments); + if(rangeStart != null) + graph.claimLiteral(variable, sr.HasRangeStart, rangeStart); + if(rangeEnd != null) + graph.claimLiteral(variable, sr.HasRangeEnd, rangeEnd); + if(rangeStep != null) + graph.claimLiteral(variable, sr.HasRangeStep, rangeStep); + + graph.claim(configuration, l0.ConsistsOf, variable); + + + Resource symbol = GraphUtils.create2(graph, + symbolType, + mr.ElementToComponent, variable); + + double[] transform = {1.0, 0.0, 0.0, 1.0, x + xOffset, y + yOffset}; + graph.claimLiteral(symbol, dr.HasTransform, g2d.Transform, transform); + + OrderedSetUtils.add(graph, diagram, symbol); + + resource = variable; + } + + + public String getUnits() { + return units; + } + + public void setUnits(String units) { + this.units = units; + } + + public String getComments() { + return comments; + } + + public void setComments(String comments) { + this.comments = comments; + } + + public ArrayList getExpressions() { + if(expressions == null) { + expressions = new ArrayList(); + } + return expressions; + } + + public void setExpressions(ArrayList expressions) { + this.expressions = expressions; + } + + public ArrayList getSubscripts() { + if(subscripts == null) + subscripts = new ArrayList(); + return subscripts; + } + + public void setSubscripts(ArrayList subscripts) { + this.subscripts = subscripts; + } + + + public Double getRangeStart() { + return rangeStart; + } + + public void setRangeStart(Double rangeStart) { + this.rangeStart = rangeStart; + } + + public Double getRangeEnd() { + return rangeEnd; + } + + public void setRangeEnd(Double rangeEnd) { + this.rangeEnd = rangeEnd; + } + + public Double getRangeStep() { + return rangeStep; + } + + public void setRangeStep(Double rangeStep) { + this.rangeStep = rangeStep; + } + + /** + * Use this to set subscripts after all elements have been read + * + * @param model The model where the variable is located + */ + public void initializeSubscripts(Model model) { + for(Expression ex : getExpressions()) { + if(ex.getRange() != null) { + + // Subscripts exist, check that subscripts -array is initialized + getSubscripts(); + + String[] elements = ex.getRange().split(","); + // Search the corresponding subscript for each element, if it has not been searched already + for(int i = 0; i < elements.length; i++) { + // The subscript has been defined, move to next + if(subscripts.size() > i) + continue; + + String element = elements[i].trim(); + for(Subscript sub : model.getSubscripts()) { + if(sub.getName().equals(element)) { + subscripts.add(sub); + break; + } + for(String index : sub.getExpressions().get(0).getExpression().split(",")) { + if(index.trim().equals(element)) { + subscripts.add(sub); + break; + } + } + // Subscript was defined for this index in previous for-loop + if(subscripts.size() == i + 1) + break; + } + } + } + } + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/View.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/View.java new file mode 100644 index 00000000..88fe41e6 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/mdlImport/mdlElements/View.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.mdlImport.mdlElements; + +import java.util.ArrayList; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; + +public class View implements IWriteableMDLObject { + + private int minX = 0, maxX = 0, minY = 0, maxY = 0; + private double xOffset = 0, yOffset = 0; + private String name, fontParameters; + + private ArrayList elements = new ArrayList(); + + + @Override + public void write(WriteGraph graph, Resource parent) { + xOffset = xOffset - minX; + yOffset = yOffset - minY; + for(Element e : elements) { + e.write(graph, parent, xOffset, yOffset); + } + } + + public void addElement(Element e) { + if(e instanceof Subscript || + e instanceof Function) + return; + + if(e.getX()maxX) + maxX = e.getX(); + if(e.getY()maxY) + maxY = e.getY(); + this.elements.add(e); + } + + public ArrayList getElements() { + return elements; + } + + public void setElements(ArrayList elements) { + this.elements = elements; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + public String getFontParameters() { + return fontParameters; + } + + + public void setFontParameters(String fontParameters) { + this.fontParameters = fontParameters; + } + + + public int getMinX() { + return minX; + } + + public void setMinX(int minX) { + this.minX = minX; + } + + public int getMaxX() { + return maxX; + } + + public void setMaxX(int maxX) { + this.maxX = maxX; + } + + public int getMinY() { + return minY; + } + + public void setMinY(int minY) { + this.minY = minY; + } + + public int getMaxY() { + return maxY; + } + + public void setMaxY(int maxY) { + this.maxY = maxY; + } + + public double getxOffset() { + return xOffset; + } + + public void setxOffset(double xOffset) { + this.xOffset = xOffset; + } + + public double getyOffset() { + return yOffset; + } + + public void setyOffset(double yOffset) { + this.yOffset = yOffset; + } + + public int getWidth() { + return maxX - minX; + } + + public int getHeight() { + return maxY - minY; + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ModelParser.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ModelParser.java new file mode 100644 index 00000000..b069dc03 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ModelParser.java @@ -0,0 +1,3728 @@ +/* Generated By:JavaCC: Do not edit this line. ModelParser.java */ +package org.simantics.sysdyn.modelParser; + +public class ModelParser implements ModelParserConstants { + +/*** Parser ********************************************************/ + +// https://javacc.dev.java.net/doc/javaccgrm.html +// add_op -> add_op() +// [ add_op ] -> ( add_op() )? +// { add_op term } -> ( add_op() term() )* + final public void parse() throws ParseException { + stored_definition(); + jj_consume_token(0); + } + +/*** Stored Definition - Within ************************************/ + final public void stored_definition() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 53: + jj_consume_token(53); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + case IDENT: + name(); + break; + default: + jj_la1[0] = jj_gen; + ; + } + jj_consume_token(70); + break; + default: + jj_la1[1] = jj_gen; + ; + } + label_1: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 7: + case 11: + case 17: + case 24: + case 26: + case 30: + case 34: + case 37: + case 38: + case 44: + case 47: + case 50: + case 61: + case 94: + case 95: + ; + break; + default: + jj_la1[2] = jj_gen; + break label_1; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 11: + jj_consume_token(11); + break; + default: + jj_la1[3] = jj_gen; + ; + } + class_definition(); + jj_consume_token(70); + } + } + +/*** Class Definition **********************************************/ + final public void class_definition() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 30: + jj_consume_token(30); + break; + default: + jj_la1[4] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 47: + jj_consume_token(47); + break; + default: + jj_la1[5] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 34: + jj_consume_token(34); + break; + case 7: + jj_consume_token(7); + break; + case 61: + jj_consume_token(61); + break; + case 24: + jj_consume_token(24); + break; + case 44: + case 50: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 50: + jj_consume_token(50); + break; + default: + jj_la1[6] = jj_gen; + ; + } + jj_consume_token(44); + break; + case 38: + jj_consume_token(38); + break; + case 37: + jj_consume_token(37); + break; + case 26: + jj_consume_token(26); + break; + case 17: + jj_consume_token(17); + break; + case 94: + jj_consume_token(94); + break; + case 95: + jj_consume_token(95); + break; + default: + jj_la1[7] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + class_specifier(); + } + + final public void class_specifier() throws ParseException { + if (jj_2_1(2)) { + jj_consume_token(IDENT); + string_comment(); + composition(); + jj_consume_token(35); + jj_consume_token(IDENT); + } else if (jj_2_2(2)) { + jj_consume_token(IDENT); + jj_consume_token(88); + base_prefix(); + name(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 66: + array_subscripts(); + break; + default: + jj_la1[8] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 62: + class_modification(); + break; + default: + jj_la1[9] = jj_gen; + ; + } + comment(); + } else if (jj_2_3(3)) { + jj_consume_token(IDENT); + jj_consume_token(88); + jj_consume_token(40); + jj_consume_token(62); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IDENT: + enum_list(); + break; + default: + jj_la1[10] = jj_gen; + ; + } + jj_consume_token(63); + comment(); + } else if (jj_2_4(3)) { + jj_consume_token(IDENT); + jj_consume_token(88); + jj_consume_token(58); + jj_consume_token(62); + name(); + jj_consume_token(71); + jj_consume_token(IDENT); + label_2: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + ; + break; + default: + jj_la1[11] = jj_gen; + break label_2; + } + jj_consume_token(71); + jj_consume_token(IDENT); + } + jj_consume_token(63); + comment(); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 55: + jj_consume_token(55); + jj_consume_token(IDENT); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 62: + class_modification(); + break; + default: + jj_la1[12] = jj_gen; + ; + } + string_comment(); + composition(); + jj_consume_token(35); + jj_consume_token(IDENT); + break; + default: + jj_la1[13] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + + final public void base_prefix() throws ParseException { + type_prefix(); + } + + final public void enum_list() throws ParseException { + enumeration_literal(); + label_3: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + ; + break; + default: + jj_la1[14] = jj_gen; + break label_3; + } + jj_consume_token(71); + enumeration_literal(); + } + } + + final public void enumeration_literal() throws ParseException { + jj_consume_token(IDENT); + comment(); + } + + final public void parse_composition() throws ParseException { + composition(); + jj_consume_token(0); + } + + final public void composition() throws ParseException { + element_list(); + label_4: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 4: + case 45: + case 46: + case 52: + case 57: + ; + break; + default: + jj_la1[15] = jj_gen; + break label_4; + } + if (jj_2_5(2)) { + jj_consume_token(57); + element_list(); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 52: + jj_consume_token(52); + element_list(); + break; + case 45: + case 46: + equation_section(); + break; + case 4: + algorithm_section(); + break; + default: + jj_la1[16] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 59: + jj_consume_token(59); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + language_specification(); + break; + default: + jj_la1[17] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + case IDENT: + external_function_call(); + break; + default: + jj_la1[18] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 14: + annotation(); + break; + default: + jj_la1[19] = jj_gen; + ; + } + jj_consume_token(70); + break; + default: + jj_la1[20] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 14: + annotation(); + jj_consume_token(70); + break; + default: + jj_la1[21] = jj_gen; + ; + } + } + + final public void language_specification() throws ParseException { + jj_consume_token(STRING); + } + + final public void external_function_call() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + case IDENT: + component_reference(); + jj_consume_token(88); + break; + default: + jj_la1[22] = jj_gen; + ; + } + jj_consume_token(IDENT); + jj_consume_token(62); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 31: + case 33: + case 35: + case 46: + case 58: + case 62: + case 64: + case 66: + case 68: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + expression_list(); + break; + default: + jj_la1[23] = jj_gen; + ; + } + jj_consume_token(63); + } + + final public void element_list() throws ParseException { + label_5: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 5: + case 7: + case 8: + case 11: + case 13: + case 16: + case 17: + case 23: + case 24: + case 26: + case 27: + case 30: + case 32: + case 34: + case 36: + case 37: + case 38: + case 42: + case 44: + case 47: + case 49: + case 50: + case 51: + case 55: + case 56: + case 61: + case 68: + case IDENT: + case 94: + case 95: + ; + break; + default: + jj_la1[24] = jj_gen; + break label_5; + } + element(); + jj_consume_token(70); + } + } + + final public void element() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 36: + import_clause(); + break; + case 55: + extends_clause(); + break; + case 5: + case 7: + case 8: + case 11: + case 13: + case 16: + case 17: + case 23: + case 24: + case 26: + case 27: + case 30: + case 32: + case 34: + case 37: + case 38: + case 42: + case 44: + case 47: + case 49: + case 50: + case 51: + case 56: + case 61: + case 68: + case IDENT: + case 94: + case 95: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 8: + jj_consume_token(8); + break; + default: + jj_la1[25] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 11: + jj_consume_token(11); + break; + default: + jj_la1[26] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 51: + jj_consume_token(51); + break; + default: + jj_la1[27] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 27: + jj_consume_token(27); + break; + default: + jj_la1[28] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 5: + case 7: + case 16: + case 17: + case 23: + case 24: + case 26: + case 30: + case 32: + case 34: + case 37: + case 38: + case 42: + case 44: + case 47: + case 49: + case 50: + case 56: + case 61: + case 68: + case IDENT: + case 94: + case 95: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 7: + case 17: + case 24: + case 26: + case 30: + case 34: + case 37: + case 38: + case 44: + case 47: + case 50: + case 61: + case 94: + case 95: + class_definition(); + break; + case 5: + case 16: + case 23: + case 32: + case 42: + case 49: + case 56: + case 68: + case IDENT: + component_clause(); + break; + default: + jj_la1[29] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + case 13: + jj_consume_token(13); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 7: + case 17: + case 24: + case 26: + case 30: + case 34: + case 37: + case 38: + case 44: + case 47: + case 50: + case 61: + case 94: + case 95: + class_definition(); + break; + case 5: + case 16: + case 23: + case 32: + case 42: + case 49: + case 56: + case 68: + case IDENT: + component_clause(); + break; + default: + jj_la1[30] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 54: + constraining_clause(); + comment(); + break; + default: + jj_la1[31] = jj_gen; + ; + } + break; + default: + jj_la1[32] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[33] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void import_clause() throws ParseException { + jj_consume_token(36); + if (jj_2_6(2)) { + jj_consume_token(IDENT); + jj_consume_token(88); + name(); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + case IDENT: + name(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + jj_consume_token(68); + jj_consume_token(82); + break; + default: + jj_la1[34] = jj_gen; + ; + } + break; + default: + jj_la1[35] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + comment(); + } + +/*** Extends *******************************************************/ + final public void extends_clause() throws ParseException { + jj_consume_token(55); + name(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 62: + class_modification(); + break; + default: + jj_la1[36] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 14: + annotation(); + break; + default: + jj_la1[37] = jj_gen; + ; + } + } + + final public void constraining_clause() throws ParseException { + jj_consume_token(54); + name(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 62: + class_modification(); + break; + default: + jj_la1[38] = jj_gen; + ; + } + } + +/*** Component Clause **********************************************/ + final public void component_clause() throws ParseException { + type_prefix(); + type_specifier(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 66: + array_subscripts(); + break; + default: + jj_la1[39] = jj_gen; + ; + } + component_list(); + } + + final public void type_prefix() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 16: + case 23: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 16: + jj_consume_token(16); + break; + case 23: + jj_consume_token(23); + break; + default: + jj_la1[40] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[41] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 5: + case 42: + case 49: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 5: + jj_consume_token(5); + break; + case 42: + jj_consume_token(42); + break; + case 49: + jj_consume_token(49); + break; + default: + jj_la1[42] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[43] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 32: + case 56: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 56: + jj_consume_token(56); + break; + case 32: + jj_consume_token(32); + break; + default: + jj_la1[44] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[45] = jj_gen; + ; + } + } + + final public void type_specifier() throws ParseException { + name(); + } + + final public void component_list() throws ParseException { + component_declaration(); + label_6: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + ; + break; + default: + jj_la1[46] = jj_gen; + break label_6; + } + jj_consume_token(71); + component_declaration(); + } + } + + final public void component_declaration() throws ParseException { + declaration(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 31: + conditional_attribute(); + break; + default: + jj_la1[47] = jj_gen; + ; + } + comment(); + } + + final public void conditional_attribute() throws ParseException { + jj_consume_token(31); + expression(); + } + + final public void declaration() throws ParseException { + jj_consume_token(IDENT); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 66: + array_subscripts(); + break; + default: + jj_la1[48] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 62: + case 88: + case 89: + modification(); + break; + default: + jj_la1[49] = jj_gen; + ; + } + } + +/*** Modification **********************************************/ + final public void modification() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 62: + class_modification(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 88: + jj_consume_token(88); + expression(); + break; + default: + jj_la1[50] = jj_gen; + ; + } + break; + case 88: + jj_consume_token(88); + expression(); + break; + case 89: + jj_consume_token(89); + expression(); + break; + default: + jj_la1[51] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void class_modification() throws ParseException { + jj_consume_token(62); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 8: + case 10: + case 11: + case 13: + case 68: + case IDENT: + argument_list(); + break; + default: + jj_la1[52] = jj_gen; + ; + } + jj_consume_token(63); + } + + final public void argument_list() throws ParseException { + argument(); + label_7: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + ; + break; + default: + jj_la1[53] = jj_gen; + break label_7; + } + jj_consume_token(71); + argument(); + } + } + + final public void argument() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 10: + case 11: + case 13: + case 68: + case IDENT: + element_modification_or_replaceable(); + break; + case 8: + element_redeclaration(); + break; + default: + jj_la1[54] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void element_modification_or_replaceable() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 10: + jj_consume_token(10); + break; + default: + jj_la1[55] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 11: + jj_consume_token(11); + break; + default: + jj_la1[56] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + case IDENT: + element_modification(); + break; + case 13: + element_replaceable(); + break; + default: + jj_la1[57] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void element_modification() throws ParseException { + name(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 62: + case 88: + case 89: + modification(); + break; + default: + jj_la1[58] = jj_gen; + ; + } + string_comment(); + } + + final public void element_redeclaration() throws ParseException { + jj_consume_token(8); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 10: + jj_consume_token(10); + break; + default: + jj_la1[59] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 11: + jj_consume_token(11); + break; + default: + jj_la1[60] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 5: + case 7: + case 16: + case 17: + case 23: + case 24: + case 26: + case 30: + case 32: + case 34: + case 37: + case 38: + case 42: + case 44: + case 47: + case 49: + case 50: + case 56: + case 61: + case 68: + case IDENT: + case 94: + case 95: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 7: + case 17: + case 24: + case 26: + case 30: + case 34: + case 37: + case 38: + case 44: + case 47: + case 50: + case 61: + case 94: + case 95: + class_definition(); + break; + case 5: + case 16: + case 23: + case 32: + case 42: + case 49: + case 56: + case 68: + case IDENT: + component_clause1(); + break; + default: + jj_la1[61] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + case 13: + element_replaceable(); + break; + default: + jj_la1[62] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void element_replaceable() throws ParseException { + jj_consume_token(13); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 7: + case 17: + case 24: + case 26: + case 30: + case 34: + case 37: + case 38: + case 44: + case 47: + case 50: + case 61: + case 94: + case 95: + class_definition(); + break; + case 5: + case 16: + case 23: + case 32: + case 42: + case 49: + case 56: + case 68: + case IDENT: + component_clause1(); + break; + default: + jj_la1[63] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 54: + constraining_clause(); + break; + default: + jj_la1[64] = jj_gen; + ; + } + } + + final public void component_clause1() throws ParseException { + type_prefix(); + type_specifier(); + component_declaration1(); + } + + final public void component_declaration1() throws ParseException { + declaration(); + comment(); + } + +/*** Equations *************************************************/ + final public void equation_section() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 46: + jj_consume_token(46); + break; + default: + jj_la1[65] = jj_gen; + ; + } + jj_consume_token(45); + label_8: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 21: + case 31: + case 33: + case 35: + case 39: + case 43: + case 46: + case 58: + case 62: + case 64: + case 66: + case 68: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + ; + break; + default: + jj_la1[66] = jj_gen; + break label_8; + } + equation(); + jj_consume_token(70); + } + } + + final public void algorithm_section() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 46: + jj_consume_token(46); + break; + default: + jj_la1[67] = jj_gen; + ; + } + jj_consume_token(4); + label_9: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 18: + case 21: + case 29: + case 31: + case 43: + case 48: + case 62: + case 68: + case IDENT: + ; + break; + default: + jj_la1[68] = jj_gen; + break label_9; + } + statement(); + jj_consume_token(70); + } + } + + final public void equation() throws ParseException { + if (jj_2_7(3)) { + simple_expression(); + jj_consume_token(88); + expression(); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 31: + if_equation(); + break; + case 21: + for_equation(); + break; + case 39: + connect_clause(); + break; + case 43: + when_equation(); + break; + case IDENT: + jj_consume_token(IDENT); + function_call_args(); + break; + default: + jj_la1[69] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + comment(); + } + + final public void statement() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + case IDENT: + component_reference(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 89: + jj_consume_token(89); + expression(); + break; + case 62: + function_call_args(); + break; + default: + jj_la1[70] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + case 62: + jj_consume_token(62); + output_expression_list(); + jj_consume_token(63); + jj_consume_token(89); + component_reference(); + function_call_args(); + break; + case 29: + jj_consume_token(29); + break; + case 18: + jj_consume_token(18); + break; + case 31: + if_statement(); + break; + case 21: + for_statement(); + break; + case 48: + while_statement(); + break; + case 43: + when_statement(); + break; + default: + jj_la1[71] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + comment(); + } + + final public void if_equation() throws ParseException { + jj_consume_token(31); + expression(); + jj_consume_token(28); + label_10: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 21: + case 31: + case 33: + case 35: + case 39: + case 43: + case 46: + case 58: + case 62: + case 64: + case 66: + case 68: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + ; + break; + default: + jj_la1[72] = jj_gen; + break label_10; + } + equation(); + jj_consume_token(70); + } + label_11: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 20: + ; + break; + default: + jj_la1[73] = jj_gen; + break label_11; + } + jj_consume_token(20); + expression(); + jj_consume_token(28); + label_12: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 21: + case 31: + case 33: + case 35: + case 39: + case 43: + case 46: + case 58: + case 62: + case 64: + case 66: + case 68: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + ; + break; + default: + jj_la1[74] = jj_gen; + break label_12; + } + equation(); + jj_consume_token(70); + } + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 15: + jj_consume_token(15); + label_13: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 21: + case 31: + case 33: + case 35: + case 39: + case 43: + case 46: + case 58: + case 62: + case 64: + case 66: + case 68: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + ; + break; + default: + jj_la1[75] = jj_gen; + break label_13; + } + equation(); + jj_consume_token(70); + } + break; + default: + jj_la1[76] = jj_gen; + ; + } + jj_consume_token(35); + jj_consume_token(31); + } + + final public void if_statement() throws ParseException { + jj_consume_token(31); + expression(); + jj_consume_token(28); + label_14: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 18: + case 21: + case 29: + case 31: + case 43: + case 48: + case 62: + case 68: + case IDENT: + ; + break; + default: + jj_la1[77] = jj_gen; + break label_14; + } + statement(); + jj_consume_token(70); + } + label_15: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 20: + ; + break; + default: + jj_la1[78] = jj_gen; + break label_15; + } + jj_consume_token(20); + expression(); + jj_consume_token(28); + label_16: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 18: + case 21: + case 29: + case 31: + case 43: + case 48: + case 62: + case 68: + case IDENT: + ; + break; + default: + jj_la1[79] = jj_gen; + break label_16; + } + statement(); + jj_consume_token(70); + } + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 15: + jj_consume_token(15); + label_17: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 18: + case 21: + case 29: + case 31: + case 43: + case 48: + case 62: + case 68: + case IDENT: + ; + break; + default: + jj_la1[80] = jj_gen; + break label_17; + } + statement(); + jj_consume_token(70); + } + break; + default: + jj_la1[81] = jj_gen; + ; + } + jj_consume_token(35); + jj_consume_token(31); + } + + final public void for_equation() throws ParseException { + jj_consume_token(21); + for_indices(); + jj_consume_token(60); + label_18: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 21: + case 31: + case 33: + case 35: + case 39: + case 43: + case 46: + case 58: + case 62: + case 64: + case 66: + case 68: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + ; + break; + default: + jj_la1[82] = jj_gen; + break label_18; + } + equation(); + jj_consume_token(70); + } + jj_consume_token(35); + jj_consume_token(21); + } + + final public void for_statement() throws ParseException { + jj_consume_token(21); + for_indices(); + jj_consume_token(60); + label_19: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 18: + case 21: + case 29: + case 31: + case 43: + case 48: + case 62: + case 68: + case IDENT: + ; + break; + default: + jj_la1[83] = jj_gen; + break label_19; + } + statement(); + jj_consume_token(70); + } + jj_consume_token(35); + jj_consume_token(21); + } + + final public void for_indices() throws ParseException { + for_index(); + label_20: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + ; + break; + default: + jj_la1[84] = jj_gen; + break label_20; + } + jj_consume_token(71); + for_index(); + } + } + + final public void for_index() throws ParseException { + jj_consume_token(IDENT); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 41: + jj_consume_token(41); + expression(); + break; + default: + jj_la1[85] = jj_gen; + ; + } + } + + final public void while_statement() throws ParseException { + jj_consume_token(48); + expression(); + jj_consume_token(60); + label_21: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 18: + case 21: + case 29: + case 31: + case 43: + case 48: + case 62: + case 68: + case IDENT: + ; + break; + default: + jj_la1[86] = jj_gen; + break label_21; + } + statement(); + jj_consume_token(70); + } + jj_consume_token(35); + jj_consume_token(48); + } + + final public void when_equation() throws ParseException { + jj_consume_token(43); + expression(); + jj_consume_token(28); + label_22: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 21: + case 31: + case 33: + case 35: + case 39: + case 43: + case 46: + case 58: + case 62: + case 64: + case 66: + case 68: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + ; + break; + default: + jj_la1[87] = jj_gen; + break label_22; + } + equation(); + jj_consume_token(70); + } + label_23: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 25: + ; + break; + default: + jj_la1[88] = jj_gen; + break label_23; + } + jj_consume_token(25); + expression(); + jj_consume_token(28); + label_24: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 21: + case 31: + case 33: + case 35: + case 39: + case 43: + case 46: + case 58: + case 62: + case 64: + case 66: + case 68: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + ; + break; + default: + jj_la1[89] = jj_gen; + break label_24; + } + equation(); + jj_consume_token(70); + } + } + jj_consume_token(35); + jj_consume_token(43); + } + + final public void when_statement() throws ParseException { + jj_consume_token(43); + expression(); + jj_consume_token(28); + label_25: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 18: + case 21: + case 29: + case 31: + case 43: + case 48: + case 62: + case 68: + case IDENT: + ; + break; + default: + jj_la1[90] = jj_gen; + break label_25; + } + statement(); + jj_consume_token(70); + } + label_26: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 25: + ; + break; + default: + jj_la1[91] = jj_gen; + break label_26; + } + jj_consume_token(25); + expression(); + jj_consume_token(28); + label_27: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 18: + case 21: + case 29: + case 31: + case 43: + case 48: + case 62: + case 68: + case IDENT: + ; + break; + default: + jj_la1[92] = jj_gen; + break label_27; + } + statement(); + jj_consume_token(70); + } + } + jj_consume_token(35); + jj_consume_token(43); + } + + final public void connect_clause() throws ParseException { + jj_consume_token(39); + jj_consume_token(62); + component_reference(); + jj_consume_token(71); + component_reference(); + jj_consume_token(63); + } + +/*** Expressions ***************************************************/ + final public void expr() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 33: + case 35: + case 46: + case 58: + case 62: + case 64: + case 66: + case 68: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + simple_expression(); + jj_consume_token(0); + break; + case 31: + jj_consume_token(31); + expression(); + jj_consume_token(28); + expression(); + label_28: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 20: + ; + break; + default: + jj_la1[93] = jj_gen; + break label_28; + } + jj_consume_token(20); + expression(); + jj_consume_token(28); + expression(); + } + jj_consume_token(15); + expression(); + jj_consume_token(0); + break; + default: + jj_la1[94] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void expression() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 33: + case 35: + case 46: + case 58: + case 62: + case 64: + case 66: + case 68: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + simple_expression(); + break; + case 31: + jj_consume_token(31); + expression(); + jj_consume_token(28); + expression(); + label_29: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 20: + ; + break; + default: + jj_la1[95] = jj_gen; + break label_29; + } + jj_consume_token(20); + expression(); + jj_consume_token(28); + expression(); + } + jj_consume_token(15); + expression(); + break; + default: + jj_la1[96] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void simple_expression() throws ParseException { + logical_expression(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 69: + jj_consume_token(69); + logical_expression(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 69: + jj_consume_token(69); + logical_expression(); + break; + default: + jj_la1[97] = jj_gen; + ; + } + break; + default: + jj_la1[98] = jj_gen; + ; + } + } + + final public void logical_expression() throws ParseException { + logical_term(); + label_30: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 22: + ; + break; + default: + jj_la1[99] = jj_gen; + break label_30; + } + jj_consume_token(22); + logical_term(); + } + } + + final public void logical_term() throws ParseException { + logical_factor(); + label_31: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 9: + ; + break; + default: + jj_la1[100] = jj_gen; + break label_31; + } + jj_consume_token(9); + logical_factor(); + } + } + + final public void logical_factor() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 12: + jj_consume_token(12); + break; + default: + jj_la1[101] = jj_gen; + ; + } + relation(); + } + + final public void relation() throws ParseException { + arithmetic_expression(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 72: + case 73: + case 74: + case 75: + case 76: + case 77: + rel_op(); + arithmetic_expression(); + break; + default: + jj_la1[102] = jj_gen; + ; + } + } + + final public void rel_op() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 72: + jj_consume_token(72); + break; + case 73: + jj_consume_token(73); + break; + case 74: + jj_consume_token(74); + break; + case 75: + jj_consume_token(75); + break; + case 76: + jj_consume_token(76); + break; + case 77: + jj_consume_token(77); + break; + default: + jj_la1[103] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void arithmetic_expression() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 78: + case 79: + case 80: + case 81: + add_op(); + break; + default: + jj_la1[104] = jj_gen; + ; + } + term(); + label_32: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 78: + case 79: + case 80: + case 81: + ; + break; + default: + jj_la1[105] = jj_gen; + break label_32; + } + add_op(); + term(); + } + } + + final public void add_op() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 78: + jj_consume_token(78); + break; + case 79: + jj_consume_token(79); + break; + case 80: + jj_consume_token(80); + break; + case 81: + jj_consume_token(81); + break; + default: + jj_la1[106] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void term() throws ParseException { + factor(); + label_33: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 82: + case 83: + case 84: + case 85: + ; + break; + default: + jj_la1[107] = jj_gen; + break label_33; + } + mul_op(); + factor(); + } + } + + final public void mul_op() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 82: + jj_consume_token(82); + break; + case 83: + jj_consume_token(83); + break; + case 84: + jj_consume_token(84); + break; + case 85: + jj_consume_token(85); + break; + default: + jj_la1[108] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void factor() throws ParseException { + primary(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 86: + case 87: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 86: + jj_consume_token(86); + break; + case 87: + jj_consume_token(87); + primary(); + break; + default: + jj_la1[109] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[110] = jj_gen; + ; + } + } + + final public void primary() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case UNSIGNED_NUMBER: + jj_consume_token(UNSIGNED_NUMBER); + break; + case UNSIGNED_INTEGER: + jj_consume_token(UNSIGNED_INTEGER); + break; + case STRING: + jj_consume_token(STRING); + break; + case 6: + jj_consume_token(6); + break; + case 33: + jj_consume_token(33); + break; + default: + jj_la1[113] = jj_gen; + if (jj_2_8(2147483647)) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + case IDENT: + name(); + break; + case 58: + jj_consume_token(58); + break; + case 46: + jj_consume_token(46); + break; + default: + jj_la1[111] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + function_call_args(); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + case IDENT: + component_reference(); + break; + case 62: + jj_consume_token(62); + output_expression_list(); + jj_consume_token(63); + break; + case 66: + jj_consume_token(66); + expression_list(); + label_34: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 70: + ; + break; + default: + jj_la1[112] = jj_gen; + break label_34; + } + jj_consume_token(70); + expression_list(); + } + jj_consume_token(67); + break; + case 64: + jj_consume_token(64); + function_arguments(); + jj_consume_token(65); + break; + case 35: + jj_consume_token(35); + break; + default: + jj_la1[114] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + } + + final public void name() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + jj_consume_token(68); + break; + default: + jj_la1[115] = jj_gen; + ; + } + jj_consume_token(IDENT); + label_35: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + ; + break; + default: + jj_la1[116] = jj_gen; + break label_35; + } + jj_consume_token(68); + jj_consume_token(IDENT); + } + } + + final public void component_reference() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + jj_consume_token(68); + break; + default: + jj_la1[117] = jj_gen; + ; + } + jj_consume_token(IDENT); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 66: + array_subscripts(); + break; + default: + jj_la1[118] = jj_gen; + ; + } + label_36: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 68: + ; + break; + default: + jj_la1[119] = jj_gen; + break label_36; + } + jj_consume_token(68); + jj_consume_token(IDENT); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 66: + array_subscripts(); + break; + default: + jj_la1[120] = jj_gen; + ; + } + } + } + + final public void function_call_args() throws ParseException { + jj_consume_token(62); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 31: + case 33: + case 35: + case 46: + case 58: + case 62: + case 64: + case 66: + case 68: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + function_arguments(); + break; + default: + jj_la1[121] = jj_gen; + ; + } + jj_consume_token(63); + } + + final public void function_arguments() throws ParseException { + if (jj_2_9(2)) { + expression(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 21: + case 71: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + jj_consume_token(71); + function_arguments(); + break; + case 21: + jj_consume_token(21); + for_indices(); + break; + default: + jj_la1[122] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[123] = jj_gen; + ; + } + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IDENT: + named_arguments(); + break; + default: + jj_la1[124] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + + final public void named_arguments() throws ParseException { + named_argument(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + jj_consume_token(71); + named_arguments(); + break; + default: + jj_la1[125] = jj_gen; + ; + } + } + + final public void named_argument() throws ParseException { + jj_consume_token(IDENT); + jj_consume_token(88); + expression(); + } + + final public void output_expression_list() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 31: + case 33: + case 35: + case 46: + case 58: + case 62: + case 64: + case 66: + case 68: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + expression(); + break; + default: + jj_la1[126] = jj_gen; + ; + } + label_37: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + ; + break; + default: + jj_la1[127] = jj_gen; + break label_37; + } + jj_consume_token(71); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 31: + case 33: + case 35: + case 46: + case 58: + case 62: + case 64: + case 66: + case 68: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + expression(); + break; + default: + jj_la1[128] = jj_gen; + ; + } + } + } + + final public void expression_list() throws ParseException { + expression(); + label_38: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + ; + break; + default: + jj_la1[129] = jj_gen; + break label_38; + } + jj_consume_token(71); + expression(); + } + } + + final public void array_subscripts() throws ParseException { + jj_consume_token(66); + subscript(); + label_39: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + ; + break; + default: + jj_la1[130] = jj_gen; + break label_39; + } + jj_consume_token(71); + subscript(); + } + jj_consume_token(67); + } + + final public void subscript() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 69: + jj_consume_token(69); + break; + case 6: + case 12: + case 31: + case 33: + case 35: + case 46: + case 58: + case 62: + case 64: + case 66: + case 68: + case 78: + case 79: + case 80: + case 81: + case IDENT: + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + expression(); + break; + default: + jj_la1[131] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void comment() throws ParseException { + string_comment(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 14: + annotation(); + break; + default: + jj_la1[132] = jj_gen; + ; + } + } + + final public void string_comment() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + jj_consume_token(STRING); + label_40: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 78: + ; + break; + default: + jj_la1[133] = jj_gen; + break label_40; + } + jj_consume_token(78); + jj_consume_token(STRING); + } + break; + default: + jj_la1[134] = jj_gen; + ; + } + } + + final public void annotation() throws ParseException { + jj_consume_token(14); + class_modification(); + } + + private boolean jj_2_1(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_1(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(0, xla); } + } + + private boolean jj_2_2(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_2(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(1, xla); } + } + + private boolean jj_2_3(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_3(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(2, xla); } + } + + private boolean jj_2_4(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_4(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(3, xla); } + } + + private boolean jj_2_5(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_5(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(4, xla); } + } + + private boolean jj_2_6(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_6(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(5, xla); } + } + + private boolean jj_2_7(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_7(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(6, xla); } + } + + private boolean jj_2_8(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_8(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(7, xla); } + } + + private boolean jj_2_9(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_9(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(8, xla); } + } + + private boolean jj_3R_72() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(8)) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_scan_token(11)) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_scan_token(51)) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_scan_token(27)) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_77()) { + jj_scanpos = xsp; + if (jj_3R_78()) return true; + } + return false; + } + + private boolean jj_3R_95() { + if (jj_3R_101()) return true; + if (jj_3R_94()) return true; + return false; + } + + private boolean jj_3R_71() { + if (jj_3R_76()) return true; + return false; + } + + private boolean jj_3R_64() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_70()) { + jj_scanpos = xsp; + if (jj_3R_71()) { + jj_scanpos = xsp; + if (jj_3R_72()) return true; + } + } + return false; + } + + private boolean jj_3R_70() { + if (jj_3R_75()) return true; + return false; + } + + private boolean jj_3R_83() { + if (jj_3R_89()) return true; + if (jj_3R_82()) return true; + return false; + } + + private boolean jj_3R_88() { + if (jj_3R_93()) return true; + if (jj_3R_87()) return true; + return false; + } + + private boolean jj_3R_101() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(82)) { + jj_scanpos = xsp; + if (jj_scan_token(83)) { + jj_scanpos = xsp; + if (jj_scan_token(84)) { + jj_scanpos = xsp; + if (jj_scan_token(85)) return true; + } + } + } + return false; + } + + private boolean jj_3R_87() { + if (jj_3R_94()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_95()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_52() { + if (jj_3R_64()) return true; + return false; + } + + private boolean jj_3R_43() { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_52()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_93() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(78)) { + jj_scanpos = xsp; + if (jj_scan_token(79)) { + jj_scanpos = xsp; + if (jj_scan_token(80)) { + jj_scanpos = xsp; + if (jj_scan_token(81)) return true; + } + } + } + return false; + } + + private boolean jj_3R_74() { + if (jj_scan_token(9)) return true; + if (jj_3R_73()) return true; + return false; + } + + private boolean jj_3R_86() { + if (jj_3R_93()) return true; + return false; + } + + private boolean jj_3R_82() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_86()) jj_scanpos = xsp; + if (jj_3R_87()) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3R_88()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_89() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(72)) { + jj_scanpos = xsp; + if (jj_scan_token(73)) { + jj_scanpos = xsp; + if (jj_scan_token(74)) { + jj_scanpos = xsp; + if (jj_scan_token(75)) { + jj_scanpos = xsp; + if (jj_scan_token(76)) { + jj_scanpos = xsp; + if (jj_scan_token(77)) return true; + } + } + } + } + } + return false; + } + + private boolean jj_3R_54() { + if (jj_scan_token(69)) return true; + if (jj_3R_53()) return true; + return false; + } + + private boolean jj_3R_66() { + if (jj_scan_token(22)) return true; + if (jj_3R_65()) return true; + return false; + } + + private boolean jj_3_7() { + if (jj_3R_44()) return true; + if (jj_scan_token(88)) return true; + if (jj_3R_45()) return true; + return false; + } + + private boolean jj_3R_79() { + if (jj_3R_82()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_83()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_51() { + if (jj_3R_63()) return true; + return false; + } + + private boolean jj_3R_50() { + if (jj_scan_token(59)) return true; + return false; + } + + private boolean jj_3R_49() { + Token xsp; + xsp = jj_scanpos; + if (jj_3_5()) { + jj_scanpos = xsp; + if (jj_3R_60()) { + jj_scanpos = xsp; + if (jj_3R_61()) { + jj_scanpos = xsp; + if (jj_3R_62()) return true; + } + } + } + return false; + } + + private boolean jj_3_5() { + if (jj_scan_token(57)) return true; + if (jj_3R_43()) return true; + return false; + } + + private boolean jj_3R_73() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(12)) jj_scanpos = xsp; + if (jj_3R_79()) return true; + return false; + } + + private boolean jj_3R_42() { + if (jj_3R_43()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_49()) { jj_scanpos = xsp; break; } + } + xsp = jj_scanpos; + if (jj_3R_50()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_51()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_65() { + if (jj_3R_73()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_74()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_69() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(46)) jj_scanpos = xsp; + if (jj_scan_token(4)) return true; + return false; + } + + private boolean jj_3R_53() { + if (jj_3R_65()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_66()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_68() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(46)) jj_scanpos = xsp; + if (jj_scan_token(45)) return true; + return false; + } + + private boolean jj_3R_90() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(50)) jj_scanpos = xsp; + if (jj_scan_token(44)) return true; + return false; + } + + private boolean jj_3R_44() { + if (jj_3R_53()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_54()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_56() { + if (jj_scan_token(31)) return true; + if (jj_3R_45()) return true; + return false; + } + + private boolean jj_3R_55() { + if (jj_3R_44()) return true; + return false; + } + + private boolean jj_3R_45() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_55()) { + jj_scanpos = xsp; + if (jj_3R_56()) return true; + } + return false; + } + + private boolean jj_3_4() { + if (jj_scan_token(IDENT)) return true; + if (jj_scan_token(88)) return true; + if (jj_scan_token(58)) return true; + return false; + } + + private boolean jj_3_3() { + if (jj_scan_token(IDENT)) return true; + if (jj_scan_token(88)) return true; + if (jj_scan_token(40)) return true; + return false; + } + + private boolean jj_3_2() { + if (jj_scan_token(IDENT)) return true; + if (jj_scan_token(88)) return true; + return false; + } + + private boolean jj_3_1() { + if (jj_scan_token(IDENT)) return true; + if (jj_3R_41()) return true; + if (jj_3R_42()) return true; + if (jj_scan_token(35)) return true; + return false; + } + + private boolean jj_3R_84() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(30)) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_scan_token(47)) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_scan_token(34)) { + jj_scanpos = xsp; + if (jj_scan_token(7)) { + jj_scanpos = xsp; + if (jj_scan_token(61)) { + jj_scanpos = xsp; + if (jj_scan_token(24)) { + jj_scanpos = xsp; + if (jj_3R_90()) { + jj_scanpos = xsp; + if (jj_scan_token(38)) { + jj_scanpos = xsp; + if (jj_scan_token(37)) { + jj_scanpos = xsp; + if (jj_scan_token(26)) { + jj_scanpos = xsp; + if (jj_scan_token(17)) { + jj_scanpos = xsp; + if (jj_scan_token(94)) { + jj_scanpos = xsp; + if (jj_scan_token(95)) return true; + } + } + } + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_59() { + if (jj_scan_token(21)) return true; + return false; + } + + private boolean jj_3R_63() { + if (jj_scan_token(14)) return true; + return false; + } + + private boolean jj_3R_48() { + if (jj_scan_token(STRING)) return true; + return false; + } + + private boolean jj_3R_41() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_48()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_127() { + if (jj_3R_45()) return true; + return false; + } + + private boolean jj_3R_123() { + if (jj_3R_45()) return true; + return false; + } + + private boolean jj_3R_98() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(56)) { + jj_scanpos = xsp; + if (jj_scan_token(32)) return true; + } + return false; + } + + private boolean jj_3R_119() { + if (jj_scan_token(71)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_123()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_125() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(69)) { + jj_scanpos = xsp; + if (jj_3R_127()) return true; + } + return false; + } + + private boolean jj_3R_120() { + if (jj_scan_token(71)) return true; + return false; + } + + private boolean jj_3R_122() { + if (jj_scan_token(66)) return true; + if (jj_3R_125()) return true; + return false; + } + + private boolean jj_3R_117() { + if (jj_scan_token(68)) return true; + if (jj_scan_token(IDENT)) return true; + return false; + } + + private boolean jj_3R_58() { + if (jj_scan_token(71)) return true; + return false; + } + + private boolean jj_3R_47() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_58()) { + jj_scanpos = xsp; + if (jj_3R_59()) return true; + } + return false; + } + + private boolean jj_3R_118() { + if (jj_3R_45()) return true; + return false; + } + + private boolean jj_3R_112() { + if (jj_3R_45()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_120()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_111() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_118()) jj_scanpos = xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_119()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_62() { + if (jj_3R_69()) return true; + return false; + } + + private boolean jj_3R_126() { + if (jj_scan_token(IDENT)) return true; + if (jj_scan_token(88)) return true; + return false; + } + + private boolean jj_3R_108() { + if (jj_3R_57()) return true; + return false; + } + + private boolean jj_3R_124() { + if (jj_3R_126()) return true; + return false; + } + + private boolean jj_3R_116() { + if (jj_3R_122()) return true; + return false; + } + + private boolean jj_3R_121() { + if (jj_3R_124()) return true; + return false; + } + + private boolean jj_3R_92() { + if (jj_3R_57()) return true; + return false; + } + + private boolean jj_3R_114() { + Token xsp; + xsp = jj_scanpos; + if (jj_3_9()) { + jj_scanpos = xsp; + if (jj_3R_121()) return true; + } + return false; + } + + private boolean jj_3_9() { + if (jj_3R_45()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_47()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_67() { + if (jj_scan_token(68)) return true; + if (jj_scan_token(IDENT)) return true; + return false; + } + + private boolean jj_3R_115() { + if (jj_3R_114()) return true; + return false; + } + + private boolean jj_3R_97() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(5)) { + jj_scanpos = xsp; + if (jj_scan_token(42)) { + jj_scanpos = xsp; + if (jj_scan_token(49)) return true; + } + } + return false; + } + + private boolean jj_3R_96() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(16)) { + jj_scanpos = xsp; + if (jj_scan_token(23)) return true; + } + return false; + } + + private boolean jj_3R_91() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_96()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_97()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_98()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_113() { + if (jj_scan_token(70)) return true; + return false; + } + + private boolean jj_3R_109() { + if (jj_scan_token(62)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_115()) jj_scanpos = xsp; + if (jj_scan_token(63)) return true; + return false; + } + + private boolean jj_3R_61() { + if (jj_3R_68()) return true; + return false; + } + + private boolean jj_3R_85() { + if (jj_3R_91()) return true; + if (jj_3R_92()) return true; + return false; + } + + private boolean jj_3R_110() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(68)) jj_scanpos = xsp; + if (jj_scan_token(IDENT)) return true; + xsp = jj_scanpos; + if (jj_3R_116()) jj_scanpos = xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_117()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_81() { + if (jj_3R_85()) return true; + return false; + } + + private boolean jj_3R_57() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(68)) jj_scanpos = xsp; + if (jj_scan_token(IDENT)) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3R_67()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_46() { + if (jj_3R_57()) return true; + return false; + } + + private boolean jj_3_6() { + if (jj_scan_token(IDENT)) return true; + if (jj_scan_token(88)) return true; + return false; + } + + private boolean jj_3_8() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_46()) { + jj_scanpos = xsp; + if (jj_scan_token(58)) { + jj_scanpos = xsp; + if (jj_scan_token(46)) return true; + } + } + if (jj_scan_token(62)) return true; + return false; + } + + private boolean jj_3R_107() { + if (jj_scan_token(87)) return true; + if (jj_3R_99()) return true; + return false; + } + + private boolean jj_3R_76() { + if (jj_scan_token(55)) return true; + return false; + } + + private boolean jj_3R_100() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(86)) { + jj_scanpos = xsp; + if (jj_3R_107()) return true; + } + return false; + } + + private boolean jj_3R_106() { + if (jj_scan_token(64)) return true; + if (jj_3R_114()) return true; + if (jj_scan_token(65)) return true; + return false; + } + + private boolean jj_3R_78() { + if (jj_scan_token(13)) return true; + return false; + } + + private boolean jj_3R_105() { + if (jj_scan_token(66)) return true; + if (jj_3R_112()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_113()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(67)) return true; + return false; + } + + private boolean jj_3R_75() { + if (jj_scan_token(36)) return true; + return false; + } + + private boolean jj_3R_104() { + if (jj_scan_token(62)) return true; + if (jj_3R_111()) return true; + if (jj_scan_token(63)) return true; + return false; + } + + private boolean jj_3R_102() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_108()) { + jj_scanpos = xsp; + if (jj_scan_token(58)) { + jj_scanpos = xsp; + if (jj_scan_token(46)) return true; + } + } + if (jj_3R_109()) return true; + return false; + } + + private boolean jj_3R_103() { + if (jj_3R_110()) return true; + return false; + } + + private boolean jj_3R_99() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(93)) { + jj_scanpos = xsp; + if (jj_scan_token(92)) { + jj_scanpos = xsp; + if (jj_scan_token(91)) { + jj_scanpos = xsp; + if (jj_scan_token(6)) { + jj_scanpos = xsp; + if (jj_scan_token(33)) { + jj_scanpos = xsp; + if (jj_3R_102()) { + jj_scanpos = xsp; + if (jj_3R_103()) { + jj_scanpos = xsp; + if (jj_3R_104()) { + jj_scanpos = xsp; + if (jj_3R_105()) { + jj_scanpos = xsp; + if (jj_3R_106()) { + jj_scanpos = xsp; + if (jj_scan_token(35)) return true; + } + } + } + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_60() { + if (jj_scan_token(52)) return true; + return false; + } + + private boolean jj_3R_80() { + if (jj_3R_84()) return true; + return false; + } + + private boolean jj_3R_77() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_80()) { + jj_scanpos = xsp; + if (jj_3R_81()) return true; + } + return false; + } + + private boolean jj_3R_94() { + if (jj_3R_99()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_100()) jj_scanpos = xsp; + return false; + } + + /** Generated Token Manager. */ + public ModelParserTokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private Token jj_scanpos, jj_lastpos; + private int jj_la; + private int jj_gen; + final private int[] jj_la1 = new int[135]; + static private int[] jj_la1_0; + static private int[] jj_la1_1; + static private int[] jj_la1_2; + static { + jj_la1_init_0(); + jj_la1_init_1(); + jj_la1_init_2(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x0,0x0,0x45020880,0x800,0x40000000,0x0,0x0,0x5020080,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10,0x10,0x0,0x0,0x4000,0x0,0x4000,0x0,0x80001040,0x4d8329a0,0x100,0x800,0x0,0x8000000,0x458300a0,0x458300a0,0x0,0x458320a0,0x4d8329a0,0x0,0x0,0x0,0x4000,0x0,0x0,0x810000,0x810000,0x20,0x20,0x0,0x0,0x0,0x80000000,0x0,0x0,0x0,0x0,0x2d00,0x0,0x2d00,0x400,0x800,0x2000,0x0,0x400,0x800,0x458300a0,0x458320a0,0x458300a0,0x0,0x0,0x80201040,0x0,0xa0240000,0x80200000,0x0,0xa0240000,0x80201040,0x100000,0x80201040,0x80201040,0x8000,0xa0240000,0x100000,0xa0240000,0xa0240000,0x8000,0x80201040,0xa0240000,0x0,0x0,0xa0240000,0x80201040,0x2000000,0x80201040,0xa0240000,0x2000000,0xa0240000,0x100000,0x80001040,0x100000,0x80001040,0x0,0x0,0x400000,0x200,0x1000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x80001040,0x200000,0x200000,0x0,0x0,0x80001040,0x0,0x80001040,0x0,0x0,0x80001040,0x4000,0x0,0x0,}; + } + private static void jj_la1_init_1() { + jj_la1_1 = new int[] {0x0,0x200000,0x20049064,0x0,0x0,0x8000,0x40000,0x20041064,0x0,0x40000000,0x0,0x0,0x40000000,0x800000,0x0,0x2106000,0x106000,0x0,0x0,0x0,0x8000000,0x0,0x0,0x4400400a,0x218e9475,0x0,0x0,0x80000,0x0,0x21069465,0x21069465,0x400000,0x21069465,0x218e9475,0x0,0x0,0x40000000,0x0,0x40000000,0x0,0x0,0x0,0x20400,0x20400,0x1000001,0x1000001,0x0,0x0,0x0,0x40000000,0x0,0x40000000,0x0,0x0,0x0,0x0,0x0,0x0,0x40000000,0x0,0x0,0x21069465,0x21069465,0x21069465,0x400000,0x4000,0x4400488a,0x4000,0x40010800,0x880,0x40000000,0x40010800,0x4400488a,0x0,0x4400488a,0x4400488a,0x0,0x40010800,0x0,0x40010800,0x40010800,0x0,0x4400488a,0x40010800,0x0,0x200,0x40010800,0x4400488a,0x0,0x4400488a,0x40010800,0x0,0x40010800,0x0,0x4400400a,0x0,0x4400400a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x4004000,0x0,0x2,0x40000008,0x0,0x0,0x0,0x0,0x0,0x0,0x4400400a,0x0,0x0,0x0,0x0,0x4400400a,0x0,0x4400400a,0x0,0x0,0x4400400a,0x0,0x0,0x0,}; + } + private static void jj_la1_init_2() { + jj_la1_2 = new int[] {0x4000010,0x0,0xc0000000,0x0,0x0,0x0,0x0,0xc0000000,0x4,0x0,0x4000000,0x80,0x0,0x0,0x80,0x0,0x0,0x8000000,0x4000010,0x0,0x0,0x0,0x4000010,0x3c03c015,0xc4000010,0x0,0x0,0x0,0x0,0xc4000010,0xc4000010,0x0,0xc4000010,0xc4000010,0x10,0x4000010,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x80,0x0,0x4,0x3000000,0x1000000,0x3000000,0x4000010,0x80,0x4000010,0x0,0x0,0x4000010,0x3000000,0x0,0x0,0xc4000010,0xc4000010,0xc4000010,0x0,0x0,0x3c03c015,0x0,0x4000010,0x4000000,0x2000000,0x4000010,0x3c03c015,0x0,0x3c03c015,0x3c03c015,0x0,0x4000010,0x0,0x4000010,0x4000010,0x0,0x3c03c015,0x4000010,0x80,0x0,0x4000010,0x3c03c015,0x0,0x3c03c015,0x4000010,0x0,0x4000010,0x0,0x3c03c015,0x0,0x3c03c015,0x20,0x20,0x0,0x0,0x0,0x3f00,0x3f00,0x3c000,0x3c000,0x3c000,0x3c0000,0x3c0000,0xc00000,0xc00000,0x4000010,0x40,0x38000000,0x4000015,0x10,0x10,0x10,0x4,0x10,0x4,0x3c03c015,0x80,0x80,0x4000000,0x80,0x3c03c015,0x80,0x3c03c015,0x80,0x80,0x3c03c035,0x0,0x4000,0x8000000,}; + } + final private JJCalls[] jj_2_rtns = new JJCalls[9]; + private boolean jj_rescan = false; + private int jj_gc = 0; + + /** Constructor with InputStream. */ + public ModelParser(java.io.InputStream stream) { + this(stream, null); + } + /** Constructor with InputStream and supplied encoding */ + public ModelParser(java.io.InputStream stream, String encoding) { + try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source = new ModelParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 135; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream) { + ReInit(stream, null); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream, String encoding) { + try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 135; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor. */ + public ModelParser(java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new ModelParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 135; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader stream) { + jj_input_stream.ReInit(stream, 1, 1); + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 135; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor with generated Token Manager. */ + public ModelParser(ModelParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 135; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(ModelParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 135; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + private Token jj_consume_token(int kind) throws ParseException { + Token oldToken; + if ((oldToken = token).next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + if (++jj_gc > 100) { + jj_gc = 0; + for (int i = 0; i < jj_2_rtns.length; i++) { + JJCalls c = jj_2_rtns[i]; + while (c != null) { + if (c.gen < jj_gen) c.first = null; + c = c.next; + } + } + } + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + static private final class LookaheadSuccess extends java.lang.Error { } + final private LookaheadSuccess jj_ls = new LookaheadSuccess(); + private boolean jj_scan_token(int kind) { + if (jj_scanpos == jj_lastpos) { + jj_la--; + if (jj_scanpos.next == null) { + jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); + } else { + jj_lastpos = jj_scanpos = jj_scanpos.next; + } + } else { + jj_scanpos = jj_scanpos.next; + } + if (jj_rescan) { + int i = 0; Token tok = token; + while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } + if (tok != null) jj_add_error_token(kind, i); + } + if (jj_scanpos.kind != kind) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; + return false; + } + + +/** Get the next Token. */ + final public Token getNextToken() { + if (token.next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + +/** Get the specific Token. */ + final public Token getToken(int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next != null) t = t.next; + else t = t.next = token_source.getNextToken(); + } + return t; + } + + private int jj_ntk() { + if ((jj_nt=token.next) == null) + return (jj_ntk = (token.next=token_source.getNextToken()).kind); + else + return (jj_ntk = jj_nt.kind); + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + private int[] jj_lasttokens = new int[100]; + private int jj_endpos; + + private void jj_add_error_token(int kind, int pos) { + if (pos >= 100) return; + if (pos == jj_endpos + 1) { + jj_lasttokens[jj_endpos++] = kind; + } else if (jj_endpos != 0) { + jj_expentry = new int[jj_endpos]; + for (int i = 0; i < jj_endpos; i++) { + jj_expentry[i] = jj_lasttokens[i]; + } + jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) { + int[] oldentry = (int[])(it.next()); + if (oldentry.length == jj_expentry.length) { + for (int i = 0; i < jj_expentry.length; i++) { + if (oldentry[i] != jj_expentry[i]) { + continue jj_entries_loop; + } + } + jj_expentries.add(jj_expentry); + break jj_entries_loop; + } + } + if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; + } + } + + /** Generate ParseException. */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[96]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 135; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1< jj_gen) { + jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; + switch (i) { + case 0: jj_3_1(); break; + case 1: jj_3_2(); break; + case 2: jj_3_3(); break; + case 3: jj_3_4(); break; + case 4: jj_3_5(); break; + case 5: jj_3_6(); break; + case 6: jj_3_7(); break; + case 7: jj_3_8(); break; + case 8: jj_3_9(); break; + } + } + p = p.next; + } while (p != null); + } catch(LookaheadSuccess ls) { } + } + jj_rescan = false; + } + + private void jj_save(int index, int xla) { + JJCalls p = jj_2_rtns[index]; + while (p.gen > jj_gen) { + if (p.next == null) { p = p.next = new JJCalls(); break; } + p = p.next; + } + p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; + } + + static final class JJCalls { + int gen; + Token first; + int arg; + JJCalls next; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ModelParserConstants.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ModelParserConstants.java new file mode 100644 index 00000000..b307d246 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ModelParserConstants.java @@ -0,0 +1,131 @@ +/* Generated By:JavaCC: Do not edit this line. ModelParserConstants.java */ +package org.simantics.sysdyn.modelParser; + + +/** + * Token literal values and constants. + * Generated by org.javacc.parser.OtherFilesGen#start() + */ +public interface ModelParserConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int WHITESPACE = 1; + /** RegularExpression Id. */ + int COMMENT1 = 2; + /** RegularExpression Id. */ + int COMMENT2 = 3; + /** RegularExpression Id. */ + int IDENT = 90; + /** RegularExpression Id. */ + int STRING = 91; + /** RegularExpression Id. */ + int UNSIGNED_INTEGER = 92; + /** RegularExpression Id. */ + int UNSIGNED_NUMBER = 93; + + /** Lexical state. */ + int DEFAULT = 0; + + /** Literal token values. */ + String[] tokenImage = { + "", + "", + "", + "", + "\"algorithm\"", + "\"discrete\"", + "\"false\"", + "\"model\"", + "\"redeclare\"", + "\"and\"", + "\"each\"", + "\"final\"", + "\"not\"", + "\"replaceable\"", + "\"annotation\"", + "\"else\"", + "\"flow\"", + "\"operator\"", + "\"return\"", + "\"assert\"", + "\"elseif\"", + "\"for\"", + "\"or\"", + "\"stream\"", + "\"block\"", + "\"elsewhen\"", + "\"function\"", + "\"outer\"", + "\"then\"", + "\"break\"", + "\"encapsulated\"", + "\"if\"", + "\"output\"", + "\"true\"", + "\"class\"", + "\"end\"", + "\"import\"", + "\"package\"", + "\"type\"", + "\"connect\"", + "\"enumeration\"", + "\"in\"", + "\"parameter\"", + "\"when\"", + "\"connector\"", + "\"equation\"", + "\"initial\"", + "\"partial\"", + "\"while\"", + "\"constant\"", + "\"expandable\"", + "\"inner\"", + "\"protected\"", + "\"within\"", + "\"constrainedby\"", + "\"extends\"", + "\"input\"", + "\"public\"", + "\"der\"", + "\"external\"", + "\"loop\"", + "\"record\"", + "\"(\"", + "\")\"", + "\"{\"", + "\"}\"", + "\"[\"", + "\"]\"", + "\".\"", + "\":\"", + "\";\"", + "\",\"", + "\"<\"", + "\"<=\"", + "\">\"", + "\">=\"", + "\"==\"", + "\"<>\"", + "\"+\"", + "\"-\"", + "\".+\"", + "\".-\"", + "\"*\"", + "\"/\"", + "\".*\"", + "\"./\"", + "\"^\"", + "\".^\"", + "\"=\"", + "\":=\"", + "", + "", + "", + "", + "\"operator function\"", + "\"operator record\"", + }; + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ModelParserTokenManager.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ModelParserTokenManager.java new file mode 100644 index 00000000..5fbdba7f --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ModelParserTokenManager.java @@ -0,0 +1,1434 @@ +/* Generated By:JavaCC: Do not edit this line. ModelParserTokenManager.java */ +package org.simantics.sysdyn.modelParser; + +/** Token Manager. */ +public class ModelParserTokenManager implements ModelParserConstants +{ + + /** Debug output. */ + public java.io.PrintStream debugStream = System.out; + /** Set debug output. */ + public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } +private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1) +{ + switch (pos) + { + case 0: + if ((active0 & 0x3ffffffffffffff0L) != 0L || (active1 & 0xc0000000L) != 0L) + { + jjmatchedKind = 90; + return 2; + } + if ((active1 & 0x80000L) != 0L) + return 13; + if ((active1 & 0xb30010L) != 0L) + return 9; + return -1; + case 1: + if ((active0 & 0x108420080400000L) != 0L) + return 2; + if ((active0 & 0x3ef7bdff7fbffff0L) != 0L || (active1 & 0xc0000000L) != 0L) + { + if (jjmatchedPos != 1) + { + jjmatchedKind = 90; + jjmatchedPos = 1; + } + return 2; + } + return -1; + case 2: + if ((active0 & 0x400000800201200L) != 0L) + return 2; + if ((active0 & 0x3bfffdf77f9fedf0L) != 0L || (active1 & 0xc0000000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 2; + return 2; + } + return -1; + case 3: + if ((active0 & 0x1000084212118400L) != 0L) + return 2; + if ((active0 & 0x2bfff5b56d8e69f0L) != 0L || (active1 & 0xc0000000L) != 0L) + { + if (jjmatchedPos != 3) + { + jjmatchedKind = 90; + jjmatchedPos = 3; + } + return 2; + } + return -1; + case 4: + if ((active0 & 0x1090004290008c0L) != 0L) + return 2; + if ((active0 & 0x2af6f5b1469e6130L) != 0L || (active1 & 0xc0000000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 4; + return 2; + } + return -1; + case 5: + if ((active0 & 0x22200011009c0000L) != 0L) + return 2; + if ((active0 & 0x8d6f5a046026130L) != 0L || (active1 & 0xc0000000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 5; + return 2; + } + return -1; + case 6: + if ((active0 & 0x80d0a000000000L) != 0L) + return 2; + if ((active0 & 0x856250046026130L) != 0L || (active1 & 0xc0000000L) != 0L) + { + if (jjmatchedPos != 6) + { + jjmatchedKind = 90; + jjmatchedPos = 6; + } + return 2; + } + return -1; + case 7: + if ((active0 & 0x54150040006110L) != 0L) + { + if (jjmatchedPos != 7) + { + jjmatchedKind = 90; + jjmatchedPos = 7; + } + return 2; + } + if ((active0 & 0x802200006020020L) != 0L || (active1 & 0xc0000000L) != 0L) + return 2; + return -1; + case 8: + if ((active0 & 0x10140000000110L) != 0L) + return 2; + if ((active0 & 0x44010040006000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 8; + return 2; + } + return -1; + case 9: + if ((active0 & 0x40010040002000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 9; + return 2; + } + if ((active0 & 0x4000000004000L) != 0L) + return 2; + return -1; + case 10: + if ((active0 & 0x10000002000L) != 0L) + return 2; + if ((active0 & 0x40000040000000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 10; + return 2; + } + return -1; + case 11: + if ((active0 & 0x40000000L) != 0L) + return 2; + if ((active0 & 0x40000000000000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 11; + return 2; + } + return -1; + case 12: + if ((active0 & 0x40000000000000L) != 0L) + return 2; + return -1; + default : + return -1; + } +} +private final int jjStartNfa_0(int pos, long active0, long active1) +{ + return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0, active1), pos + 1); +} +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0() +{ + switch(curChar) + { + case 40: + return jjStopAtPos(0, 62); + case 41: + return jjStopAtPos(0, 63); + case 42: + return jjStopAtPos(0, 82); + case 43: + return jjStopAtPos(0, 78); + case 44: + return jjStopAtPos(0, 71); + case 45: + return jjStopAtPos(0, 79); + case 46: + jjmatchedKind = 68; + return jjMoveStringLiteralDfa1_0(0x0L, 0xb30000L); + case 47: + return jjStartNfaWithStates_0(0, 83, 13); + case 58: + jjmatchedKind = 69; + return jjMoveStringLiteralDfa1_0(0x0L, 0x2000000L); + case 59: + return jjStopAtPos(0, 70); + case 60: + jjmatchedKind = 72; + return jjMoveStringLiteralDfa1_0(0x0L, 0x2200L); + case 61: + jjmatchedKind = 88; + return jjMoveStringLiteralDfa1_0(0x0L, 0x1000L); + case 62: + jjmatchedKind = 74; + return jjMoveStringLiteralDfa1_0(0x0L, 0x800L); + case 91: + return jjStopAtPos(0, 66); + case 93: + return jjStopAtPos(0, 67); + case 94: + return jjStopAtPos(0, 86); + case 97: + return jjMoveStringLiteralDfa1_0(0x84210L, 0x0L); + case 98: + return jjMoveStringLiteralDfa1_0(0x21000000L, 0x0L); + case 99: + return jjMoveStringLiteralDfa1_0(0x42108400000000L, 0x0L); + case 100: + return jjMoveStringLiteralDfa1_0(0x400000000000020L, 0x0L); + case 101: + return jjMoveStringLiteralDfa1_0(0x884210842108400L, 0x0L); + case 102: + return jjMoveStringLiteralDfa1_0(0x4210840L, 0x0L); + case 105: + return jjMoveStringLiteralDfa1_0(0x108421080000000L, 0x0L); + case 108: + return jjMoveStringLiteralDfa1_0(0x1000000000000000L, 0x0L); + case 109: + return jjMoveStringLiteralDfa1_0(0x80L, 0x0L); + case 110: + return jjMoveStringLiteralDfa1_0(0x1000L, 0x0L); + case 111: + return jjMoveStringLiteralDfa1_0(0x108420000L, 0xc0000000L); + case 112: + return jjMoveStringLiteralDfa1_0(0x210842000000000L, 0x0L); + case 114: + return jjMoveStringLiteralDfa1_0(0x2000000000042100L, 0x0L); + case 115: + return jjMoveStringLiteralDfa1_0(0x800000L, 0x0L); + case 116: + return jjMoveStringLiteralDfa1_0(0x4210000000L, 0x0L); + case 119: + return jjMoveStringLiteralDfa1_0(0x21080000000000L, 0x0L); + case 123: + return jjStopAtPos(0, 64); + case 125: + return jjStopAtPos(0, 65); + default : + return jjMoveNfa_0(0, 0); + } +} +private int jjMoveStringLiteralDfa1_0(long active0, long active1) +{ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(0, active0, active1); + return 1; + } + switch(curChar) + { + case 42: + if ((active1 & 0x100000L) != 0L) + return jjStopAtPos(1, 84); + break; + case 43: + if ((active1 & 0x10000L) != 0L) + return jjStopAtPos(1, 80); + break; + case 45: + if ((active1 & 0x20000L) != 0L) + return jjStopAtPos(1, 81); + break; + case 47: + if ((active1 & 0x200000L) != 0L) + return jjStopAtPos(1, 85); + break; + case 61: + if ((active1 & 0x200L) != 0L) + return jjStopAtPos(1, 73); + else if ((active1 & 0x800L) != 0L) + return jjStopAtPos(1, 75); + else if ((active1 & 0x1000L) != 0L) + return jjStopAtPos(1, 76); + else if ((active1 & 0x2000000L) != 0L) + return jjStopAtPos(1, 89); + break; + case 62: + if ((active1 & 0x2000L) != 0L) + return jjStopAtPos(1, 77); + break; + case 94: + if ((active1 & 0x800000L) != 0L) + return jjStopAtPos(1, 87); + break; + case 97: + return jjMoveStringLiteralDfa2_0(active0, 0x842000000440L, active1, 0L); + case 101: + return jjMoveStringLiteralDfa2_0(active0, 0x2400000000042100L, active1, 0L); + case 102: + if ((active0 & 0x80000000L) != 0L) + return jjStartNfaWithStates_0(1, 31, 2); + break; + case 104: + return jjMoveStringLiteralDfa2_0(active0, 0x1080010000000L, active1, 0L); + case 105: + return jjMoveStringLiteralDfa2_0(active0, 0x20000000000820L, active1, 0L); + case 108: + return jjMoveStringLiteralDfa2_0(active0, 0x403118010L, active1, 0L); + case 109: + return jjMoveStringLiteralDfa2_0(active0, 0x1000000000L, active1, 0L); + case 110: + if ((active0 & 0x20000000000L) != 0L) + { + jjmatchedKind = 41; + jjmatchedPos = 1; + } + return jjMoveStringLiteralDfa2_0(active0, 0x108410840004200L, active1, 0L); + case 111: + return jjMoveStringLiteralDfa2_0(active0, 0x1042108000201080L, active1, 0L); + case 112: + return jjMoveStringLiteralDfa2_0(active0, 0x20000L, active1, 0xc0000000L); + case 113: + return jjMoveStringLiteralDfa2_0(active0, 0x200000000000L, active1, 0L); + case 114: + if ((active0 & 0x400000L) != 0L) + return jjStartNfaWithStates_0(1, 22, 2); + return jjMoveStringLiteralDfa2_0(active0, 0x10000220000000L, active1, 0L); + case 115: + return jjMoveStringLiteralDfa2_0(active0, 0x80000L, active1, 0L); + case 116: + return jjMoveStringLiteralDfa2_0(active0, 0x800000L, active1, 0L); + case 117: + return jjMoveStringLiteralDfa2_0(active0, 0x20000010c000000L, active1, 0L); + case 120: + return jjMoveStringLiteralDfa2_0(active0, 0x884000000000000L, active1, 0L); + case 121: + return jjMoveStringLiteralDfa2_0(active0, 0x4000000000L, active1, 0L); + default : + break; + } + return jjStartNfa_0(0, active0, active1); +} +private int jjMoveStringLiteralDfa2_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(0, old0, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(1, active0, active1); + return 2; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa3_0(active0, 0x400000000L, active1, 0L); + case 98: + return jjMoveStringLiteralDfa3_0(active0, 0x200000000000000L, active1, 0L); + case 99: + return jjMoveStringLiteralDfa3_0(active0, 0x2000002040000400L, active1, 0L); + case 100: + if ((active0 & 0x200L) != 0L) + return jjStartNfaWithStates_0(2, 9, 2); + else if ((active0 & 0x800000000L) != 0L) + return jjStartNfaWithStates_0(2, 35, 2); + return jjMoveStringLiteralDfa3_0(active0, 0x180L, active1, 0L); + case 101: + return jjMoveStringLiteralDfa3_0(active0, 0x80030020000L, active1, 0xc0000000L); + case 103: + return jjMoveStringLiteralDfa3_0(active0, 0x10L, active1, 0L); + case 105: + return jjMoveStringLiteralDfa3_0(active0, 0x1400000000000L, active1, 0L); + case 108: + return jjMoveStringLiteralDfa3_0(active0, 0x40L, active1, 0L); + case 110: + return jjMoveStringLiteralDfa3_0(active0, 0x4a108004004800L, active1, 0L); + case 111: + return jjMoveStringLiteralDfa3_0(active0, 0x1010000001010000L, active1, 0L); + case 112: + return jjMoveStringLiteralDfa3_0(active0, 0x104005000002000L, active1, 0L); + case 114: + if ((active0 & 0x200000L) != 0L) + return jjStartNfaWithStates_0(2, 21, 2); + else if ((active0 & 0x400000000000000L) != 0L) + return jjStartNfaWithStates_0(2, 58, 2); + return jjMoveStringLiteralDfa3_0(active0, 0x840000800000L, active1, 0L); + case 115: + return jjMoveStringLiteralDfa3_0(active0, 0x2188020L, active1, 0L); + case 116: + if ((active0 & 0x1000L) != 0L) + return jjStartNfaWithStates_0(2, 12, 2); + return jjMoveStringLiteralDfa3_0(active0, 0x8a0000108040000L, active1, 0L); + case 117: + return jjMoveStringLiteralDfa3_0(active0, 0x210200000000L, active1, 0L); + default : + break; + } + return jjStartNfa_0(1, active0, active1); +} +private int jjMoveStringLiteralDfa3_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(1, old0, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(2, active0, active1); + return 3; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa4_0(active0, 0x4240060000800L, active1, 0L); + case 99: + return jjMoveStringLiteralDfa4_0(active0, 0x5000020L, active1, 0L); + case 101: + if ((active0 & 0x8000L) != 0L) + { + jjmatchedKind = 15; + jjmatchedPos = 3; + } + else if ((active0 & 0x200000000L) != 0L) + return jjStartNfaWithStates_0(3, 33, 2); + else if ((active0 & 0x4000000000L) != 0L) + return jjStartNfaWithStates_0(3, 38, 2); + return jjMoveStringLiteralDfa4_0(active0, 0x88800000a980180L, active1, 0L); + case 104: + if ((active0 & 0x400L) != 0L) + return jjStartNfaWithStates_0(3, 10, 2); + return jjMoveStringLiteralDfa4_0(active0, 0x20000000000000L, active1, 0L); + case 107: + return jjMoveStringLiteralDfa4_0(active0, 0x2000000000L, active1, 0L); + case 108: + return jjMoveStringLiteralDfa4_0(active0, 0x201000000002000L, active1, 0L); + case 109: + return jjMoveStringLiteralDfa4_0(active0, 0x10000000000L, active1, 0L); + case 110: + if ((active0 & 0x10000000L) != 0L) + return jjStartNfaWithStates_0(3, 28, 2); + else if ((active0 & 0x80000000000L) != 0L) + return jjStartNfaWithStates_0(3, 43, 2); + return jjMoveStringLiteralDfa4_0(active0, 0x108000000000L, active1, 0L); + case 111: + return jjMoveStringLiteralDfa4_0(active0, 0x2000001000004010L, active1, 0L); + case 112: + if ((active0 & 0x1000000000000000L) != 0L) + return jjStartNfaWithStates_0(3, 60, 2); + return jjMoveStringLiteralDfa4_0(active0, 0x100000000L, active1, 0L); + case 114: + return jjMoveStringLiteralDfa4_0(active0, 0x20000L, active1, 0xc0000000L); + case 115: + return jjMoveStringLiteralDfa4_0(active0, 0x42000400000040L, active1, 0L); + case 116: + return jjMoveStringLiteralDfa4_0(active0, 0x10c00000000000L, active1, 0L); + case 117: + return jjMoveStringLiteralDfa4_0(active0, 0x100000000040000L, active1, 0L); + case 119: + if ((active0 & 0x10000L) != 0L) + return jjStartNfaWithStates_0(3, 16, 2); + break; + default : + break; + } + return jjStartNfa_0(2, active0, active1); +} +private int jjMoveStringLiteralDfa4_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(2, old0, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(3, active0, active1); + return 4; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa5_0(active0, 0x2000822000L, active1, 0xc0000000L); + case 99: + return jjMoveStringLiteralDfa5_0(active0, 0x100L, active1, 0L); + case 101: + if ((active0 & 0x40L) != 0L) + return jjStartNfaWithStates_0(4, 6, 2); + else if ((active0 & 0x1000000000000L) != 0L) + return jjStartNfaWithStates_0(4, 48, 2); + return jjMoveStringLiteralDfa5_0(active0, 0x10118000000000L, active1, 0L); + case 105: + return jjMoveStringLiteralDfa5_0(active0, 0x220c00000100000L, active1, 0L); + case 107: + if ((active0 & 0x1000000L) != 0L) + return jjStartNfaWithStates_0(4, 24, 2); + else if ((active0 & 0x20000000L) != 0L) + return jjStartNfaWithStates_0(4, 29, 2); + break; + case 108: + if ((active0 & 0x80L) != 0L) + return jjStartNfaWithStates_0(4, 7, 2); + else if ((active0 & 0x800L) != 0L) + return jjStartNfaWithStates_0(4, 11, 2); + break; + case 109: + return jjMoveStringLiteralDfa5_0(active0, 0x40000000000L, active1, 0L); + case 110: + return jjMoveStringLiteralDfa5_0(active0, 0x84000000000000L, active1, 0L); + case 112: + return jjMoveStringLiteralDfa5_0(active0, 0x40000000L, active1, 0L); + case 114: + if ((active0 & 0x8000000L) != 0L) + return jjStartNfaWithStates_0(4, 27, 2); + else if ((active0 & 0x8000000000000L) != 0L) + return jjStartNfaWithStates_0(4, 51, 2); + return jjMoveStringLiteralDfa5_0(active0, 0x28000010000c0030L, active1, 0L); + case 115: + if ((active0 & 0x400000000L) != 0L) + return jjStartNfaWithStates_0(4, 34, 2); + break; + case 116: + if ((active0 & 0x100000000000000L) != 0L) + return jjStartNfaWithStates_0(4, 56, 2); + return jjMoveStringLiteralDfa5_0(active0, 0x42200004004000L, active1, 0L); + case 117: + return jjMoveStringLiteralDfa5_0(active0, 0x100000000L, active1, 0L); + case 119: + return jjMoveStringLiteralDfa5_0(active0, 0x2000000L, active1, 0L); + default : + break; + } + return jjStartNfa_0(3, active0, active1); +} +private int jjMoveStringLiteralDfa5_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(3, old0, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(4, active0, active1); + return 5; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa6_0(active0, 0x2c00000004000L, active1, 0L); + case 99: + if ((active0 & 0x200000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 57, 2); + return jjMoveStringLiteralDfa6_0(active0, 0x10108000002000L, active1, 0L); + case 100: + if ((active0 & 0x2000000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 61, 2); + return jjMoveStringLiteralDfa6_0(active0, 0x84000000000000L, active1, 0L); + case 101: + return jjMoveStringLiteralDfa6_0(active0, 0x40000000020L, active1, 0L); + case 102: + if ((active0 & 0x100000L) != 0L) + return jjStartNfaWithStates_0(5, 20, 2); + break; + case 103: + return jjMoveStringLiteralDfa6_0(active0, 0x2000000000L, active1, 0L); + case 104: + return jjMoveStringLiteralDfa6_0(active0, 0x2000000L, active1, 0L); + case 105: + return jjMoveStringLiteralDfa6_0(active0, 0x200004000010L, active1, 0L); + case 108: + return jjMoveStringLiteralDfa6_0(active0, 0x100L, active1, 0L); + case 109: + if ((active0 & 0x800000L) != 0L) + return jjStartNfaWithStates_0(5, 23, 2); + break; + case 110: + if ((active0 & 0x40000L) != 0L) + return jjStartNfaWithStates_0(5, 18, 2); + else if ((active0 & 0x20000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 53, 2); + return jjMoveStringLiteralDfa6_0(active0, 0x800000000000000L, active1, 0L); + case 114: + return jjMoveStringLiteralDfa6_0(active0, 0x40010000000000L, active1, 0L); + case 115: + return jjMoveStringLiteralDfa6_0(active0, 0x40000000L, active1, 0L); + case 116: + if ((active0 & 0x80000L) != 0L) + return jjStartNfaWithStates_0(5, 19, 2); + else if ((active0 & 0x100000000L) != 0L) + return jjStartNfaWithStates_0(5, 32, 2); + else if ((active0 & 0x1000000000L) != 0L) + return jjStartNfaWithStates_0(5, 36, 2); + return jjMoveStringLiteralDfa6_0(active0, 0x20000L, active1, 0xc0000000L); + default : + break; + } + return jjStartNfa_0(4, active0, active1); +} +private int jjMoveStringLiteralDfa6_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(4, old0, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(5, active0, active1); + return 6; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa7_0(active0, 0x844010000000100L, active1, 0L); + case 101: + if ((active0 & 0x2000000000L) != 0L) + return jjStartNfaWithStates_0(6, 37, 2); + return jjMoveStringLiteralDfa7_0(active0, 0x2002000L, active1, 0L); + case 108: + if ((active0 & 0x400000000000L) != 0L) + return jjStartNfaWithStates_0(6, 46, 2); + else if ((active0 & 0x800000000000L) != 0L) + return jjStartNfaWithStates_0(6, 47, 2); + break; + case 110: + return jjMoveStringLiteralDfa7_0(active0, 0x2000000000000L, active1, 0L); + case 111: + return jjMoveStringLiteralDfa7_0(active0, 0x200004020000L, active1, 0xc0000000L); + case 115: + if ((active0 & 0x80000000000000L) != 0L) + return jjStartNfaWithStates_0(6, 55, 2); + break; + case 116: + if ((active0 & 0x8000000000L) != 0L) + { + jjmatchedKind = 39; + jjmatchedPos = 6; + } + return jjMoveStringLiteralDfa7_0(active0, 0x10140000004030L, active1, 0L); + case 117: + return jjMoveStringLiteralDfa7_0(active0, 0x40000000L, active1, 0L); + default : + break; + } + return jjStartNfa_0(5, active0, active1); +} +private int jjMoveStringLiteralDfa7_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(5, old0, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(6, active0, active1); + return 7; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa8_0(active0, 0x2000L, active1, 0L); + case 98: + return jjMoveStringLiteralDfa8_0(active0, 0x4000000000000L, active1, 0L); + case 101: + if ((active0 & 0x20L) != 0L) + return jjStartNfaWithStates_0(7, 5, 2); + return jjMoveStringLiteralDfa8_0(active0, 0x10040000000000L, active1, 0L); + case 104: + return jjMoveStringLiteralDfa8_0(active0, 0x10L, active1, 0L); + case 105: + return jjMoveStringLiteralDfa8_0(active0, 0x40000000004000L, active1, 0L); + case 108: + if ((active0 & 0x800000000000000L) != 0L) + return jjStartNfaWithStates_0(7, 59, 2); + return jjMoveStringLiteralDfa8_0(active0, 0x40000000L, active1, 0L); + case 110: + if ((active0 & 0x2000000L) != 0L) + return jjStartNfaWithStates_0(7, 25, 2); + else if ((active0 & 0x4000000L) != 0L) + return jjStartNfaWithStates_0(7, 26, 2); + else if ((active0 & 0x200000000000L) != 0L) + return jjStartNfaWithStates_0(7, 45, 2); + break; + case 111: + return jjMoveStringLiteralDfa8_0(active0, 0x100000000000L, active1, 0L); + case 114: + if ((active0 & 0x20000L) != 0L) + { + jjmatchedKind = 17; + jjmatchedPos = 7; + } + return jjMoveStringLiteralDfa8_0(active0, 0x100L, active1, 0xc0000000L); + case 116: + if ((active0 & 0x2000000000000L) != 0L) + return jjStartNfaWithStates_0(7, 49, 2); + return jjMoveStringLiteralDfa8_0(active0, 0x10000000000L, active1, 0L); + default : + break; + } + return jjStartNfa_0(6, active0, active1); +} +private int jjMoveStringLiteralDfa8_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(6, old0, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(7, active0, active1); + return 8; + } + switch(curChar) + { + case 32: + return jjMoveStringLiteralDfa9_0(active0, 0L, active1, 0xc0000000L); + case 97: + return jjMoveStringLiteralDfa9_0(active0, 0x40000000L, active1, 0L); + case 98: + return jjMoveStringLiteralDfa9_0(active0, 0x2000L, active1, 0L); + case 100: + if ((active0 & 0x10000000000000L) != 0L) + return jjStartNfaWithStates_0(8, 52, 2); + break; + case 101: + if ((active0 & 0x100L) != 0L) + return jjStartNfaWithStates_0(8, 8, 2); + break; + case 105: + return jjMoveStringLiteralDfa9_0(active0, 0x10000000000L, active1, 0L); + case 108: + return jjMoveStringLiteralDfa9_0(active0, 0x4000000000000L, active1, 0L); + case 109: + if ((active0 & 0x10L) != 0L) + return jjStartNfaWithStates_0(8, 4, 2); + break; + case 110: + return jjMoveStringLiteralDfa9_0(active0, 0x40000000000000L, active1, 0L); + case 111: + return jjMoveStringLiteralDfa9_0(active0, 0x4000L, active1, 0L); + case 114: + if ((active0 & 0x40000000000L) != 0L) + return jjStartNfaWithStates_0(8, 42, 2); + else if ((active0 & 0x100000000000L) != 0L) + return jjStartNfaWithStates_0(8, 44, 2); + break; + default : + break; + } + return jjStartNfa_0(7, active0, active1); +} +private int jjMoveStringLiteralDfa9_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(7, old0, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(8, active0, active1); + return 9; + } + switch(curChar) + { + case 101: + if ((active0 & 0x4000000000000L) != 0L) + return jjStartNfaWithStates_0(9, 50, 2); + return jjMoveStringLiteralDfa10_0(active0, 0x40000000000000L, active1, 0L); + case 102: + return jjMoveStringLiteralDfa10_0(active0, 0L, active1, 0x40000000L); + case 108: + return jjMoveStringLiteralDfa10_0(active0, 0x2000L, active1, 0L); + case 110: + if ((active0 & 0x4000L) != 0L) + return jjStartNfaWithStates_0(9, 14, 2); + break; + case 111: + return jjMoveStringLiteralDfa10_0(active0, 0x10000000000L, active1, 0L); + case 114: + return jjMoveStringLiteralDfa10_0(active0, 0L, active1, 0x80000000L); + case 116: + return jjMoveStringLiteralDfa10_0(active0, 0x40000000L, active1, 0L); + default : + break; + } + return jjStartNfa_0(8, active0, active1); +} +private int jjMoveStringLiteralDfa10_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(8, old0, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(9, active0, active1); + return 10; + } + switch(curChar) + { + case 100: + return jjMoveStringLiteralDfa11_0(active0, 0x40000000000000L, active1, 0L); + case 101: + if ((active0 & 0x2000L) != 0L) + return jjStartNfaWithStates_0(10, 13, 2); + return jjMoveStringLiteralDfa11_0(active0, 0x40000000L, active1, 0x80000000L); + case 110: + if ((active0 & 0x10000000000L) != 0L) + return jjStartNfaWithStates_0(10, 40, 2); + break; + case 117: + return jjMoveStringLiteralDfa11_0(active0, 0L, active1, 0x40000000L); + default : + break; + } + return jjStartNfa_0(9, active0, active1); +} +private int jjMoveStringLiteralDfa11_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(9, old0, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(10, active0, active1); + return 11; + } + switch(curChar) + { + case 98: + return jjMoveStringLiteralDfa12_0(active0, 0x40000000000000L, active1, 0L); + case 99: + return jjMoveStringLiteralDfa12_0(active0, 0L, active1, 0x80000000L); + case 100: + if ((active0 & 0x40000000L) != 0L) + return jjStartNfaWithStates_0(11, 30, 2); + break; + case 110: + return jjMoveStringLiteralDfa12_0(active0, 0L, active1, 0x40000000L); + default : + break; + } + return jjStartNfa_0(10, active0, active1); +} +private int jjMoveStringLiteralDfa12_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(10, old0, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(11, active0, active1); + return 12; + } + switch(curChar) + { + case 99: + return jjMoveStringLiteralDfa13_0(active0, 0L, active1, 0x40000000L); + case 111: + return jjMoveStringLiteralDfa13_0(active0, 0L, active1, 0x80000000L); + case 121: + if ((active0 & 0x40000000000000L) != 0L) + return jjStartNfaWithStates_0(12, 54, 2); + break; + default : + break; + } + return jjStartNfa_0(11, active0, active1); +} +private int jjMoveStringLiteralDfa13_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(11, old0, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(12, 0L, active1); + return 13; + } + switch(curChar) + { + case 114: + return jjMoveStringLiteralDfa14_0(active1, 0x80000000L); + case 116: + return jjMoveStringLiteralDfa14_0(active1, 0x40000000L); + default : + break; + } + return jjStartNfa_0(12, 0L, active1); +} +private int jjMoveStringLiteralDfa14_0(long old1, long active1) +{ + if (((active1 &= old1)) == 0L) + return jjStartNfa_0(12, 0L, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(13, 0L, active1); + return 14; + } + switch(curChar) + { + case 100: + if ((active1 & 0x80000000L) != 0L) + return jjStopAtPos(14, 95); + break; + case 105: + return jjMoveStringLiteralDfa15_0(active1, 0x40000000L); + default : + break; + } + return jjStartNfa_0(13, 0L, active1); +} +private int jjMoveStringLiteralDfa15_0(long old1, long active1) +{ + if (((active1 &= old1)) == 0L) + return jjStartNfa_0(13, 0L, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(14, 0L, active1); + return 15; + } + switch(curChar) + { + case 111: + return jjMoveStringLiteralDfa16_0(active1, 0x40000000L); + default : + break; + } + return jjStartNfa_0(14, 0L, active1); +} +private int jjMoveStringLiteralDfa16_0(long old1, long active1) +{ + if (((active1 &= old1)) == 0L) + return jjStartNfa_0(14, 0L, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(15, 0L, active1); + return 16; + } + switch(curChar) + { + case 110: + if ((active1 & 0x40000000L) != 0L) + return jjStopAtPos(16, 94); + break; + default : + break; + } + return jjStartNfa_0(15, 0L, active1); +} +private int jjStartNfaWithStates_0(int pos, int kind, int state) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return pos + 1; } + return jjMoveNfa_0(state, pos + 1); +} +static final long[] jjbitVec0 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +private int jjMoveNfa_0(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 31; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 13: + if (curChar == 47) + { + if (kind > 3) + kind = 3; + jjCheckNAdd(20); + } + else if (curChar == 42) + jjCheckNAddStates(0, 2); + break; + case 0: + if ((0x3ff000000000000L & l) != 0L) + { + if (kind > 92) + kind = 92; + jjCheckNAddStates(3, 7); + } + else if ((0x100002600L & l) != 0L) + { + if (kind > 1) + kind = 1; + } + else if (curChar == 47) + jjAddStates(8, 9); + else if (curChar == 46) + jjCheckNAdd(9); + else if (curChar == 34) + jjCheckNAddStates(10, 12); + break; + case 2: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 90) + kind = 90; + jjstateSet[jjnewStateCnt++] = 2; + break; + case 3: + if (curChar == 34) + jjCheckNAddStates(10, 12); + break; + case 4: + if ((0xfffffffbfffffbffL & l) != 0L) + jjCheckNAddStates(10, 12); + break; + case 6: + if ((0xfffffffffffffbffL & l) != 0L) + jjCheckNAddStates(10, 12); + break; + case 7: + if (curChar == 34 && kind > 91) + kind = 91; + break; + case 8: + if (curChar == 46) + jjCheckNAdd(9); + break; + case 9: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjCheckNAddTwoStates(9, 10); + break; + case 11: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjstateSet[jjnewStateCnt++] = 11; + break; + case 12: + if (curChar == 47) + jjAddStates(8, 9); + break; + case 14: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddStates(0, 2); + break; + case 15: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 16; + break; + case 16: + if ((0xffff7fffffffffffL & l) != 0L) + jjCheckNAddStates(0, 2); + break; + case 17: + if (curChar == 47 && kind > 2) + kind = 2; + break; + case 18: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 17; + break; + case 19: + if (curChar != 47) + break; + if (kind > 3) + kind = 3; + jjCheckNAdd(20); + break; + case 20: + if ((0xfffffffffffffbffL & l) == 0L) + break; + if (kind > 3) + kind = 3; + jjCheckNAdd(20); + break; + case 21: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 92) + kind = 92; + jjCheckNAddStates(3, 7); + break; + case 22: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 92) + kind = 92; + jjCheckNAdd(22); + break; + case 23: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(23, 24); + break; + case 24: + if (curChar != 46) + break; + if (kind > 93) + kind = 93; + jjCheckNAddTwoStates(25, 26); + break; + case 25: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjCheckNAddTwoStates(25, 26); + break; + case 27: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjstateSet[jjnewStateCnt++] = 27; + break; + case 28: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(28, 29); + break; + case 30: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjstateSet[jjnewStateCnt++] = 30; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 0: + case 2: + if ((0x7fffffe87fffffeL & l) == 0L) + break; + if (kind > 90) + kind = 90; + jjCheckNAdd(2); + break; + case 4: + if ((0xffffffffefffffffL & l) != 0L) + jjCheckNAddStates(10, 12); + break; + case 5: + if (curChar == 92) + jjstateSet[jjnewStateCnt++] = 6; + break; + case 6: + jjCheckNAddStates(10, 12); + break; + case 10: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 11; + break; + case 14: + case 16: + jjCheckNAddStates(0, 2); + break; + case 20: + if (kind > 3) + kind = 3; + jjstateSet[jjnewStateCnt++] = 20; + break; + case 26: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 27; + break; + case 29: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 30; + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 4: + case 6: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddStates(10, 12); + break; + case 14: + case 16: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddStates(0, 2); + break; + case 20: + if ((jjbitVec0[i2] & l2) == 0L) + break; + if (kind > 3) + kind = 3; + jjstateSet[jjnewStateCnt++] = 20; + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + if ((i = jjnewStateCnt) == (startsAt = 31 - (jjnewStateCnt = startsAt))) + return curPos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return curPos; } + } +} +static final int[] jjnextStates = { + 14, 15, 18, 22, 23, 24, 28, 29, 13, 19, 4, 5, 7, +}; + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, "\141\154\147\157\162\151\164\150\155", +"\144\151\163\143\162\145\164\145", "\146\141\154\163\145", "\155\157\144\145\154", +"\162\145\144\145\143\154\141\162\145", "\141\156\144", "\145\141\143\150", "\146\151\156\141\154", "\156\157\164", +"\162\145\160\154\141\143\145\141\142\154\145", "\141\156\156\157\164\141\164\151\157\156", "\145\154\163\145", +"\146\154\157\167", "\157\160\145\162\141\164\157\162", "\162\145\164\165\162\156", +"\141\163\163\145\162\164", "\145\154\163\145\151\146", "\146\157\162", "\157\162", +"\163\164\162\145\141\155", "\142\154\157\143\153", "\145\154\163\145\167\150\145\156", +"\146\165\156\143\164\151\157\156", "\157\165\164\145\162", "\164\150\145\156", "\142\162\145\141\153", +"\145\156\143\141\160\163\165\154\141\164\145\144", "\151\146", "\157\165\164\160\165\164", "\164\162\165\145", +"\143\154\141\163\163", "\145\156\144", "\151\155\160\157\162\164", "\160\141\143\153\141\147\145", +"\164\171\160\145", "\143\157\156\156\145\143\164", +"\145\156\165\155\145\162\141\164\151\157\156", "\151\156", "\160\141\162\141\155\145\164\145\162", "\167\150\145\156", +"\143\157\156\156\145\143\164\157\162", "\145\161\165\141\164\151\157\156", "\151\156\151\164\151\141\154", +"\160\141\162\164\151\141\154", "\167\150\151\154\145", "\143\157\156\163\164\141\156\164", +"\145\170\160\141\156\144\141\142\154\145", "\151\156\156\145\162", "\160\162\157\164\145\143\164\145\144", +"\167\151\164\150\151\156", "\143\157\156\163\164\162\141\151\156\145\144\142\171", +"\145\170\164\145\156\144\163", "\151\156\160\165\164", "\160\165\142\154\151\143", "\144\145\162", +"\145\170\164\145\162\156\141\154", "\154\157\157\160", "\162\145\143\157\162\144", "\50", "\51", "\173", "\175", +"\133", "\135", "\56", "\72", "\73", "\54", "\74", "\74\75", "\76", "\76\75", +"\75\75", "\74\76", "\53", "\55", "\56\53", "\56\55", "\52", "\57", "\56\52", "\56\57", +"\136", "\56\136", "\75", "\72\75", null, null, null, null, +"\157\160\145\162\141\164\157\162\40\146\165\156\143\164\151\157\156", "\157\160\145\162\141\164\157\162\40\162\145\143\157\162\144", }; + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", +}; +static final long[] jjtoToken = { + 0xfffffffffffffff1L, 0xffffffffL, +}; +static final long[] jjtoSkip = { + 0xeL, 0x0L, +}; +protected SimpleCharStream input_stream; +private final int[] jjrounds = new int[31]; +private final int[] jjstateSet = new int[62]; +private final StringBuilder jjimage = new StringBuilder(); +private StringBuilder image = jjimage; +private int jjimageLen; +private int lengthOfMatch; +protected char curChar; +/** Constructor. */ +public ModelParserTokenManager(SimpleCharStream stream){ + if (SimpleCharStream.staticFlag) + throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); + input_stream = stream; +} + +/** Constructor. */ +public ModelParserTokenManager(SimpleCharStream stream, int lexState){ + this(stream); + SwitchTo(lexState); +} + +/** Reinitialise parser. */ +public void ReInit(SimpleCharStream stream) +{ + jjmatchedPos = jjnewStateCnt = 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); +} +private void ReInitRounds() +{ + int i; + jjround = 0x80000001; + for (i = 31; i-- > 0;) + jjrounds[i] = 0x80000000; +} + +/** Reinitialise parser. */ +public void ReInit(SimpleCharStream stream, int lexState) +{ + ReInit(stream); + SwitchTo(lexState); +} + +/** Switch to specified lex state. */ +public void SwitchTo(int lexState) +{ + if (lexState >= 1 || lexState < 0) + throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); + else + curLexState = lexState; +} + +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = (im == null) ? input_stream.GetImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind, curTokenImage); + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop : + for (;;) + { + try + { + curChar = input_stream.BeginToken(); + } + catch(java.io.IOException e) + { + jjmatchedKind = 0; + matchedToken = jjFillToken(); + return matchedToken; + } + image = jjimage; + image.setLength(0); + jjimageLen = 0; + + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + TokenLexicalActions(matchedToken); + return matchedToken; + } + else + { + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { input_stream.readChar(); input_stream.backup(1); } + catch (java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + } + throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); + } +} + +void TokenLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + case 91 : + image.append(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))); + matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); + break; + default : + break; + } +} +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + +private void jjCheckNAddStates(int start, int end) +{ + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); +} + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ModelicaParser.jj b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ModelicaParser.jj new file mode 100644 index 00000000..cc155d08 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ModelicaParser.jj @@ -0,0 +1,634 @@ +options { + JDK_VERSION = "1.6"; + STATIC = false; +} + +PARSER_BEGIN(ModelParser) +package org.simantics.sysdyn.modelParser; + +public class ModelParser { + +} + +PARSER_END(ModelParser) + +/*** Lexer *********************************************************/ + +SKIP: +{ +| +| +} + +TOKEN: +{ +"algorithm" | "discrete" | "false" | "model" | "redeclare" +| "and" | "each" | "final" | "not" | "replaceable" +| "annotation" | "else" | "flow" | "operator" | "return" +|"assert" | "elseif" | "for" | "or" | "stream" +| "block" | "elsewhen" | "function" | "outer" | "then" +| "break" | "encapsulated" | "if" | "output" | "true" +| "class" | "end" | "import" | "package" | "type" +| "connect" | "enumeration" | "in" | "parameter" | "when" +| "connector" | "equation" | "initial" | "partial" | "while" +| "constant" | "expandable" | "inner" | "protected" | "within" +| "constrainedby" | "extends" | "input" | "public" +| "der" | "external" | "loop" | "record" +| "(" | ")" | "{" | "}" | "[" | "]" | "." | ":" | ";" | "," +| "<" | "<=" | ">" | ">=" | "==" | "<>" +| "+" | "-" | ".+" | ".-" +| "*" | "/" | ".*" | "./" +| "^" | ".^" +| "=" | ":=" +| +| + { matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); } +| +| "." ()? (["e","E"] )? + | "." (["e","E"] )? + | ["e","E"] + ) > +} + +/*** Parser ********************************************************/ + +// https://javacc.dev.java.net/doc/javaccgrm.html +// add_op -> add_op() +// [ add_op ] -> ( add_op() )? +// { add_op term } -> ( add_op() term() )* + +void parse() : { } { stored_definition() +} + +/*** Stored Definition - Within ************************************/ + +void stored_definition() : { +} { +// stored_definition: +// [ within [ name ] ";" ] +// { [ final ] class_definition ";" } + ( "within" ( name() )? ";" )? + ( ( "final" )? class_definition() ";" )* } +/*** Class Definition **********************************************/ + +void class_definition() : { +} { +// class_definition : +// [ encapsulated ] +// [ partial +// ] ( class modelrecordblock expandableconnectortype +// | | | | [ ] | | package | function | operator | operator function | operator record ) +// class_specifier + ( "encapsulated" )? + ( "partial" )? + ( "class" | "model" | "record" | "block" | ( "expandable" )? "connector" | "type" | + "package" | "function" | "operator" | "operator function" | "operator record" ) + class_specifier() } + + +void class_specifier() : { +} { +// class_specifier : +// IDENT string_comment composition end IDENT +// | IDENT "=" base_prefix name [ array_subscripts ] +// [ class_modification ] comment +// | IDENT "=" enumeration "(" ( [enum_list] | ":" ) ")" comment +// | IDENT "=" der "(" name "," IDENT { "," IDENT } ")" comment +// | extends IDENT [ class_modification ] string_comment composition +// end IDENT + LOOKAHEAD(2) string_comment() composition() "end" + | LOOKAHEAD(2) "=" base_prefix() name() ( array_subscripts() )? ( class_modification() )? comment() + | LOOKAHEAD(3) "=" "enumeration" "(" ( ( enum_list() )? | ":" ) ")" comment() + |LOOKAHEAD(3) "=" "der" "(" name() "," ( "," )* ")" comment() + | "extends" ( class_modification() )? string_comment() composition() "end" +} + +void base_prefix() : { +} { + type_prefix() +} + +void enum_list() : { +} { +// enumeration_literal { "," enumeration_literal} + enumeration_literal() ( "," enumeration_literal() )* +} + +void enumeration_literal() : { +} { + comment() +} + +void parse_composition() : { +} { + composition() +} + +void composition() : { +} { +// element_list +// { public element_list | +// protected element_list | +// equation_section | +// algorithm_section +// } +// [ external [ language_specification ] +// [ external_function_call ] [ annotation ] ";" ] +// [ annotation ";" ] + element_list() + ( LOOKAHEAD(2) "public" element_list() | "protected" element_list() | equation_section() | algorithm_section() )* + ( "external" ( language_specification() )? ( external_function_call() )? ( annotation() )? ";" )? + ( annotation() ";" )? } + +void language_specification() : { +} { + +} + +void external_function_call() : { +} { +// [ component_reference "=" ] +// IDENT "(" [ expression_list ] ")" + ( component_reference() "=" )? + "(" ( expression_list() )? ")" } + +void element_list() : { +} { + ( element() ";" )* } + +void element() : { +} { +// import_clause | +// extends_clause | +// [ redeclare ] +// [ final ] +// [ inner ] [ outer ] +// ( ( class_definition | component_clause) | +// replaceable ( class_definition | component_clause) +// [constraining_clause comment]) + import_clause() | + extends_clause() | + ( "redeclare" )? + ( "final" )? + ( "inner" )? ( "outer" )? + ( (class_definition() | component_clause()) | + "replaceable" (class_definition() | component_clause()) + (constraining_clause() comment())?) } + +void import_clause() : { +} { +// import ( IDENT "=" name | name ["." "*"] ) comment + "import" (LOOKAHEAD(2) "=" name() | name() ("." "*")? ) comment() +} + +/*** Extends *******************************************************/ +void extends_clause() : { +} { +// extends name [ class_modification ] [annotation] + "extends" name() ( class_modification() )? ( annotation() )? +} + +void constraining_clause() : { +} { +// constrainedby name [ class_modification ] + "constrainedby" name() ( class_modification() )? +} + +/*** Component Clause **********************************************/ +void component_clause() : { +} { +// type_prefix type_specifier [ array_subscripts ] component_list + type_prefix() type_specifier() ( array_subscripts() )? component_list() +} + +void type_prefix() : { +} { +// [ flow | stream ] +// [ discrete | parameter | constant ] [ input | output ] + ( "flow" | "stream" )? + ( "discrete" | "parameter" | "constant" )? ( "input" | "output" )? } + +void type_specifier() : { +} { + name() +} + +void component_list() : { +} { +// component_declaration { "," component_declaration } + component_declaration() ( "," component_declaration() )* +} + +void component_declaration() : { +} { +// declaration [ conditional_attribute ] comment + declaration() ( conditional_attribute() )? comment() +} + +void conditional_attribute() : { +} { + "if" expression() +} + +void declaration() : { +} { +// IDENT [ array_subscripts ] [ modification ] + ( array_subscripts() )? ( modification() )? +} + +/*** Modification **********************************************/ +void modification() : { +} { +// class_modification [ "=" expression ] +// | "=" expression +// | ":=" expression + class_modification() ( "=" expression() )? + | "=" expression() + | ":=" expression() +} + +void class_modification() : { +} { +// "(" [ argument_list ] ")" + "(" ( argument_list() )? ")" +} + +void argument_list() : { +} { +// argument { "," argument } + argument() ( "," argument() )* +} + +void argument() : { +} { +// element_modification_or_replaceable +// | element_redeclaration + element_modification_or_replaceable() | + element_redeclaration() +} + +void element_modification_or_replaceable() : { +} { +// [ each ] [ final ] ( element_modification | element_replaceable) + ( "each" )? ( "final" )? ( element_modification() | element_replaceable() ) } + +void element_modification() : { +} { +// name [ modification ] string_comment + name() ( modification() )? string_comment() +} + +void element_redeclaration() : { +} { +// redeclare [ each ] [ final ] +// ( ( class_definition | component_clause1) | element_replaceable ) + "redeclare" ( "each" )? ( "final" )? + ( ( class_definition() | component_clause1() ) | element_replaceable() ) } + +void element_replaceable() : { +} { +// replaceable ( class_definition | component_clause1) +// [constraining_clause] + "replaceable" ( class_definition() | component_clause1() ) ( constraining_clause() )? +} + +void component_clause1() : { +} { +// type_prefix type_specifier component_declaration1 + type_prefix() type_specifier() component_declaration1() +} + +void component_declaration1() : { +} { + declaration() comment() +} + + +/*** Equations *************************************************/ +void equation_section() : { +} { +// [ initial ] equation { equation ";" } + ( "initial" )? "equation" ( equation() ";" )* +} + +void algorithm_section() : { +} { +// [ initial ] algorithm { statement ";" } + ( "initial" )? "algorithm" ( statement() ";" )* } + +void equation() : { +} { +// ( simple_expression "=" expression +// | if_equation +// | for_equation +// | connect_clause +// | when_equation +// | IDENT function_call_args ) +// comment + ( LOOKAHEAD(3) simple_expression() "=" expression() + | if_equation() + | for_equation() + | connect_clause() + | when_equation() + | function_call_args() ) + comment() } + +void statement() : { +} { +// ( component_reference ( ":=" expression | function_call_args ) +// | "(" output_expression_list ")" ":=" component_reference function_call_args +// | break +// | return +// | if_statement +// | for_statement +// | while_statement +// | when_statement ) +// comment + ( component_reference() ( ":=" expression() | function_call_args() ) + | "(" output_expression_list() ")" ":=" component_reference() function_call_args() + | "break" + | "return" + | if_statement() + | for_statement() + | while_statement() + | when_statement() ) + comment() +} + +void if_equation() : { +} { +// if expression then +// { equation ";" } +// { elseif expression then +// { equation ";" } +// } +// [ else +// { equation ";" } +// ] +// end if + "if" expression() "then" + ( equation() ";" )* + ( "elseif" expression() "then" + ( equation() ";" )* + )* + ( "else" + ( equation() ";" )* + )? + "end" "if" } + +void if_statement() : { +} { +// if expression then +// { statement ";" } +// { elseif expression then +// { statement ";" } +// } +// [ else +// { statement ";" } +// ] +// end if + "if" expression() "then" + ( statement() ";" )* + ( "elseif" expression() "then" + ( statement() ";" )* + )* + ( "else" + ( statement() ";" )* + )? + "end" "if" } + +void for_equation() : { +} { +// for for_indices loop +// { equation ";" } +// end for + "for" for_indices() "loop" + ( equation() ";" )* + "end" "for" } + +void for_statement() : { +} { +// for for_indices loop +// { equation ";" } +// end for + "for" for_indices() "loop" + ( statement() ";" )* + "end" "for" } + +void for_indices() : { +} { + //for_index {"," for_index} + for_index() ("," for_index())* +} + +void for_index() : { +} { + //IDENT [ in expression ] + ( "in" expression() )? +} + +void while_statement() : { +} { +// while expression loop +// { statement ";" } +// end while + "while" expression() "loop" + ( statement() ";" )* + "end" "while" } + +void when_equation() : { +} { +// when expression then +// { equation ";" } +// { elsewhen expression then +// { equation ";" } } +// end when + "when" expression() "then" + ( equation() ";" )* + ( "elsewhen" expression() "then" + ( equation() ";" )* + )* + "end" "when" } + +void when_statement() : { +} { +// when expression then +// { statement ";" } +// { elsewhen expression then +// { statement ";" } } +// end when + "when" expression() "then" + ( statement() ";" )* + ( "elsewhen" expression() "then" + ( statement() ";" )* + )* + "end" "when" } + +void connect_clause() : { +} { +// connect "(" component_reference "," component_reference ")" + "connect" "(" component_reference() "," component_reference() ")" +} + +/*** Expressions ***************************************************/ +void expr() : { +} { + simple_expression() + | + "if" expression() "then" expression() ( "elseif" expression() "then" expression() )* + "else" expression() +} + +void expression() : { +} { + simple_expression() + | "if" expression() "then" expression() ( "elseif" expression() "then" expression() )* + "else" expression() +} + +void simple_expression() : { +} { + logical_expression() ( ":" logical_expression() ( ":" logical_expression() )? )? +} + +void logical_expression() : { +} { + logical_term() ( "or" logical_term() )* +} + +void logical_term() : { +} { + logical_factor() ( "and" logical_factor() )* +} + +void logical_factor() : { +} { + ( "not" )? relation() +} + +void relation() : { +} { + arithmetic_expression() ( rel_op() arithmetic_expression() )? +} + +void rel_op() : { +} { + "<" | "<=" | ">" | ">=" | "==" | "<>" +} + +void arithmetic_expression() : { +} { + (add_op())? term() (add_op() term())* +} + +void add_op() : { +} { + "+" | "-" | ".+" | ".-" +} + +void term() : { +} { + factor() ( mul_op() factor() )* +} + +void mul_op() : { +} { + "*" | "/" | ".*" | "./" +} + +void factor() : { +} { + primary() ( "^" | ".^" primary() )? +} + +void primary() : { +} { + + | + | + | "false" + | "true" + | LOOKAHEAD( (name()|"der"|"initial") "(" ) (name()|"der"|"initial") function_call_args() + | component_reference() + | "(" output_expression_list() ")" + | "[" expression_list() ( ";" expression_list() )* "]" + | "{" function_arguments() "}" + | "end" +} + +void name() : { +} { +// [ "." ] IDENT { "." IDENT } + ( "." )? ( "." )* +} + +void component_reference() : { +} { +// [ "." ] IDENT [ array_subscripts ] { "." IDENT [ array_subscripts ] } + ( "." )? ( array_subscripts() )? ( "." ( array_subscripts() )? )* +} + +void function_call_args() : { +} { +// "(" [ function_arguments ] ")" + "(" ( function_arguments() )? ")" +} + +void function_arguments() : { +} { + //expression [ "," function_arguments | for for_indices ] + //| named_arguments + LOOKAHEAD(2) expression() ( "," function_arguments() | "for" for_indices() )? + | named_arguments() +} + +void named_arguments() : { +} { +// named_argument [ "," named_arguments ] + named_argument() ( "," named_arguments() )? +} + +void named_argument() : { +} { + "=" expression() +} + +void output_expression_list() : { +} { +// [ expression ] { "," [ expression ] } + ( expression() )? ( "," ( expression() )? )* +} + +void expression_list() : { +} { +// expression { "," expression } + expression() ( "," expression() )* +} + +void array_subscripts() : { +} { +// "[" subscript { "," subscript } "]" + "[" subscript() ( "," subscript() )* "]" +} + +void subscript() : { +} { +// ":" | expression ":" | expression() +} + +void comment() : { } { // string_comment [ annotation ] + string_comment() ( annotation() )? +} + +void string_comment() : { +} { +// [ STRING { "+" STRING } ] + ( ( "+" )* )? } + +void annotation() : { +} { +// annotation class_modification + "annotation" class_modification() +} + diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ParseException.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ParseException.java new file mode 100644 index 00000000..86734a78 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/ParseException.java @@ -0,0 +1,187 @@ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */ +/* JavaCCOptions:KEEP_LINE_COL=null */ +package org.simantics.sysdyn.modelParser; + +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(Token currentTokenVal, + int[][] expectedTokenSequencesVal, + String[] tokenImageVal + ) + { + super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String initialise(Token currentToken, + int[][] expectedTokenSequences, + String[] tokenImage) { + String eol = System.getProperty("line.separator", "\n"); + StringBuffer expected = new StringBuffer(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) { + maxSize = expectedTokenSequences[i].length; + } + for (int j = 0; j < expectedTokenSequences[i].length; j++) { + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + } + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { + expected.append("..."); + } + expected.append(eol).append(" "); + } + String retval = "Encountered \""; + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + if (i != 0) retval += " "; + if (tok.kind == 0) { + retval += tokenImage[0]; + break; + } + retval += " " + tokenImage[tok.kind]; + retval += " \""; + retval += add_escapes(tok.image); + retval += " \""; + tok = tok.next; + } + retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; + retval += "." + eol; + if (expectedTokenSequences.length == 1) { + retval += "Was expecting:" + eol + " "; + } else { + retval += "Was expecting one of:" + eol + " "; + } + retval += expected.toString(); + return retval; + } + + /** + * The end of line string for this machine. + */ + protected String eol = System.getProperty("line.separator", "\n"); + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + +} +/* JavaCC - OriginalChecksum=e46c56bfa832359193465f81e8a2147e (do not edit this line) */ diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/SimpleCharStream.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/SimpleCharStream.java new file mode 100644 index 00000000..102b285e --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/SimpleCharStream.java @@ -0,0 +1,471 @@ +/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 5.0 */ +/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +package org.simantics.sysdyn.modelParser; + +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public class SimpleCharStream +{ +/** Whether parser is static. */ + public static final boolean staticFlag = false; + int bufsize; + int available; + int tokenBegin; +/** Position in buffer. */ + public int bufpos = -1; + protected int bufline[]; + protected int bufcolumn[]; + + protected int column = 0; + protected int line = 1; + + protected boolean prevCharIsCR = false; + protected boolean prevCharIsLF = false; + + protected java.io.Reader inputStream; + + protected char[] buffer; + protected int maxNextCharInd = 0; + protected int inBuf = 0; + protected int tabSize = 8; + + protected void setTabSize(int i) { tabSize = i; } + protected int getTabSize(int i) { return tabSize; } + + + protected void ExpandBuff(boolean wrapAround) + { + char[] newbuffer = new char[bufsize + 2048]; + int newbufline[] = new int[bufsize + 2048]; + int newbufcolumn[] = new int[bufsize + 2048]; + + try + { + if (wrapAround) + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos += (bufsize - tokenBegin)); + } + else + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos -= tokenBegin); + } + } + catch (Throwable t) + { + throw new Error(t.getMessage()); + } + + + bufsize += 2048; + available = bufsize; + tokenBegin = 0; + } + + protected void FillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + { + if (available == bufsize) + { + if (tokenBegin > 2048) + { + bufpos = maxNextCharInd = 0; + available = tokenBegin; + } + else if (tokenBegin < 0) + bufpos = maxNextCharInd = 0; + else + ExpandBuff(false); + } + else if (available > tokenBegin) + available = bufsize; + else if ((tokenBegin - available) < 2048) + ExpandBuff(true); + else + available = tokenBegin; + } + + int i; + try { + if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) + { + inputStream.close(); + throw new java.io.IOException(); + } + else + maxNextCharInd += i; + return; + } + catch(java.io.IOException e) { + --bufpos; + backup(0); + if (tokenBegin == -1) + tokenBegin = bufpos; + throw e; + } + } + +/** Start. */ + public char BeginToken() throws java.io.IOException + { + tokenBegin = -1; + char c = readChar(); + tokenBegin = bufpos; + + return c; + } + + protected void UpdateLineColumn(char c) + { + column++; + + if (prevCharIsLF) + { + prevCharIsLF = false; + line += (column = 1); + } + else if (prevCharIsCR) + { + prevCharIsCR = false; + if (c == '\n') + { + prevCharIsLF = true; + } + else + line += (column = 1); + } + + switch (c) + { + case '\r' : + prevCharIsCR = true; + break; + case '\n' : + prevCharIsLF = true; + break; + case '\t' : + column--; + column += (tabSize - (column % tabSize)); + break; + default : + break; + } + + bufline[bufpos] = line; + bufcolumn[bufpos] = column; + } + +/** Read a character. */ + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + --inBuf; + + if (++bufpos == bufsize) + bufpos = 0; + + return buffer[bufpos]; + } + + if (++bufpos >= maxNextCharInd) + FillBuff(); + + char c = buffer[bufpos]; + + UpdateLineColumn(c); + return c; + } + + @Deprecated + /** + * @deprecated + * @see #getEndColumn + */ + + public int getColumn() { + return bufcolumn[bufpos]; + } + + @Deprecated + /** + * @deprecated + * @see #getEndLine + */ + + public int getLine() { + return bufline[bufpos]; + } + + /** Get token end column number. */ + public int getEndColumn() { + return bufcolumn[bufpos]; + } + + /** Get token end line number. */ + public int getEndLine() { + return bufline[bufpos]; + } + + /** Get token beginning column number. */ + public int getBeginColumn() { + return bufcolumn[tokenBegin]; + } + + /** Get token beginning line number. */ + public int getBeginLine() { + return bufline[tokenBegin]; + } + +/** Backup a number of characters. */ + public void backup(int amount) { + + inBuf += amount; + if ((bufpos -= amount) < 0) + bufpos += bufsize; + } + + /** Constructor. */ + public SimpleCharStream(java.io.Reader dstream, int startline, + int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } + + /** Constructor. */ + public SimpleCharStream(java.io.Reader dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.Reader dstream) + { + this(dstream, 1, 1, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader dstream, int startline, + int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + if (buffer == null || buffersize != buffer.length) + { + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } + prevCharIsLF = prevCharIsCR = false; + tokenBegin = inBuf = maxNextCharInd = 0; + bufpos = -1; + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader dstream) + { + ReInit(dstream, 1, 1, 4096); + } + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream) + { + this(dstream, 1, 1, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, 1, 1, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream) + { + ReInit(dstream, 1, 1, 4096); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, startline, startcolumn, 4096); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + /** Get token literal value. */ + public String GetImage() + { + if (bufpos >= tokenBegin) + return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); + else + return new String(buffer, tokenBegin, bufsize - tokenBegin) + + new String(buffer, 0, bufpos + 1); + } + + /** Get the suffix. */ + public char[] GetSuffix(int len) + { + char[] ret = new char[len]; + + if ((bufpos + 1) >= len) + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + else + { + System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, + len - bufpos - 1); + System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); + } + + return ret; + } + + /** Reset buffer when finished. */ + public void Done() + { + buffer = null; + bufline = null; + bufcolumn = null; + } + + /** + * Method to adjust line and column numbers for the start of a token. + */ + public void adjustBeginLineColumn(int newLine, int newCol) + { + int start = tokenBegin; + int len; + + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0, j = 0, k = 0; + int nextColDiff = 0, columnDiff = 0; + + while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) + { + bufline[j] = newLine; + nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; + bufcolumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + bufline[j] = newLine++; + bufcolumn[j] = newCol + columnDiff; + + while (i++ < len) + { + if (bufline[j = start % bufsize] != bufline[++start % bufsize]) + bufline[j] = newLine++; + else + bufline[j] = newLine; + } + } + + line = bufline[j]; + column = bufcolumn[j]; + } + +} +/* JavaCC - OriginalChecksum=7ab7faca15b64bda32c7a4effb209066 (do not edit this line) */ diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/Token.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/Token.java new file mode 100644 index 00000000..25d36184 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/Token.java @@ -0,0 +1,131 @@ +/* Generated By:JavaCC: Do not edit this line. Token.java Version 5.0 */ +/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +package org.simantics.sysdyn.modelParser; + +/** + * Describes the input token stream. + */ + +public class Token implements java.io.Serializable { + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(int kind) + { + this(kind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(int kind, String image) + { + this.kind = kind; + this.image = image; + } + + /** + * Returns the image. + */ + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* JavaCC - OriginalChecksum=8584b8a0988c627589640a007dbfe0bb (do not edit this line) */ diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/TokenMgrError.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/TokenMgrError.java new file mode 100644 index 00000000..60c67454 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelParser/TokenMgrError.java @@ -0,0 +1,147 @@ +/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */ +/* JavaCCOptions: */ +package org.simantics.sysdyn.modelParser; + +/** Token Manager Error. */ +public class TokenMgrError extends Error +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + + /** No arg constructor. */ + public TokenMgrError() { + } + + /** Constructor with message and reason. */ + public TokenMgrError(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { + this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* JavaCC - OriginalChecksum=d047fc9c0c00c40e4d34a354929bb60c (do not edit this line) */ diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java new file mode 100644 index 00000000..a9a7be8b --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java @@ -0,0 +1,208 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.modelica; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.simantics.sysdyn.representation.Book; +import org.simantics.sysdyn.representation.Configuration; +import org.simantics.sysdyn.representation.Dependency; +import org.simantics.sysdyn.representation.Enumeration; +import org.simantics.sysdyn.representation.IElement; +import org.simantics.sysdyn.representation.IndependentVariable; +import org.simantics.sysdyn.representation.Input; +import org.simantics.sysdyn.representation.Module; +import org.simantics.sysdyn.representation.ModuleType; +import org.simantics.sysdyn.representation.Stock; +import org.simantics.sysdyn.representation.Variable; + +public class ModelicaWriter { + + StringBuilder b = new StringBuilder(); + String app; + boolean enumerationsWritten = false; + + public void write(Configuration conf) { + + if(!enumerationsWritten) { + b.append("partial class Enumeration_class\n"); + b.append(" parameter Integer size;\n"); + b.append(" parameter Integer elements[:];\n"); + b.append("end Enumeration_class;\n\n"); + enumerationsWritten = true; + } + + writeConfiguration(conf); + } + + private void writeConfiguration(Configuration configuration) { + + ArrayList variables = new ArrayList(); + ArrayList inputs = new ArrayList(); + ArrayList modules = new ArrayList(); + ArrayList stocks = new ArrayList(); + ArrayList enumerations = new ArrayList(); + ArrayList inputDependencies = new ArrayList(); + ArrayList outputDependencies = new ArrayList(); + HashMap> moduleInputs = new HashMap>(); + Book book = null; + + // Initialize lists + for(IElement element : configuration.getElements()) { + if(element instanceof IndependentVariable) { + variables.add((IndependentVariable)element); + if(element instanceof Stock) + stocks.add((Stock)element); + } else if (element instanceof Module) { + Module m = (Module)element; + modules.add(m); + moduleInputs.put(m.getName(), new ArrayList()); + for(IElement e : m.getType().getConfiguration().getElements()) + if(e instanceof Input && !((Input)e).isHeadOfDependency()) { + moduleInputs.get(m.getName()).add((Input)e); + } + } else if (element instanceof Input) { + inputs.add((Input)element); + } else if (element instanceof Enumeration) { + enumerations.add((Enumeration)element); + } else if (element instanceof Dependency) { + Dependency dependency = (Dependency)element; + if(dependency.getHead() instanceof Module) { + outputDependencies.add(dependency); + } else if(dependency.getTail() instanceof Module){ + inputDependencies.add(dependency); + } + } else if (element instanceof Book) { + book = (Book)element; + } + } + + ModuleType mt = configuration.getModuleType(); + String className = mt != null ? (mt.getName().replace(" ", "")) : (configuration.getName().replace(" ", "")); + b.append("class ").append(className).append('\n'); + + b.append("// Variable definitions\n"); + for(IndependentVariable variable : variables) { + app = variable.getDeclaration(); + if (app != null) b.append(app); + } + + if(!modules.isEmpty()) { + b.append("// Module definitions\n"); + for(Module m : modules) { + b.append(m.getDeclaration()); + } + } + + if(!inputs.isEmpty()) { + b.append("// Input definitions\n"); + for(Input i : inputs) { + b.append(i.getDeclaration()); + } + } + + if(!enumerations.isEmpty()) { + b.append("// Enumeration definitions\n"); + for(Enumeration e : enumerations) { + b.append(e.getDeclaration()); + } + } + + if(book != null) { + b.append("// Spreadsheet definition\n"); + b.append(book.markBook()); + } + + boolean initialEquations = false; + for(Stock stock : stocks) { + app = stock.getInitialEquation(); + if (app != null) { + if(initialEquations == false) { + initialEquations = true; + b.append("// Initial Equations\n"); + b.append("initial equation\n"); + } + b.append(app); + } + } + + b.append("equation\n"); + + b.append("// Equations\n"); + for(IndependentVariable variable : variables) { + app = variable.getEquation(); + if (app != null) b.append(app); + } + + + b.append("// Inputs\n"); + for(Dependency dependency : inputDependencies) { + Input variable = (Input)dependency.getHead(); + Module module = (Module)dependency.getTail(); + Variable reference = (Variable)dependency.refersTo(); + if(reference != null && reference.getName() != null) + b.append(" " + variable.getName() + " = " + module.getName() + "." + reference.getName() + ";\n"); + else + b.append(" " + variable.getName() + " = " + variable.getDefaultInputValue() + ";\n"); + + if(configuration.getModel() != null) { + // Root configuration + inputs.remove(variable); + } + } + + // Set root configuration input defaults + if(configuration.getModel() != null) { + for(Input i : inputs) { + b.append(" " + i.getName() + " = " + i.getDefaultInputValue() + ";\n"); + } + } + + b.append("// Outputs\n"); + for(Dependency dependency : outputDependencies) { + Variable variable = (Variable)dependency.getTail(); + Module module = (Module)dependency.getHead(); + Input reference = (Input)dependency.refersTo(); + if(reference != null) { + b.append(" " + module.getName() + "." + reference.getName() + " = " + variable.getName() + ";\n"); + moduleInputs.get(module.getName()).remove(reference); + } + } + + b.append("// Default values for inputs in modules\n"); + for(String moduleLabel : moduleInputs.keySet()) { + for(Input input : moduleInputs.get(moduleLabel)) { + b.append(" " + moduleLabel + "." + input.getName() + " = " + input.getDefaultInputValue() + ";\n"); + } + } + + b.append("end ").append(className).append(";\n\n"); + + + // Update sheet definitions to contain the elements that were used. + if(book != null) { + int s = b.indexOf(book.markBook()); + b.replace(s, s + book.markBook().length(), book.getBook()); + } + } + + public String escape(String name) { + return name.replace(' ', '_'); + } + + @Override + public String toString() { + return b.toString(); + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ArrayIndexes.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ArrayIndexes.java new file mode 100644 index 00000000..1db1239b --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ArrayIndexes.java @@ -0,0 +1,18 @@ +package org.simantics.sysdyn.representation; + +import java.util.ArrayList; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedOrderedSetElements; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/ArrayIndexes") +public class ArrayIndexes { + + @RelatedOrderedSetElements + private ArrayList enumerations = new ArrayList(); + + public ArrayList getEnumerations() { + return enumerations; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Auxiliary.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Auxiliary.java new file mode 100644 index 00000000..fa150c78 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Auxiliary.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/Auxiliary") +public class Auxiliary extends IndependentVariable { + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Book.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Book.java new file mode 100644 index 00000000..8456e27c --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Book.java @@ -0,0 +1,38 @@ +package org.simantics.sysdyn.representation; + +import java.util.ArrayList; +import java.util.List; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedElements; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Spreadsheet-1.1/Book") +public class Book extends Variable { + + @RelatedElements( + value = "http://www.simantics.org/Layer0-1.0/ConsistsOf", + composition = true) + private ArrayList sheets = new ArrayList(); + + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } + + public List getSheets() { + return sheets; + } + + public String markBook() { + return "BOOK " + this.getName(); + } + + public String getBook() { + StringBuilder book = new StringBuilder(); + for(Sheet sheet : sheets) + book.append(sheet.getStringRepresentation()); + return book.toString(); + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Cloud.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Cloud.java new file mode 100644 index 00000000..56840b6c --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Cloud.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/Cloud") +public class Cloud implements IElement { + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Configuration.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Configuration.java new file mode 100644 index 00000000..b2e8e8a5 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Configuration.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import java.util.ArrayList; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedElement; +import org.simantics.objmap.annotations.RelatedElements; +import org.simantics.objmap.annotations.RelatedValue; + + +@GraphType("http://www.simantics.org/Sysdyn-1.1/Configuration") +public class Configuration { + + @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName") + private String name; + + @RelatedValue("http://www.simantics.org/Layer0-1.0/HasLabel") + private String label; + + @RelatedElement("http://www.simantics.org/Structural-1.0/Defines") + private ModuleType moduleType; + + @RelatedElement("http://www.simantics.org/Simulation-1.0/IsConfigurationOf") + private Model model; + + @RelatedElements( + value = "http://www.simantics.org/Layer0-1.0/ConsistsOf", + composition = true) + private ArrayList elements = new ArrayList(); + + + public ArrayList getElements() { + ArrayList elements = new ArrayList(); + elements.addAll(this.elements); + for(IElement e : this.elements) { + if(e instanceof Book) { + elements.addAll(((Book)e).getSheets()); + } + } + return elements; + } + + public String getName() { + return name; + } + + public String getLabel() { + return label; + } + + public ModuleType getModuleType() { + return moduleType; + } + + public Model getModel() { + return model; + } + + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Dependency.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Dependency.java new file mode 100644 index 00000000..2b220fbf --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Dependency.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedElement; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/Dependency") +public class Dependency implements IElement { + @RelatedElement("http://www.simantics.org/Sysdyn-1.1/HasTail") + private IElement tail; + @RelatedElement("http://www.simantics.org/Sysdyn-1.1/HasHead") + private IElement head; + @RelatedElement("http://www.simantics.org/Sysdyn-1.1/RefersTo") + private IElement refersTo; + + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } + + public IElement getTail() { + return this.tail; + } + + public IElement getHead() { + return this.head; + } + + public IElement refersTo() { + return this.refersTo; + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/DiagramContainerDummy.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/DiagramContainerDummy.java new file mode 100644 index 00000000..f30cc284 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/DiagramContainerDummy.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Diagram-2.1/DiagramContainer") +public class DiagramContainerDummy implements IElement { + + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } + +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java new file mode 100644 index 00000000..741f3375 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import java.util.ArrayList; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedElement; +import org.simantics.objmap.annotations.RelatedElements; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/Enumeration") +public class Enumeration extends Variable { + + @RelatedElement("http://www.simantics.org/Sysdyn-1.1/HasEnumerationIndexes") + private EnumerationIndexes enumerationIndexes; + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/IsReplaceable") + private Boolean isReplaceable; + + @RelatedElements( + value = "http://www.simantics.org/Sysdyn-1.1/ReplacedEnumeration/Inverse", + composition = true) + private ArrayList redeclarations = new ArrayList(); + + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } + + public String getDeclaration() { + StringBuilder sb = new StringBuilder(); + sb.append(getEnumerationClassDefinition()); + sb.append(" "); + sb.append(this.name + "_class"); + sb.append(" " + this.name); + sb.append(";\n"); + return sb.toString(); + } + + public ArrayList getEnumerationIndexes() { + return enumerationIndexes.getEnumerationIndexes(); + } + + public boolean isReplaceable() { + return Boolean.TRUE.equals(isReplaceable); + } + + public String getEnumerationClassDefinition() { + + // Build indexes (one = 1, two = 2, etc..) and elements {1,2,3,..,size} + ArrayList indexes = getEnumerationIndexes(); + StringBuilder elementsBuilder = new StringBuilder(); + elementsBuilder.append("{"); + StringBuilder indexesBuilder = new StringBuilder(); + for(int i = 1; i <= indexes.size(); i++) { + indexesBuilder.append(" constant Integer "); + indexesBuilder.append(indexes.get(i - 1).getName()); + indexesBuilder.append(" = " + i + ";\n"); + + elementsBuilder.append(i); + if(i < indexes.size()) + elementsBuilder.append(","); + } + elementsBuilder.append("}"); + + /* + * class E_class + * extends Enumeration_class(size = n, elements = {1,2,3,..n}); + * constant Integer index1 = 1; + * constant Integer index2 = 2; + * .... + * constant Integer indexn = n; + * end E_class; + */ + + StringBuilder sb = new StringBuilder(); + sb.append(" class "); + sb.append(this.name); + sb.append("_class\n"); + sb.append(" extends Enumeration_class(size="); + sb.append(indexes.size()); + sb.append(", elements="); + sb.append(elementsBuilder); + sb.append(");\n"); + sb.append(indexesBuilder); + sb.append(" end "); + sb.append(this.name); + sb.append("_class;\n"); + + return sb.toString(); + } + + public ArrayList getRedeclarations() { + return redeclarations; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/EnumerationIndex.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/EnumerationIndex.java new file mode 100644 index 00000000..0d565c41 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/EnumerationIndex.java @@ -0,0 +1,16 @@ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedValue; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/EnumerationIndex") +public class EnumerationIndex { + + @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName") + protected String name; + + public String getName() { + return this.name; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/EnumerationIndexes.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/EnumerationIndexes.java new file mode 100644 index 00000000..43e111f3 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/EnumerationIndexes.java @@ -0,0 +1,17 @@ +package org.simantics.sysdyn.representation; + +import java.util.ArrayList; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedOrderedSetElements; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/EnumerationIndexes") +public class EnumerationIndexes { + + @RelatedOrderedSetElements + private ArrayList enumerationIndexes = new ArrayList(); + + public ArrayList getEnumerationIndexes() { + return enumerationIndexes; + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Flow.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Flow.java new file mode 100644 index 00000000..98996b11 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Flow.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedElement; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/Flow") +public class Flow implements IElement { + @RelatedElement("http://www.simantics.org/Sysdyn-1.1/HasTail") + private IElement tail; + @RelatedElement("http://www.simantics.org/Sysdyn-1.1/HasHead") + private IElement head; + + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } + + public IElement getTail() { + return this.tail; + } + + public IElement getHead() { + return this.head; + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IElement.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IElement.java new file mode 100644 index 00000000..a44aafa2 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IElement.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +public interface IElement { + void accept(IElementVisitorVoid v); +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IndependentVariable.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IndependentVariable.java new file mode 100644 index 00000000..fa6b9f59 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IndependentVariable.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import java.util.ArrayList; + +import org.simantics.sysdyn.representation.expressions.IExpression; +import org.simantics.sysdyn.representation.expressions.ParameterExpression; + +public abstract class IndependentVariable extends Variable { + + public String getDeclaration() { + ArrayList expressions = this.expressions.getExpressions(); + return expressions.get(0).getDeclaration(this); + + /* + ArrayList expressions = this.expressions.getExpressions(); + ArrayIndexes ai = this.getArrayIndexes(); + ArrayList enumerations = null; + if(ai != null) + enumerations = ai.getEnumerations(); + if(enumerations == null || enumerations.size() < 1) { + // NOT an array variable, get declaration from the only expression. + if(expressions.get(0) == null) + return null; + else + return expressions.get(0).getDeclaration(this); + } else { + // ARRAY variable. Create declaration according to the type, name and indexes + //TODO: check if all of them are parameters -> form a parameter + StringBuilder sb = new StringBuilder(); + sb.append(" "); + sb.append(this.getType()); + sb.append(" "); + sb.append(this.getName()); + sb.append("["); + Iterator iterator = enumerations.iterator(); + while(iterator.hasNext()) { + sb.append(iterator.next().getName()); + if(iterator.hasNext()) { + sb.append(", "); + } + } + sb.append("];\n"); + return sb.toString(); + } + */ + } + + public String getInitialEquation() { + StringBuilder sb = new StringBuilder(); + + for(IExpression expression : expressions.getExpressions()) { + String initialEquation = expression.getInitialEquation(this); + if(initialEquation != null) + sb.append(initialEquation); + } + String result = sb.toString(); + return result.length() > 0 ? result : null; + } + + public String getEquation() { + ArrayList expressions = this.expressions.getExpressions(); + ArrayIndexes ai = this.getArrayIndexes(); + ArrayList enumerations = null; + if(ai != null) + enumerations = ai.getEnumerations(); + IExpression firstExpression = expressions.get(0); + if(enumerations == null || enumerations.size() < 1) { + // NOT an array variable, get equation from the only expression. + if(firstExpression == null || firstExpression instanceof ParameterExpression) + return null; + else + return firstExpression.getEquation(this); + } else { + // ARRAY variable. Create all equations for the variable + //TODO: check that it has not been a parameter + StringBuilder sb = new StringBuilder(); + for(IExpression expression : expressions) { + sb.append(expression.getEquation(this)); + } + return sb.toString(); + } + + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Input.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Input.java new file mode 100644 index 00000000..5ad136a2 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Input.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedElements; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/Input") +public class Input extends Variable { + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/HasDefaultInputValue") + private Double defaultInputValue; + @RelatedElements("http://www.simantics.org/Sysdyn-1.1/IsHeadOf") + private List isHeadOf; + + + + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } + + public String getDefaultInputValue() { + if( getArrayIndexes() == null || getArrayIndexes().getEnumerations().isEmpty()) { + return defaultInputValue.toString(); + } else { + StringBuilder sb = new StringBuilder(); + sb.append("fill("); + sb.append(defaultInputValue); + sb.append(", "); + Iterator i = getArrayIndexes().getEnumerations().iterator(); + while(i.hasNext()) { + Enumeration e = i.next(); + sb.append(e.getEnumerationIndexes().size()); + if(i.hasNext()) + sb.append(", "); + } + sb.append(")"); + return sb.toString(); + } + } + + public boolean isHeadOfDependency() { + return !isHeadOf.isEmpty(); + } + + public String getDeclaration() { + ArrayIndexes ai = getArrayIndexes(); + ArrayList enumerations = null; + if(ai != null) + enumerations = ai.getEnumerations(); + + String range = ""; + if(enumerations != null && enumerations.size() > 0) { + StringBuilder sb = new StringBuilder(); + sb.append("["); + Iterator iterator = enumerations.iterator(); + while(iterator.hasNext()) { + sb.append(iterator.next().getName() + ".size"); + if(iterator.hasNext()) { + sb.append(", "); + } + } + sb.append("]"); + range = sb.toString(); + } + + return " " + getType() + " " + getName() + range + ";\n"; + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LibraryDummy.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LibraryDummy.java new file mode 100644 index 00000000..8762ade8 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LibraryDummy.java @@ -0,0 +1,15 @@ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + + +@GraphType("http://www.simantics.org/Layer0-1.0/Library") +public class LibraryDummy implements IElement { + + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LoadRepresentation.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LoadRepresentation.java new file mode 100644 index 00000000..912f2e9b --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LoadRepresentation.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.objmap.IMapping; +import org.simantics.objmap.Mappings; + +public class LoadRepresentation { + + public static IMapping loadMappedMapping(Session session, final Resource configuration) throws DatabaseException { + return session.syncRequest(new Read() { + + @Override + public IMapping perform(ReadGraph graph) + throws DatabaseException { + SysdynSchema schema = new SysdynSchema(graph); + IMapping mapping = Mappings.createWithoutListening(schema); + mapping.map(graph, configuration); + return mapping; + } + + }); + } + + public static Configuration loadConfiguration(Session session, final Resource configuration) throws DatabaseException { + return session.syncRequest(new Read() { + + @Override + public Configuration perform(ReadGraph graph) + throws DatabaseException { + SysdynSchema schema = new SysdynSchema(graph); + IMapping mapping = Mappings.createWithoutListening(schema); + return (Configuration)mapping.map(graph, configuration); + } + + }); + } + + public static IElement loadElement(Session session, final Resource element) throws DatabaseException { + return session.syncRequest(new Read() { + + @Override + public IElement perform(ReadGraph graph) + throws DatabaseException { + SysdynSchema schema = new SysdynSchema(graph); + IMapping mapping = Mappings.createWithoutListening(schema); + return (IElement)mapping.map(graph, element); + } + + }); + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Model.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Model.java new file mode 100644 index 00000000..8be91f13 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Model.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedValue; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/SysdynModel") +public class Model { + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/HasStartTime") + private Double startTime = 0.0; + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/HasStopTime") + private Double stopTime = 10.0; + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/HasOutputInterval") + private Double outputInterval; + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/HasTolerance") + private Double tolerance; + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/HasSolver") + private String solver; + + public Double getStartTime() { + return startTime; + } + + public Double getStopTime() { + return stopTime; + } + + public Double getOutputInterval() { + return outputInterval; + } + + public Double getTolerance() { + return tolerance; + } + + public String getSolver() { + return solver; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java new file mode 100644 index 00000000..4c7fb5ba --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedElement; +import org.simantics.objmap.annotations.RelatedElements; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/Module") +public class Module implements IElement { + + @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName") + private String name; + + @RelatedElement("http://www.simantics.org/Layer0-1.0/PartOf") + private Configuration parentConfiguration; + + @RelatedElement("http://www.simantics.org/Layer0-1.0/InstanceOf") + private ModuleType type; + + @RelatedElements("http://www.simantics.org/Sysdyn-1.1/HasRedeclaration") + private List redeclarations; + + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } + + public String getName() { + return name; + } + + public ModuleType getType() { + return type; + } + + /** + * Returns the declaration of a module with possible redeclared enumerations + * + * parameter Integer Enum__size = Enum.size; + * parameter Integer Enum__elements[:] = Enum.elements; + * ModuleType ModuleType1(Enum.size = Enum__size, Enum.elements = Enum__elements); + * + * Temporary parameter variables are needed to avoid name conflicts when redeclaring an + * enumeration with the same name. + * + * @return Declaration of a module instance + */ + public String getDeclaration() { + + StringBuilder parameters = new StringBuilder(); + StringBuilder redeclarations = new StringBuilder(); + + + if(!getRedeclarations().isEmpty()) { + redeclarations.append("("); + Iterator i = getRedeclarations().iterator(); + while(i.hasNext()) { + Redeclaration rd = i.next(); + redeclarations.append(rd.getRedeclaration()); + parameters.append(rd.getParameters()); + if(i.hasNext()) + redeclarations.append(","); + } + redeclarations.append(")"); + } + + + StringBuilder sb = new StringBuilder(); + sb.append(parameters); + sb.append(" "); + sb.append(getType().getName()); + sb.append(" "); + sb.append(getName()); + sb.append(redeclarations.toString()); + sb.append(";\n"); + return sb.toString(); + } + + public Configuration getParentConfiguration() { + return this.parentConfiguration; + } + + /** + * Return the list of the defined redeclarations for this module instance. + * + * @return List of the defined redeclarations or an empty list if redeclarations have not been set + */ + public List getRedeclarations() { + if(redeclarations == null) { + redeclarations = new ArrayList(); + } + return redeclarations; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ModuleType.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ModuleType.java new file mode 100644 index 00000000..826937b9 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ModuleType.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedElement; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Structural-1.0/ComponentType") +public class ModuleType implements IElement { + + @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName") + private String name; + + @RelatedElement("http://www.simantics.org/Structural-1.0/IsDefinedBy") + private Configuration configuration; + + public String getName() { + return name; + } + + public Configuration getConfiguration() { + return this.configuration; + } + + @Override + public void accept(IElementVisitorVoid v) { + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java new file mode 100644 index 00000000..417fbbab --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedElement; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/Redeclaration") +public class Redeclaration { + + @RelatedElement("http://www.simantics.org/Sysdyn-1.1/ReplacedEnumeration") + private Enumeration replacedEnumeration; + + @RelatedElement("http://www.simantics.org/Sysdyn-1.1/ReplacingEnumeration") + private Enumeration replacingEnumeration; + + public String getRedeclaration() { + if(replacedEnumeration == null || replacingEnumeration == null) { + return ""; + } + String separator = getSeparator(); + StringBuilder sb = new StringBuilder(); + sb.append(replacedEnumeration.getName()); + sb.append(".size = "); + sb.append(replacingEnumeration.getName()); + sb.append(separator + "size, "); + sb.append(replacedEnumeration.getName()); + sb.append(".elements = "); + sb.append(replacingEnumeration.getName()); + sb.append(separator + "elements"); + + return sb.toString(); + } + + /** + * Change the name of the re-declaration parameters to enable the use of + * enumerations with same names. + * + * @return + */ + public String getParameters() { + String separator = getSeparator(); + StringBuilder sb = new StringBuilder(); + sb.append(" parameter Integer " + replacingEnumeration.getName() + separator + "size = " + replacingEnumeration.getName() + ".size;\n"); + sb.append(" parameter Integer " + replacingEnumeration.getName() + separator + "elements[:] = " + replacingEnumeration.getName() + ".elements;\n"); + return sb.toString(); + } + + private String getSeparator() { + return getSeparator(this, "_"); + } + + /** + * Add enough separation marks that name conflicts would not exist. + * + * @param redeclaration + * @param separator + * @return + */ + private String getSeparator(Redeclaration redeclaration, String separator) { + if(redeclaration == null || redeclaration.replacedEnumeration == null || + redeclaration.replacedEnumeration.getParentConfiguration() == null) + return separator = "_"; + for(IElement e : redeclaration.replacedEnumeration.getParentConfiguration().getElements()) { + if(e instanceof Module) { + for(Redeclaration rd : ((Module)e).getRedeclarations()) { + if(rd.replacedEnumeration.name.equals(redeclaration.replacedEnumeration.name) && + rd.replacingEnumeration.equals(redeclaration.replacedEnumeration)) { + String separatorTmp = getSeparator(rd, separator); + if(separatorTmp.length() > separator.length()) + separator = separatorTmp; + } + } + } + } + return separator + "_"; + } + + public Enumeration getReplacedEnumeration() { + return replacedEnumeration; + } + + public Enumeration getReplacingEnumeration() { + return replacingEnumeration; + } + + + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Sheet.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Sheet.java new file mode 100644 index 00000000..00fcf7cc --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Sheet.java @@ -0,0 +1,202 @@ +package org.simantics.sysdyn.representation; + +import java.util.HashMap; +import java.util.HashSet; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.binding.mutable.Variant; +import org.simantics.databoard.primitives.MutableString; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.MissingVariableException; +import org.simantics.db.layer0.util.Simantics; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedElement; +import org.simantics.objmap.annotations.UpdateMethod; +import org.simantics.spreadsheet.SheetVariables; +import org.simantics.spreadsheet.common.exception.CellParseException; +import org.simantics.spreadsheet.common.matrix.VariantMatrix; +import org.simantics.spreadsheet.util.SpreadsheetUtils; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Spreadsheet-1.1/Spreadsheet") +public class Sheet extends org.simantics.sysdyn.representation.Variable { + + @RelatedElement("http://www.simantics.org/Layer0-1.0/PartOf") + protected Book book; + + HashMap cells = new HashMap(); + HashSet usedRanges = new HashSet(); + + Resource resource; + + public String getSheet() { + return "Sheet"; + } + + @UpdateMethod + public boolean updateCells(ReadGraph g, Resource r) throws DatabaseException { + this.resource = r; + + g.getObjects(r, Layer0.getInstance(g).ConsistsOf); + + Variable v = g.adapt(r, Variable.class); + cells.clear(); + usedRanges.clear(); + for(Variable child : v.browseChildren(g)) { + String name = child.getPropertyValue(g, Variables.NAME); + try { + SpreadsheetUtils.decodeCellAbsolute(name); + Variant value = child.getPropertyValue(g, SheetVariables.CONTENT, Bindings.VARIANT); + cells.put(name, value.getValue()); + } catch (CellParseException e) { + } catch (MissingVariableException e) { + System.out.println("missing content for: " + name); + } + } + return true; + } + + public String getStringRepresentation() { + final StringBuilder clazz = new StringBuilder(); + final HashSet possibleRanges = new HashSet(); + + clazz.append(" class " + name + "_class\n "); + + // Write all doubles that have been used in expressions + int counter = 0; + for(String key : usedRanges) { + if(cells.containsKey(key)) { + Object value = cells.get(key); + if(value instanceof String || value instanceof MutableString) { + try { + Double d = Double.parseDouble(value.toString()); + value = d; + } catch (NumberFormatException e) { + } + } + + if(value instanceof Double) { + Double d = (Double)value; + clazz.append("constant Real " + key + " = " + d + "; "); + counter++; + if(counter > 10) { + counter = 0; + clazz.append("\n "); + } + } + } else { + possibleRanges.add(key); + } + } + + try { + Simantics.getSession().syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Variable v = graph.adapt(resource, Variable.class); + for(String possibleRange : possibleRanges) { + String[] parts = possibleRange.split(":"); + if(parts.length != 2 || !cells.containsKey(parts[0]) || !cells.containsKey(parts[1])) + continue; + Variable range = v.getChild(graph, possibleRange); + if(range == null) + continue; + Variant content = range.getPropertyValue(graph, SheetVariables.CONTENT, Bindings.VARIANT); + Object matrixValue = content.getValue(); + if(matrixValue instanceof VariantMatrix) { + VariantMatrix vm = (VariantMatrix)matrixValue; + Double[][] array = toDoubleMatrix(vm); + + if(array[0].length > 1) { + // Has two dimensions + clazz.append("constant Real[" + array.length + ", " + array[0].length + "] "); + clazz.append(possibleRange.replace(":", "_") + " = {"); + for(int i = 0; i < array.length; i++) { + clazz.append("{"); + for(int j = 0; j < array[i].length; j++) { + clazz.append(array[i][j]); + if(j < array[i].length - 1) + clazz.append(", "); + } + clazz.append("}"); + if(i < array.length - 1) + clazz.append(", "); + } + clazz.append("};\n"); + } else { + // Has one dimension + clazz.append("constant Real[" + array.length + "] "); + clazz.append(possibleRange.replace(":", "_") + " = {"); + for(int i = 0; i < array.length; i++) { + clazz.append(array[i][0]); + if(i < array.length - 1) + clazz.append(", "); + } + clazz.append("};\n"); + } + + } + } + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + + clazz.append("\n end " + name + "_class;\n"); + clazz.append(" " + name + "_class " + name + ";\n"); + return clazz.toString(); + } + + private Double[][] toDoubleMatrix(VariantMatrix matrix) { + Double[][] array = new Double[matrix.getRowCount()][matrix.getColumnCount()]; + for(int i = 0; i < matrix.getRowCount(); i++) { + for(int j = 0; j < matrix.getColumnCount(); j++) { + Variant cell = matrix.get(i, j); + if(cell.getBinding().equals(Bindings.DOUBLE)) { + array[i][j] = (Double)cell.getValue(); + } else if (cell.getBinding().equals(Bindings.MUTABLE_STRING)) { + try { + array[i][j] = Double.parseDouble(cell.getValue().toString()); + } catch (NumberFormatException e) { + array[i][j] = 0.0; + } + } else { + array[i][j] = 0.0; + } + } + } + return array; + } + + public HashMap getCells() { + return cells; + } + + @Override + public void accept(IElementVisitorVoid v) { + + } + + /** + * Add a range that has been used for this sheet. + * + * Used ranges help to reduce code sent to Modelica. + * + * @param range range of cell/cells. (e.g. B2 or B4:B6) + */ + public void use(String range) { + usedRanges.add(range); + } + + + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Stock.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Stock.java new file mode 100644 index 00000000..8aee598a --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Stock.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import java.util.ArrayList; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedElements; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/Stock") +public class Stock extends IndependentVariable { + + @RelatedElements( + value = "http://www.simantics.org/Sysdyn-1.1/IsHeadOf", + composition = true) + private ArrayList incomingConnections = new ArrayList(); + + + @RelatedElements( + value = "http://www.simantics.org/Sysdyn-1.1/IsTailOf", + composition = true) + private ArrayList outgoingConnections = new ArrayList(); + + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } + + public ArrayList getIncomingValves() { + ArrayList valves = new ArrayList(); + for(IElement element : incomingConnections) { + if(element instanceof Flow) { + Flow flow = (Flow)element; + valves.add((Valve)flow.getTail()); + } + } + return valves; + } + + public ArrayList getOutgoingValves() { + ArrayList valves = new ArrayList(); + for(IElement element : outgoingConnections) { + if(element instanceof Flow) { + Flow flow = (Flow)element; + valves.add((Valve)flow.getHead()); + } + } + return valves; + } + + +} + + diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java new file mode 100644 index 00000000..aadf2a0f --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.schema.MappingSchemas; +import org.simantics.objmap.schema.SimpleSchema; +import org.simantics.sysdyn.representation.expressions.ConstantExpression; +import org.simantics.sysdyn.representation.expressions.DelayExpression; +import org.simantics.sysdyn.representation.expressions.Expressions; +import org.simantics.sysdyn.representation.expressions.LookupExpression; +import org.simantics.sysdyn.representation.expressions.NormalExpression; +import org.simantics.sysdyn.representation.expressions.ParameterExpression; +import org.simantics.sysdyn.representation.expressions.StockExpression; +import org.simantics.sysdyn.representation.expressions.WithLookupExpression; + +public class SysdynSchema extends SimpleSchema { + + public SysdynSchema(ReadGraph g) { + try { + addLinkType(MappingSchemas.fromAnnotations(g, Auxiliary.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Cloud.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Configuration.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Dependency.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Flow.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Stock.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Valve.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Module.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Input.class)); + addLinkType(MappingSchemas.fromAnnotations(g, ModuleType.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Model.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Expressions.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Enumeration.class)); + addLinkType(MappingSchemas.fromAnnotations(g, EnumerationIndex.class)); + addLinkType(MappingSchemas.fromAnnotations(g, EnumerationIndexes.class)); + addLinkType(MappingSchemas.fromAnnotations(g, ArrayIndexes.class)); + addLinkType(MappingSchemas.fromAnnotations(g, NormalExpression.class)); + addLinkType(MappingSchemas.fromAnnotations(g, ParameterExpression.class)); + addLinkType(MappingSchemas.fromAnnotations(g, StockExpression.class)); + addLinkType(MappingSchemas.fromAnnotations(g, ConstantExpression.class)); + addLinkType(MappingSchemas.fromAnnotations(g, WithLookupExpression.class)); + addLinkType(MappingSchemas.fromAnnotations(g, LookupExpression.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Redeclaration.class)); + addLinkType(MappingSchemas.fromAnnotations(g, LibraryDummy.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Book.class)); + addLinkType(MappingSchemas.fromAnnotations(g, Sheet.class)); + addLinkType(MappingSchemas.fromAnnotations(g, DiagramContainerDummy.class)); + addLinkType(MappingSchemas.fromAnnotations(g, DelayExpression.class)); + } catch (DatabaseException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Valve.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Valve.java new file mode 100644 index 00000000..0ae3c3b0 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Valve.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/Valve") +public class Valve extends IndependentVariable { + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variable.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variable.java new file mode 100644 index 00000000..69c03432 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variable.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation; + +import org.simantics.objmap.annotations.RelatedElement; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.sysdyn.representation.expressions.Expressions; + +public abstract class Variable implements IElement { + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/Variable/Type") + protected String type; + + @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName") + protected String name; + + @RelatedElement("http://www.simantics.org/Layer0-1.0/PartOf") + protected Object parent; + + @RelatedElement("http://www.simantics.org/Sysdyn-1.1/HasArrayIndexes") + protected ArrayIndexes arrayIndexes; + + @RelatedElement("http://www.simantics.org/Sysdyn-1.1/HasExpressions") + protected Expressions expressions; + + + public String getName() { + return this.name; + } + + public Configuration getParentConfiguration() { + if(parent instanceof Configuration) { + return (Configuration)parent; + } else if(parent instanceof Book) { + return (Configuration)((Book)parent).getParentConfiguration(); + } else { + return null; + } + } + + public String getType() { + return this.type; + } + + public ArrayIndexes getArrayIndexes() { + return this.arrayIndexes; + } + + public Expressions getExpressions() { + return this.expressions; + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ConstantExpression.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ConstantExpression.java new file mode 100644 index 00000000..c4a3d1e6 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ConstantExpression.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation.expressions; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.sysdyn.representation.IndependentVariable; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/ConstantExpression") +public class ConstantExpression extends Expression { + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/HasEquation") + private String equation; + + @Override + public String getDeclaration(IndependentVariable variable) { + StringBuilder b = new StringBuilder(); + b.append(" constant " + variable.getType() + " " + variable.getName()); + b.append(" = " + equation + ";\n"); + return b.toString(); } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/DelayExpression.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/DelayExpression.java new file mode 100644 index 00000000..852ea14c --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/DelayExpression.java @@ -0,0 +1,199 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation.expressions; + +import java.util.ArrayList; +import java.util.Iterator; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.sysdyn.representation.ArrayIndexes; +import org.simantics.sysdyn.representation.Enumeration; +import org.simantics.sysdyn.representation.IndependentVariable; +import org.simantics.sysdyn.representation.Variable; +import org.simantics.sysdyn.representation.utils.FormatUtils; +import org.simantics.sysdyn.representation.utils.IndexUtils; + +/** + * Representation of a delay expression. The order of the + * delay can be 1-n. + * + * Delay with n = 3: + * + * DELAY3=LV3/DL + * LV3=INTEG(RT2-DELAY3,DL*input) + * RT2=LV2/DL + * LV2=INTEG(RT1-RT2,LV3) + * RT1=LV1/DL + * LV1=INTEG(input-RT1,LV3) + * DL=delay time/3 + * + * DELAY3I=LV3/DL + * LV3=INTEG(RT2-DELAY3I,initial value*DL) + * RT2=LV2/DL + * LV2=INTEG(RT1-RT2,LV3) + * RT1=LV1/DL + * LV1=INTEG(input-RT1,LV3) + * DL=delay time/3 + * + * @author Teemu Lempinen + * + */ +@GraphType("http://www.simantics.org/Sysdyn-1.1/DelayExpression") +public class DelayExpression extends Expression { + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/DelayExpression/initialValue") + private String initialValue; + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/DelayExpression/delayTime") + private String delayTime; + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/DelayExpression/order") + private Integer order; + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/DelayExpression/expression") + private String equation; + + @Override + public String getDeclaration(IndependentVariable variable) { + + // Calculate range for the variable + ArrayIndexes ai = variable.getArrayIndexes(); + ArrayList enumerations = null; + if(ai != null) + enumerations = ai.getEnumerations(); + + String range = ""; + if(enumerations != null && enumerations.size() > 0) { + StringBuilder sb = new StringBuilder(); + sb.append("["); + Iterator iterator = enumerations.iterator(); + while(iterator.hasNext()) { + sb.append(iterator.next().getName() + ".size"); + if(iterator.hasNext()) { + sb.append(", "); + } + } + sb.append("]"); + range = sb.toString(); + } + + /* Build the declaration */ + StringBuilder declaration = new StringBuilder(); + // Variable declaration + declaration.append(" " + variable.getType() + " " + variable.getName() + range + ";\n"); + // Delay declaration + declaration.append(" " + variable.getName() + "_delayClass " + variable.getName() + "_delayClass_instance"); + // Change enumeration sizes from the delay class. Supports overridden enumerations in modules. + if(range.length() > 0) { + declaration.append("("); + String[] ranges = range.substring(1, range.length() - 1).split(","); + for(int i = 0; i < ranges.length; i++ ) { + String r = ranges[i]; + declaration.append(r.replace(".size", "size") + " = " + r); + if(i < ranges.length - 1) { + declaration.append(", "); + } + } + declaration.append(")"); + } + declaration.append(";\n"); + + // Write the delay class + declaration.append(getDelayClass(variable, range, order)); + return declaration.toString(); + } + + /** + * Creates a class that is used to implement the delay. Class contains + * a basic delay structure with "stocks and flows". The number of + * stocks and flows is determined by the order of the delay + * + * @param variable The variable for which the delay is created + * @param range Array range + * @param n Order of the delay + * @return + */ + private String getDelayClass(Variable variable, String range, int n) { + StringBuilder sb = new StringBuilder(); + + sb.append("class " + variable.getName() + "_delayClass\n"); + + // Auxiliary variable + sb.append("\tReal DL;\n"); + // Delay time + sb.append("\tReal delayTime;\n"); + + // Enumeration sizes as parameters. Sizes correspond the enumeration sizes of variable + if(range.length() > 0) { + range = range.replaceAll(".size", "size"); + for(String r : range.substring(1, range.length() - 1).split(",")) { + sb.append("\t parameter Integer " + r + ";\n"); + } + } + + if(initialValue == null || initialValue.length() == 0) + // Use "random" number as initial value, if initial value is not set + sb.append("\tReal" + range + " initialValue = " + (range.length() > 0 ? "fill(-137543," + range.substring(1, range.length() - 1) + ")" : -137543) + ";\n"); + else + // Initial value + sb.append("\tReal" + range + " initialValue = " + FormatUtils.formatExpressionForModelica(variable, this.initialValue) + ";\n"); + + // First valve + sb.append("\tReal" + range + " delay0;\n"); + + // Stocks and valves. Valves are the delayed values of the variable + for(int i = 1; i <= n; i++) { + sb.append("\tReal" + range + " LV" + i + "(" + (range.length() > 0 ? "each " : "") + "fixed=false);\n"); + sb.append("\tReal" + range + " delay" + i + ";\n"); + } + + sb.append("initial equation\n"); + + // "Generic" structure selection. If the "random" number is not used in initial value, use delay0 as initial value + // Each stock gets the same initial value + for(int i = 1; i <= n; i++) + sb.append("\tLV" + i +" = DL * " + + (range.length() > 0 ? "(if max(initialValue) < -137543 or max(initialValue) > -137543 then initialValue else delay0)" : + "(if initialValue < -137543 or initialValue > -137543 then initialValue else delay0)") + ";\n"); + + sb.append("equation\n"); + sb.append("\tDL = delayTime/" + n + ";\n"); + + // Valves and stocks + for(int i = 1; i <= n; i++) { + sb.append("\tder(LV" + i + ") = - delay" + i + " + delay" + (i - 1) + ";\n"); + sb.append("\tdelay" + i + " = LV" + i + "/DL;\n"); + } + + sb.append("end " + variable.getName() + "_delayClass;\n"); + return sb.toString(); + } + + @Override + public String getEquation(IndependentVariable variable) { + String equation = FormatUtils.formatExpressionForModelica(variable, this.equation); + String delayTime = FormatUtils.formatExpressionForModelica(variable, this.delayTime); + + // Set delay properties + StringBuilder sb = new StringBuilder(); + sb.append(" " + variable.getName() + "_delayClass_instance.delayTime = " + delayTime + ";\n"); + sb.append(" " + variable.getName() + "_delayClass_instance.delay0 = " + equation + ";\n"); + + // Use the delay in the value of variable + String range = IndexUtils.rangeToIndexes(variable, this.getArrayRange()); + sb.append(" " + variable.getName() + (range.equals("[:]") ? "" : range) + " = " + variable.getName() + "_delayClass_instance.delay" + order + ";\n"); + return sb.toString(); + } + + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expression.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expression.java new file mode 100644 index 00000000..ea8eb302 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expression.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation.expressions; + +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.sysdyn.representation.IndependentVariable; + +public abstract class Expression implements IExpression { + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/HasArrayRange") + private String range; + + @Override + public String getDeclaration(IndependentVariable variable) { + return null; + } + + @Override + public String getEquation(IndependentVariable variable) { + return null; + } + + @Override + public String getInitialEquation(IndependentVariable variable) { + return null; + } + + @Override + public String getArrayRange() { + if(range == null) + return ""; + else + return range; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expressions.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expressions.java new file mode 100644 index 00000000..394ce422 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expressions.java @@ -0,0 +1,17 @@ +package org.simantics.sysdyn.representation.expressions; + +import java.util.ArrayList; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedOrderedSetElements; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/Expressions") +public class Expressions { + + @RelatedOrderedSetElements + private ArrayList expressions = new ArrayList(); + + public ArrayList getExpressions() { + return expressions; + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/IExpression.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/IExpression.java new file mode 100644 index 00000000..54431347 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/IExpression.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation.expressions; + +import org.simantics.sysdyn.representation.IndependentVariable; + +public interface IExpression { + + String getDeclaration(IndependentVariable variable); + String getInitialEquation(IndependentVariable variable); + String getEquation(IndependentVariable variable); + String getArrayRange(); + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/LookupExpression.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/LookupExpression.java new file mode 100644 index 00000000..e6ef859c --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/LookupExpression.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation.expressions; + +import org.simantics.objmap.annotations.GraphType; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/LookupExpression") +public class LookupExpression extends Expression { + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/NormalExpression.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/NormalExpression.java new file mode 100644 index 00000000..6495c4d6 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/NormalExpression.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation.expressions; + +import java.util.ArrayList; +import java.util.Iterator; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.sysdyn.representation.ArrayIndexes; +import org.simantics.sysdyn.representation.Enumeration; +import org.simantics.sysdyn.representation.IndependentVariable; +import org.simantics.sysdyn.representation.utils.FormatUtils; +import org.simantics.sysdyn.representation.utils.IndexUtils; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/NormalExpression") +public class NormalExpression extends Expression { + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/HasEquation") + private String equation; + + @Override + public String getDeclaration(IndependentVariable variable) { + + ArrayIndexes ai = variable.getArrayIndexes(); + ArrayList enumerations = null; + if(ai != null) + enumerations = ai.getEnumerations(); + + String range = ""; + if(enumerations != null && enumerations.size() > 0) { + StringBuilder sb = new StringBuilder(); + sb.append("["); + Iterator iterator = enumerations.iterator(); + while(iterator.hasNext()) { + sb.append(iterator.next().getName() + ".size"); + if(iterator.hasNext()) { + sb.append(", "); + } + } + sb.append("]"); + range = sb.toString(); + } + + return " " + variable.getType() + " " + variable.getName() + range + ";\n"; + } + + @Override + public String getEquation(IndependentVariable variable) { + String equation = FormatUtils.formatExpressionForModelica(variable, this.equation); + String range = IndexUtils.rangeToIndexes(variable, this.getArrayRange()); + return " " + variable.getName() + (range.equals("[:]") ? "" : range) + " = " + equation + ";\n"; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ParameterExpression.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ParameterExpression.java new file mode 100644 index 00000000..14819372 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ParameterExpression.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation.expressions; + +import java.util.ArrayList; +import java.util.Iterator; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.sysdyn.representation.ArrayIndexes; +import org.simantics.sysdyn.representation.Enumeration; +import org.simantics.sysdyn.representation.IndependentVariable; +import org.simantics.sysdyn.representation.utils.IndexUtils; + +@GraphType("http://www.simantics.org/Sysdyn-1.1/ParameterExpression") +public class ParameterExpression extends Expression { + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/HasEquation") + private String equation; + + @Override + public String getDeclaration(IndependentVariable variable) { + // FIXME: Still needs to manually confirm that really is parameter + ArrayIndexes ai = variable.getArrayIndexes(); + ArrayList enumerations = null; + if(ai != null) + enumerations = ai.getEnumerations(); + + boolean parameter = true; + String range = ""; + if(enumerations != null && enumerations.size() > 0) { + parameter = false; + StringBuilder sb = new StringBuilder(); + sb.append("["); + Iterator iterator = enumerations.iterator(); + while(iterator.hasNext()) { + sb.append(iterator.next().getName() + ".size"); + if(iterator.hasNext()) { + sb.append(", "); + } + } + sb.append("]"); + range = sb.toString(); + } + + StringBuilder sb = new StringBuilder(); + sb.append(" " + (parameter ? "parameter " : "") + variable.getType() + " " + variable.getName() + range); + if(parameter) + sb.append(" = " + getValue() + " /* Actual value read from init file */"); + sb.append(";\n"); + return sb.toString(); + } + + + /** + * Used when the expression is a part of an array variable. Then it is like a normal auxiliary. + */ + @Override + public String getEquation(IndependentVariable variable) { + String range = IndexUtils.rangeToIndexes(variable, this.getArrayRange()); + return " " + variable.getName() + (range.equals("[:]") ? "" : range) + " = " + equation + ";\n"; + }; + + public Double getValue() { + try { + return Double.parseDouble(equation); + } catch(NumberFormatException e) { + return null; + } + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java new file mode 100644 index 00000000..32608c3b --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java @@ -0,0 +1,231 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation.expressions; + +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.Set; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.sysdyn.expressionParser.ExpressionParser; +import org.simantics.sysdyn.expressionParser.ParseException; +import org.simantics.sysdyn.representation.ArrayIndexes; +import org.simantics.sysdyn.representation.Book; +import org.simantics.sysdyn.representation.Enumeration; +import org.simantics.sysdyn.representation.IElement; +import org.simantics.sysdyn.representation.IndependentVariable; +import org.simantics.sysdyn.representation.Sheet; +import org.simantics.sysdyn.representation.Stock; +import org.simantics.sysdyn.representation.Valve; +import org.simantics.sysdyn.representation.utils.FormatUtils; +import org.simantics.sysdyn.representation.utils.IndexUtils; + +/** + * Class representing a stock expression in a variable + * + * @author Teemu Lempinen + * + */ +@GraphType("http://www.simantics.org/Sysdyn-1.1/StockExpression") +public class StockExpression extends Expression { + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/HasInitialEquation") + private String initialEquation; + + @Override + public String getDeclaration(IndependentVariable variable) { + + // See if the start parameter is used Stock(start = x, fixed = y) + String value = null; + if(useStartValue(variable)) + value = FormatUtils.formatExpressionForModelica(variable, initialEquation); + + + // Build the enumeration indexes, if there are enumerations. Stock[enumIndexes, enum2Indexes, ...] + ArrayIndexes ai = variable.getArrayIndexes(); + ArrayList enumerations = null; + if(ai != null) + enumerations = ai.getEnumerations(); + + String range = ""; + if(enumerations != null && enumerations.size() > 0) { + StringBuilder sb = new StringBuilder(); + sb.append("["); + Iterator iterator = enumerations.iterator(); + while(iterator.hasNext()) { + sb.append(iterator.next().getName() + ".size"); + if(iterator.hasNext()) { + sb.append(", "); + } + } + sb.append("]"); + range = sb.toString(); + } + + String each = ""; + // each is required when a single value is used for all dimensions e.g. Stock[30](each start = 0) + if (value == null) { + // start parameter is not used, everything needs to be fixed=false + if(ai != null && !ai.getEnumerations().isEmpty()) + each = "each"; + return " " + variable.getType() + " " + variable.getName() + range + "(" + each + " fixed=false);\n"; + } else { + // start parameter is used + + if(getStartValue(variable) != null) { + // a single number is used as the initial equation -> (each start, each fixed) if there are dimensions + if(ai != null && !ai.getEnumerations().isEmpty()) + each = "each"; + return " " + variable.getType() + " " + variable.getName() + range + "(" + each+ " start=" + value + ", " + each + " fixed=true);\n"; + } else { + // a function or array constructor {.., .., ..} is used as the initial equation -> (start, each fixed) if there are dimensions + if(ai != null && !ai.getEnumerations().isEmpty()) + each = "each"; + return " " + variable.getType() + " " + variable.getName() + range + "(start=" + value + ", " + each + " fixed=true);\n"; + } + } + } + + @Override + public String getEquation(IndependentVariable variable) { + + // Build range e.g. Stock[2,3] + String range = IndexUtils.rangeToIndexes(variable, this.getArrayRange()); + + // Stock equation is always der(Stock) + StringBuilder b = new StringBuilder(); + b.append(" der(") + .append(variable.getName() + range) + .append(") ="); + + // Stock equation is formed automatically using incoming and outgoing flows (actually the nearest valves in those flows) + ArrayList incoming = ((Stock)variable).getIncomingValves(); + ArrayList outgoing = ((Stock)variable).getOutgoingValves(); + if(incoming.isEmpty() && outgoing.isEmpty()) { + // No connections, add 0 for each array index if any. + ArrayIndexes ai = variable.getArrayIndexes(); + ArrayList enumerations = null; + if(ai != null) + enumerations = ai.getEnumerations(); + + if(ai == null || enumerations == null || enumerations.isEmpty()) { + b.append(" 0.0"); + } else { + b.append(" zeros("); + for(int i = 0; i < enumerations.size(); i++) { + b.append(enumerations.get(i).getEnumerationIndexes().size()); + if(i != enumerations.size() - 1) + b.append(", "); + } + b.append(")"); + } + + } else { + // incoming valves add and outgoing valves reduce the stock + for(Valve valve : outgoing) + b.append("\n - ").append(valve.getName() + range); + for(Valve valve : incoming) + b.append("\n + ").append(valve.getName() + range); + } + b.append(";\n"); + return b.toString(); + } + + /** + * Check whether to use fixed=true and start=... in Modelica code + * @return + */ + private boolean useStartValue(IndependentVariable variable) { + // If no variables are used in the equation, start value is used + + // First the equation is formatted and parsed + String equation = FormatUtils.formatExpressionForModelica(variable, initialEquation); + ExpressionParser parser = new ExpressionParser(new StringReader(equation)); + try { + parser.expr(); + if(parser.getReferences().isEmpty()) { + // if equation did not contain any references, start value is used + return true; + } else { + // Check if references are references to sheets. + // Sheet references are allowed, since sheets contain only constants + boolean found = false; + Set references = parser.getReferences().keySet(); + + // Go through each reference + for(String reference : references) { + // We only need the first element to know that it is a Sheet (SheetName.CellOrRange) + reference = reference.split("\\.")[0]; + found = false; + for(IElement element : variable.getParentConfiguration().getElements()) { + if(element instanceof Book) { + for(Sheet sheet : ((Book)element).getSheets()) { + if(reference.equals(sheet.getName())) { + found = true; + break; + } + } + } + if(found) + break; + } + + // If there was no sheet for this reference name, return false + if(!found) + return false; + } + } + } catch (ParseException e) { + } + return true; + } + + @Override + public String getInitialEquation(IndependentVariable variable) { + // if start value is used, no initial equation is returned + if(useStartValue(variable)) + return null; + // format the initial equation for modelica execution + String equation = FormatUtils.formatExpressionForModelica(variable, initialEquation); + String range = IndexUtils.rangeToIndexes(variable, this.getArrayRange()); + if(range == null) + range = ""; + return " " + variable.getName() + range + " = " + equation + ";\n"; + } + + + /** + * Return Double representation of the initial equation for given variable + * + * @param variable + * @return Double representing the initial equation or null if initial equation is not a double + */ + private Double getStartValue(IndependentVariable variable) { + Double value = null; + ArrayList expressions = variable.getExpressions().getExpressions(); + if(expressions.size() == 1) { + IExpression e = expressions.get(0); + if(e.getInitialEquation(variable) == null) { + try { + value = Double.parseDouble(initialEquation); + } catch(NumberFormatException e1) { + + } + } + } + return value; + } + + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/WithLookupExpression.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/WithLookupExpression.java new file mode 100644 index 00000000..3de4ffe7 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/WithLookupExpression.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation.expressions; + +import java.util.ArrayList; +import java.util.Iterator; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.objmap.annotations.RelatedValue; +import org.simantics.sysdyn.representation.ArrayIndexes; +import org.simantics.sysdyn.representation.Enumeration; +import org.simantics.sysdyn.representation.IndependentVariable; +import org.simantics.sysdyn.representation.utils.FormatUtils; +import org.simantics.sysdyn.representation.utils.IndexUtils; + + +@GraphType("http://www.simantics.org/Sysdyn-1.1/WithLookupExpression") +public class WithLookupExpression extends Expression { + + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/HasLookup") + private String lookupTable; + @RelatedValue("http://www.simantics.org/Sysdyn-1.1/HasEquation") + private String equation; + + @Override + public String getDeclaration(IndependentVariable variable) { + ArrayIndexes ai = variable.getArrayIndexes(); + ArrayList enumerations = null; + if(ai != null) + enumerations = ai.getEnumerations(); + + String range = ""; + if(enumerations != null && enumerations.size() > 0) { + StringBuilder sb = new StringBuilder(); + sb.append("["); + Iterator iterator = enumerations.iterator(); + while(iterator.hasNext()) { + sb.append(iterator.next().getName() + ".size"); + if(iterator.hasNext()) { + sb.append(", "); + } + } + sb.append("]"); + range = sb.toString(); + } + + return " " + variable.getType() + " " + variable.getName() + range + ";\n"; + + } + + @Override + public String getEquation(IndependentVariable variable) { + String equation = FormatUtils.formatExpressionForModelica(variable, this.equation); + String range = IndexUtils.rangeToIndexes(variable, this.getArrayRange()); + + return + " " + variable.getName() + (range.equals("[:]") ? "" : range) + " = interpolate(" + equation + ", " + lookupTable + ");\n"; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/FormatUtils.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/FormatUtils.java new file mode 100644 index 00000000..68bd0f19 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/FormatUtils.java @@ -0,0 +1,14 @@ +package org.simantics.sysdyn.representation.utils; + +import org.simantics.sysdyn.representation.Variable; + +public class FormatUtils { + + public static String formatExpressionForModelica(Variable variable, String expression) { + String modified = expression; + modified = IndexUtils.equationRangesToIndexes(variable, modified); + modified = SheetFormatUtils.reformatSheetReferences(variable, modified); + return modified; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/IndexUtils.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/IndexUtils.java new file mode 100644 index 00000000..e2bfc7a0 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/IndexUtils.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation.utils; + +import java.io.StringReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + +import org.simantics.sysdyn.expressionParser.ExpressionParser; +import org.simantics.sysdyn.expressionParser.ExpressionParser.ForRange; +import org.simantics.sysdyn.expressionParser.ParseException; +import org.simantics.sysdyn.representation.ArrayIndexes; +import org.simantics.sysdyn.representation.Configuration; +import org.simantics.sysdyn.representation.Enumeration; +import org.simantics.sysdyn.representation.EnumerationIndex; +import org.simantics.sysdyn.representation.IElement; +import org.simantics.sysdyn.representation.Variable; + +public class IndexUtils { + + public static int indexOf(Enumeration enumeration, String index) { + int result = -1; + ArrayList indexes = enumeration.getEnumerationIndexes(); + for(int i = 0; i < indexes.size(); i++) { + if(indexes.get(i).getName().equals(index)) { + result = i +1; + break; + } + } + return result; + } + + + public static String rangeToIndexes(Variable variable, String range) { + if(variable == null) + return range; + StringBuilder sb = new StringBuilder(); + ArrayIndexes arrayIndexes = variable.getArrayIndexes(); + if(arrayIndexes == null || range == null) + return ""; + ArrayList enumerations = arrayIndexes.getEnumerations(); + StringTokenizer st = new StringTokenizer(range, "[]:,", true); + int index = 0; + while(st.hasMoreTokens()) { + String rangeToken = st.nextToken().trim(); + if(rangeToken.matches("[\\[\\]:]")) { + sb.append(rangeToken); + } else if (rangeToken.equals(",")) { + sb.append(rangeToken); + index++; + } else if(rangeToken.equals(enumerations.get(index).getName())) { + sb.append(":"); + } else { + int i = indexOf(enumerations.get(index), rangeToken); + if(i >= 0) + sb.append(i); + else + sb.append(rangeToken); + } + + } + return sb.toString(); + } + + private static String fixForRangeEnumerations(Variable variable, String equation) { + ExpressionParser parser = new ExpressionParser(new StringReader(equation)); + try { + parser.expr(); + for(ForRange forRange : parser.getForRanges()) { + if(forRange.start.equals(forRange.end)) { + Variable v = getVariable(variable.getParentConfiguration(), forRange.start.image); + if(v instanceof Enumeration) { + equation = equation.replaceAll("in[\\s]*" + forRange.start.image + "($|[^\\.])", "in " + forRange.start.image + ".elements$1"); + } + } + } + } catch (ParseException e) { + e.printStackTrace(); + } + return equation; + } + + public static String equationRangesToIndexes(Variable variable, String equation) { + if(equation == null || !equation.contains("[")) return equation; + + StringBuilder result = new StringBuilder(); + String delimiters = "+-*/(){}[],. "; + StringTokenizer st = new StringTokenizer(equation, delimiters, true); + String prevToken = st.nextToken(); + result.append(prevToken); + while (st.hasMoreTokens()) { + String nextToken = st.nextToken(); + if (nextToken.equals("[")) { + StringBuilder range = new StringBuilder(); + range.append("["); + String rangeToken = st.nextToken(); + while(!rangeToken.equals("]")) { + range.append(rangeToken); + rangeToken = st.nextToken(); + } + range.append("]"); + + Variable prevVar = getVariable(variable.getParentConfiguration(), prevToken.trim()); + result.append(rangeToIndexes(prevVar, range.toString())); + } else { + result.append(nextToken); + } + prevToken = nextToken; + } + + equation = fixForRangeEnumerations(variable, result.toString()); + return equation; + } + + private static Variable getVariable(Configuration configuration, String name) { + for(IElement element : configuration.getElements()) { + if(element instanceof Variable) { + Variable variable = (Variable) element; + if(variable.getName().equals(name)) { + return variable; + } + } + } + return null; + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/SheetFormatUtils.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/SheetFormatUtils.java new file mode 100644 index 00000000..5923c194 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/SheetFormatUtils.java @@ -0,0 +1,92 @@ +package org.simantics.sysdyn.representation.utils; + +import java.io.StringReader; +import java.util.HashMap; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.simantics.sysdyn.expressionParser.ExpressionParser; +import org.simantics.sysdyn.expressionParser.ParseException; +import org.simantics.sysdyn.expressionParser.Token; +import org.simantics.sysdyn.representation.Configuration; +import org.simantics.sysdyn.representation.IElement; +import org.simantics.sysdyn.representation.Sheet; +import org.simantics.sysdyn.representation.Variable; + +public class SheetFormatUtils { + + public static String reformatSheetReferences(Variable v, String expression) { + if(expression == null || !expression.contains("(")) + return expression; + ExpressionParser parser = new ExpressionParser(new StringReader(expression)); + try { + parser.expr(); + + HashMap> functionCalls = parser.getFunctionCallReferences(); + for(String key : functionCalls.keySet()) { + String[] parts = key.split("\\."); + Object current = v.getParentConfiguration(); + Object found = null; + for(int i = 0; i < parts.length && current != null; i++) { + found = null; + if(current instanceof Configuration) { + for(IElement e : ((Configuration)current).getElements()) { + if(e instanceof Configuration && + ((Variable)e).getName().equals(parts[i])) { + found = e; + break; + } else if(e instanceof Variable && + ((Variable)e).getName().equals(parts[i])) { + found = e; + break; + } + } + } + current = found; + } + + if(current != null && current instanceof Sheet) { + + String tmp = ""; + int start = 0, end = 0, call = 0; + String cellOrRange = null; + while((call = expression.indexOf(key, end)) >= 0) { + start = expression.indexOf("(", call); + + tmp += expression.substring(end, start); + + end = expression.indexOf(")", start) + 1; + if(start < 0 || end < 0 || end < start) { + break; + } + cellOrRange = expression.substring(start, end); + cellOrRange = cellOrRange.substring(1, cellOrRange.length() - 1); + cellOrRange = cellOrRange.trim(); + cellOrRange = cellOrRange.replace(" ", ""); + + Pattern p = Pattern.compile("[-\\+\\*\\/\\(\\)\\{\\}\\[\\],\\.\\t\\n\\r\\f]"); + Matcher m = p.matcher(cellOrRange); + if (m.find() || cellOrRange.split(":").length > 2 || cellOrRange.length() == 0) { + continue; + } + + // Use the cell or range in the sheet. + ((Sheet)current).use(cellOrRange); + + cellOrRange = cellOrRange.replace(":", "_"); + + tmp += "." + cellOrRange; + } + tmp += expression.substring(end, expression.length()); + return tmp; + } + } + + } catch (ParseException e) { + e.printStackTrace(); + } + return expression; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java new file mode 100644 index 00000000..64c7d287 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation.visitors; + +import org.simantics.sysdyn.representation.Auxiliary; +import org.simantics.sysdyn.representation.Cloud; +import org.simantics.sysdyn.representation.Configuration; +import org.simantics.sysdyn.representation.Dependency; +import org.simantics.sysdyn.representation.DiagramContainerDummy; +import org.simantics.sysdyn.representation.Enumeration; +import org.simantics.sysdyn.representation.Flow; +import org.simantics.sysdyn.representation.Input; +import org.simantics.sysdyn.representation.LibraryDummy; +import org.simantics.sysdyn.representation.Module; +import org.simantics.sysdyn.representation.Book; +import org.simantics.sysdyn.representation.Stock; +import org.simantics.sysdyn.representation.Valve; + +public class ElementVisitorVoidAdapter implements IElementVisitorVoid { + + @Override + public void visit(Auxiliary auxiliary) { + } + + @Override + public void visit(Stock stock) { + } + + @Override + public void visit(Valve valve) { + } + + @Override + public void visit(Cloud cloud) { + } + + @Override + public void visit(Input input) { + } + + @Override + public void visit(Dependency dependency) { + } + + @Override + public void visit(Flow flow) { + } + + @Override + public void visit(Module module) { + } + + @Override + public void visit(Configuration configuration) { + } + + @Override + public void visit(Enumeration enumeration) { + } + + @Override + public void visit(LibraryDummy libraryDummy) { + } + + @Override + public void visit(Book sheet) { + } + + @Override + public void visit(DiagramContainerDummy container) { + } +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java new file mode 100644 index 00000000..3c78343b --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.representation.visitors; + +import org.simantics.sysdyn.representation.Auxiliary; +import org.simantics.sysdyn.representation.Cloud; +import org.simantics.sysdyn.representation.Configuration; +import org.simantics.sysdyn.representation.Dependency; +import org.simantics.sysdyn.representation.DiagramContainerDummy; +import org.simantics.sysdyn.representation.Enumeration; +import org.simantics.sysdyn.representation.Flow; +import org.simantics.sysdyn.representation.Input; +import org.simantics.sysdyn.representation.LibraryDummy; +import org.simantics.sysdyn.representation.Module; +import org.simantics.sysdyn.representation.Book; +import org.simantics.sysdyn.representation.Stock; +import org.simantics.sysdyn.representation.Valve; + +public interface IElementVisitorVoid { + + void visit(Auxiliary auxiliary); + void visit(Stock stock); + void visit(Valve valve); + void visit(Cloud cloud); + void visit(Input input); + void visit(Dependency dependency); + void visit(Flow flow); + void visit(Module module); + void visit(Configuration configuration); + void visit(Enumeration enumeration); + void visit(LibraryDummy libraryDummy); + void visit(Book sheet); + void visit(DiagramContainerDummy container); +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java new file mode 100644 index 00000000..3d51aa8f --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java @@ -0,0 +1,301 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.simulation; + +import java.text.SimpleDateFormat; +import java.util.Calendar; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.IHyperlink; +import org.eclipse.ui.console.IPatternMatchListener; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; +import org.eclipse.ui.console.PatternMatchEvent; +import org.eclipse.ui.console.TextConsole; +import org.simantics.modelica.IModelicaMonitor; +import org.simantics.simulation.experiment.Experiment; +import org.simantics.sysdyn.manager.SysdynModel; + +public class SimulationJob extends Job { + + SysdynModel model; + Experiment experiment; + IModelicaMonitor monitor; + + public SimulationJob(SysdynModel model, Experiment experiment) { + super("Simulate " + model.getConfiguration().getName()); + this.model = model; + this.experiment = experiment; + if(PlatformUI.isWorkbenchRunning()) { + this.monitor = new ModelicaMonitor(); + } else { + // Fallback to headless + this.monitor = new HeadlessModelicaMonitor(); + } + } + + @Override + protected IStatus run(IProgressMonitor monitor) { + monitor.beginTask("Simulate " + model.getConfiguration().getName(), 5); + this.monitor.message("Simulate " + model.getConfiguration().getName()); + try { + model.update(); + model.simulate(this.monitor, monitor, experiment); + } catch (Exception e) { + e.printStackTrace(); + this.monitor.showConsole(); + return new Status( + Status.ERROR, + "org.simantics.sysdyn.ui", + "Simulation failed: \n" + e.getMessage()); + } + this.monitor.message("\n"); + monitor.done(); + return Status.OK_STATUS; + } + + @Override + public boolean belongsTo(Object family) { + return "SimulationJob".equals(family); + } + + private class HeadlessModelicaMonitor implements IModelicaMonitor { + public HeadlessModelicaMonitor() { + } + + @Override + public void message(String message) { + message(message, "hh:mm:ss"); + } + + /** + * Print message to a console with a specified time stamp format + * + * @param message the message to be printed + * @param timeStampFormat simpledateformat timestamp format. null if no timestamp wanted + */ + public void message(String message, String timeStampFormat) { + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat(timeStampFormat); + String time = sdf.format(cal.getTime()); + + System.out.println("[" + time +"] " + message); + } + + public void clearConsole() { + } + + public void showConsole() { + } + + } + //org.simantics.sysdyn.ui.modelicaEditor + private class ModelicaMonitor implements IModelicaMonitor { + + MessageConsole console; + + public ModelicaMonitor() { + ConsolePlugin plugin = ConsolePlugin.getDefault(); + IConsoleManager conMan = plugin.getConsoleManager(); + IConsole[] existing = conMan.getConsoles(); + for (int i = 0; i < existing.length; i++) + if (existing[i].getName().equals("Simulation")) + console = (MessageConsole) existing[i]; + if(console == null) { + MessageConsole myConsole = new MessageConsole("Simulation", null); + conMan.addConsoles(new IConsole[]{myConsole}); + console = myConsole; + console.addPatternMatchListener(new IPatternMatchListener() { + + @Override + public void matchFound(PatternMatchEvent event) { + try { + console.addHyperlink(new IssueLink(), event.getOffset(), event.getLength()); + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + + @Override + public void disconnect() { + } + + @Override + public void connect(TextConsole console) { + } + + @Override + public String getPattern() { + + return "Issues view"; + } + + @Override + public String getLineQualifier() { + return null; + } + + @Override + public int getCompilerFlags() { + return 0; + } + }); + + /* Link to the modelica document: to be opened to a modelica code viewer. + console.addPatternMatchListener(new IPatternMatchListener() { + + @Override + public void matchFound(PatternMatchEvent event) { + try { + if(event.getSource() instanceof MessageConsole) { + MessageConsole console = (MessageConsole) event.getSource(); + IDocument document = console.getDocument(); + String s = document.get(event.getOffset(), event.getLength()); + s = s.substring(s.indexOf(":") + 1, s.lastIndexOf(":")); + String[] split = s.split(":|-"); + + //TODO: Find the modelica document and its locations + int startOffset = modelicaDocument.getLineOffset(Integer.parseInt(split[0])) + Integer.parseInt(split[1]); + int endOffset = modelicaDocument.getLineOffset(Integer.parseInt(split[2])) + Integer.parseInt(split[3]); + System.out.println("Open modelica editor for model at: " + startOffset + ", " + (endOffset - startOffset)); + + } + + console.addHyperlink(new ModelicaLink(), event.getOffset(), event.getLength()); + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + + @Override + public void disconnect() { + } + + @Override + public void connect(TextConsole console) { + } + + @Override + public String getPattern() { + return "\\[[^\\[]*:[\\d]*:[\\d]*\\-[\\d]*:[\\d]*:writable\\]"; + + } + + @Override + public String getLineQualifier() { + return null; + } + + @Override + public int getCompilerFlags() { + return 0; + } + }); + */ + + + } + } + + @Override + public void message(String message) { + message(message, "hh:mm:ss"); + } + + /** + * Print message to a console with a specified time stamp format + * + * @param message the message to be printed + * @param timeStampFormat simpledateformat timestamp format. null if no timestamp wanted + */ + public void message(String message, String timeStampFormat) { + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat(timeStampFormat); + String time = sdf.format(cal.getTime()); + + MessageConsoleStream out = this.console.newMessageStream(); + if(message.length() > 1) + out.println("[" + time +"] " + message); + + + + if(message.contains("Error")) { + showConsole(); + out.println("See Issues view"); + } + } + + public void clearConsole() { + this.console.clearConsole(); + } + + public void showConsole() { + ConsolePlugin plugin = ConsolePlugin.getDefault(); + IConsoleManager conMan = plugin.getConsoleManager(); + conMan.showConsoleView(console); + } + + } + + @Override + protected void canceling() { + + } + + + class IssueLink implements IHyperlink { + + @Override + public void linkEntered() { + } + + @Override + public void linkExited() { + } + + @Override + public void linkActivated() { + try { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.simantics.issues.ui.issueview"); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + } + + class ModelicaLink implements IHyperlink { + + @Override + public void linkEntered() { + } + + @Override + public void linkExited() { + } + + @Override + public void linkActivated() { + System.out.println("MODELICA LINK"); + } + + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationScheduler.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationScheduler.java new file mode 100644 index 00000000..eb9ac911 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationScheduler.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.simulation; + +import org.simantics.simulation.experiment.Experiment; +import org.simantics.sysdyn.manager.SysdynModel; + +public class SimulationScheduler { + SysdynModel model; + Experiment experiment; + SimulationJob job; + + private SimulationScheduler(SysdynModel model, Experiment experiment) { + this.model = model; + this.experiment = experiment; + this.job = new SimulationJob(model, experiment); + } + + private void start() { + job.schedule(); + } + + public static synchronized SimulationScheduler start(SysdynModel model, Experiment experiment) { + SimulationScheduler scheduler = model.getService(SimulationScheduler.class); + if(scheduler == null || !scheduler.experiment.equals(experiment)) { + scheduler = new SimulationScheduler(model, experiment); + model.addService(SimulationScheduler.class, scheduler); + scheduler.start(); + } else { + scheduler.start(); + } + return scheduler; + } + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/ParseException.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/ParseException.java new file mode 100644 index 00000000..57f889b6 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/ParseException.java @@ -0,0 +1,198 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */ +/* JavaCCOptions:KEEP_LINE_COL=null */ +package org.simantics.sysdyn.tableParser; + +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(Token currentTokenVal, + int[][] expectedTokenSequencesVal, + String[] tokenImageVal + ) + { + super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String initialise(Token currentToken, + int[][] expectedTokenSequences, + String[] tokenImage) { + String eol = System.getProperty("line.separator", "\n"); + StringBuffer expected = new StringBuffer(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) { + maxSize = expectedTokenSequences[i].length; + } + for (int j = 0; j < expectedTokenSequences[i].length; j++) { + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + } + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { + expected.append("..."); + } + expected.append(eol).append(" "); + } + String retval = "Encountered \""; + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + if (i != 0) retval += " "; + if (tok.kind == 0) { + retval += tokenImage[0]; + break; + } + retval += " " + tokenImage[tok.kind]; + retval += " \""; + retval += add_escapes(tok.image); + retval += " \""; + tok = tok.next; + } + retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; + retval += "." + eol; + if (expectedTokenSequences.length == 1) { + retval += "Was expecting:" + eol + " "; + } else { + retval += "Was expecting one of:" + eol + " "; + } + retval += expected.toString(); + return retval; + } + + /** + * The end of line string for this machine. + */ + protected String eol = System.getProperty("line.separator", "\n"); + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + +} +/* JavaCC - OriginalChecksum=812397ddfc370286eccefa2f873e20e3 (do not edit this line) */ diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/SimpleCharStream.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/SimpleCharStream.java new file mode 100644 index 00000000..70ba9d99 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/SimpleCharStream.java @@ -0,0 +1,482 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 5.0 */ +/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +package org.simantics.sysdyn.tableParser; + +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public class SimpleCharStream +{ +/** Whether parser is static. */ + public static final boolean staticFlag = false; + int bufsize; + int available; + int tokenBegin; +/** Position in buffer. */ + public int bufpos = -1; + protected int bufline[]; + protected int bufcolumn[]; + + protected int column = 0; + protected int line = 1; + + protected boolean prevCharIsCR = false; + protected boolean prevCharIsLF = false; + + protected java.io.Reader inputStream; + + protected char[] buffer; + protected int maxNextCharInd = 0; + protected int inBuf = 0; + protected int tabSize = 8; + + protected void setTabSize(int i) { tabSize = i; } + protected int getTabSize(int i) { return tabSize; } + + + protected void ExpandBuff(boolean wrapAround) + { + char[] newbuffer = new char[bufsize + 2048]; + int newbufline[] = new int[bufsize + 2048]; + int newbufcolumn[] = new int[bufsize + 2048]; + + try + { + if (wrapAround) + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos += (bufsize - tokenBegin)); + } + else + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos -= tokenBegin); + } + } + catch (Throwable t) + { + throw new Error(t.getMessage()); + } + + + bufsize += 2048; + available = bufsize; + tokenBegin = 0; + } + + protected void FillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + { + if (available == bufsize) + { + if (tokenBegin > 2048) + { + bufpos = maxNextCharInd = 0; + available = tokenBegin; + } + else if (tokenBegin < 0) + bufpos = maxNextCharInd = 0; + else + ExpandBuff(false); + } + else if (available > tokenBegin) + available = bufsize; + else if ((tokenBegin - available) < 2048) + ExpandBuff(true); + else + available = tokenBegin; + } + + int i; + try { + if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) + { + inputStream.close(); + throw new java.io.IOException(); + } + else + maxNextCharInd += i; + return; + } + catch(java.io.IOException e) { + --bufpos; + backup(0); + if (tokenBegin == -1) + tokenBegin = bufpos; + throw e; + } + } + +/** Start. */ + public char BeginToken() throws java.io.IOException + { + tokenBegin = -1; + char c = readChar(); + tokenBegin = bufpos; + + return c; + } + + protected void UpdateLineColumn(char c) + { + column++; + + if (prevCharIsLF) + { + prevCharIsLF = false; + line += (column = 1); + } + else if (prevCharIsCR) + { + prevCharIsCR = false; + if (c == '\n') + { + prevCharIsLF = true; + } + else + line += (column = 1); + } + + switch (c) + { + case '\r' : + prevCharIsCR = true; + break; + case '\n' : + prevCharIsLF = true; + break; + case '\t' : + column--; + column += (tabSize - (column % tabSize)); + break; + default : + break; + } + + bufline[bufpos] = line; + bufcolumn[bufpos] = column; + } + +/** Read a character. */ + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + --inBuf; + + if (++bufpos == bufsize) + bufpos = 0; + + return buffer[bufpos]; + } + + if (++bufpos >= maxNextCharInd) + FillBuff(); + + char c = buffer[bufpos]; + + UpdateLineColumn(c); + return c; + } + + @Deprecated + /** + * @deprecated + * @see #getEndColumn + */ + + public int getColumn() { + return bufcolumn[bufpos]; + } + + @Deprecated + /** + * @deprecated + * @see #getEndLine + */ + + public int getLine() { + return bufline[bufpos]; + } + + /** Get token end column number. */ + public int getEndColumn() { + return bufcolumn[bufpos]; + } + + /** Get token end line number. */ + public int getEndLine() { + return bufline[bufpos]; + } + + /** Get token beginning column number. */ + public int getBeginColumn() { + return bufcolumn[tokenBegin]; + } + + /** Get token beginning line number. */ + public int getBeginLine() { + return bufline[tokenBegin]; + } + +/** Backup a number of characters. */ + public void backup(int amount) { + + inBuf += amount; + if ((bufpos -= amount) < 0) + bufpos += bufsize; + } + + /** Constructor. */ + public SimpleCharStream(java.io.Reader dstream, int startline, + int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } + + /** Constructor. */ + public SimpleCharStream(java.io.Reader dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.Reader dstream) + { + this(dstream, 1, 1, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader dstream, int startline, + int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + if (buffer == null || buffersize != buffer.length) + { + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } + prevCharIsLF = prevCharIsCR = false; + tokenBegin = inBuf = maxNextCharInd = 0; + bufpos = -1; + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader dstream) + { + ReInit(dstream, 1, 1, 4096); + } + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream) + { + this(dstream, 1, 1, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, 1, 1, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream) + { + ReInit(dstream, 1, 1, 4096); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, startline, startcolumn, 4096); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + /** Get token literal value. */ + public String GetImage() + { + if (bufpos >= tokenBegin) + return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); + else + return new String(buffer, tokenBegin, bufsize - tokenBegin) + + new String(buffer, 0, bufpos + 1); + } + + /** Get the suffix. */ + public char[] GetSuffix(int len) + { + char[] ret = new char[len]; + + if ((bufpos + 1) >= len) + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + else + { + System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, + len - bufpos - 1); + System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); + } + + return ret; + } + + /** Reset buffer when finished. */ + public void Done() + { + buffer = null; + bufline = null; + bufcolumn = null; + } + + /** + * Method to adjust line and column numbers for the start of a token. + */ + public void adjustBeginLineColumn(int newLine, int newCol) + { + int start = tokenBegin; + int len; + + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0, j = 0, k = 0; + int nextColDiff = 0, columnDiff = 0; + + while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) + { + bufline[j] = newLine; + nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; + bufcolumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + bufline[j] = newLine++; + bufcolumn[j] = newCol + columnDiff; + + while (i++ < len) + { + if (bufline[j = start % bufsize] != bufline[++start % bufsize]) + bufline[j] = newLine++; + else + bufline[j] = newLine; + } + } + + line = bufline[j]; + column = bufcolumn[j]; + } + +} +/* JavaCC - OriginalChecksum=6ae427b43f697d2e9732f56763450bf7 (do not edit this line) */ diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParser.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParser.java new file mode 100644 index 00000000..a8f1dd22 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParser.java @@ -0,0 +1,303 @@ +/* Generated By:JavaCC: Do not edit this line. TableParser.java */ +package org.simantics.sysdyn.tableParser; + +import java.util.ArrayList; + +public class TableParser implements TableParserConstants { + ArrayList xTokens = new ArrayList(); + ArrayList yTokens = new ArrayList(); + + public ArrayList getXTokens() { + return xTokens; + } + + public ArrayList getYTokens() { + return yTokens; + } + +/*** Parser ********************************************************/ + final public void table() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 64: + case 66: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 64: + curlyTable(); + break; + case 66: + bracketTable(); + break; + default: + jj_la1[0] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[1] = jj_gen; + ; + } + jj_consume_token(0); + } + + final public void curlyTable() throws ParseException { + jj_consume_token(64); + jj_consume_token(64); + table_element(); + jj_consume_token(65); + label_1: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + ; + break; + default: + jj_la1[2] = jj_gen; + break label_1; + } + jj_consume_token(71); + jj_consume_token(64); + table_element(); + jj_consume_token(65); + } + jj_consume_token(65); + } + + final public void bracketTable() throws ParseException { + jj_consume_token(66); + table_element(); + label_2: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 70: + ; + break; + default: + jj_la1[3] = jj_gen; + break label_2; + } + jj_consume_token(70); + table_element(); + } + jj_consume_token(67); + } + + final public void table_element() throws ParseException { + x_value(); + jj_consume_token(71); + y_value(); + } + + final public void x_value() throws ParseException { + signed_number(); + xTokens.add(token); + } + + final public void y_value() throws ParseException { + signed_number(); + yTokens.add(token); + } + + final public void signed_number() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case UNSIGNED_INTEGER: + jj_consume_token(UNSIGNED_INTEGER); + break; + case UNSIGNED_NUMBER: + jj_consume_token(UNSIGNED_NUMBER); + break; + case SIGNED_NUMBER: + jj_consume_token(SIGNED_NUMBER); + break; + default: + jj_la1[4] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + /** Generated Token Manager. */ + public TableParserTokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private int jj_gen; + final private int[] jj_la1 = new int[5]; + static private int[] jj_la1_0; + static private int[] jj_la1_1; + static private int[] jj_la1_2; + static { + jj_la1_init_0(); + jj_la1_init_1(); + jj_la1_init_2(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x0,0x0,0x0,0x0,0x0,}; + } + private static void jj_la1_init_1() { + jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,}; + } + private static void jj_la1_init_2() { + jj_la1_2 = new int[] {0x5,0x5,0x80,0x40,0x70000000,}; + } + + /** Constructor with InputStream. */ + public TableParser(java.io.InputStream stream) { + this(stream, null); + } + /** Constructor with InputStream and supplied encoding */ + public TableParser(java.io.InputStream stream, String encoding) { + try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source = new TableParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 5; i++) jj_la1[i] = -1; + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream) { + ReInit(stream, null); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream, String encoding) { + try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 5; i++) jj_la1[i] = -1; + } + + /** Constructor. */ + public TableParser(java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new TableParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 5; i++) jj_la1[i] = -1; + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader stream) { + jj_input_stream.ReInit(stream, 1, 1); + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 5; i++) jj_la1[i] = -1; + } + + /** Constructor with generated Token Manager. */ + public TableParser(TableParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 5; i++) jj_la1[i] = -1; + } + + /** Reinitialise. */ + public void ReInit(TableParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 5; i++) jj_la1[i] = -1; + } + + private Token jj_consume_token(int kind) throws ParseException { + Token oldToken; + if ((oldToken = token).next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + +/** Get the next Token. */ + final public Token getNextToken() { + if (token.next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + +/** Get the specific Token. */ + final public Token getToken(int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next != null) t = t.next; + else t = t.next = token_source.getNextToken(); + } + return t; + } + + private int jj_ntk() { + if ((jj_nt=token.next) == null) + return (jj_ntk = (token.next=token_source.getNextToken()).kind); + else + return (jj_ntk = jj_nt.kind); + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + + /** Generate ParseException. */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[95]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 5; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1< xTokens = new ArrayList(); + ArrayList yTokens = new ArrayList(); + + public ArrayList getXTokens() { + return xTokens; + } + + public ArrayList getYTokens() { + return yTokens; + } + + +} +PARSER_END(TableParser) + +/*** Lexer *********************************************************/ + +SKIP: +{ +| +| +} + +TOKEN: +{ +"algorithm" | "discrete" | "false" | "model" | "redeclare" +| "and" | "each" | "final" | "not" | "replaceable" +| "annotation" | "else" | "flow" | "operator" | "return" +|"assert" | "elseif" | "for" | "or" | "stream" +| "block" | "elsewhen" | "function" | "outer" | "then" +| "break" | "encapsulated" | "if" | "output" | "true" +| "class" | "end" | "import" | "package" | "type" +| "connect" | "enumeration" | "in" | "parameter" | "when" +| "connector" | "equation" | "initial" | "partial" | "while" +| "constant" | "expandable" | "inner" | "protected" | "within" +| "constrainedby" | "extends" | "input" | "public" +| "der" | "external" | "loop" | "record" +| "(" | ")" | "{" | "}" | "[" | "]" | "." | ":" | ";" | "," +| "<" | "<=" | ">" | ">=" | "==" | "<>" +| "+" | "-" | ".+" | ".-" +| "*" | "/" | ".*" | "./" +| "^" | ".^" +| "=" | ":=" +| +| + { matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); } +| +| "." ()? (["e","E"] )? + | "." (["e","E"] )? + | ["e","E"] + ) > +| | ))> +} + +/*** Parser ********************************************************/ + +void table() : { +} { + ( curlyTable() | bracketTable())? +} + +void curlyTable() : { } { + ( "{" "{" table_element() "}" ( "," "{" table_element() "}" )* "}" ) +} +void bracketTable() : { } { + ( "[" table_element() ( ";" table_element() )* "]" ) +} + +void table_element() : { +} { + (x_value() "," y_value()) +} + +void x_value() : { +} { + + signed_number() { + xTokens.add(token); + } +} + +void y_value() : { +} { + signed_number() { + yTokens.add(token); + } +} + +void signed_number() : { +} { + ( | | ) +} \ No newline at end of file diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParserConstants.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParserConstants.java new file mode 100644 index 00000000..6b5f0838 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParserConstants.java @@ -0,0 +1,132 @@ +/* Generated By:JavaCC: Do not edit this line. TableParserConstants.java */ +package org.simantics.sysdyn.tableParser; + + +/** + * Token literal values and constants. + * Generated by org.javacc.parser.OtherFilesGen#start() + */ +public interface TableParserConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int WHITESPACE = 1; + /** RegularExpression Id. */ + int COMMENT1 = 2; + /** RegularExpression Id. */ + int COMMENT2 = 3; + /** RegularExpression Id. */ + int IDENT = 90; + /** RegularExpression Id. */ + int STRING = 91; + /** RegularExpression Id. */ + int UNSIGNED_INTEGER = 92; + /** RegularExpression Id. */ + int UNSIGNED_NUMBER = 93; + /** RegularExpression Id. */ + int SIGNED_NUMBER = 94; + + /** Lexical state. */ + int DEFAULT = 0; + + /** Literal token values. */ + String[] tokenImage = { + "", + "", + "", + "", + "\"algorithm\"", + "\"discrete\"", + "\"false\"", + "\"model\"", + "\"redeclare\"", + "\"and\"", + "\"each\"", + "\"final\"", + "\"not\"", + "\"replaceable\"", + "\"annotation\"", + "\"else\"", + "\"flow\"", + "\"operator\"", + "\"return\"", + "\"assert\"", + "\"elseif\"", + "\"for\"", + "\"or\"", + "\"stream\"", + "\"block\"", + "\"elsewhen\"", + "\"function\"", + "\"outer\"", + "\"then\"", + "\"break\"", + "\"encapsulated\"", + "\"if\"", + "\"output\"", + "\"true\"", + "\"class\"", + "\"end\"", + "\"import\"", + "\"package\"", + "\"type\"", + "\"connect\"", + "\"enumeration\"", + "\"in\"", + "\"parameter\"", + "\"when\"", + "\"connector\"", + "\"equation\"", + "\"initial\"", + "\"partial\"", + "\"while\"", + "\"constant\"", + "\"expandable\"", + "\"inner\"", + "\"protected\"", + "\"within\"", + "\"constrainedby\"", + "\"extends\"", + "\"input\"", + "\"public\"", + "\"der\"", + "\"external\"", + "\"loop\"", + "\"record\"", + "\"(\"", + "\")\"", + "\"{\"", + "\"}\"", + "\"[\"", + "\"]\"", + "\".\"", + "\":\"", + "\";\"", + "\",\"", + "\"<\"", + "\"<=\"", + "\">\"", + "\">=\"", + "\"==\"", + "\"<>\"", + "\"+\"", + "\"-\"", + "\".+\"", + "\".-\"", + "\"*\"", + "\"/\"", + "\".*\"", + "\"./\"", + "\"^\"", + "\".^\"", + "\"=\"", + "\":=\"", + "", + "", + "", + "", + "", + }; + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParserTokenManager.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParserTokenManager.java new file mode 100644 index 00000000..3883fff9 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TableParserTokenManager.java @@ -0,0 +1,1437 @@ +/* Generated By:JavaCC: Do not edit this line. TableParserTokenManager.java */ +package org.simantics.sysdyn.tableParser; +import java.util.ArrayList; + +/** Token Manager. */ +public class TableParserTokenManager implements TableParserConstants +{ + + /** Debug output. */ + public java.io.PrintStream debugStream = System.out; + /** Set debug output. */ + public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } +private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1) +{ + switch (pos) + { + case 0: + if ((active1 & 0x80000L) != 0L) + return 24; + if ((active0 & 0x3ffffffffffffff0L) != 0L) + { + jjmatchedKind = 90; + return 2; + } + if ((active1 & 0xb30010L) != 0L) + return 46; + if ((active1 & 0x8000L) != 0L) + return 9; + return -1; + case 1: + if ((active0 & 0x108420080400000L) != 0L) + return 2; + if ((active0 & 0x3ef7bdff7fbffff0L) != 0L) + { + if (jjmatchedPos != 1) + { + jjmatchedKind = 90; + jjmatchedPos = 1; + } + return 2; + } + return -1; + case 2: + if ((active0 & 0x400000800201200L) != 0L) + return 2; + if ((active0 & 0x3bfffdf77f9fedf0L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 2; + return 2; + } + return -1; + case 3: + if ((active0 & 0x1000084212118400L) != 0L) + return 2; + if ((active0 & 0x2bfff5b56d8e69f0L) != 0L) + { + if (jjmatchedPos != 3) + { + jjmatchedKind = 90; + jjmatchedPos = 3; + } + return 2; + } + return -1; + case 4: + if ((active0 & 0x1090004290008c0L) != 0L) + return 2; + if ((active0 & 0x2af6f5b1469e6130L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 4; + return 2; + } + return -1; + case 5: + if ((active0 & 0x22200011009c0000L) != 0L) + return 2; + if ((active0 & 0x8d6f5a046026130L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 5; + return 2; + } + return -1; + case 6: + if ((active0 & 0x80d0a000000000L) != 0L) + return 2; + if ((active0 & 0x856250046026130L) != 0L) + { + if (jjmatchedPos != 6) + { + jjmatchedKind = 90; + jjmatchedPos = 6; + } + return 2; + } + return -1; + case 7: + if ((active0 & 0x54150040006110L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 7; + return 2; + } + if ((active0 & 0x802200006020020L) != 0L) + return 2; + return -1; + case 8: + if ((active0 & 0x10140000000110L) != 0L) + return 2; + if ((active0 & 0x44010040006000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 8; + return 2; + } + return -1; + case 9: + if ((active0 & 0x40010040002000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 9; + return 2; + } + if ((active0 & 0x4000000004000L) != 0L) + return 2; + return -1; + case 10: + if ((active0 & 0x10000002000L) != 0L) + return 2; + if ((active0 & 0x40000040000000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 10; + return 2; + } + return -1; + case 11: + if ((active0 & 0x40000000L) != 0L) + return 2; + if ((active0 & 0x40000000000000L) != 0L) + { + jjmatchedKind = 90; + jjmatchedPos = 11; + return 2; + } + return -1; + default : + return -1; + } +} +private final int jjStartNfa_0(int pos, long active0, long active1) +{ + return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0, active1), pos + 1); +} +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0() +{ + switch(curChar) + { + case 40: + return jjStopAtPos(0, 62); + case 41: + return jjStopAtPos(0, 63); + case 42: + return jjStopAtPos(0, 82); + case 43: + return jjStopAtPos(0, 78); + case 44: + return jjStopAtPos(0, 71); + case 45: + return jjStartNfaWithStates_0(0, 79, 9); + case 46: + jjmatchedKind = 68; + return jjMoveStringLiteralDfa1_0(0x0L, 0xb30000L); + case 47: + return jjStartNfaWithStates_0(0, 83, 24); + case 58: + jjmatchedKind = 69; + return jjMoveStringLiteralDfa1_0(0x0L, 0x2000000L); + case 59: + return jjStopAtPos(0, 70); + case 60: + jjmatchedKind = 72; + return jjMoveStringLiteralDfa1_0(0x0L, 0x2200L); + case 61: + jjmatchedKind = 88; + return jjMoveStringLiteralDfa1_0(0x0L, 0x1000L); + case 62: + jjmatchedKind = 74; + return jjMoveStringLiteralDfa1_0(0x0L, 0x800L); + case 91: + return jjStopAtPos(0, 66); + case 93: + return jjStopAtPos(0, 67); + case 94: + return jjStopAtPos(0, 86); + case 97: + return jjMoveStringLiteralDfa1_0(0x84210L, 0x0L); + case 98: + return jjMoveStringLiteralDfa1_0(0x21000000L, 0x0L); + case 99: + return jjMoveStringLiteralDfa1_0(0x42108400000000L, 0x0L); + case 100: + return jjMoveStringLiteralDfa1_0(0x400000000000020L, 0x0L); + case 101: + return jjMoveStringLiteralDfa1_0(0x884210842108400L, 0x0L); + case 102: + return jjMoveStringLiteralDfa1_0(0x4210840L, 0x0L); + case 105: + return jjMoveStringLiteralDfa1_0(0x108421080000000L, 0x0L); + case 108: + return jjMoveStringLiteralDfa1_0(0x1000000000000000L, 0x0L); + case 109: + return jjMoveStringLiteralDfa1_0(0x80L, 0x0L); + case 110: + return jjMoveStringLiteralDfa1_0(0x1000L, 0x0L); + case 111: + return jjMoveStringLiteralDfa1_0(0x108420000L, 0x0L); + case 112: + return jjMoveStringLiteralDfa1_0(0x210842000000000L, 0x0L); + case 114: + return jjMoveStringLiteralDfa1_0(0x2000000000042100L, 0x0L); + case 115: + return jjMoveStringLiteralDfa1_0(0x800000L, 0x0L); + case 116: + return jjMoveStringLiteralDfa1_0(0x4210000000L, 0x0L); + case 119: + return jjMoveStringLiteralDfa1_0(0x21080000000000L, 0x0L); + case 123: + return jjStopAtPos(0, 64); + case 125: + return jjStopAtPos(0, 65); + default : + return jjMoveNfa_0(0, 0); + } +} +private int jjMoveStringLiteralDfa1_0(long active0, long active1) +{ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(0, active0, active1); + return 1; + } + switch(curChar) + { + case 42: + if ((active1 & 0x100000L) != 0L) + return jjStopAtPos(1, 84); + break; + case 43: + if ((active1 & 0x10000L) != 0L) + return jjStopAtPos(1, 80); + break; + case 45: + if ((active1 & 0x20000L) != 0L) + return jjStopAtPos(1, 81); + break; + case 47: + if ((active1 & 0x200000L) != 0L) + return jjStopAtPos(1, 85); + break; + case 61: + if ((active1 & 0x200L) != 0L) + return jjStopAtPos(1, 73); + else if ((active1 & 0x800L) != 0L) + return jjStopAtPos(1, 75); + else if ((active1 & 0x1000L) != 0L) + return jjStopAtPos(1, 76); + else if ((active1 & 0x2000000L) != 0L) + return jjStopAtPos(1, 89); + break; + case 62: + if ((active1 & 0x2000L) != 0L) + return jjStopAtPos(1, 77); + break; + case 94: + if ((active1 & 0x800000L) != 0L) + return jjStopAtPos(1, 87); + break; + case 97: + return jjMoveStringLiteralDfa2_0(active0, 0x842000000440L, active1, 0L); + case 101: + return jjMoveStringLiteralDfa2_0(active0, 0x2400000000042100L, active1, 0L); + case 102: + if ((active0 & 0x80000000L) != 0L) + return jjStartNfaWithStates_0(1, 31, 2); + break; + case 104: + return jjMoveStringLiteralDfa2_0(active0, 0x1080010000000L, active1, 0L); + case 105: + return jjMoveStringLiteralDfa2_0(active0, 0x20000000000820L, active1, 0L); + case 108: + return jjMoveStringLiteralDfa2_0(active0, 0x403118010L, active1, 0L); + case 109: + return jjMoveStringLiteralDfa2_0(active0, 0x1000000000L, active1, 0L); + case 110: + if ((active0 & 0x20000000000L) != 0L) + { + jjmatchedKind = 41; + jjmatchedPos = 1; + } + return jjMoveStringLiteralDfa2_0(active0, 0x108410840004200L, active1, 0L); + case 111: + return jjMoveStringLiteralDfa2_0(active0, 0x1042108000201080L, active1, 0L); + case 112: + return jjMoveStringLiteralDfa2_0(active0, 0x20000L, active1, 0L); + case 113: + return jjMoveStringLiteralDfa2_0(active0, 0x200000000000L, active1, 0L); + case 114: + if ((active0 & 0x400000L) != 0L) + return jjStartNfaWithStates_0(1, 22, 2); + return jjMoveStringLiteralDfa2_0(active0, 0x10000220000000L, active1, 0L); + case 115: + return jjMoveStringLiteralDfa2_0(active0, 0x80000L, active1, 0L); + case 116: + return jjMoveStringLiteralDfa2_0(active0, 0x800000L, active1, 0L); + case 117: + return jjMoveStringLiteralDfa2_0(active0, 0x20000010c000000L, active1, 0L); + case 120: + return jjMoveStringLiteralDfa2_0(active0, 0x884000000000000L, active1, 0L); + case 121: + return jjMoveStringLiteralDfa2_0(active0, 0x4000000000L, active1, 0L); + default : + break; + } + return jjStartNfa_0(0, active0, active1); +} +private int jjMoveStringLiteralDfa2_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(0, old0, old1); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(1, active0, 0L); + return 2; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa3_0(active0, 0x400000000L); + case 98: + return jjMoveStringLiteralDfa3_0(active0, 0x200000000000000L); + case 99: + return jjMoveStringLiteralDfa3_0(active0, 0x2000002040000400L); + case 100: + if ((active0 & 0x200L) != 0L) + return jjStartNfaWithStates_0(2, 9, 2); + else if ((active0 & 0x800000000L) != 0L) + return jjStartNfaWithStates_0(2, 35, 2); + return jjMoveStringLiteralDfa3_0(active0, 0x180L); + case 101: + return jjMoveStringLiteralDfa3_0(active0, 0x80030020000L); + case 103: + return jjMoveStringLiteralDfa3_0(active0, 0x10L); + case 105: + return jjMoveStringLiteralDfa3_0(active0, 0x1400000000000L); + case 108: + return jjMoveStringLiteralDfa3_0(active0, 0x40L); + case 110: + return jjMoveStringLiteralDfa3_0(active0, 0x4a108004004800L); + case 111: + return jjMoveStringLiteralDfa3_0(active0, 0x1010000001010000L); + case 112: + return jjMoveStringLiteralDfa3_0(active0, 0x104005000002000L); + case 114: + if ((active0 & 0x200000L) != 0L) + return jjStartNfaWithStates_0(2, 21, 2); + else if ((active0 & 0x400000000000000L) != 0L) + return jjStartNfaWithStates_0(2, 58, 2); + return jjMoveStringLiteralDfa3_0(active0, 0x840000800000L); + case 115: + return jjMoveStringLiteralDfa3_0(active0, 0x2188020L); + case 116: + if ((active0 & 0x1000L) != 0L) + return jjStartNfaWithStates_0(2, 12, 2); + return jjMoveStringLiteralDfa3_0(active0, 0x8a0000108040000L); + case 117: + return jjMoveStringLiteralDfa3_0(active0, 0x210200000000L); + default : + break; + } + return jjStartNfa_0(1, active0, 0L); +} +private int jjMoveStringLiteralDfa3_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(1, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(2, active0, 0L); + return 3; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa4_0(active0, 0x4240060000800L); + case 99: + return jjMoveStringLiteralDfa4_0(active0, 0x5000020L); + case 101: + if ((active0 & 0x8000L) != 0L) + { + jjmatchedKind = 15; + jjmatchedPos = 3; + } + else if ((active0 & 0x200000000L) != 0L) + return jjStartNfaWithStates_0(3, 33, 2); + else if ((active0 & 0x4000000000L) != 0L) + return jjStartNfaWithStates_0(3, 38, 2); + return jjMoveStringLiteralDfa4_0(active0, 0x88800000a980180L); + case 104: + if ((active0 & 0x400L) != 0L) + return jjStartNfaWithStates_0(3, 10, 2); + return jjMoveStringLiteralDfa4_0(active0, 0x20000000000000L); + case 107: + return jjMoveStringLiteralDfa4_0(active0, 0x2000000000L); + case 108: + return jjMoveStringLiteralDfa4_0(active0, 0x201000000002000L); + case 109: + return jjMoveStringLiteralDfa4_0(active0, 0x10000000000L); + case 110: + if ((active0 & 0x10000000L) != 0L) + return jjStartNfaWithStates_0(3, 28, 2); + else if ((active0 & 0x80000000000L) != 0L) + return jjStartNfaWithStates_0(3, 43, 2); + return jjMoveStringLiteralDfa4_0(active0, 0x108000000000L); + case 111: + return jjMoveStringLiteralDfa4_0(active0, 0x2000001000004010L); + case 112: + if ((active0 & 0x1000000000000000L) != 0L) + return jjStartNfaWithStates_0(3, 60, 2); + return jjMoveStringLiteralDfa4_0(active0, 0x100000000L); + case 114: + return jjMoveStringLiteralDfa4_0(active0, 0x20000L); + case 115: + return jjMoveStringLiteralDfa4_0(active0, 0x42000400000040L); + case 116: + return jjMoveStringLiteralDfa4_0(active0, 0x10c00000000000L); + case 117: + return jjMoveStringLiteralDfa4_0(active0, 0x100000000040000L); + case 119: + if ((active0 & 0x10000L) != 0L) + return jjStartNfaWithStates_0(3, 16, 2); + break; + default : + break; + } + return jjStartNfa_0(2, active0, 0L); +} +private int jjMoveStringLiteralDfa4_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(2, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(3, active0, 0L); + return 4; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa5_0(active0, 0x2000822000L); + case 99: + return jjMoveStringLiteralDfa5_0(active0, 0x100L); + case 101: + if ((active0 & 0x40L) != 0L) + return jjStartNfaWithStates_0(4, 6, 2); + else if ((active0 & 0x1000000000000L) != 0L) + return jjStartNfaWithStates_0(4, 48, 2); + return jjMoveStringLiteralDfa5_0(active0, 0x10118000000000L); + case 105: + return jjMoveStringLiteralDfa5_0(active0, 0x220c00000100000L); + case 107: + if ((active0 & 0x1000000L) != 0L) + return jjStartNfaWithStates_0(4, 24, 2); + else if ((active0 & 0x20000000L) != 0L) + return jjStartNfaWithStates_0(4, 29, 2); + break; + case 108: + if ((active0 & 0x80L) != 0L) + return jjStartNfaWithStates_0(4, 7, 2); + else if ((active0 & 0x800L) != 0L) + return jjStartNfaWithStates_0(4, 11, 2); + break; + case 109: + return jjMoveStringLiteralDfa5_0(active0, 0x40000000000L); + case 110: + return jjMoveStringLiteralDfa5_0(active0, 0x84000000000000L); + case 112: + return jjMoveStringLiteralDfa5_0(active0, 0x40000000L); + case 114: + if ((active0 & 0x8000000L) != 0L) + return jjStartNfaWithStates_0(4, 27, 2); + else if ((active0 & 0x8000000000000L) != 0L) + return jjStartNfaWithStates_0(4, 51, 2); + return jjMoveStringLiteralDfa5_0(active0, 0x28000010000c0030L); + case 115: + if ((active0 & 0x400000000L) != 0L) + return jjStartNfaWithStates_0(4, 34, 2); + break; + case 116: + if ((active0 & 0x100000000000000L) != 0L) + return jjStartNfaWithStates_0(4, 56, 2); + return jjMoveStringLiteralDfa5_0(active0, 0x42200004004000L); + case 117: + return jjMoveStringLiteralDfa5_0(active0, 0x100000000L); + case 119: + return jjMoveStringLiteralDfa5_0(active0, 0x2000000L); + default : + break; + } + return jjStartNfa_0(3, active0, 0L); +} +private int jjMoveStringLiteralDfa5_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(3, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(4, active0, 0L); + return 5; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa6_0(active0, 0x2c00000004000L); + case 99: + if ((active0 & 0x200000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 57, 2); + return jjMoveStringLiteralDfa6_0(active0, 0x10108000002000L); + case 100: + if ((active0 & 0x2000000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 61, 2); + return jjMoveStringLiteralDfa6_0(active0, 0x84000000000000L); + case 101: + return jjMoveStringLiteralDfa6_0(active0, 0x40000000020L); + case 102: + if ((active0 & 0x100000L) != 0L) + return jjStartNfaWithStates_0(5, 20, 2); + break; + case 103: + return jjMoveStringLiteralDfa6_0(active0, 0x2000000000L); + case 104: + return jjMoveStringLiteralDfa6_0(active0, 0x2000000L); + case 105: + return jjMoveStringLiteralDfa6_0(active0, 0x200004000010L); + case 108: + return jjMoveStringLiteralDfa6_0(active0, 0x100L); + case 109: + if ((active0 & 0x800000L) != 0L) + return jjStartNfaWithStates_0(5, 23, 2); + break; + case 110: + if ((active0 & 0x40000L) != 0L) + return jjStartNfaWithStates_0(5, 18, 2); + else if ((active0 & 0x20000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 53, 2); + return jjMoveStringLiteralDfa6_0(active0, 0x800000000000000L); + case 114: + return jjMoveStringLiteralDfa6_0(active0, 0x40010000000000L); + case 115: + return jjMoveStringLiteralDfa6_0(active0, 0x40000000L); + case 116: + if ((active0 & 0x80000L) != 0L) + return jjStartNfaWithStates_0(5, 19, 2); + else if ((active0 & 0x100000000L) != 0L) + return jjStartNfaWithStates_0(5, 32, 2); + else if ((active0 & 0x1000000000L) != 0L) + return jjStartNfaWithStates_0(5, 36, 2); + return jjMoveStringLiteralDfa6_0(active0, 0x20000L); + default : + break; + } + return jjStartNfa_0(4, active0, 0L); +} +private int jjMoveStringLiteralDfa6_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(4, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(5, active0, 0L); + return 6; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa7_0(active0, 0x844010000000100L); + case 101: + if ((active0 & 0x2000000000L) != 0L) + return jjStartNfaWithStates_0(6, 37, 2); + return jjMoveStringLiteralDfa7_0(active0, 0x2002000L); + case 108: + if ((active0 & 0x400000000000L) != 0L) + return jjStartNfaWithStates_0(6, 46, 2); + else if ((active0 & 0x800000000000L) != 0L) + return jjStartNfaWithStates_0(6, 47, 2); + break; + case 110: + return jjMoveStringLiteralDfa7_0(active0, 0x2000000000000L); + case 111: + return jjMoveStringLiteralDfa7_0(active0, 0x200004020000L); + case 115: + if ((active0 & 0x80000000000000L) != 0L) + return jjStartNfaWithStates_0(6, 55, 2); + break; + case 116: + if ((active0 & 0x8000000000L) != 0L) + { + jjmatchedKind = 39; + jjmatchedPos = 6; + } + return jjMoveStringLiteralDfa7_0(active0, 0x10140000004030L); + case 117: + return jjMoveStringLiteralDfa7_0(active0, 0x40000000L); + default : + break; + } + return jjStartNfa_0(5, active0, 0L); +} +private int jjMoveStringLiteralDfa7_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(5, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(6, active0, 0L); + return 7; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa8_0(active0, 0x2000L); + case 98: + return jjMoveStringLiteralDfa8_0(active0, 0x4000000000000L); + case 101: + if ((active0 & 0x20L) != 0L) + return jjStartNfaWithStates_0(7, 5, 2); + return jjMoveStringLiteralDfa8_0(active0, 0x10040000000000L); + case 104: + return jjMoveStringLiteralDfa8_0(active0, 0x10L); + case 105: + return jjMoveStringLiteralDfa8_0(active0, 0x40000000004000L); + case 108: + if ((active0 & 0x800000000000000L) != 0L) + return jjStartNfaWithStates_0(7, 59, 2); + return jjMoveStringLiteralDfa8_0(active0, 0x40000000L); + case 110: + if ((active0 & 0x2000000L) != 0L) + return jjStartNfaWithStates_0(7, 25, 2); + else if ((active0 & 0x4000000L) != 0L) + return jjStartNfaWithStates_0(7, 26, 2); + else if ((active0 & 0x200000000000L) != 0L) + return jjStartNfaWithStates_0(7, 45, 2); + break; + case 111: + return jjMoveStringLiteralDfa8_0(active0, 0x100000000000L); + case 114: + if ((active0 & 0x20000L) != 0L) + return jjStartNfaWithStates_0(7, 17, 2); + return jjMoveStringLiteralDfa8_0(active0, 0x100L); + case 116: + if ((active0 & 0x2000000000000L) != 0L) + return jjStartNfaWithStates_0(7, 49, 2); + return jjMoveStringLiteralDfa8_0(active0, 0x10000000000L); + default : + break; + } + return jjStartNfa_0(6, active0, 0L); +} +private int jjMoveStringLiteralDfa8_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(6, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(7, active0, 0L); + return 8; + } + switch(curChar) + { + case 97: + return jjMoveStringLiteralDfa9_0(active0, 0x40000000L); + case 98: + return jjMoveStringLiteralDfa9_0(active0, 0x2000L); + case 100: + if ((active0 & 0x10000000000000L) != 0L) + return jjStartNfaWithStates_0(8, 52, 2); + break; + case 101: + if ((active0 & 0x100L) != 0L) + return jjStartNfaWithStates_0(8, 8, 2); + break; + case 105: + return jjMoveStringLiteralDfa9_0(active0, 0x10000000000L); + case 108: + return jjMoveStringLiteralDfa9_0(active0, 0x4000000000000L); + case 109: + if ((active0 & 0x10L) != 0L) + return jjStartNfaWithStates_0(8, 4, 2); + break; + case 110: + return jjMoveStringLiteralDfa9_0(active0, 0x40000000000000L); + case 111: + return jjMoveStringLiteralDfa9_0(active0, 0x4000L); + case 114: + if ((active0 & 0x40000000000L) != 0L) + return jjStartNfaWithStates_0(8, 42, 2); + else if ((active0 & 0x100000000000L) != 0L) + return jjStartNfaWithStates_0(8, 44, 2); + break; + default : + break; + } + return jjStartNfa_0(7, active0, 0L); +} +private int jjMoveStringLiteralDfa9_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(7, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(8, active0, 0L); + return 9; + } + switch(curChar) + { + case 101: + if ((active0 & 0x4000000000000L) != 0L) + return jjStartNfaWithStates_0(9, 50, 2); + return jjMoveStringLiteralDfa10_0(active0, 0x40000000000000L); + case 108: + return jjMoveStringLiteralDfa10_0(active0, 0x2000L); + case 110: + if ((active0 & 0x4000L) != 0L) + return jjStartNfaWithStates_0(9, 14, 2); + break; + case 111: + return jjMoveStringLiteralDfa10_0(active0, 0x10000000000L); + case 116: + return jjMoveStringLiteralDfa10_0(active0, 0x40000000L); + default : + break; + } + return jjStartNfa_0(8, active0, 0L); +} +private int jjMoveStringLiteralDfa10_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(8, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(9, active0, 0L); + return 10; + } + switch(curChar) + { + case 100: + return jjMoveStringLiteralDfa11_0(active0, 0x40000000000000L); + case 101: + if ((active0 & 0x2000L) != 0L) + return jjStartNfaWithStates_0(10, 13, 2); + return jjMoveStringLiteralDfa11_0(active0, 0x40000000L); + case 110: + if ((active0 & 0x10000000000L) != 0L) + return jjStartNfaWithStates_0(10, 40, 2); + break; + default : + break; + } + return jjStartNfa_0(9, active0, 0L); +} +private int jjMoveStringLiteralDfa11_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(9, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(10, active0, 0L); + return 11; + } + switch(curChar) + { + case 98: + return jjMoveStringLiteralDfa12_0(active0, 0x40000000000000L); + case 100: + if ((active0 & 0x40000000L) != 0L) + return jjStartNfaWithStates_0(11, 30, 2); + break; + default : + break; + } + return jjStartNfa_0(10, active0, 0L); +} +private int jjMoveStringLiteralDfa12_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(10, old0, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(11, active0, 0L); + return 12; + } + switch(curChar) + { + case 121: + if ((active0 & 0x40000000000000L) != 0L) + return jjStartNfaWithStates_0(12, 54, 2); + break; + default : + break; + } + return jjStartNfa_0(11, active0, 0L); +} +private int jjStartNfaWithStates_0(int pos, int kind, int state) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return pos + 1; } + return jjMoveNfa_0(state, pos + 1); +} +static final long[] jjbitVec0 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +private int jjMoveNfa_0(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 46; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 24: + if (curChar == 47) + { + if (kind > 3) + kind = 3; + jjCheckNAdd(31); + } + else if (curChar == 42) + jjCheckNAddStates(0, 2); + break; + case 46: + if ((0x3ff000000000000L & l) != 0L) + { + if (kind > 94) + kind = 94; + jjCheckNAddTwoStates(10, 11); + } + if ((0x3ff000000000000L & l) != 0L) + { + if (kind > 93) + kind = 93; + jjCheckNAddTwoStates(43, 44); + } + break; + case 9: + if ((0x3ff000000000000L & l) != 0L) + { + if (kind > 94) + kind = 94; + jjCheckNAddStates(3, 7); + } + else if (curChar == 46) + jjCheckNAdd(10); + break; + case 0: + if ((0x3ff000000000000L & l) != 0L) + { + if (kind > 92) + kind = 92; + jjCheckNAddStates(8, 17); + } + else if ((0x100002600L & l) != 0L) + { + if (kind > 1) + kind = 1; + } + else if (curChar == 46) + jjCheckNAddTwoStates(43, 10); + else if (curChar == 47) + jjAddStates(18, 19); + else if (curChar == 45) + jjAddStates(20, 21); + else if (curChar == 34) + jjCheckNAddStates(22, 24); + break; + case 2: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 90) + kind = 90; + jjstateSet[jjnewStateCnt++] = 2; + break; + case 3: + if (curChar == 34) + jjCheckNAddStates(22, 24); + break; + case 4: + if ((0xfffffffbfffffbffL & l) != 0L) + jjCheckNAddStates(22, 24); + break; + case 6: + if ((0xfffffffffffffbffL & l) != 0L) + jjCheckNAddStates(22, 24); + break; + case 7: + if (curChar == 34 && kind > 91) + kind = 91; + break; + case 8: + if (curChar == 45) + jjAddStates(20, 21); + break; + case 10: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 94) + kind = 94; + jjCheckNAddTwoStates(10, 11); + break; + case 12: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 94) + kind = 94; + jjstateSet[jjnewStateCnt++] = 12; + break; + case 13: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 94) + kind = 94; + jjCheckNAddStates(3, 7); + break; + case 14: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 94) + kind = 94; + jjCheckNAdd(14); + break; + case 15: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(15, 16); + break; + case 17: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 94) + kind = 94; + jjstateSet[jjnewStateCnt++] = 17; + break; + case 18: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(18, 19); + break; + case 19: + if (curChar != 46) + break; + if (kind > 94) + kind = 94; + jjCheckNAddTwoStates(20, 21); + break; + case 20: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 94) + kind = 94; + jjCheckNAddTwoStates(20, 21); + break; + case 22: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 94) + kind = 94; + jjstateSet[jjnewStateCnt++] = 22; + break; + case 23: + if (curChar == 47) + jjAddStates(18, 19); + break; + case 25: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddStates(0, 2); + break; + case 26: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 27; + break; + case 27: + if ((0xffff7fffffffffffL & l) != 0L) + jjCheckNAddStates(0, 2); + break; + case 28: + if (curChar == 47 && kind > 2) + kind = 2; + break; + case 29: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 28; + break; + case 30: + if (curChar != 47) + break; + if (kind > 3) + kind = 3; + jjCheckNAdd(31); + break; + case 31: + if ((0xfffffffffffffbffL & l) == 0L) + break; + if (kind > 3) + kind = 3; + jjCheckNAdd(31); + break; + case 32: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 92) + kind = 92; + jjCheckNAddStates(8, 17); + break; + case 33: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 92) + kind = 92; + jjCheckNAdd(33); + break; + case 34: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(34, 35); + break; + case 35: + if (curChar != 46) + break; + if (kind > 93) + kind = 93; + jjCheckNAddTwoStates(36, 37); + break; + case 36: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjCheckNAddTwoStates(36, 37); + break; + case 38: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjstateSet[jjnewStateCnt++] = 38; + break; + case 39: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(39, 40); + break; + case 41: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjstateSet[jjnewStateCnt++] = 41; + break; + case 42: + if (curChar == 46) + jjCheckNAddTwoStates(43, 10); + break; + case 43: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjCheckNAddTwoStates(43, 44); + break; + case 45: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 93) + kind = 93; + jjstateSet[jjnewStateCnt++] = 45; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 0: + case 2: + if ((0x7fffffe87fffffeL & l) == 0L) + break; + if (kind > 90) + kind = 90; + jjCheckNAdd(2); + break; + case 4: + if ((0xffffffffefffffffL & l) != 0L) + jjCheckNAddStates(22, 24); + break; + case 5: + if (curChar == 92) + jjstateSet[jjnewStateCnt++] = 6; + break; + case 6: + jjCheckNAddStates(22, 24); + break; + case 11: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 12; + break; + case 16: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 17; + break; + case 21: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 22; + break; + case 25: + case 27: + jjCheckNAddStates(0, 2); + break; + case 31: + if (kind > 3) + kind = 3; + jjstateSet[jjnewStateCnt++] = 31; + break; + case 37: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 38; + break; + case 40: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 41; + break; + case 44: + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 45; + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 4: + case 6: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddStates(22, 24); + break; + case 25: + case 27: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddStates(0, 2); + break; + case 31: + if ((jjbitVec0[i2] & l2) == 0L) + break; + if (kind > 3) + kind = 3; + jjstateSet[jjnewStateCnt++] = 31; + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + if ((i = jjnewStateCnt) == (startsAt = 46 - (jjnewStateCnt = startsAt))) + return curPos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return curPos; } + } +} +static final int[] jjnextStates = { + 25, 26, 29, 14, 15, 16, 18, 19, 33, 34, 35, 39, 40, 14, 15, 16, + 18, 19, 24, 30, 9, 13, 4, 5, 7, +}; + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, "\141\154\147\157\162\151\164\150\155", +"\144\151\163\143\162\145\164\145", "\146\141\154\163\145", "\155\157\144\145\154", +"\162\145\144\145\143\154\141\162\145", "\141\156\144", "\145\141\143\150", "\146\151\156\141\154", "\156\157\164", +"\162\145\160\154\141\143\145\141\142\154\145", "\141\156\156\157\164\141\164\151\157\156", "\145\154\163\145", +"\146\154\157\167", "\157\160\145\162\141\164\157\162", "\162\145\164\165\162\156", +"\141\163\163\145\162\164", "\145\154\163\145\151\146", "\146\157\162", "\157\162", +"\163\164\162\145\141\155", "\142\154\157\143\153", "\145\154\163\145\167\150\145\156", +"\146\165\156\143\164\151\157\156", "\157\165\164\145\162", "\164\150\145\156", "\142\162\145\141\153", +"\145\156\143\141\160\163\165\154\141\164\145\144", "\151\146", "\157\165\164\160\165\164", "\164\162\165\145", +"\143\154\141\163\163", "\145\156\144", "\151\155\160\157\162\164", "\160\141\143\153\141\147\145", +"\164\171\160\145", "\143\157\156\156\145\143\164", +"\145\156\165\155\145\162\141\164\151\157\156", "\151\156", "\160\141\162\141\155\145\164\145\162", "\167\150\145\156", +"\143\157\156\156\145\143\164\157\162", "\145\161\165\141\164\151\157\156", "\151\156\151\164\151\141\154", +"\160\141\162\164\151\141\154", "\167\150\151\154\145", "\143\157\156\163\164\141\156\164", +"\145\170\160\141\156\144\141\142\154\145", "\151\156\156\145\162", "\160\162\157\164\145\143\164\145\144", +"\167\151\164\150\151\156", "\143\157\156\163\164\162\141\151\156\145\144\142\171", +"\145\170\164\145\156\144\163", "\151\156\160\165\164", "\160\165\142\154\151\143", "\144\145\162", +"\145\170\164\145\162\156\141\154", "\154\157\157\160", "\162\145\143\157\162\144", "\50", "\51", "\173", "\175", +"\133", "\135", "\56", "\72", "\73", "\54", "\74", "\74\75", "\76", "\76\75", +"\75\75", "\74\76", "\53", "\55", "\56\53", "\56\55", "\52", "\57", "\56\52", "\56\57", +"\136", "\56\136", "\75", "\72\75", null, null, null, null, null, }; + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", +}; +static final long[] jjtoToken = { + 0xfffffffffffffff1L, 0x7fffffffL, +}; +static final long[] jjtoSkip = { + 0xeL, 0x0L, +}; +protected SimpleCharStream input_stream; +private final int[] jjrounds = new int[46]; +private final int[] jjstateSet = new int[92]; +private final StringBuilder jjimage = new StringBuilder(); +private StringBuilder image = jjimage; +private int jjimageLen; +private int lengthOfMatch; +protected char curChar; +/** Constructor. */ +public TableParserTokenManager(SimpleCharStream stream){ + if (SimpleCharStream.staticFlag) + throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); + input_stream = stream; +} + +/** Constructor. */ +public TableParserTokenManager(SimpleCharStream stream, int lexState){ + this(stream); + SwitchTo(lexState); +} + +/** Reinitialise parser. */ +public void ReInit(SimpleCharStream stream) +{ + jjmatchedPos = jjnewStateCnt = 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); +} +private void ReInitRounds() +{ + int i; + jjround = 0x80000001; + for (i = 46; i-- > 0;) + jjrounds[i] = 0x80000000; +} + +/** Reinitialise parser. */ +public void ReInit(SimpleCharStream stream, int lexState) +{ + ReInit(stream); + SwitchTo(lexState); +} + +/** Switch to specified lex state. */ +public void SwitchTo(int lexState) +{ + if (lexState >= 1 || lexState < 0) + throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); + else + curLexState = lexState; +} + +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = (im == null) ? input_stream.GetImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind, curTokenImage); + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop : + for (;;) + { + try + { + curChar = input_stream.BeginToken(); + } + catch(java.io.IOException e) + { + jjmatchedKind = 0; + matchedToken = jjFillToken(); + return matchedToken; + } + image = jjimage; + image.setLength(0); + jjimageLen = 0; + + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + TokenLexicalActions(matchedToken); + return matchedToken; + } + else + { + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { input_stream.readChar(); input_stream.backup(1); } + catch (java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + } + throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); + } +} + +void TokenLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + case 91 : + image.append(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))); + matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); + break; + default : + break; + } +} +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + +private void jjCheckNAddStates(int start, int end) +{ + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); +} + +} diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/Token.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/Token.java new file mode 100644 index 00000000..e5636f30 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/Token.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +/* Generated By:JavaCC: Do not edit this line. Token.java Version 5.0 */ +/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +package org.simantics.sysdyn.tableParser; + +/** + * Describes the input token stream. + */ + +public class Token implements java.io.Serializable { + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(int kind) + { + this(kind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(int kind, String image) + { + this.kind = kind; + this.image = image; + } + + /** + * Returns the image. + */ + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* JavaCC - OriginalChecksum=d63d0e2011f8ce7fbf4f8ee6fd4e3986 (do not edit this line) */ diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TokenMgrError.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TokenMgrError.java new file mode 100644 index 00000000..49dbdbf9 --- /dev/null +++ b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/tableParser/TokenMgrError.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */ +/* JavaCCOptions: */ +package org.simantics.sysdyn.tableParser; + +/** Token Manager Error. */ +public class TokenMgrError extends Error +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + + /** No arg constructor. */ + public TokenMgrError() { + } + + /** Constructor with message and reason. */ + public TokenMgrError(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { + this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* JavaCC - OriginalChecksum=abb0cd060e347479552118d1e61a7e46 (do not edit this line) */ diff --git a/stable/sysdyn_ontologies/.hgignore b/stable/sysdyn_ontologies/.hgignore new file mode 100644 index 00000000..93c8bfa6 --- /dev/null +++ b/stable/sysdyn_ontologies/.hgignore @@ -0,0 +1,9 @@ +syntax: regexp +^org/ +^c_sharp/ +^layer0c.bin +^layer0c.txt +^directories.log + +syntax: glob +*.svn/* \ No newline at end of file diff --git a/stable/sysdyn_ontologies/.project b/stable/sysdyn_ontologies/.project new file mode 100644 index 00000000..56d3ddcb --- /dev/null +++ b/stable/sysdyn_ontologies/.project @@ -0,0 +1,11 @@ + + + sysdyn_ontologies + + + + + + + + diff --git a/stable/sysdyn_ontologies/dependencies.txt b/stable/sysdyn_ontologies/dependencies.txt new file mode 100644 index 00000000..37576309 --- /dev/null +++ b/stable/sysdyn_ontologies/dependencies.txt @@ -0,0 +1,3 @@ +../foundation_ontologies +../2d_ontologies +../modeling_ontologies diff --git a/stable/sysdyn_ontologies/generate_sysdyn.bat b/stable/sysdyn_ontologies/generate_sysdyn.bat new file mode 100644 index 00000000..a4127347 --- /dev/null +++ b/stable/sysdyn_ontologies/generate_sysdyn.bat @@ -0,0 +1,13 @@ +@rem *************************************************************************** +@rem Copyright (c) 2007, 2010 Association for Decentralized Information Management +@rem in Industry THTH ry. +@rem All rights reserved. This program and the accompanying materials +@rem are made available under the terms of the Eclipse Public License v1.0 +@rem which accompanies this distribution, and is available at +@rem http://www.eclipse.org/legal/epl-v10.html +@rem +@rem Contributors: +@rem VTT Technical Research Centre of Finland - initial API and implementation +@rem *************************************************************************** +@echo off +call "%~dp0..\org.simantics.db.build\build" "%~dp0" ..\foundation_ontologies\foundation.graph ..\sysdyn_ontologies\sysdyn.graph ..\modeling_ontologies\modeling.graph ..\modeling_ontologies\devs.graph ..\webmon_ontologies\webmon.graph ..\modeling_ontologies\spreadsheet.graph \ No newline at end of file diff --git a/stable/sysdyn_ontologies/install.map b/stable/sysdyn_ontologies/install.map new file mode 100644 index 00000000..a3fbef17 --- /dev/null +++ b/stable/sysdyn_ontologies/install.map @@ -0,0 +1 @@ +copy=org/simantics/sysdyn=../org.simantics.sysdyn/src diff --git a/stable/sysdyn_ontologies/sysdyn.graph b/stable/sysdyn_ontologies/sysdyn.graph new file mode 100644 index 00000000..e4492db7 --- /dev/null +++ b/stable/sysdyn_ontologies/sysdyn.graph @@ -0,0 +1,1733 @@ +%import "layer0.graph" L0 +%import "diagram2.graph" DIA +%import "g2d.graph" G2D +%import "structural2.graph" ST +%import "modeling.graph" MOD +%import "project.graph" PROJ +%import "simulation.graph" SIMU +%import "workbench.graph" WORKBENCH + +%deflib L0.Type Sysdyn +%deflib L0.Relation Sysdyn +%deflib DIA.ElementClass Symbols + +%define assert($pred,$obj) + $subject + L0.Asserts _ : L0.Assertion + L0.HasPredicate $pred + L0.HasObject $obj + +%define tag($pred) + $subject + $pred $subject + +%define symmetric() + $subject + $layer0.InverseOf $subject + +%define defSymbol($label, $componentType) + $subject