├── .classpath ├── .gitignore ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── LICENSE ├── conf ├── A3_Hoch.plotterconf ├── A3_Quer.plotterconf ├── A4_Hoch.plotterconf ├── A4_Quer.plotterconf ├── default.plotterconf └── gpio.properties ├── pom.xml └── src └── main ├── java └── de │ └── revout │ └── pi │ └── vplotter │ ├── converter │ ├── BezierCurve.java │ ├── Pair.java │ ├── SVGToPolygonConverter.java │ ├── Section.java │ └── VDPConverter.java │ ├── imagefilter │ ├── EdgeDetectionFilter.java │ ├── Filter.java │ ├── GrayscaleFilter.java │ ├── ImageConverter.java │ └── RotateFilter.java │ ├── lang │ └── Dictionary.java │ ├── main │ ├── Driver.java │ ├── DriverMoveObserverIf.java │ ├── PiVPlotter.java │ └── ServoMotor.java │ ├── model │ ├── Model.java │ └── Update.java │ ├── saves │ ├── SettingsManager.java │ └── VPlotterPropertiesManager.java │ ├── setting │ ├── ComboSetting.java │ ├── Setting.java │ └── SliderSetting.java │ ├── version │ └── Version.java │ └── view │ ├── FilterBox.java │ ├── FilterPanel.java │ ├── HomePage.java │ ├── ImagePanel.java │ ├── LivePlotterView.java │ ├── LiveView.java │ ├── MainView.java │ ├── PlotterPreview.java │ ├── PlotterView.java │ ├── StackLayout.java │ └── close2.png └── resources └── de └── revout └── pi └── vplotter └── resources └── lang ├── messages.properties └── messages_de_DE.properties /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | programm.settings 3 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | PiVPlotter 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=17 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 12 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 13 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 14 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 15 | org.eclipse.jdt.core.compiler.release=disabled 16 | org.eclipse.jdt.core.compiler.source=17 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /conf/A3_Hoch.plotterconf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1451 5 | 0.4 6 | 160.4278074866310160427807486631 7 | 8 | 250 9 | 200 10 | 500000 11 | 12 | 390 13 | 270 14 | 15 | 390 16 | 180 17 | 18 | 590 19 | 196 20 | 21 | 297 22 | 420 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /conf/A3_Quer.plotterconf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1451 5 | 0.4 6 | 160.4278074866310160427807486631 7 | 8 | 250 9 | 200 10 | 500000 11 | 12 | 270 13 | 390 14 | 15 | 390 16 | 180 17 | 18 | 530 19 | 196 20 | 21 | 420 22 | 297 23 | 24 | 25 | -------------------------------------------------------------------------------- /conf/A4_Hoch.plotterconf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1451 5 | 0.4 6 | 160.4278074866310160427807486631 7 | 8 | 300 9 | 200 10 | 500000 11 | 12 | 270 13 | 190 14 | 15 | 390 16 | 180 17 | 18 | 630 19 | 196 20 | 21 | 210 22 | 297 23 | 24 | 25 | -------------------------------------------------------------------------------- /conf/A4_Quer.plotterconf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1451 5 | 0.4 6 | 160.4278074866310160427807486631 7 | 8 | 300 9 | 200 10 | 500000 11 | 12 | 190 13 | 270 14 | 15 | 390 16 | 180 17 | 18 | 590 19 | 196 20 | 21 | 297 22 | 210 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /conf/default.plotterconf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1451 5 | 160.4278074866310160427807486631 6 | 0.4 7 | 8 | 200 9 | 100 10 | 500000 11 | 12 | 600 13 | 890 14 | 15 | 389 16 | 179 17 | 18 | 280 19 | 196 20 | 21 | 841 22 | 594 23 | 24 | 25 | -------------------------------------------------------------------------------- /conf/gpio.properties: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4 5 | 17 6 | 22 7 | 5 8 | 13 9 | 26 10 | 83 11 | 90 12 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 5 | 4.0.0 6 | 7 | de.revout.pi.vplotter 8 | PiVPlotter 9 | 2.0.0 10 | PiVPlotter 11 | V-Plotter mit Raspberry Pi 12 | 13 | 14 | 15 | UTF-8 16 | 17 17 | 2.8.0 18 | 3.10.1 19 | 3.3.0 20 | 21 | 22 | 23 | 24 | com.pi4j 25 | pi4j-core 26 | ${pi4j.version} 27 | 28 | 29 | com.pi4j 30 | pi4j-plugin-raspberrypi 31 | ${pi4j.version} 32 | 33 | 34 | com.pi4j 35 | pi4j-plugin-gpiod 36 | ${pi4j.version} 37 | 38 | 39 | com.pi4j 40 | pi4j-plugin-linuxfs 41 | ${pi4j.version} 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.apache.maven.plugins 50 | maven-compiler-plugin 51 | ${maven.compiler.plugin.version} 52 | 53 | ${maven.compiler.release} 54 | 55 | 56 | 57 | 58 | 59 | org.apache.maven.plugins 60 | maven-assembly-plugin 61 | ${maven.assembly.plugin.version} 62 | 63 | PiVPlotter 64 | false 65 | 66 | jar-with-dependencies 67 | 68 | 69 | 70 | 71 | de.revout.pi.vplotter.main.PiVPlotter 72 | 73 | 74 | 75 | 76 | 77 | package 78 | 79 | single 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/converter/BezierCurve.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.converter; 2 | 3 | import java.math.BigInteger; 4 | 5 | public class BezierCurve { 6 | 7 | private int pointsCount; 8 | 9 | public BezierCurve(int paramPointsCount) { 10 | pointsCount = paramPointsCount; 11 | } 12 | 13 | public static BigInteger factorial(long number) { 14 | BigInteger result = BigInteger.valueOf(1); 15 | 16 | for (long factor = 2; factor <= number; factor++) { 17 | result = result.multiply(BigInteger.valueOf(factor)); 18 | } 19 | 20 | return result; 21 | } 22 | 23 | private double ni(int n, int i) { 24 | double ni; 25 | double a1 = factorial(n).doubleValue(); 26 | double a2 = factorial(i).doubleValue(); 27 | double a3 = factorial(n - i).doubleValue(); 28 | ni = a1 / (a2 * a3); 29 | return ni; 30 | } 31 | 32 | 33 | // Calculate Bernstein basis 34 | private double bernstein(int n, int i, double t) 35 | { 36 | double basis; 37 | double ti; /* t^i */ 38 | double tni; /* (1 - t)^i */ 39 | 40 | if (t == 0.0 && i == 0) 41 | ti = 1.0; 42 | else 43 | ti = Math.pow(t, i); 44 | 45 | if (n == i && t == 1.0) 46 | tni = 1.0; 47 | else 48 | tni = Math.pow((1 - t), (n - i)); 49 | 50 | basis = ni(n, i) * ti * tni; 51 | return basis; 52 | } 53 | 54 | public double[] bezier2D(double[] b) 55 | { 56 | double[] result = new double[pointsCount*2]; 57 | int npts = (b.length) / 2; 58 | int icount, jcount; 59 | double step, t; 60 | 61 | 62 | icount = 0; 63 | t = 0; 64 | step = (double)1.0 / (pointsCount - 1); 65 | 66 | for (int i1 = 0; i1 < pointsCount; i1++) 67 | { 68 | if ((1.0 - t) < 5e-6) 69 | t = 1.0; 70 | 71 | jcount = 0; 72 | result[icount] = 0.0; 73 | result[icount + 1] = 0.0; 74 | for (int i = 0; i < npts; i++) 75 | { 76 | double basis = bernstein(npts - 1, i, t); 77 | result[icount] += basis * b[jcount]; 78 | result[icount + 1] += basis * b[jcount + 1]; 79 | jcount = jcount +2; 80 | } 81 | 82 | icount += 2; 83 | t += step; 84 | } 85 | return result; 86 | } 87 | 88 | 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/converter/Pair.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.converter; 2 | 3 | public class Pair { 4 | 5 | private double x; 6 | private double y; 7 | 8 | 9 | public Pair(double paramX, double paramY) { 10 | x= paramX; 11 | y= paramY; 12 | } 13 | 14 | public double getX() { 15 | return x; 16 | } 17 | public void setX(double x) { 18 | this.x = x; 19 | } 20 | public double getY() { 21 | return y; 22 | } 23 | public void setY(double y) { 24 | this.y = y; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getX()+" : "+getY(); //$NON-NLS-1$ 30 | } 31 | 32 | public Pair calulateDifferenceTo(Pair paramToPair) { 33 | return new Pair(x-paramToPair.getX(), y-paramToPair.getY()); 34 | } 35 | 36 | public Pair add(Pair paramToPair) { 37 | x=x+paramToPair.getX(); 38 | y=y+paramToPair.getY(); 39 | return this; 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/converter/SVGToPolygonConverter.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.converter; 2 | 3 | import java.io.InputStream; 4 | import java.nio.file.Files; 5 | import java.nio.file.Path; 6 | import java.nio.file.StandardOpenOption; 7 | import java.util.ArrayList; 8 | import java.util.Arrays; 9 | import java.util.Collections; 10 | import java.util.List; 11 | 12 | import javax.xml.parsers.DocumentBuilder; 13 | import javax.xml.parsers.DocumentBuilderFactory; 14 | import javax.xml.xpath.XPath; 15 | import javax.xml.xpath.XPathConstants; 16 | import javax.xml.xpath.XPathFactory; 17 | 18 | import org.w3c.dom.Document; 19 | import org.w3c.dom.Element; 20 | import org.w3c.dom.NamedNodeMap; 21 | import org.w3c.dom.Node; 22 | import org.w3c.dom.NodeList; 23 | 24 | public class SVGToPolygonConverter { 25 | 26 | // Dimensionen und Transformationen der SVG 27 | private double width = 0; 28 | private double height = 0; 29 | private double translateX = 0; 30 | private double translateY = 0; 31 | private double scaleX = 1; 32 | private double scaleY = 1; 33 | private double minX = 0; 34 | private double maxX = 0; 35 | private double minY = 0; 36 | private double maxY = 0; 37 | 38 | /** 39 | * Wandelt das gegebene SVG-Dokument (Pfad) in eine Liste von absoluten 40 | * Polygon-Pfad-Daten um. 41 | * 42 | * @param paramPathToSVG Pfad zur SVG-Datei 43 | * @return Liste der konvertierten Pfaddaten 44 | */ 45 | public List convertSVG(Path paramPathToSVG) { 46 | // Reset der globalen Variablen 47 | width = 0; 48 | height = 0; 49 | translateX = 0; 50 | translateY = 0; 51 | scaleX = 1; 52 | scaleY = 1; 53 | minX = 0; 54 | maxX = 0; 55 | minY = 0; 56 | maxY = 0; 57 | 58 | try (InputStream fileIS = Files.newInputStream(paramPathToSVG, StandardOpenOption.READ)) { 59 | // XML-Dokument einlesen 60 | DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); 61 | DocumentBuilder builder = builderFactory.newDocumentBuilder(); 62 | Document xmlDocument = builder.parse(fileIS); 63 | Element root = xmlDocument.getDocumentElement(); 64 | 65 | // Lese width und height (ohne Einheiten) 66 | width = parseDoubleClean(root.getAttribute("width")); 67 | height = parseDoubleClean(root.getAttribute("height")); 68 | 69 | // Transformationswerte aus dem ersten -Element auslesen (falls vorhanden) 70 | NodeList gList = root.getElementsByTagName("g"); 71 | if (gList.getLength() > 0) { 72 | Node gNode = gList.item(0); 73 | NamedNodeMap attrs = gNode.getAttributes(); 74 | Node transformAttr = attrs.getNamedItem("transform"); 75 | if (transformAttr != null) { 76 | String transformStr = transformAttr.getNodeValue(); 77 | double[] translate = getValuePair(transformStr, "translate", 0); 78 | double[] scale = getValuePair(transformStr, "scale", 1); 79 | translateX = translate[0]; 80 | translateY = translate[1]; 81 | scaleX = scale[0]; 82 | scaleY = scale[1]; 83 | } 84 | } else { 85 | translateX = 0; 86 | translateY = 0; 87 | scaleX = 1; 88 | scaleY = 1; 89 | } 90 | 91 | // Suche alle -Elemente mittels XPath 92 | XPath xPath = XPathFactory.newInstance().newXPath(); 93 | String expression = "//path"; 94 | NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET); 95 | List dataList = new ArrayList<>(); 96 | for (int i = 0; i < nodeList.getLength(); i++) { 97 | Node node = nodeList.item(i); 98 | String pathData = node.getAttributes().getNamedItem("d").getNodeValue(); 99 | dataList.addAll(getDataFromPath(pathData)); 100 | } 101 | 102 | // Umrechnung in absolute Koordinaten 103 | List absolutList = convertToAbsolute(dataList, width, height); 104 | // Korrigiere Werte aus negativen Bereichen (falls erforderlich) 105 | return adjustForNegativeCoordinates(absolutList); 106 | } catch (Exception e) { 107 | e.printStackTrace(); 108 | } 109 | return Collections.emptyList(); 110 | } 111 | 112 | /** 113 | * Entfernt alle Buchstaben aus einem Zahlen-String und liefert diesen als double. 114 | */ 115 | private double parseDoubleClean(String value) { 116 | return Double.parseDouble(value.replaceAll("\\p{Alpha}", "")); 117 | } 118 | 119 | /** 120 | * Extrahiert aus einem Transformations-String (z. B. "translate(10,20) scale(2)") 121 | * ein Zahlenpaar für den angegebenen Schlüssel. 122 | * 123 | * @param paramString Der Transformations-String 124 | * @param paramKey Der zu suchende Schlüssel, z. B. "translate" oder "scale" 125 | * @param paramDefault Standardwert für beide Werte, falls nicht gefunden 126 | * @return Ein Array mit zwei double-Werten 127 | */ 128 | private double[] getValuePair(String paramString, String paramKey, double paramDefault) { 129 | double[] result = new double[] { paramDefault, paramDefault }; 130 | int startIndex = paramString.indexOf(paramKey); 131 | if (startIndex > -1) { 132 | int endIndex = paramString.indexOf(")", startIndex); 133 | if (endIndex > startIndex) { 134 | String content = paramString.substring(startIndex + paramKey.length() + 1, endIndex); 135 | // Splitte anhand von Komma und/oder Leerzeichen und filtere leere Strings 136 | String[] parts = content.split("[,\\s]+"); 137 | try { 138 | result = Arrays.stream(parts).mapToDouble(Double::parseDouble).toArray(); 139 | } catch (NumberFormatException e) { 140 | e.printStackTrace(); 141 | } 142 | } 143 | } 144 | return result; 145 | } 146 | 147 | /** 148 | * Wandelt die gesammelten Pfaddaten aus relativen SVG-Koordinaten in absolute Koordinaten um. 149 | */ 150 | private List convertToAbsolute(List dataList, double svgWidth, double svgHeight) { 151 | List absolutList = new ArrayList<>(); 152 | double beginX = 0, beginY = 0, lastMoveX = 0, lastMoveY = 0; 153 | boolean endWithZ; 154 | BezierCurve bezierCurve = new BezierCurve(20); 155 | 156 | for (String rowData : dataList) { 157 | rowData = rowData.trim(); 158 | int length = rowData.length(); 159 | endWithZ = false; 160 | if (rowData.endsWith("z") || rowData.endsWith("Z")) { 161 | endWithZ = true; 162 | length--; // Ignoriere das letzte Zeichen 163 | } 164 | String command = rowData.substring(0, 1); 165 | String newLine = command.toUpperCase(); 166 | // Für manche Befehle wird die Abfolge zu "L" geändert 167 | if (command.matches("[cCvVHh]")) { 168 | newLine = "L"; 169 | } 170 | rowData = rowData.substring(1, length).replaceAll(",", " "); 171 | double[] values = Arrays.stream(rowData.split("\\s+")) 172 | .mapToDouble(Double::parseDouble) 173 | .toArray(); 174 | double x = beginX, y = beginY; 175 | for (int i = 0; i < values.length; i += 2) { 176 | switch (command) { 177 | case "M": 178 | x = values[i]; 179 | y = values[i + 1]; 180 | beginX = x; 181 | beginY = y; 182 | lastMoveX = x; 183 | lastMoveY = y; 184 | newLine += " " + convertX(svgWidth, x, translateX, scaleX) 185 | + " " + convertY(svgHeight, y, translateY, scaleY); 186 | newLine = newLine.trim(); 187 | absolutList.add(newLine); 188 | command = "L"; // Folgebefehle als "L" 189 | newLine = ""; 190 | break; 191 | case "m": 192 | x = beginX + values[i]; 193 | y = beginY + values[i + 1]; 194 | beginX = x; 195 | beginY = y; 196 | lastMoveX = x; 197 | lastMoveY = y; 198 | newLine += " " + convertX(svgWidth, x, translateX, scaleX) 199 | + " " + convertY(svgHeight, y, translateY, scaleY); 200 | newLine = newLine.trim(); 201 | absolutList.add(newLine); 202 | command = "l"; // Folgebefehle als relativ 203 | newLine = ""; 204 | break; 205 | case "L": 206 | case "l": 207 | // Bei L oder l werden direkte Koordinaten übernommen; bei "l" werden diese relativ addiert. 208 | if ("L".equals(command)) { 209 | x = values[i]; 210 | y = values[i + 1]; 211 | } else { // "l" 212 | x = beginX + values[i]; 213 | y = beginY + values[i + 1]; 214 | } 215 | beginX = x; 216 | beginY = y; 217 | if (newLine.isEmpty()) { 218 | newLine = "L"; 219 | } 220 | newLine += " " + convertX(svgWidth, x, translateX, scaleX) 221 | + " " + convertY(svgHeight, y, translateY, scaleY); 222 | break; 223 | case "V": 224 | case "v": 225 | // Vertikale Linien: nur y wird gesetzt; x bleibt gleich. 226 | if ("V".equals(command)) { 227 | y = values[i]; 228 | } else { 229 | y = beginY + values[i]; 230 | } 231 | beginY = y; 232 | if (newLine.isEmpty()) { 233 | newLine = "L"; 234 | } 235 | newLine += " " + convertX(svgWidth, beginX, translateX, scaleX) 236 | + " " + convertY(svgHeight, y, translateY, scaleY); 237 | break; 238 | case "H": 239 | case "h": 240 | // Horizontale Linien: nur x wird gesetzt; y bleibt konstant. 241 | if ("H".equals(command)) { 242 | x = values[i]; 243 | } else { 244 | x = beginX + values[i]; 245 | } 246 | beginX = x; 247 | if (newLine.isEmpty()) { 248 | newLine = "L"; 249 | } 250 | newLine += " " + convertX(svgWidth, x, translateX, scaleX) 251 | + " " + convertY(svgHeight, beginY, translateY, scaleY); 252 | break; 253 | case "C": 254 | // Kubische Bézierkurve; nimm 6 Werte (drei Punkte) 255 | double x1 = values[i]; 256 | double y1 = values[i + 1]; 257 | double x2 = values[i + 2]; 258 | double y2 = values[i + 3]; 259 | x = values[i + 4]; 260 | y = values[i + 5]; 261 | i += 4; // Überspringe zusätzliche Werte 262 | double[] bezPoints = bezierCurve.bezier2D(new double[]{beginX, beginY, x1, y1, x2, y2, x, y}); 263 | // Beginne ab dem zweiten Punkt (Index 2) 264 | for (int j = 2; j < bezPoints.length; j += 2) { 265 | newLine += " " + convertX(svgWidth, bezPoints[j], translateX, scaleX) 266 | + " " + convertY(svgHeight, bezPoints[j + 1], translateY, scaleY); 267 | } 268 | beginX = x; 269 | beginY = y; 270 | break; 271 | case "c": 272 | // Relative kubische Bézierkurve 273 | double rx1 = beginX + values[i]; 274 | double ry1 = beginY + values[i + 1]; 275 | double rx2 = beginX + values[i + 2]; 276 | double ry2 = beginY + values[i + 3]; 277 | x = beginX + values[i + 4]; 278 | y = beginY + values[i + 5]; 279 | i += 4; 280 | double[] bezRelPoints = bezierCurve.bezier2D(new double[]{beginX, beginY, rx1, ry1, rx2, ry2, x, y}); 281 | for (int j = 2; j < bezRelPoints.length; j += 2) { 282 | newLine += " " + convertX(svgWidth, bezRelPoints[j], translateX, scaleX) 283 | + " " + convertY(svgHeight, bezRelPoints[j + 1], translateY, scaleY); 284 | } 285 | beginX = x; 286 | beginY = y; 287 | break; 288 | default: 289 | // Unbekannte Befehle werden ignoriert 290 | break; 291 | } 292 | } 293 | newLine = newLine.trim(); 294 | if (!newLine.isEmpty()) { 295 | absolutList.add(newLine); 296 | } 297 | if (endWithZ) { 298 | absolutList.add("L" + convertX(svgWidth, lastMoveX, translateX, scaleX) + " " + 299 | convertY(svgHeight, lastMoveY, translateY, scaleY)); 300 | beginX = lastMoveX; 301 | beginY = lastMoveY; 302 | } 303 | } 304 | 305 | return absolutList; 306 | } 307 | 308 | /** 309 | * Passt die absoluten Pfaddaten an, falls negative Werte vorhanden sind. 310 | * Es werden Korrekturwerte (xCor, yCor) berechnet und auf alle Koordinaten addiert. 311 | */ 312 | private List adjustForNegativeCoordinates(List absolutList) { 313 | // Setze Breiten/Hohen basierend auf bisherigen Min-/Max-Werten 314 | double xCor = 0, yCor = 0; 315 | if (minX < 0) { 316 | xCor = Math.abs(minX) + 1; 317 | } 318 | if (minY < 0) { 319 | yCor = Math.abs(minY) + 1; 320 | } 321 | 322 | List result = new ArrayList<>(); 323 | for (String row : absolutList) { 324 | // Der erste Buchstabe ist der Befehlsbuchstabe 325 | String command = row.substring(0, 1); 326 | // Parse die restlichen Werte 327 | double[] values = Arrays.stream(row.substring(1).trim().split("\\s+")) 328 | .mapToDouble(Double::parseDouble) 329 | .toArray(); 330 | String newLine = command; 331 | for (int i = 0; i < values.length; i += 2) { 332 | newLine += " " + (values[i] + xCor) + " " + (values[i + 1] + yCor); 333 | } 334 | result.add(newLine.trim()); 335 | } 336 | return result; 337 | } 338 | 339 | /** 340 | * Extrahiert Pfaddaten aus dem "d"-Attribut eines SVG--Elements. 341 | * 342 | * @param pathData Der Inhalt des d-Attributs 343 | * @return Liste von Datenzeilen, die den Befehlen entsprechen. 344 | */ 345 | private List getDataFromPath(String pathData) { 346 | List result = new ArrayList<>(); 347 | // Statt StringTokenizer wird split genutzt, um Tokens anhand von Leerzeichen zu erhalten. 348 | String[] tokens = pathData.split("\\s+"); 349 | String dataRow = ""; 350 | boolean commandFlag = false; 351 | for (String token : tokens) { 352 | if (token.matches("[MmLlCcVvHh].*")) { 353 | if (!dataRow.isEmpty()) { 354 | result.add(dataRow); 355 | } 356 | dataRow = token; 357 | // Wenn das Token exakt einen Buchstaben enthält, gilt es als reiner Befehl 358 | commandFlag = token.matches("[MmLlCcVvHh]"); 359 | } else if (token.matches(".*[zZ]")) { 360 | if (token.matches("[zZ]")) { 361 | dataRow += token; 362 | } else { 363 | dataRow += " " + token.replace(',', ' '); 364 | } 365 | result.add(dataRow); 366 | dataRow = ""; 367 | commandFlag = false; 368 | } else if (token.matches("[\\-0-9].*")) { 369 | String prefix = commandFlag ? "" : " "; 370 | dataRow += prefix + token.replace(',', ' '); 371 | commandFlag = false; 372 | } 373 | } 374 | if (!dataRow.isEmpty()) { 375 | result.add(dataRow); 376 | } 377 | return result; 378 | } 379 | 380 | private void setMinMaxX(double value) { 381 | minX = Math.min(minX, value); 382 | maxX = Math.max(maxX, value); 383 | } 384 | 385 | private void setMinMaxY(double value) { 386 | minY = Math.min(minY, value); 387 | maxY = Math.max(maxY, value); 388 | } 389 | 390 | private double convertX(double maxValue, double value, double translate, double scale) { 391 | double result; 392 | if (scale > 0) { 393 | result = (value + translate) * scale; 394 | } else { 395 | result = maxValue - (value + translate) * -scale; 396 | } 397 | setMinMaxX(result); 398 | return result; 399 | } 400 | 401 | private double convertY(double maxValue, double value, double translate, double scale) { 402 | double result; 403 | if (scale > 0) { 404 | result = (value + translate) * scale; 405 | } else { 406 | result = maxValue - (value + translate) * -scale; 407 | } 408 | setMinMaxY(result); 409 | return result; 410 | } 411 | 412 | // Zugriffsmethoden für die ermittelten SVG-Dimensionen und Transformationen 413 | public double getWidth() { 414 | return width; 415 | } 416 | public double getHeight() { 417 | return height; 418 | } 419 | public double getTranslateX() { 420 | return translateX; 421 | } 422 | public double getTranslateY() { 423 | return translateY; 424 | } 425 | public double getScaleX() { 426 | return scaleX; 427 | } 428 | public double getScaleY() { 429 | return scaleY; 430 | } 431 | public double getMaxX() { 432 | return maxX; 433 | } 434 | public double getMaxY() { 435 | return maxY; 436 | } 437 | } 438 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/converter/Section.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.converter; 2 | 3 | import java.util.Arrays; 4 | 5 | public class Section{ 6 | 7 | private double x; 8 | private double y; 9 | 10 | private String lineData; 11 | 12 | public Section(double paramX, double paramY) { 13 | x= paramX; 14 | y= paramY; 15 | lineData = ""; //$NON-NLS-1$ 16 | } 17 | 18 | public double getX() { 19 | return x; 20 | } 21 | 22 | public void setX(double x) { 23 | this.x = x; 24 | } 25 | 26 | public double getY() { 27 | return y; 28 | } 29 | 30 | public void setY(double y) { 31 | this.y = y; 32 | } 33 | 34 | public String getLineData() { 35 | return lineData.trim(); 36 | } 37 | 38 | public void addLineData(String lineData) { 39 | this.lineData+=" "+lineData.trim(); //$NON-NLS-1$ 40 | } 41 | 42 | public Pair getStartPoint() { 43 | return new Pair(x, y); 44 | 45 | } 46 | public Pair getLastPoint() { 47 | if(lineData.isEmpty()) { 48 | return new Pair(x, y); 49 | } 50 | double[] data = Arrays.asList(lineData.trim().split(" ")).stream().mapToDouble(Double::parseDouble).toArray(); //$NON-NLS-1$ 51 | return new Pair(data[data.length-2], data[data.length-1]); 52 | 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/converter/VDPConverter.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.converter; 2 | 3 | import java.io.BufferedWriter; 4 | import java.nio.file.Files; 5 | import java.nio.file.Path; 6 | import java.nio.file.StandardOpenOption; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | public class VDPConverter { 11 | 12 | private double maxWidth; 13 | private double maxHeight; 14 | private Path fileWithData; 15 | public Path getFileWithData() { 16 | return fileWithData; 17 | } 18 | 19 | private long size; 20 | 21 | public long getSize() { 22 | return size; 23 | } 24 | 25 | private VDPConverter() { 26 | } 27 | 28 | public static VDPConverter buildFromSections(List
paramSectionList) throws Exception{ 29 | VDPConverter converter = new VDPConverter(); 30 | converter.fileWithData = Files.createTempFile("VDPData", ""); 31 | converter.createListForVDP(paramSectionList); 32 | return converter; 33 | } 34 | 35 | 36 | public static VDPConverter buildFromStrings(List paramLineList) throws Exception{ 37 | VDPConverter converter = new VDPConverter(); 38 | converter.fileWithData = Files.createTempFile("VDPData", ""); 39 | try(BufferedWriter writer = Files.newBufferedWriter(converter.fileWithData,StandardOpenOption.CREATE)){ 40 | for (String s : paramLineList) { 41 | converter.maxWidth = Math.max(converter.maxWidth, Double.parseDouble(s.split(",")[1])); 42 | converter.maxHeight = Math.max(converter.maxHeight, Double.parseDouble(s.split(",")[2])); 43 | 44 | writer.write(s); 45 | writer.newLine(); 46 | converter.size++; 47 | } 48 | } 49 | return converter; 50 | 51 | } 52 | 53 | private void createListForVDP(List
paramSectionList) throws Exception{ 54 | try(BufferedWriter writer = Files.newBufferedWriter(fileWithData,StandardOpenOption.CREATE)){ 55 | for (Section s : paramSectionList) { 56 | createStringForVDP(writer,s); 57 | } 58 | } 59 | } 60 | /** 61 | * Passt die section an 62 | * @param paramSection 63 | * @return return string mit text der section 64 | */ 65 | private void createStringForVDP(BufferedWriter writer, Section paramSection) throws Exception{ 66 | maxWidth = Math.max(maxWidth, paramSection.getX()); 67 | maxHeight = Math.max(maxHeight, paramSection.getY()); 68 | writer.write("0," + paramSection.getX() + "," + paramSection.getY()); 69 | writer.newLine(); 70 | size++; 71 | if (!paramSection.getLineData().isEmpty()) { 72 | double[] data = Arrays.asList(paramSection.getLineData().split(" ")).stream().mapToDouble(Double::parseDouble).toArray(); //$NON-NLS-1$ 73 | for (int i = 0; i < data.length; i = i + 2) { 74 | maxWidth = Math.max(maxWidth, data[i]); 75 | maxHeight = Math.max(maxHeight, data[i+1]); 76 | writer.write("1," + data[i] + "," + data[i + 1]); //$NON-NLS-1$ //$NON-NLS-2$ 77 | writer.newLine(); 78 | size++; 79 | } 80 | } 81 | } 82 | 83 | 84 | public double getMaxWidth() { 85 | return maxWidth; 86 | } 87 | 88 | public double getMaxHeight() { 89 | return maxHeight; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/imagefilter/EdgeDetectionFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package de.revout.pi.vplotter.imagefilter; 5 | 6 | import java.awt.Color; 7 | import java.awt.image.BufferedImage; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | import de.revout.pi.vplotter.lang.Dictionary; 12 | import de.revout.pi.vplotter.setting.Setting; 13 | import de.revout.pi.vplotter.setting.SliderSetting; 14 | 15 | /** 16 | * @author User 17 | * 18 | */ 19 | public class EdgeDetectionFilter implements Filter { 20 | 21 | private SliderSetting sliderSetting; 22 | private List settingsList; 23 | 24 | 25 | public EdgeDetectionFilter() { 26 | sliderSetting = new SliderSetting(Dictionary.getCurrent().getString("EdgeDetectionFilter.SettingsName"), "50", 0, 255, 1); //$NON-NLS-1$ //$NON-NLS-2$ 27 | settingsList = new ArrayList<>(); 28 | settingsList.add(sliderSetting); 29 | } 30 | 31 | /* (non-Javadoc) 32 | * @see de.revout.imageFilter.Filter#filter(java.awt.image.BufferedImage) 33 | */ 34 | @Override 35 | public BufferedImage filter(BufferedImage paramImage) { 36 | BufferedImage image=null; 37 | 38 | try { 39 | 40 | int[][] filter1= { 41 | {-1,0,1}, 42 | {-2,0,2}, 43 | {-1,0,1} 44 | }; 45 | int[][] filter2= { 46 | {1,2,1}, 47 | {0,0,0}, 48 | {-1,-2,-1} 49 | }; 50 | 51 | 52 | image = new BufferedImage(paramImage.getWidth(),paramImage.getHeight(), paramImage.getType()); 53 | 54 | double[][] lum = luminanz(paramImage); 55 | 56 | int width = paramImage.getWidth(); 57 | int height = paramImage.getHeight(); 58 | 59 | for(int x=1;x getSettings() { 87 | return settingsList; 88 | } 89 | 90 | /* (non-Javadoc) 91 | * @see de.revout.imageFilter.Filter#getName() 92 | */ 93 | @Override 94 | public String getName() { 95 | return this.getClass().getSimpleName().toUpperCase(); 96 | } 97 | 98 | /* (non-Javadoc) 99 | * @see de.revout.imageFilter.Filter#createNewFilter() 100 | */ 101 | @Override 102 | public Filter createNewFilter() { 103 | return new EdgeDetectionFilter(); 104 | } 105 | 106 | private int cut(int paramValue) { 107 | if(paramValue>Integer.parseInt(sliderSetting.getValue())) { 108 | return 0; 109 | }else if(paramValue getSettings(); 12 | public String getName(); 13 | public Filter createNewFilter(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/imagefilter/GrayscaleFilter.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.imagefilter; 2 | 3 | import java.awt.Color; 4 | import java.awt.image.BufferedImage; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import de.revout.pi.vplotter.lang.Dictionary; 9 | import de.revout.pi.vplotter.setting.ComboSetting; 10 | import de.revout.pi.vplotter.setting.Setting; 11 | import de.revout.pi.vplotter.setting.SliderSetting; 12 | 13 | public class GrayscaleFilter implements Filter { 14 | private ComboSetting comboSetting; 15 | private SliderSetting sliderSetting; 16 | private List list; 17 | private static final String NORMAL = "Normal"; //$NON-NLS-1$ 18 | private static final String GREY_IS_R = "Grey is R"; //$NON-NLS-1$ 19 | private static final String GREY_IS_G = "Grey is G"; //$NON-NLS-1$ 20 | private static final String GREY_IS_B = "Grey is B"; //$NON-NLS-1$ 21 | private static final String GREY_IS_R_G_B_3 = "Grey is (R+G+B)/3"; //$NON-NLS-1$ 22 | 23 | public GrayscaleFilter() { 24 | 25 | comboSetting = new ComboSetting(Dictionary.getCurrent().getString("GrayscaleFilter.SettingsName"), NORMAL); //$NON-NLS-1$ 26 | comboSetting.getValueList().add(NORMAL); 27 | comboSetting.getValueList().add(GREY_IS_R); 28 | comboSetting.getValueList().add(GREY_IS_G); 29 | comboSetting.getValueList().add(GREY_IS_B); 30 | comboSetting.getValueList().add(GREY_IS_R_G_B_3); 31 | list = new ArrayList<>(); 32 | list.add(comboSetting); 33 | 34 | sliderSetting = new SliderSetting(Dictionary.getCurrent().getString("GrayscaleFilter.Cut"), "0", 0, 255, 1); //$NON-NLS-1$ //$NON-NLS-2$ 35 | list.add(sliderSetting); 36 | } 37 | 38 | @Override 39 | public BufferedImage filter(BufferedImage paramImage) { 40 | BufferedImage newImage = null; 41 | switch (comboSetting.getValue()) { 42 | case (NORMAL): 43 | newImage = new BufferedImage(paramImage.getWidth(), paramImage.getHeight(), BufferedImage.TYPE_INT_RGB); 44 | for (int x = 0; x < paramImage.getWidth(); x++) { 45 | for (int y = 0; y < paramImage.getHeight(); y++) { 46 | int rgb = paramImage.getRGB(x, y); 47 | int alpha = (rgb >> 24) & 0xff; 48 | int red = (rgb >> 16) & 0xff; 49 | int green = (rgb >> 8) & 0xff; 50 | int blue = rgb & 0xff; 51 | int avg = (int) ((0.21*red) + (0.72*green) + (0.07*blue)); 52 | int grey = (alpha << 24) | (avg << 16) | (avg << 8) | avg; 53 | newImage.setRGB(x, y, grey); 54 | } 55 | } 56 | break; 57 | case (GREY_IS_R): 58 | newImage = generateGreyWith1BaseColor(paramImage, GREY_IS_R); 59 | break; 60 | case (GREY_IS_G): 61 | newImage = generateGreyWith1BaseColor(paramImage, GREY_IS_G); 62 | break; 63 | case (GREY_IS_B): 64 | newImage = generateGreyWith1BaseColor(paramImage, GREY_IS_B); 65 | break; 66 | case (GREY_IS_R_G_B_3): 67 | newImage = new BufferedImage(paramImage.getWidth(), paramImage.getHeight(), BufferedImage.TYPE_INT_RGB); 68 | for (int x = 0; x < paramImage.getWidth(); x++) { 69 | for (int y = 0; y < paramImage.getHeight(); y++) { 70 | int rgb = paramImage.getRGB(x, y); 71 | int alpha = (rgb >> 24) & 0xff; 72 | int red = (rgb >> 16) & 0xff; 73 | int green = (rgb >> 8) & 0xff; 74 | int blue = rgb & 0xff; 75 | int avg = (red + green + blue) / 3; 76 | int grey = (alpha << 24) | (avg << 16) | (avg << 8) | avg; 77 | newImage.setRGB(x, y, grey); 78 | } 79 | } 80 | break; 81 | 82 | } 83 | return newImage; 84 | } 85 | 86 | private BufferedImage generateGreyWith1BaseColor(BufferedImage paramImage, String paramColor) { 87 | BufferedImage newImage; 88 | newImage = new BufferedImage(paramImage.getWidth(), paramImage.getHeight(), BufferedImage.TYPE_INT_RGB); 89 | for (int x = 0; x < paramImage.getWidth(); x++) { 90 | for (int y = 0; y < paramImage.getHeight(); y++) { 91 | int rgb = paramImage.getRGB(x, y); 92 | int red = (rgb >> 16) & 0xff; 93 | int green = (rgb >> 8) & 0xff; 94 | int blue = rgb & 0xff; 95 | int color = 0; 96 | switch (paramColor) { 97 | case (GREY_IS_R): 98 | color = red; 99 | break; 100 | case (GREY_IS_G): 101 | color = green; 102 | break; 103 | case (GREY_IS_B): 104 | color = blue; 105 | break; 106 | } 107 | 108 | if(color getSettings() { 120 | return list; 121 | } 122 | 123 | @Override 124 | public String getName() { 125 | return Dictionary.getCurrent().getString("GrayscaleFilter.FilterName"); //$NON-NLS-1$ 126 | } 127 | 128 | @Override 129 | public Filter createNewFilter() { 130 | return new GrayscaleFilter(); 131 | } 132 | 133 | @Override 134 | public Setting getSetting(Setting paramSetting) { 135 | for (Setting setting : list) { 136 | if (paramSetting==setting) { 137 | return setting; 138 | } 139 | } 140 | return null; 141 | } 142 | 143 | 144 | 145 | 146 | 147 | } 148 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/imagefilter/ImageConverter.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.imagefilter; 2 | 3 | import java.awt.image.BufferedImage; 4 | import java.util.ArrayList; 5 | 6 | public class ImageConverter{ 7 | 8 | private ArrayList filterList; 9 | 10 | public ImageConverter() { 11 | filterList = new ArrayList<>(); 12 | } 13 | 14 | public BufferedImage filter(BufferedImage paramImage) { 15 | BufferedImage image = paramImage; 16 | for(Filter filter:filterList) { 17 | image = filter.filter(image); 18 | } 19 | filterList.clear(); 20 | return image; 21 | } 22 | 23 | public void addFilter(Filter paramFilter) { 24 | filterList.add(paramFilter); 25 | } 26 | 27 | public void removeFilter(int paramIndex) { 28 | filterList.remove(paramIndex); 29 | } 30 | 31 | public void clear() { 32 | filterList.clear(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/imagefilter/RotateFilter.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.imagefilter; 2 | 3 | import java.awt.image.BufferedImage; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import de.revout.pi.vplotter.lang.Dictionary; 8 | import de.revout.pi.vplotter.setting.ComboSetting; 9 | import de.revout.pi.vplotter.setting.Setting; 10 | 11 | public class RotateFilter implements Filter { 12 | 13 | private ComboSetting comboSetting; 14 | private List list; 15 | private static final String NEUNZIG = "90"; //$NON-NLS-1$ 16 | private static final String HUNDERT80 = "180"; //$NON-NLS-1$ 17 | private static final String ZWEIHUNDER70 = "270"; //$NON-NLS-1$ 18 | 19 | 20 | public RotateFilter() { 21 | comboSetting = new ComboSetting(Dictionary.getCurrent().getString("RotateFilter.SettingsName"), NEUNZIG); //$NON-NLS-1$ 22 | comboSetting.getValueList().add(NEUNZIG); 23 | comboSetting.getValueList().add(HUNDERT80); 24 | comboSetting.getValueList().add(ZWEIHUNDER70); 25 | list = new ArrayList<>(); 26 | list.add(comboSetting); 27 | } 28 | 29 | @Override 30 | public BufferedImage filter(BufferedImage paramImage) { 31 | BufferedImage filterimage = paramImage; 32 | BufferedImage newImage = null; 33 | int counter = 0; 34 | switch (comboSetting.getValue()) { 35 | case (NEUNZIG): 36 | counter = 1; 37 | break; 38 | case (HUNDERT80): 39 | counter = 2; 40 | break; 41 | case (ZWEIHUNDER70): 42 | counter = 3; 43 | break; 44 | } 45 | for (int i = 0; counter > i;i++) { 46 | newImage = new BufferedImage(filterimage.getHeight(), filterimage.getWidth(), paramImage.getType()); 47 | for (int x = 0; x < filterimage.getWidth(); x++) { 48 | for (int y = 0; y < filterimage.getHeight(); y++) { 49 | newImage.setRGB(y, (filterimage.getWidth() - 1) - x, filterimage.getRGB(x, y)); 50 | } 51 | } 52 | filterimage = newImage; 53 | } 54 | return newImage; 55 | } 56 | @Override 57 | public List getSettings() { 58 | return list; 59 | } 60 | 61 | @Override 62 | public String getName() { 63 | return Dictionary.getCurrent().getString("RotateFilter.FilterName"); //$NON-NLS-1$ 64 | } 65 | 66 | @Override 67 | public Filter createNewFilter() { 68 | return new RotateFilter(); 69 | } 70 | 71 | @Override 72 | public Setting getSetting(Setting paramSetting) { 73 | for (Setting setting : list) { 74 | if (paramSetting==setting) { 75 | return setting; 76 | } 77 | } 78 | return null; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/lang/Dictionary.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.lang; 2 | 3 | import java.util.Locale; 4 | import java.util.MissingResourceException; 5 | import java.util.ResourceBundle; 6 | 7 | public class Dictionary { 8 | 9 | private ResourceBundle RESOURCE_BUNDLE; 10 | 11 | 12 | private static Dictionary current; 13 | 14 | private Dictionary() { 15 | 16 | try { 17 | RESOURCE_BUNDLE = ResourceBundle.getBundle("de/revout/pi/vplotter/resources/lang/messages", Locale.getDefault()); //$NON-NLS-1$ 18 | 19 | System.out.println(""); 20 | 21 | } catch (Exception e1) { 22 | new RuntimeException(e1.getMessage()); 23 | } 24 | 25 | } 26 | 27 | public static Dictionary getCurrent() { 28 | 29 | if(current==null) { 30 | current = new Dictionary(); 31 | } 32 | 33 | return current; 34 | } 35 | 36 | public String getString(String key) { 37 | try { 38 | return RESOURCE_BUNDLE.getString(key); 39 | } catch (MissingResourceException e) { 40 | return '!' + key + '!'; 41 | } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/main/Driver.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.main; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.math.BigDecimal; 8 | import java.math.RoundingMode; 9 | import java.nio.file.Files; 10 | import java.nio.file.Path; 11 | import java.nio.file.Paths; 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | import java.util.Properties; 15 | 16 | import com.pi4j.Pi4J; 17 | import com.pi4j.context.Context; 18 | import com.pi4j.io.gpio.digital.DigitalOutput; 19 | import com.pi4j.io.gpio.digital.DigitalState; 20 | 21 | import de.revout.pi.vplotter.converter.Pair; 22 | import de.revout.pi.vplotter.converter.VDPConverter; 23 | import de.revout.pi.vplotter.saves.SettingsManager; 24 | import de.revout.pi.vplotter.saves.VPlotterPropertiesManager; 25 | import de.revout.pi.vplotter.saves.VPlotterPropertiesManager.KEY; 26 | 27 | public class Driver { 28 | 29 | // GPIO-Pin-Konfiguration 30 | private int ENALeft; 31 | private int ENARight; 32 | private int DIRLeft; 33 | private int DIRRight; 34 | private int PULLeft; 35 | private int PULLRight; 36 | private float penaway; 37 | private float pendraw; 38 | 39 | private float servoCurrentPosition=Integer.MIN_VALUE; 40 | 41 | private final static int RANGE = 20; 42 | 43 | // Plotter-Parameter 44 | private double minX; 45 | private double minY; 46 | private double maxX; 47 | private double maxY; 48 | private double paperHeight; 49 | private double paperWidth; 50 | // Offsets zur Zentrierung 51 | private double offsetX; 52 | private double offsetY; 53 | private double[] plotterSide = new double[2]; 54 | private int lastDraw; 55 | private double lengthBetween; 56 | private double step; 57 | private double stepsPerMM; 58 | private double scale; 59 | private Pair startPoint; 60 | private Pair currentPoint; 61 | 62 | private long stepPauseDraw; 63 | private long stepPauseSlack; 64 | private long currentPause; 65 | 66 | private Pair motorLinks; 67 | private Pair motorRechts; 68 | 69 | private boolean gpio = false; 70 | private static Driver current; 71 | 72 | private boolean simulation = false; 73 | private boolean pause; 74 | private boolean stop; 75 | private boolean used = false; 76 | 77 | private ArrayList observerList; 78 | private boolean init; 79 | 80 | // Globaler Pi4J-Kontext – wird beim Start der Anwendung initialisiert 81 | private Context pi4j; 82 | 83 | private ServoMotor servoMotor; 84 | 85 | // Digitale Ausgänge 86 | private DigitalOutput enaLeftOutput; 87 | private DigitalOutput enaRightOutput; 88 | private DigitalOutput dirLeft; 89 | private DigitalOutput dirRight; 90 | private DigitalOutput pulLeft; 91 | private DigitalOutput pulRight; 92 | 93 | long index=0; 94 | 95 | public static Driver getCurrent() { 96 | if (current == null) { 97 | current = new Driver(); 98 | } 99 | return current; 100 | } 101 | 102 | private Driver() { 103 | setGpioSetting(); 104 | init = false; 105 | pause = false; 106 | stop = false; 107 | // Letzter Status des Stiftes (2 als Initialwert) 108 | lastDraw = 2; 109 | scale = 0; 110 | observerList = new ArrayList<>(); 111 | } 112 | 113 | private void setGpioSetting() { 114 | Path path = Paths.get("conf/gpio.properties"); 115 | if (Files.exists(path)) { 116 | try (InputStream inputStream = Files.newInputStream(path)) { 117 | Properties properties = new Properties(); 118 | properties.loadFromXML(inputStream); 119 | ENALeft = Integer.parseInt(properties.getProperty("ENALEFT")); 120 | ENARight = Integer.parseInt(properties.getProperty("ENARIGHT")); 121 | DIRLeft = Integer.parseInt(properties.getProperty("DIRLEFT")); 122 | DIRRight = Integer.parseInt(properties.getProperty("DIRRIGHT")); 123 | PULLeft = Integer.parseInt(properties.getProperty("PULLEFT")); 124 | PULLRight = Integer.parseInt(properties.getProperty("PULLRIGHT")); 125 | penaway = Integer.parseInt(properties.getProperty("PENAWAY")); 126 | pendraw = Integer.parseInt(properties.getProperty("PENDRAW")); 127 | } catch (Exception e) { 128 | throw new RuntimeException(path.toString() + " Error:" + e.getMessage()); 129 | } 130 | if (pi4j == null) { 131 | pi4j = Pi4J.newAutoContext(); 132 | } 133 | } else { 134 | throw new RuntimeException(path.toString() + " not found!"); 135 | } 136 | } 137 | 138 | /** 139 | * Führt einen Testlauf durch, indem Testdaten erzeugt und geplottet werden. 140 | */ 141 | public void test() throws Exception{ 142 | List testData = new ArrayList<>(); 143 | loadProperty(); 144 | testData.add("0,0,0"); 145 | testData.add("1,0," + plotterSide[1]); 146 | testData.add("1," + plotterSide[0] + "," + plotterSide[1]); 147 | testData.add("1," + plotterSide[0] + ",0"); 148 | testData.add("1,0,0"); 149 | testData.add("1," + plotterSide[0] + "," + plotterSide[1]); 150 | testData.add("0," + plotterSide[0] + ",0"); 151 | testData.add("1,0," + plotterSide[1]); 152 | plotte(VDPConverter.buildFromStrings(testData)); 153 | } 154 | 155 | /** 156 | * Startet einen neuen Plot-Prozess, der eine Liste von Zeichenbefehlen (als CSV-Strings) abarbeitet. 157 | * 158 | * @param commands Liste der Befehle im Format "drawState,x,y" 159 | * @param width Breite des Plotterbereichs 160 | * @param height Höhe des Plotterbereichs 161 | */ 162 | public void plotte(VDPConverter paramVdpConverter) { 163 | if (!gpioInit() && !simulation) { 164 | return; 165 | } 166 | observerList.forEach(DriverMoveObserverIf::init); 167 | motorsOn(); 168 | stop = false; 169 | pause = false; 170 | index=0; 171 | 172 | new Thread(() -> { 173 | try { 174 | scale = calculateScale(paramVdpConverter.getMaxWidth(), paramVdpConverter.getMaxHeight()); 175 | ArrayList pathPoints = new ArrayList(); 176 | try(BufferedReader reader=Files.newBufferedReader(paramVdpConverter.getFileWithData())){ 177 | String line=null; 178 | while((line = reader.readLine())!=null) { 179 | index++; 180 | // Bei Pause schrittweise warten 181 | while (pause) { 182 | if (stop) return; 183 | Thread.sleep(1000); 184 | } 185 | String[] parts = line.split(","); 186 | int drawState = Integer.parseInt(parts[0]); 187 | if (lastDraw != drawState) { 188 | draw(drawState); 189 | } 190 | // Umrechnung der Koordinaten unter Berücksichtigung der Skalierung und des Versatzes 191 | Pair toPoint = new Pair((Double.parseDouble(parts[1]) / scale) + minX, 192 | (Double.parseDouble(parts[2]) / scale) + minY); 193 | getPathPoints(pathPoints, currentPoint, toPoint); 194 | for (Pair point : pathPoints) { 195 | if (isInRange(point)) { 196 | Pair diff = getDifferences(currentPoint, point); 197 | Pair driveDelta = move(diff); 198 | calculateRealCurrentPosition(driveDelta); 199 | } 200 | } 201 | observerList.forEach(observer -> 202 | observer.currentMove(drawState, currentPoint, paramVdpConverter.getSize(), index) 203 | ); 204 | }} 205 | } catch (Exception e) { 206 | e.printStackTrace(); 207 | } finally { 208 | try { 209 | Files.deleteIfExists(paramVdpConverter.getFileWithData()); 210 | } catch (IOException e) { 211 | e.printStackTrace(); 212 | } 213 | finish(); 214 | } 215 | }).start(); 216 | } 217 | 218 | private boolean gpioInit() { 219 | if (!init) { 220 | init = gpioStart(); 221 | } 222 | return init; 223 | } 224 | 225 | /** 226 | * Berechnet anhand der Verschiebungsdifferenz die neue aktuelle Position. 227 | */ 228 | private void calculateRealCurrentPosition(Pair driveDelta) { 229 | double leftBefore = getDistance(motorLinks, currentPoint); 230 | double rightBefore = getDistance(motorRechts, currentPoint); 231 | double leftAfter = leftBefore + driveDelta.getX(); 232 | double rightAfter = rightBefore + driveDelta.getY(); 233 | double cosAlpha = (Math.pow(lengthBetween, 2) + Math.pow(leftAfter, 2) - Math.pow(rightAfter, 2)) 234 | / (2 * lengthBetween * leftAfter); 235 | double newX = cosAlpha * leftAfter; 236 | double newY = Math.sqrt(Math.max(0, Math.pow(leftAfter, 2) - Math.pow(newX, 2))); 237 | currentPoint.setX(newX); 238 | currentPoint.setY(newY); 239 | } 240 | 241 | /** 242 | * Bewegt den Plotter zum angegebenen Zielpunkt. 243 | */ 244 | public void goTo(Pair targetPosition) { 245 | if (isReady()) { 246 | draw(0); 247 | Pair diff = getDifferences(currentPoint, targetPosition); 248 | Pair driveDelta = move(diff); 249 | calculateRealCurrentPosition(driveDelta); 250 | } 251 | } 252 | 253 | /** 254 | * Nach Abschluss des Plottens wird der Stift zur Ausgangsposition gefahren 255 | * und alle registrierten Beobachter werden informiert. 256 | */ 257 | private void finish() { 258 | used = true; 259 | goTo(startPoint); 260 | observerList.forEach(DriverMoveObserverIf::finish); 261 | } 262 | 263 | // --- GPIO/Servosteuerung --- 264 | 265 | private boolean gpioStart() { 266 | if (!simulation) { 267 | try { 268 | enaLeftOutput = createDigitalOutput(pi4j, ENALeft); 269 | enaRightOutput = createDigitalOutput(pi4j, ENARight); 270 | dirLeft = createDigitalOutput(pi4j, DIRLeft); 271 | dirRight = createDigitalOutput(pi4j, DIRRight); 272 | pulLeft = createDigitalOutput(pi4j, PULLeft); 273 | pulRight = createDigitalOutput(pi4j, PULLRight); 274 | servoMotor = new ServoMotor(pi4j, 2, 50, -90.0f, 90.0f, 2.0f, 12f); 275 | gpio = true; 276 | } catch (Throwable exc) { 277 | gpio = false; 278 | simulation = true; 279 | } 280 | } 281 | return gpio; 282 | } 283 | 284 | public void motorsOff() { 285 | if (!simulation && gpioInit()) { 286 | enaLeftOutput.high(); 287 | enaRightOutput.high(); 288 | } 289 | pause = true; 290 | stop(); 291 | } 292 | 293 | public void motorsOn() { 294 | if (!simulation && gpioInit()) { 295 | enaLeftOutput.low(); 296 | enaRightOutput.low(); 297 | } 298 | } 299 | 300 | public void penAway() { 301 | if (!simulation && gpioInit()) { 302 | smoothMoveServo(penaway,0.5f,50); 303 | } 304 | } 305 | 306 | public void penDraw() { 307 | if (!simulation && gpioInit()) { 308 | smoothMoveServo(pendraw,0.5f,50); 309 | } 310 | } 311 | 312 | /** 313 | * Ändert den Winkel des Servomotors langsam von der aktuellen Position zum Zielwinkel. 314 | * 315 | * @param currentPosition Der aktuelle Winkel des Servomotors. 316 | * @param targetAngle Der Zielwinkel, den der Servo erreichen soll. 317 | * @param stepSize Die Größe der einzelnen Winkeländerungsschritte. 318 | * @param pauseMillis Die Pause in Millisekunden zwischen den einzelnen Schritten. 319 | */ 320 | private void smoothMoveServo(float targetAngle, float stepSize, long pauseMillis) { 321 | 322 | if(servoCurrentPosition==Integer.MIN_VALUE) { 323 | servoCurrentPosition = targetAngle; 324 | servoMotor.setAngle(servoCurrentPosition); 325 | return; 326 | } 327 | 328 | // Berechne die Richtung (+1 oder -1) 329 | float direction = targetAngle > servoCurrentPosition ? 1.0f : -1.0f; 330 | float newPosition = servoCurrentPosition; 331 | 332 | // Solange der aktuelle Winkel noch nicht das Ziel erreicht hat, 333 | // wird in kleinen Schritten der Winkel geändert. 334 | while ((direction > 0 && newPosition < targetAngle) || (direction < 0 && newPosition > targetAngle)) { 335 | newPosition += stepSize * direction; 336 | 337 | // Überschreiten des Zielwinkels verhindern 338 | if ((direction > 0 && newPosition > targetAngle) || (direction < 0 && newPosition < targetAngle)) { 339 | newPosition = targetAngle; 340 | } 341 | 342 | // Setzt den aktuellen Winkel am Servo – hier wird angenommen, 343 | // dass 'servoMotor' eine Instanz des ServoMotor ist und setPercent(float) den Winkel setzt. 344 | servoMotor.setAngle(newPosition); 345 | 346 | // Falls die aktuelle Position in einer Instanzvariable gespeichert werden soll: 347 | servoCurrentPosition = newPosition; 348 | 349 | try { 350 | Thread.sleep(pauseMillis); 351 | } catch (InterruptedException e) { 352 | Thread.currentThread().interrupt(); 353 | break; 354 | } 355 | } 356 | } 357 | 358 | 359 | 360 | public void gpioStop() { 361 | if (isReady()) { 362 | try { 363 | if (gpioInit()) { 364 | enaLeftOutput.low(); 365 | enaRightOutput.low(); 366 | } 367 | } catch (Exception e) { 368 | // Fehler ignorieren 369 | } 370 | } 371 | } 372 | 373 | // --- Berechnung und Hilfsmethoden --- 374 | 375 | // Berechnet den Skalierungsfaktor, um den Plotterbereich in den vorgegebenen Maßen abzubilden. 376 | private double calculateScale(double width, double height) { 377 | return Double.max(width / plotterSide[0], height / plotterSide[1]); 378 | } 379 | 380 | // Bewegt den Stift (über den Servo), um den Zeichenstatus zu ändern. 381 | private void draw(int drawState) { 382 | if (isReady()) { 383 | try { 384 | if (drawState == 0) { 385 | currentPause = stepPauseSlack; 386 | penAway(); 387 | } else { 388 | currentPause = stepPauseDraw; 389 | penDraw(); 390 | } 391 | } catch (Exception e) { 392 | e.printStackTrace(); 393 | } 394 | } 395 | lastDraw = drawState; 396 | } 397 | 398 | public void showPageLocation() throws Exception{ 399 | List testData = new ArrayList<>(); 400 | loadProperty(); 401 | // Offset-Anpassungen 402 | minX -= offsetX; 403 | minY -= offsetY; 404 | testData.add("0,15,0"); 405 | testData.add("1,0,0"); 406 | testData.add("1,0,15"); 407 | testData.add("0," + (paperWidth - 15) + ",0"); 408 | testData.add("1," + paperWidth + ",0"); 409 | testData.add("1," + paperWidth + ",15"); 410 | testData.add("0," + paperWidth + ","+(paperHeight - 15)); 411 | testData.add("1," + paperWidth + ","+paperHeight); 412 | testData.add("1," + (paperWidth-15) + ","+paperHeight); 413 | testData.add("0," + 15 + ","+paperHeight); 414 | testData.add("1,0,"+paperHeight); 415 | testData.add("1,0," + (paperHeight-15)); 416 | testData.add("0,0,0"); 417 | plotte(VDPConverter.buildFromStrings(testData)); 418 | } 419 | 420 | // Prüft, ob der gegebene Punkt noch innerhalb des erlaubten Bereichs liegt. 421 | private boolean isInRange(Pair point) { 422 | return !(point.getX() < (minX - RANGE) || point.getX() > (maxX + RANGE) || 423 | point.getY() < (minY - RANGE) || point.getY() > (maxY + RANGE)); 424 | } 425 | 426 | // Berechnet den Unterschied der Seillängen (links und rechts) zwischen zwei Punkten. 427 | private Pair getDifferences(Pair currentPoint, Pair targetPoint) { 428 | double leftDiff = getDistance(motorLinks, targetPoint) - getDistance(motorLinks, currentPoint); 429 | double rightDiff = getDistance(motorRechts, targetPoint) - getDistance(motorRechts, currentPoint); 430 | return new Pair(leftDiff, rightDiff); 431 | } 432 | 433 | // Berechnet die Distanz zwischen zwei Punkten. 434 | private double getDistance(Pair a, Pair b) { 435 | double dx = b.getX() - a.getX(); 436 | double dy = b.getY() - a.getY(); 437 | return Math.sqrt(dx * dx + dy * dy); 438 | } 439 | 440 | /** 441 | * Führt die physische Bewegung durch, indem die Differenz in Schritte umgerechnet und die 442 | * entsprechenden Signale an die Motoren gesendet werden. 443 | * 444 | * @param diff Differenz in den Seillängen (links und rechts) 445 | * @return Die tatsächlich gefahrenen Delta-Werte 446 | */ 447 | private Pair move(Pair diff) { 448 | int stepLeft = getSteps(diff.getX()); 449 | int stepRight = getSteps(diff.getY()); 450 | double leftDelta = stepLeft / stepsPerMM; 451 | double rightDelta = stepRight / stepsPerMM; 452 | if (diff.getX() < 0) { 453 | leftDelta *= -1; 454 | } 455 | if (diff.getY() < 0) { 456 | rightDelta *= -1; 457 | } 458 | Pair result = new Pair(leftDelta, rightDelta); 459 | if (simulation) { 460 | return result; 461 | } 462 | // Setzt die Fahrtrichtung 463 | if (diff.getX() > 0) { 464 | dirLeft.low(); 465 | } else { 466 | dirLeft.high(); 467 | } 468 | if (diff.getY() > 0) { 469 | dirRight.high(); 470 | } else { 471 | dirRight.low(); 472 | } 473 | int maxSteps = Math.max(stepLeft, stepRight); 474 | while (maxSteps > 0) { 475 | pause(currentPause); 476 | if (stepLeft > 0) { 477 | stepLeft--; 478 | pulLeft.high(); 479 | } 480 | if (stepRight > 0) { 481 | stepRight--; 482 | pulRight.high(); 483 | } 484 | pause(currentPause); 485 | pulLeft.low(); 486 | pulRight.low(); 487 | maxSteps--; 488 | } 489 | return result; 490 | } 491 | 492 | // Berechnet die Anzahl der Schritte, die für eine gegebene Strecke notwendig sind. 493 | private int getSteps(double diff) { 494 | return new BigDecimal(Math.abs(diff * stepsPerMM)) 495 | .setScale(0, RoundingMode.HALF_UP) 496 | .intValue(); 497 | } 498 | 499 | // Erzeugt Zwischenpunkte entlang einer Strecke, um eine glattere Bewegung zu ermöglichen. 500 | private void getPathPoints(ArrayList paramPairList, Pair currentPoint, Pair targetPoint) { 501 | paramPairList.clear(); 502 | double distance = getDistance(currentPoint, targetPoint); 503 | double path = step; 504 | while (path < distance) { 505 | paramPairList.add(calculatePoint(path, currentPoint, targetPoint)); 506 | path += step; 507 | } 508 | paramPairList.add(targetPoint); 509 | } 510 | 511 | // Berechnet einen Punkt auf der Strecke zwischen currentPoint und targetPoint bei gegebener Entfernung. 512 | private Pair calculatePoint(double path, Pair currentPoint, Pair targetPoint) { 513 | double totalDistance = getDistance(currentPoint, targetPoint); 514 | if (totalDistance == 0) { 515 | return currentPoint; 516 | } 517 | double dx = (targetPoint.getX() - currentPoint.getX()) * path / totalDistance; 518 | double dy = (targetPoint.getY() - currentPoint.getY()) * path / totalDistance; 519 | return new Pair(currentPoint.getX() + dx, currentPoint.getY() + dy); 520 | } 521 | 522 | public void addDriverMoveObserverIf(DriverMoveObserverIf observer) { 523 | observerList.add(observer); 524 | } 525 | 526 | public void setPause(boolean pause) { 527 | this.pause = pause; 528 | } 529 | 530 | public void stop() { 531 | stop = true; 532 | } 533 | 534 | public void setSimulation(boolean simulation) { 535 | this.simulation = simulation; 536 | } 537 | 538 | /** 539 | * Lädt Konfigurationen aus der Plotter-Konfigurationsdatei und aktualisiert interne Parameter. 540 | */ 541 | public void loadProperty() { 542 | String configFile = SettingsManager.getCurrent().getValue(SettingsManager.KEY.CONFIG); 543 | if (configFile == null) { 544 | configFile = "conf/default.plotterconf"; 545 | } 546 | File file = new File(configFile); 547 | if (file.exists()) { 548 | VPlotterPropertiesManager.getCurrent().load(file); 549 | } 550 | paperHeight = Double.parseDouble(VPlotterPropertiesManager.getCurrent().getValue(KEY.PAPERHEIGHT)); 551 | paperWidth = Double.parseDouble(VPlotterPropertiesManager.getCurrent().getValue(KEY.PAPERWIDTH)); 552 | minX = Integer.parseInt(VPlotterPropertiesManager.getCurrent().getValue(KEY.MINX)); 553 | minY = Integer.parseInt(VPlotterPropertiesManager.getCurrent().getValue(KEY.MINY)); 554 | plotterSide[0] = Integer.parseInt(VPlotterPropertiesManager.getCurrent().getValue(KEY.PLOTTERWIDTH)); 555 | plotterSide[1] = Integer.parseInt(VPlotterPropertiesManager.getCurrent().getValue(KEY.PLOTTERHEIGHT)); 556 | maxX = minX + plotterSide[0]; 557 | maxY = minY + plotterSide[1]; 558 | lengthBetween = Integer.parseInt(VPlotterPropertiesManager.getCurrent().getValue(KEY.SPACEBETWEEN)); 559 | step = Double.parseDouble(VPlotterPropertiesManager.getCurrent().getValue(KEY.SECTORLENGTH)); 560 | stepsPerMM = Double.parseDouble(VPlotterPropertiesManager.getCurrent().getValue(KEY.STEPSPERMM)); 561 | startPoint = new Pair( 562 | Double.parseDouble(VPlotterPropertiesManager.getCurrent().getValue(KEY.STARTPOINTX)), 563 | Double.parseDouble(VPlotterPropertiesManager.getCurrent().getValue(KEY.STARTPOINTY)) 564 | ); 565 | stepPauseDraw = Long.parseLong(VPlotterPropertiesManager.getCurrent().getValue(KEY.STEPPAUSEDRAW)); 566 | stepPauseSlack = Long.parseLong(VPlotterPropertiesManager.getCurrent().getValue(KEY.STEPPAUSESLACK)); 567 | currentPoint = new Pair(startPoint.getX(), startPoint.getY()); 568 | motorLinks = new Pair(0, 0); 569 | motorRechts = new Pair(lengthBetween, 0); 570 | // Berechne Offsets zur Zentrierung des Plotterbereichs 571 | offsetX = (paperWidth - plotterSide[0]) / 2; 572 | offsetY = (paperHeight - plotterSide[1]) / 2; 573 | } 574 | 575 | private DigitalOutput createDigitalOutput(Context pi4j, int pin) { 576 | var config = DigitalOutput.newConfigBuilder(pi4j) 577 | .address(pin) 578 | .shutdown(DigitalState.LOW) 579 | .initial(DigitalState.LOW) 580 | .provider("gpiod-digital-output"); 581 | return pi4j.create(config); 582 | } 583 | 584 | public double[] getPlotterSide() { 585 | return plotterSide; 586 | } 587 | 588 | public Pair getNullPoint() { 589 | return new Pair(minX, minY); 590 | } 591 | 592 | private boolean isReady() { 593 | return !simulation && gpio; 594 | } 595 | 596 | public boolean isUsed() { 597 | return used; 598 | } 599 | 600 | public Pair getStartPoint() { 601 | return startPoint; 602 | } 603 | 604 | /** 605 | * Wartet für die gegebene Zeit (in Mikrosekunden). 606 | */ 607 | private void pause(long micros) { 608 | long targetTime = System.nanoTime() + micros * 1000; 609 | while (System.nanoTime() < targetTime); 610 | } 611 | } 612 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/main/DriverMoveObserverIf.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.main; 2 | 3 | import de.revout.pi.vplotter.converter.Pair; 4 | 5 | public interface DriverMoveObserverIf { 6 | 7 | public void currentMove(int paramState, Pair paramToPoint, long paramStepCount, long paramActualStep); 8 | public void finish(); 9 | public void init(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/main/PiVPlotter.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.main; 2 | 3 | import de.revout.pi.vplotter.view.MainView; 4 | 5 | public class PiVPlotter { 6 | 7 | public static void main(String[] args) { 8 | new MainView(); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/main/ServoMotor.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.main; 2 | 3 | import com.pi4j.context.Context; 4 | import com.pi4j.io.pwm.Pwm; 5 | import com.pi4j.io.pwm.PwmType; 6 | 7 | public class ServoMotor { 8 | // Konstanten 9 | protected static final int DEFAULT_FREQUENCY = 50; 10 | protected static final float DEFAULT_MIN_ANGLE = -90f; 11 | protected static final float DEFAULT_MAX_ANGLE = 90f; 12 | protected static final float DEFAULT_MIN_DUTY_CYCLE = 2f; 13 | protected static final float DEFAULT_MAX_DUTY_CYCLE = 12f; 14 | 15 | // Servo-Parameter 16 | private final float minAngle; 17 | private final float maxAngle; 18 | private final float minDutyCycle; 19 | private final float maxDutyCycle; 20 | 21 | // Benutzerdefinierter Wertebereich (Standard: 0 bis 1) 22 | private float minRange = 0; 23 | private float maxRange = 1; 24 | 25 | protected final Pwm pwm; 26 | 27 | /** 28 | * Erzeugt einen neuen ServoMotor mit benutzerdefinierter PWM-Konfiguration sowie Winkel- und Duty-Cycle-Bereichen. 29 | * 30 | * @param pi4j Pi4J-Kontext 31 | * @param channel BCM-Pin-Adresse 32 | * @param frequency PWM-Frequenz 33 | * @param minAngle Minimaler Winkel in Grad 34 | * @param maxAngle Maximaler Winkel in Grad 35 | * @param minDutyCycle Minimaler Duty Cycle (in Prozent, 0 bis 100) 36 | * @param maxDutyCycle Maximaler Duty Cycle (in Prozent, 0 bis 100) 37 | */ 38 | public ServoMotor(Context pi4j, int channel, int frequency, float minAngle, float maxAngle, float minDutyCycle, float maxDutyCycle) { 39 | pwm = pi4j.create(Pwm.newConfigBuilder(pi4j) 40 | .address(channel) 41 | .pwmType(PwmType.HARDWARE) 42 | .frequency(frequency) 43 | .initial(0) 44 | .shutdown(0) 45 | .provider("linuxfs-pwm") 46 | .build()); 47 | this.minAngle = minAngle; 48 | this.maxAngle = maxAngle; 49 | this.minDutyCycle = minDutyCycle; 50 | this.maxDutyCycle = maxDutyCycle; 51 | } 52 | 53 | /** 54 | * Setzt den ServoMotor auf den Winkel 0 und schaltet den PWM-Ausgang aus. 55 | */ 56 | public void reset() { 57 | setAngle(0); 58 | pwm.off(); 59 | } 60 | 61 | /** 62 | * Rotiert den ServoMotor auf den angegebenen Winkel. 63 | * Der Winkel wird auf den Bereich [minAngle, maxAngle] begrenzt. 64 | * 65 | * @param angle Neuer absoluter Winkel in Grad. 66 | */ 67 | public void setAngle(float angle) { 68 | pwm.on(mapAngleToDutyCycle(angle)); 69 | } 70 | 71 | /** 72 | * Steuert den ServoMotor anhand eines Prozentwerts. 73 | * 0% entspricht dem minimalen, 50% dem mittleren und 100% dem maximalen Winkel. 74 | * 75 | * @param percent Prozentwert, automatisch zwischen 0 und 100 begrenzt. 76 | */ 77 | public void setPercent(float percent) { 78 | moveOnRange(percent, 0, 100); 79 | } 80 | 81 | /** 82 | * Bewegt den ServoMotor, indem ein Wert aus dem benutzerdefinierten Bereich auf den vollen Winkelbereich abgebildet wird. 83 | * Falls kein eigener Bereich definiert wurde, wird der Standardbereich von 0 bis 1 verwendet. 84 | * 85 | * @param value Wert, der abgebildet werden soll. 86 | */ 87 | public void moveOnRange(float value) { 88 | moveOnRange(value, minRange, maxRange); 89 | } 90 | 91 | /** 92 | * Bewegt den ServoMotor, indem ein Wert aus einem angegebenen Bereich auf den vollen Winkelbereich abgebildet wird. 93 | * 94 | * @param value Wert, der abgebildet werden soll. 95 | * @param minValue Minimalwert des Eingabebereichs. 96 | * @param maxValue Maximalwert des Eingabebereichs. 97 | */ 98 | public void moveOnRange(float value, float minValue, float maxValue) { 99 | pwm.on(mapToDutyCycle(value, minValue, maxValue)); 100 | } 101 | 102 | /** 103 | * Legt den benutzerdefinierten Wertebereich fest, der bei {@link #moveOnRange(float)} verwendet wird. 104 | * Diese Änderung betrifft zukünftige Aufrufe, nicht jedoch die aktuelle Position. 105 | * 106 | * @param minValue Minimalwert des Bereichs. 107 | * @param maxValue Maximalwert des Bereichs. 108 | */ 109 | public void setRange(float minValue, float maxValue) { 110 | this.minRange = minValue; 111 | this.maxRange = maxValue; 112 | } 113 | 114 | /** 115 | * Gibt den minimal konfigurierten Winkel zurück. 116 | * 117 | * @return Minimaler Winkel in Grad. 118 | */ 119 | public float getMinAngle() { 120 | return minAngle; 121 | } 122 | 123 | /** 124 | * Gibt den maximal konfigurierten Winkel zurück. 125 | * 126 | * @return Maximaler Winkel in Grad. 127 | */ 128 | public float getMaxAngle() { 129 | return maxAngle; 130 | } 131 | 132 | /** 133 | * Wandelt einen Winkel in den entsprechenden Duty Cycle um. 134 | * 135 | * @param angle Gewünschter Winkel in Grad. 136 | * @return Entsprechender Duty Cycle. 137 | */ 138 | private float mapAngleToDutyCycle(float angle) { 139 | return mapToDutyCycle(angle, minAngle, maxAngle); 140 | } 141 | 142 | /** 143 | * Wandelt einen Wert aus einem bestimmten Eingabebereich in einen Duty Cycle um. 144 | * 145 | * @param input Der umzuwandelnde Wert. 146 | * @param inputStart Minimaler Eingabewert. 147 | * @param inputEnd Maximaler Eingabewert. 148 | * @return Duty Cycle, der der gewünschten Position entspricht. 149 | * @throws IllegalArgumentException wenn inputStart gleich inputEnd ist. 150 | */ 151 | private float mapToDutyCycle(float input, float inputStart, float inputEnd) { 152 | return mapRange(input, inputStart, inputEnd, minDutyCycle, maxDutyCycle); 153 | } 154 | 155 | /** 156 | * Wandelt einen Wert von einem Eingabebereich in einen Ausgabebereich um. 157 | * Der Eingabewert wird automatisch in den gültigen Bereich eingeschränkt. 158 | * Die Abbildung ist umgekehrt, d.h. ein Wert am Anfang des Eingabebereichs 159 | * entspricht dem Ende des Ausgabebereichs. 160 | * 161 | * @param input der umzuwandelnde Wert 162 | * @param inputStart Start des Eingabebereichs 163 | * @param inputEnd Ende des Eingabebereichs 164 | * @param outputStart Start des Ausgabebereichs 165 | * @param outputEnd Ende des Ausgabebereichs 166 | * @return der abgebildete Wert im Ausgabebereich 167 | * @throws IllegalArgumentException wenn inputStart gleich inputEnd ist 168 | */ 169 | private float mapRange(float input, float inputStart, float inputEnd, float outputStart, float outputEnd) { 170 | if (inputStart == inputEnd) { 171 | throw new IllegalArgumentException("inputStart und inputEnd müssen unterschiedliche Werte sein"); 172 | } 173 | 174 | // Sicherstellen, dass der Eingabebereich in aufsteigender Reihenfolge vorliegt 175 | if (inputStart > inputEnd) { 176 | float tmp = inputStart; 177 | inputStart = inputEnd; 178 | inputEnd = tmp; 179 | } 180 | 181 | // Sicherstellen, dass der Ausgabebereich in aufsteigender Reihenfolge vorliegt 182 | if (outputStart > outputEnd) { 183 | float tmp = outputStart; 184 | outputStart = outputEnd; 185 | outputEnd = tmp; 186 | } 187 | 188 | // Clamp des Eingabewerts auf den gültigen Bereich 189 | float clampedInput = Math.max(inputStart, Math.min(input, inputEnd)); 190 | 191 | // Berechne das Verhältnis des geclampeten Wertes im Eingabebereich 192 | float ratio = (clampedInput - inputStart) / (inputEnd - inputStart); 193 | 194 | // Umgekehrte Abbildung: Bei ratio == 0 wird outputEnd, bei ratio == 1 outputStart zurückgegeben 195 | return outputEnd - (outputEnd - outputStart) * ratio; 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/model/Model.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.model; 2 | 3 | import java.awt.image.BufferedImage; 4 | import java.io.IOException; 5 | import java.nio.file.Files; 6 | import java.nio.file.Path; 7 | import java.nio.file.Paths; 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | import java.util.Collections; 11 | import java.util.Comparator; 12 | import java.util.List; 13 | 14 | import javax.imageio.ImageIO; 15 | 16 | import de.revout.pi.vplotter.converter.Pair; 17 | import de.revout.pi.vplotter.converter.SVGToPolygonConverter; 18 | import de.revout.pi.vplotter.converter.Section; 19 | import de.revout.pi.vplotter.imagefilter.EdgeDetectionFilter; 20 | import de.revout.pi.vplotter.imagefilter.Filter; 21 | import de.revout.pi.vplotter.imagefilter.GrayscaleFilter; 22 | import de.revout.pi.vplotter.imagefilter.RotateFilter; 23 | import de.revout.pi.vplotter.setting.Setting; 24 | 25 | public class Model { 26 | 27 | // Model-Daten 28 | private List svgData; 29 | private List
sectionList; 30 | private static Model current; 31 | private boolean sameFile; 32 | private SVGToPolygonConverter svgToPolygonConverter; 33 | private BufferedImage image; 34 | private BufferedImage originalImage; 35 | private BufferedImage svgImage; 36 | private List filters; 37 | private List usedFilters; 38 | private List updateList; 39 | 40 | // Privater Konstruktor – Singleton-Pattern 41 | private Model() { 42 | updateList = new ArrayList<>(); 43 | svgData = Collections.emptyList(); 44 | sameFile = true; 45 | filters = new ArrayList<>(); 46 | usedFilters = new ArrayList<>(); 47 | // Standardfilter werden hinzugefügt 48 | filters.add(new RotateFilter()); 49 | filters.add(new GrayscaleFilter()); 50 | filters.add(new EdgeDetectionFilter()); 51 | svgToPolygonConverter = new SVGToPolygonConverter(); 52 | sectionList = new ArrayList<>(); 53 | } 54 | 55 | public static Model getCurrent() { 56 | if (current == null) { 57 | current = new Model(); 58 | } 59 | return current; 60 | } 61 | 62 | // Update-Verwaltung 63 | public void register(Update update) { 64 | updateList.add(update); 65 | } 66 | 67 | private void update() { 68 | for (Update update : updateList) { 69 | update.update(); 70 | } 71 | } 72 | 73 | // --- Plotter-Utility-Methoden --- 74 | 75 | /** 76 | * Berechnet die euklidische Distanz zwischen zwei Punkten. 77 | * 78 | * @param startPoint der Startpunkt 79 | * @param endPoint der Endpunkt 80 | * @return die Länge zwischen den Punkten 81 | */ 82 | public double getLength(Pair startPoint, Pair endPoint) { 83 | double dx = startPoint.getX() - endPoint.getX(); 84 | double dy = startPoint.getY() - endPoint.getY(); 85 | return Math.sqrt(dx * dx + dy * dy); 86 | } 87 | 88 | /** 89 | * Sucht in der Liste der Sections diejenige, deren Startpunkt der 90 | * nächsten Verbindung zum letzten Punkt (lastPoint) hat. 91 | * 92 | * @param lastPoint der zuletzt benutzte Punkt 93 | * @param sections Liste verfügbarer Sections; darf nicht leer sein 94 | * @return Die Section mit der kürzesten Verbindung 95 | * @throws IllegalArgumentException falls die Liste null oder leer ist 96 | */ 97 | public Section getNextSection(Pair lastPoint, List
sections) { 98 | if (sections == null || sections.isEmpty()) { 99 | throw new IllegalArgumentException("Die Liste der Sections darf nicht null oder leer sein."); 100 | } 101 | return sections.stream() 102 | .min(Comparator.comparingDouble(s -> getLength(lastPoint, s.getStartPoint()))) 103 | .orElseThrow(() -> new IllegalStateException("Keine Section gefunden.")); 104 | } 105 | 106 | 107 | /** 108 | * Erstellt aus den geladenen SVG-Daten eine geordnete Liste von Sections. 109 | * Dazu werden die Segmente, die mit "M" beginnen, als Startpunkte interpretiert 110 | * und die folgenden Linien (beginnend mit anderen Buchstaben) der Section zugeordnet. 111 | * 112 | * @return Die geordnete Liste der Sections. 113 | */ 114 | public List
createSectionList() { 115 | // Zwischenspeicher für die unverknüpften Sections 116 | List
tempList = new ArrayList<>(); 117 | Section currentSection = null; 118 | 119 | // Erzeuge Sections basierend auf den SVG-Daten 120 | for (String line : svgData) { 121 | if (line.startsWith("M")) { 122 | // Wenn bereits eine Section aufgebaut wurde, zur Liste hinzufügen 123 | if (currentSection != null) { 124 | tempList.add(currentSection); 125 | } 126 | // Koordinaten parsen: entferne den führenden Buchstaben und splitte anhand beliebiger Leerzeichen 127 | double[] coords = Arrays.stream(line.substring(1).trim().split("\\s+")) 128 | .mapToDouble(Double::parseDouble) 129 | .toArray(); 130 | // Letzte beiden Werte als Startkoordinaten verwenden 131 | currentSection = new Section(coords[coords.length - 2], coords[coords.length - 1]); 132 | } else if (currentSection != null) { 133 | // Entferne das führende Zeichen und füge die restlichen Daten zur aktuellen Section hinzu 134 | currentSection.addLineData(line.substring(1)); 135 | } 136 | } 137 | // Letzte Section, falls vorhanden, hinzufügen 138 | if (currentSection != null) { 139 | tempList.add(currentSection); 140 | } 141 | 142 | // Nun wird eine geordnete Liste erstellt, basierend auf dem Konzept der nächsten Section mit der kürzesten Verbindung 143 | List
result = new ArrayList<>(); 144 | if (!tempList.isEmpty()) { 145 | // Starte mit der ersten Section und entferne sie aus der temporären Liste 146 | currentSection = tempList.remove(0); 147 | result.add(currentSection); 148 | 149 | // Füge solange Sections hinzu, bis alle geordnet sind 150 | while (!tempList.isEmpty()) { 151 | Section nextSection = getNextSection(currentSection.getLastPoint(), tempList); 152 | tempList.remove(nextSection); 153 | result.add(nextSection); 154 | currentSection = nextSection; 155 | } 156 | } 157 | return result; 158 | } 159 | 160 | /** 161 | * Speichert das aktuelle Bild als temporäres BMP. 162 | * 163 | * @return Der absolute Pfad zur erzeugten BMP-Datei oder null im Fehlerfall. 164 | */ 165 | public String saveBMPTemp() { 166 | try { 167 | // Temporäre Datei mit vorgegebenem Präfix und Suffix erzeugen 168 | Path tempFile = Files.createTempFile("Buff_TO_BMP_", ".bmp"); 169 | BufferedImage currentImage = this.getImage(); 170 | if (currentImage != null) { 171 | // Speichere das Bild im BMP-Format in die temporäre Datei 172 | ImageIO.write(currentImage, "bmp", tempFile.toFile()); 173 | // Zurückgeben des absoluten Pfads zur erzeugten Datei 174 | return tempFile.toAbsolutePath().toString(); 175 | } 176 | } catch (IOException e) { 177 | e.printStackTrace(); 178 | } 179 | return null; 180 | } 181 | 182 | /** 183 | * Erzeugt aus einer BMP-Datei mithilfe von Potrace eine SVG-Datei und lädt diese anschließend. 184 | * 185 | * @param potracePath Der Pfad zur Potrace-Anwendung. 186 | * @param bmpPath Der Pfad zur BMP-Datei. 187 | * @return true, wenn die SVG-Daten erfolgreich generiert wurden, ansonsten false. 188 | * @throws Exception falls Potrace nicht gefunden wird oder ein anderer Fehler auftritt. 189 | */ 190 | public boolean generateSVGFromBMP(String potracePath, String bmpPath) throws Exception { 191 | if (!bmpPath.isEmpty() && bmpPath.endsWith(".bmp")) { 192 | if (svgData.isEmpty() || !sameFile) { 193 | Path tempSvg = Files.createTempFile("BMP_TO_SVG_", ".svg"); 194 | Process process = Runtime.getRuntime().exec(new String[] { 195 | potracePath, "-o", tempSvg.toFile().getAbsolutePath(), 196 | "--flat", "-b", "svg", bmpPath 197 | }); 198 | process.waitFor(); 199 | return generateDataFromSVG(tempSvg.toString()); 200 | } 201 | return false; 202 | } 203 | return false; 204 | } 205 | 206 | /** 207 | * Lädt SVG-Daten aus einer SVG-Datei, erstellt ein leeres BufferedImage und setzt den sameFile-Status auf true. 208 | * 209 | * @param svgFilePath Der Pfad zur SVG-Datei. 210 | * @return true, wenn die Daten erfolgreich geladen wurden, ansonsten false. 211 | */ 212 | public boolean generateDataFromSVG(String svgFilePath) { 213 | if (!svgFilePath.isEmpty() && svgFilePath.endsWith(".svg")) { 214 | Path path = Paths.get(svgFilePath); 215 | try { 216 | if (Files.size(path) == 0) { 217 | return false; 218 | } 219 | svgData = svgToPolygonConverter.convertSVG(path); 220 | svgImage = new BufferedImage((int) svgToPolygonConverter.getWidth(), 221 | (int) svgToPolygonConverter.getHeight(), BufferedImage.TYPE_INT_ARGB); 222 | sameFile = true; 223 | return true; 224 | } catch (Exception ex) { 225 | ex.printStackTrace(); 226 | } 227 | } 228 | return false; 229 | } 230 | 231 | // --- Getter und Setter --- 232 | 233 | public List getSvgData() { 234 | return svgData; 235 | } 236 | 237 | public void setSvgData(List svgData) { 238 | this.svgData = svgData; 239 | } 240 | 241 | public List
getSectionList() { 242 | return sectionList; 243 | } 244 | 245 | public void setSectionList(List
sectionList) { 246 | this.sectionList = sectionList; 247 | } 248 | 249 | public boolean isSameFile() { 250 | return sameFile; 251 | } 252 | 253 | public void setSameFile(boolean sameFile) { 254 | this.sameFile = sameFile; 255 | } 256 | 257 | public SVGToPolygonConverter getSvgToPolygonConverter() { 258 | return svgToPolygonConverter; 259 | } 260 | 261 | public void setSvgToPolygonConverter(SVGToPolygonConverter svgToPolygonConverter) { 262 | this.svgToPolygonConverter = svgToPolygonConverter; 263 | } 264 | 265 | public BufferedImage getImage() { 266 | return image; 267 | } 268 | 269 | public void setImage(BufferedImage image) { 270 | this.image = image; 271 | } 272 | 273 | public BufferedImage getOriginalImage() { 274 | return originalImage; 275 | } 276 | 277 | public void setOriginalImage(BufferedImage originalImage) { 278 | this.originalImage = originalImage; 279 | } 280 | 281 | /** 282 | * Prüft, ob das aktuelle Bild in Graustufen vorliegt. 283 | * 284 | * @return true, wenn das Bild grauwertig ist, ansonsten false. 285 | */ 286 | public boolean checkIfGrey() { 287 | BufferedImage img = getImage(); 288 | if (img == null) return false; 289 | for (int x = 0; x < img.getWidth(); x++) { 290 | for (int y = 0; y < img.getHeight(); y++) { 291 | int rgb = img.getRGB(x, y); 292 | int red = (rgb >> 16) & 0xff; 293 | int green = (rgb >> 8) & 0xff; 294 | int blue = rgb & 0xff; 295 | if (!(red == green && green == blue)) { 296 | return false; 297 | } 298 | } 299 | } 300 | return true; 301 | } 302 | 303 | public List getFilters() { 304 | return filters; 305 | } 306 | 307 | public BufferedImage getSvgImage() { 308 | return svgImage; 309 | } 310 | 311 | public void setSvgImage(BufferedImage svgImage) { 312 | this.svgImage = svgImage; 313 | } 314 | 315 | // --- Filter-Methoden --- 316 | 317 | /** 318 | * Aktualisiert den Wert einer Filter-Einstellung, wendet die Änderung an und führt ein Update aus. 319 | * 320 | * @param filter Der betroffene Filter. 321 | * @param setting Die betroffene Einstellung. 322 | * @param settingValue Der neue Einstellungswert. 323 | */ 324 | public void editFilterSetting(Filter filter, Setting setting, String settingValue) { 325 | filter.getSetting(setting).setValue(settingValue); 326 | updateImage(); 327 | update(); 328 | } 329 | 330 | public void addFilter(Filter filter) { 331 | usedFilters.add(filter); 332 | updateImage(); 333 | update(); 334 | } 335 | 336 | public void removeFilter(Filter filter) { 337 | usedFilters.remove(filter); 338 | updateImage(); 339 | update(); 340 | } 341 | 342 | public void removeAllFilter() { 343 | usedFilters.clear(); 344 | updateImage(); 345 | update(); 346 | } 347 | 348 | /** 349 | * Wendet alle verwendeten Filter auf das Originalbild an und aktualisiert so das angezeigte Bild. 350 | */ 351 | public void updateImage() { 352 | image = originalImage; 353 | if (usedFilters != null && !usedFilters.isEmpty()) { 354 | for (Filter filter : usedFilters) { 355 | image = filter.filter(image); 356 | } 357 | } 358 | } 359 | 360 | public List getUsedFilter() { 361 | return usedFilters; 362 | } 363 | 364 | /** 365 | * Setzt den Zustand für einen neuen Prozess zurück. 366 | */ 367 | public void newProcess() { 368 | usedFilters.clear(); 369 | sectionList.clear(); 370 | svgData.clear(); 371 | image = null; 372 | originalImage = null; 373 | svgImage = null; 374 | update(); 375 | } 376 | } 377 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/model/Update.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.model; 2 | 3 | public interface Update { 4 | 5 | void update(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/saves/SettingsManager.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.saves; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.OutputStream; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | import java.nio.file.Paths; 10 | import java.nio.file.StandardCopyOption; 11 | import java.util.Properties; 12 | 13 | public class SettingsManager { 14 | 15 | private static final String SETTINGS_PROPERTY = "./conf/programm.settings"; 16 | private final Properties properties; 17 | 18 | public static enum KEY { 19 | FILEPATH, POTRACE, SIMULATION, CONFIG, LAST_USED 20 | } 21 | 22 | // Singleton-Instanz über ein Holder-Konstrukt (thread-safe) 23 | private static class Holder { 24 | private static final SettingsManager INSTANCE = new SettingsManager(); 25 | } 26 | 27 | public static SettingsManager getCurrent() { 28 | return Holder.INSTANCE; 29 | } 30 | 31 | private SettingsManager() { 32 | properties = new Properties(); 33 | loadProperties(); 34 | } 35 | 36 | /** 37 | * Lädt die Properties aus der XML-Datei, falls vorhanden. 38 | */ 39 | private void loadProperties() { 40 | Path settingsPath = Paths.get(SETTINGS_PROPERTY); 41 | if (Files.exists(settingsPath)) { 42 | try (FileInputStream is = new FileInputStream(settingsPath.toFile())) { 43 | properties.loadFromXML(is); 44 | } catch (IOException exc) { 45 | exc.printStackTrace(); 46 | } 47 | } 48 | } 49 | 50 | /** 51 | * Speichert die aktuellen Einstellungen in die XML-Datei. 52 | * Dabei wird zuerst ein Backup der bestehenden Datei erstellt. 53 | * 54 | * @throws IOException falls ein Fehler beim Speichern auftritt. 55 | */ 56 | public synchronized void save() throws IOException { 57 | Path settingsPath = Paths.get(SETTINGS_PROPERTY); 58 | Path backupPath = Files.createTempFile("backup", ""); 59 | 60 | // Erstelle zunächst ein Backup der bestehenden Datei 61 | if (Files.exists(settingsPath)) { 62 | Files.move(settingsPath, backupPath, StandardCopyOption.REPLACE_EXISTING); 63 | } 64 | 65 | try (OutputStream output = new FileOutputStream(settingsPath.toFile())) { 66 | properties.storeToXML(output, null); 67 | // Lösche das Backup, wenn das Speichern erfolgreich war 68 | Files.deleteIfExists(backupPath); 69 | } catch (IOException e) { 70 | // Bei einem Fehler wird das Backup zurückverschoben 71 | Files.move(backupPath, settingsPath, StandardCopyOption.REPLACE_EXISTING); 72 | e.printStackTrace(); 73 | throw e; 74 | } 75 | } 76 | 77 | /** 78 | * Liefert den in den Properties gespeicherten Wert für den angegebenen Schlüssel. 79 | * 80 | * @param key Der aufzurufende Schlüssel. 81 | * @return Der Wert als String oder null, falls nicht gesetzt. 82 | */ 83 | public synchronized String getValue(KEY key) { 84 | return properties.getProperty(key.name().toLowerCase()); 85 | } 86 | 87 | /** 88 | * Setzt den Wert zu einem bestimmten Schlüssel, sofern der neue Wert nicht null ist und sich 89 | * vom aktuellen Wert unterscheidet. 90 | * 91 | * @param key Der Schlüssel. 92 | * @param value Der neue Wert. 93 | * @throws IOException Im Falle eines Fehlers beim Speichern (kann aber hier optional sein). 94 | */ 95 | public synchronized void setValue(KEY key, String value) throws IOException { 96 | if (value != null && !value.equals(getValue(key))) { 97 | properties.setProperty(key.name().toLowerCase(), value); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/saves/VPlotterPropertiesManager.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.saves; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.util.Properties; 8 | 9 | public class VPlotterPropertiesManager { 10 | 11 | private final Properties properties; 12 | 13 | public static enum KEY { 14 | MINX, MINY, PLOTTERWIDTH, PLOTTERHEIGHT, SPACEBETWEEN, SECTORLENGTH, 15 | STARTPOINTX, STARTPOINTY, STEPSPERMM, PAPERHEIGHT, PAPERWIDTH, 16 | STEPPAUSEDRAW, STEPPAUSESLACK, DRAWPAUSE 17 | } 18 | 19 | // Private Konstruktion, Singleton über den Holder 20 | private VPlotterPropertiesManager() { 21 | properties = new Properties(); 22 | } 23 | 24 | private static class Holder { 25 | private static final VPlotterPropertiesManager INSTANCE = new VPlotterPropertiesManager(); 26 | } 27 | 28 | public static VPlotterPropertiesManager getCurrent() { 29 | return Holder.INSTANCE; 30 | } 31 | 32 | /** 33 | * Speichert die übergebenen Properties (falls nicht null) oder die internen Properties 34 | * in die angegebene Datei als XML. 35 | * 36 | * @param file Zieldatei 37 | * @param propToStore Falls nicht null, wird diese Properties-Instanz gespeichert; andernfalls die internen Properties. 38 | * @throws IOException bei Fehlern im Dateischreibprozess. 39 | */ 40 | private void save(File file, Properties propToStore) throws IOException { 41 | try (FileOutputStream output = new FileOutputStream(file)) { 42 | if (propToStore == null) { 43 | properties.storeToXML(output, null); 44 | } else { 45 | propToStore.storeToXML(output, null); 46 | } 47 | } catch (IOException e) { 48 | e.printStackTrace(); 49 | throw e; 50 | } 51 | } 52 | 53 | /** 54 | * Gibt den Wert zum angegebenen Schlüssel zurück. 55 | * 56 | * @param key der Schlüssel. 57 | * @return Der gespeicherte Wert oder null, wenn nicht vorhanden. 58 | */ 59 | public synchronized String getValue(KEY key) { 60 | return properties.getProperty(key.name().toLowerCase()); 61 | } 62 | 63 | /** 64 | * Setzt den Wert zum angegebenen Schlüssel in den übergebenen Properties (falls nicht null), 65 | * ansonsten in den internen Properties. 66 | * 67 | * @param key der Schlüssel. 68 | * @param value der zu setzende Wert. 69 | * @param targetProps Ziel-Properties, in die der Wert gesetzt werden soll, oder null für die internen Properties. 70 | */ 71 | public synchronized void setValue(KEY key, String value, Properties targetProps) { 72 | if (value != null) { 73 | if (targetProps == null) { 74 | properties.setProperty(key.name().toLowerCase(), value); 75 | } else { 76 | targetProps.setProperty(key.name().toLowerCase(), value); 77 | } 78 | } 79 | } 80 | 81 | /** 82 | * Lädt die Eigenschaften aus der angegebenen XML-Datei und aktualisiert gleichzeitig 83 | * die CONFIG-Einstellung im SettingsManager. 84 | * 85 | * @param file Die Konfigurationsdatei. 86 | */ 87 | public void load(File file) { 88 | try (FileInputStream is = new FileInputStream(file)) { 89 | properties.clear(); 90 | properties.loadFromXML(is); 91 | // Aktualisiere im SettingsManager den CONFIG-Schlüssel mit dem Dateipfad. 92 | SettingsManager.getCurrent().setValue(SettingsManager.KEY.CONFIG, file.getAbsolutePath()); 93 | SettingsManager.getCurrent().save(); 94 | } catch (Exception exc) { 95 | exc.printStackTrace(); 96 | } 97 | } 98 | 99 | /** 100 | * Erstellt eine neue Konfiguration, indem bestimmte Schlüssel initial auf einen leeren String gesetzt werden. 101 | * Anschließend wird die Konfiguration in die angegebene Datei gespeichert. 102 | * 103 | * @param file Die Datei, in der die neue Konfiguration gespeichert wird. 104 | */ 105 | public void newConfig(File file) { 106 | Properties newProperties = new Properties(); 107 | // Liste der Schlüssel, die initialisiert werden sollen 108 | KEY[] keysToInitialize = { 109 | KEY.MINX, KEY.MINY, KEY.PLOTTERWIDTH, KEY.PLOTTERHEIGHT, 110 | KEY.SPACEBETWEEN, KEY.SECTORLENGTH, KEY.STEPSPERMM, 111 | KEY.DRAWPAUSE, KEY.STARTPOINTX, KEY.STARTPOINTY, 112 | KEY.STEPPAUSEDRAW, KEY.STEPPAUSESLACK 113 | }; 114 | for (KEY key : keysToInitialize) { 115 | setValue(key, "", newProperties); 116 | } 117 | try { 118 | save(file, newProperties); 119 | } catch (IOException e) { 120 | e.printStackTrace(); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/setting/ComboSetting.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.setting; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class ComboSetting extends Setting { 7 | public ComboSetting(String paramName, String paramValue) { 8 | super(paramName,paramValue); 9 | standardValue = paramValue; 10 | valueList = new ArrayList<>(); 11 | } 12 | 13 | private List valueList; 14 | private String standardValue; 15 | 16 | public List getValueList() { 17 | return valueList; 18 | } 19 | 20 | public void setValueList(List valueList) { 21 | this.valueList = valueList; 22 | } 23 | 24 | public String getStandardValue() { 25 | return standardValue; 26 | } 27 | 28 | public void setStandardValue(String standardValue) { 29 | this.standardValue = standardValue; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/setting/Setting.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.setting; 2 | 3 | public class Setting { 4 | 5 | private String name; 6 | private String value; 7 | 8 | public Setting(String paramName,String paramValue) { 9 | value = paramValue; 10 | name = paramName; 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | public void setName(String name) { 17 | this.name = name; 18 | } 19 | public String getValue() { 20 | return value; 21 | } 22 | public void setValue(String value) { 23 | this.value = value; 24 | } 25 | 26 | 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/setting/SliderSetting.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.setting; 2 | 3 | public class SliderSetting extends Setting{ 4 | 5 | private int min; 6 | private int max; 7 | private int tick; 8 | 9 | public SliderSetting(String paramName, String paramValue, int paramMin, int paramMax, int paramTick) { 10 | super(paramName, paramValue); 11 | min = paramMin; 12 | max = paramMax; 13 | tick = paramTick; 14 | } 15 | 16 | public int getMax() { 17 | return max; 18 | } 19 | 20 | public void setMax(int max) { 21 | this.max = max; 22 | } 23 | 24 | public int getMin() { 25 | return min; 26 | } 27 | 28 | public void setMin(int min) { 29 | this.min = min; 30 | } 31 | 32 | public int getTick() { 33 | return tick; 34 | } 35 | 36 | public void setTick(int tick) { 37 | this.tick = tick; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/version/Version.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.version; 2 | 3 | public interface Version { 4 | 5 | public static String number = "2.0.0"; 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/view/FilterBox.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.view; 2 | 3 | import java.awt.Color; 4 | import java.awt.Component; 5 | import java.awt.Dimension; 6 | import java.awt.Font; 7 | import java.awt.GridBagConstraints; 8 | import java.awt.GridBagLayout; 9 | import java.awt.Insets; 10 | import java.io.IOException; 11 | 12 | import javax.imageio.ImageIO; 13 | import javax.swing.BorderFactory; 14 | import javax.swing.ImageIcon; 15 | import javax.swing.JButton; 16 | import javax.swing.JComboBox; 17 | import javax.swing.JLabel; 18 | import javax.swing.JPanel; 19 | import javax.swing.JSlider; 20 | 21 | import de.revout.pi.vplotter.imagefilter.Filter; 22 | import de.revout.pi.vplotter.model.Model; 23 | import de.revout.pi.vplotter.setting.ComboSetting; 24 | import de.revout.pi.vplotter.setting.Setting; 25 | import de.revout.pi.vplotter.setting.SliderSetting; 26 | 27 | public class FilterBox extends JPanel { 28 | 29 | private static final long serialVersionUID = 1L; 30 | private final Filter filter; 31 | 32 | public FilterBox(Filter filter, FilterPanel filterPanel) { 33 | this.filter = filter; 34 | setLayout(new GridBagLayout()); 35 | setBackground(Color.WHITE); 36 | setBorder(BorderFactory.createLineBorder(Color.BLACK)); 37 | 38 | // Remove-Button erstellen 39 | ImageIcon icon = null; 40 | try { 41 | icon = new ImageIcon(ImageIO.read(FilterBox.class.getResourceAsStream("close2.png"))); 42 | } catch (IOException e) { 43 | e.printStackTrace(); 44 | } 45 | JButton removeButton = new JButton(icon); 46 | removeButton.setBackground(Color.WHITE); 47 | removeButton.setBorderPainted(false); 48 | if (icon != null) { 49 | removeButton.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight())); 50 | } 51 | addComponent(removeButton, 11, 0, 1, 1, 1, 1); 52 | 53 | // Filtername anzeigen 54 | JLabel nameLabel = new JLabel(filter.getName()); 55 | nameLabel.setFont(new Font("Verdana", Font.BOLD, 12)); 56 | addComponent(nameLabel, 0, 0, 1, 1, 10, 3); 57 | 58 | int row = 1; 59 | for (Setting setting : filter.getSettings()) { 60 | // Beschriftung für die Einstellung 61 | JLabel headerLabel = new JLabel(setting.getName() + " "); 62 | headerLabel.setFont(new Font("Verdana", Font.PLAIN, 12)); 63 | addComponent(headerLabel, 0, row, 1, 1, 5, 1); 64 | 65 | if (setting instanceof ComboSetting) { 66 | ComboSetting comboSetting = (ComboSetting) setting; 67 | JComboBox comboBox = new JComboBox<>(); 68 | for (String value : comboSetting.getValueList()) { 69 | comboBox.addItem(value); 70 | } 71 | comboBox.setSelectedItem(comboSetting.getValue()); 72 | comboBox.addActionListener(e -> 73 | Model.getCurrent().editFilterSetting(filter, setting, (String) comboBox.getSelectedItem()) 74 | ); 75 | addComponent(comboBox, 1, row, 1, 1, 5, 1); 76 | } else if (setting instanceof SliderSetting) { 77 | SliderSetting sliderSetting = (SliderSetting) setting; 78 | int sliderValue = Integer.parseInt(sliderSetting.getValue()); 79 | JSlider slider = new JSlider(sliderSetting.getMin(), sliderSetting.getMax(), sliderValue); 80 | int tick = sliderSetting.getTick(); 81 | slider.setMinorTickSpacing(tick); 82 | slider.setSnapToTicks(true); 83 | slider.setLabelTable(slider.createStandardLabels(tick)); 84 | slider.addChangeListener(e -> 85 | Model.getCurrent().editFilterSetting(filter, setting, String.valueOf(slider.getValue())) 86 | ); 87 | slider.setBackground(Color.WHITE); 88 | addComponent(slider, 1, row, 1, 1, 5, 1); 89 | } 90 | row++; 91 | } 92 | 93 | removeButton.addActionListener(e -> { 94 | Model.getCurrent().setSameFile(false); 95 | filterPanel.removeFilter(this); 96 | filterPanel.validate(); 97 | }); 98 | 99 | setVisible(true); 100 | } 101 | 102 | /** 103 | * Fügt eine Komponente in ein GridBagLayout-basiertes Panel mit den angegebenen Parametern hinzu. 104 | * 105 | * @param comp Die hinzuzufügende Komponente 106 | * @param gridx Spaltenposition 107 | * @param gridy Zeilenposition 108 | * @param gridwidth Anzahl der Spalten, die die Komponente einnehmen soll 109 | * @param gridheight Anzahl der Zeilen, die die Komponente einnehmen soll 110 | * @param weightx Gewichtung in X-Richtung 111 | * @param weighty Gewichtung in Y-Richtung 112 | */ 113 | private void addComponent(Component comp, int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty) { 114 | GridBagConstraints gbc = new GridBagConstraints(); 115 | gbc.insets = new Insets(5, 5, 5, 5); 116 | gbc.fill = GridBagConstraints.BOTH; 117 | gbc.gridx = gridx; 118 | gbc.gridy = gridy; 119 | gbc.gridwidth = gridwidth; 120 | gbc.gridheight = gridheight; 121 | gbc.weightx = weightx; 122 | gbc.weighty = weighty; 123 | add(comp, gbc); 124 | } 125 | 126 | public Filter getFilter() { 127 | return filter; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/view/FilterPanel.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.view; 2 | 3 | import java.awt.Component; 4 | import java.awt.Cursor; 5 | import java.awt.Dimension; 6 | import java.awt.GridBagConstraints; 7 | import java.awt.GridBagLayout; 8 | import java.awt.Insets; 9 | import java.awt.event.ActionEvent; 10 | import java.awt.event.ActionListener; 11 | import java.io.File; 12 | import java.nio.file.Files; 13 | import java.nio.file.Paths; 14 | 15 | import javax.swing.JButton; 16 | import javax.swing.JComboBox; 17 | import javax.swing.JFileChooser; 18 | import javax.swing.JOptionPane; 19 | import javax.swing.JPanel; 20 | import javax.swing.JScrollPane; 21 | import javax.swing.filechooser.FileFilter; 22 | 23 | import de.revout.pi.vplotter.imagefilter.Filter; 24 | import de.revout.pi.vplotter.lang.Dictionary; 25 | import de.revout.pi.vplotter.model.Model; 26 | import de.revout.pi.vplotter.model.Update; 27 | import de.revout.pi.vplotter.saves.SettingsManager; 28 | import de.revout.pi.vplotter.saves.SettingsManager.KEY; 29 | 30 | public class FilterPanel extends JPanel implements Update { 31 | 32 | private JPanel leftPanel; 33 | private JPanel rightPanel; 34 | private FilterPanel filterPanel = this; 35 | private GridBagLayout viewPortLayout; 36 | private int i=0; 37 | private JPanel jPanel; 38 | private MainView mainView; 39 | private ImagePanel imagePanel; 40 | /** 41 | * 42 | */ 43 | private static final long serialVersionUID = 1L; 44 | 45 | public FilterPanel(MainView paramMainView) { 46 | Model.getCurrent().register(this); 47 | mainView=paramMainView; 48 | init(); 49 | } 50 | 51 | private void init() { 52 | 53 | GridBagLayout filterPanelBagLayout = new GridBagLayout(); 54 | setLayout(filterPanelBagLayout); 55 | 56 | leftPanel = new JPanel(); 57 | leftPanel.setBackground(MainView.COLOR1); 58 | createConstraints(filterPanelBagLayout, leftPanel, 0, 0, 5, 1); 59 | imagePanel = new ImagePanel(); 60 | GridBagLayout leftBagLayout = new GridBagLayout(); 61 | leftPanel.setLayout(leftBagLayout); 62 | createConstraints(leftBagLayout, imagePanel, 0, 0, 1, 1); 63 | leftPanel.add(imagePanel); 64 | 65 | rightPanel = new JPanel(); 66 | rightPanel.setBackground(MainView.COLOR2); 67 | createConstraints(filterPanelBagLayout, rightPanel, 1, 0, 1, 1); 68 | 69 | add(leftPanel); 70 | add(rightPanel); 71 | 72 | GridBagLayout rightBagLayout = new GridBagLayout(); 73 | rightPanel.setLayout(rightBagLayout); 74 | 75 | JPanel viewPort = new JPanel(); 76 | viewPortLayout = new GridBagLayout(); 77 | viewPort.setLayout(viewPortLayout); 78 | jPanel = new JPanel(); 79 | GridBagLayout filterBoxGridBagLayout = new GridBagLayout(); 80 | jPanel.setLayout(filterBoxGridBagLayout); 81 | JPanel jPanel2 = new JPanel(); 82 | createConstraintsFilterBox(viewPortLayout, jPanel, 0, 0, 1, 1); 83 | createConstraints(viewPortLayout, jPanel2, 0, 1, 1, 100); 84 | viewPort.add(jPanel); 85 | viewPort.add(jPanel2); 86 | 87 | JScrollPane jScrollPane = new JScrollPane(viewPort); 88 | jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 89 | jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 90 | jScrollPane.setPreferredSize(new Dimension(50,50)); 91 | JComboBox jComboBox = new JComboBox(); 92 | 93 | jComboBox.addItem(""); 94 | for (Filter filter : Model.getCurrent().getFilters()) { 95 | jComboBox.addItem(filter.getName()); 96 | } 97 | 98 | jComboBox.addActionListener(new ActionListener() { 99 | 100 | @Override 101 | public void actionPerformed(ActionEvent e) { 102 | Filter filter = null; 103 | if (jComboBox.getSelectedIndex() > 0) { 104 | filter = Model.getCurrent().getFilters().get(jComboBox.getSelectedIndex() - 1).createNewFilter(); 105 | FilterBox filterBox = new FilterBox(filter, filterPanel); 106 | createConstraintsFilterBox(filterBoxGridBagLayout, filterBox, 0, i, 1, 1); 107 | jPanel.add(filterBox); 108 | Model.getCurrent().addFilter(filter); 109 | i++; 110 | Model.getCurrent().setSameFile(false); 111 | } 112 | } 113 | }); 114 | 115 | createConstraints(rightBagLayout, jComboBox, 0, 0, 1, 0.1); 116 | createConstraints(rightBagLayout, jScrollPane, 0, 1, 1, 3); 117 | 118 | JPanel bottomPanel = new JPanel(); 119 | bottomPanel.setBackground(MainView.COLOR2); 120 | createConstraints(rightBagLayout, bottomPanel, 0, 2, 1, 1); 121 | 122 | GridBagLayout bottomBagLayout = new GridBagLayout(); 123 | 124 | bottomPanel.setLayout(bottomBagLayout); 125 | 126 | JButton continueButton = new JButton(Dictionary.getCurrent().getString("FilterPanel.BtnContinue"));//$NON-NLS-1$ 127 | continueButton.addActionListener(new ActionListener() { 128 | 129 | @Override 130 | public void actionPerformed(ActionEvent e) { 131 | // svg file erstellen 132 | next(); 133 | } 134 | }); 135 | JButton cleanButton = new JButton(Dictionary.getCurrent().getString("FilterPanel.BtnClear"));//$NON-NLS-1$ 136 | cleanButton.addActionListener(new ActionListener() { 137 | 138 | @Override 139 | public void actionPerformed(ActionEvent e) { 140 | if (delete()) { 141 | Model.getCurrent().removeAllFilter(); 142 | jPanel.removeAll(); 143 | Model.getCurrent().setSameFile(false); 144 | } 145 | } 146 | }); 147 | 148 | createConstraints(bottomBagLayout, cleanButton, 0, 0, 1, 1); 149 | createConstraints(bottomBagLayout, continueButton, 0, 1, 1, 1); 150 | 151 | bottomPanel.add(cleanButton); 152 | bottomPanel.add(continueButton); 153 | 154 | rightPanel.add(jComboBox); 155 | rightPanel.add(jScrollPane); 156 | rightPanel.add(bottomPanel); 157 | } 158 | 159 | private boolean delete() { 160 | String[] optinons = { Dictionary.getCurrent().getString("FilterPanel.OptionYes"), //$NON-NLS-1$ 161 | Dictionary.getCurrent().getString("FilterPanel.OptionNo") }; //$NON-NLS-1$ 162 | int delete = JOptionPane.showOptionDialog(filterPanel.getParent(), 163 | Dictionary.getCurrent().getString("FilterPanel.OptionMessage"), //$NON-NLS-1$ 164 | Dictionary.getCurrent().getString("FilterPanel.OptionName"), JOptionPane.DEFAULT_OPTION, //$NON-NLS-1$ 165 | JOptionPane.WARNING_MESSAGE, null, optinons, optinons[0]); 166 | if (delete == 0) { 167 | return true; 168 | } 169 | return false; 170 | } 171 | 172 | public void removeFilter(FilterBox paramFilterBox) { 173 | Model.getCurrent().removeFilter(paramFilterBox.getFilter()); 174 | jPanel.remove(paramFilterBox); 175 | } 176 | 177 | private void createConstraints(GridBagLayout paramBagLayout, Component paramComponent, int paramx, int paramy, 178 | double paramWeightx, double paramWeighty) { 179 | GridBagConstraints constraintsRight = new GridBagConstraints(); 180 | constraintsRight.insets = new Insets(5, 5, 5, 5); 181 | constraintsRight.gridx = paramx; 182 | constraintsRight.gridy = paramy; 183 | constraintsRight.weightx = paramWeightx; 184 | constraintsRight.weighty = paramWeighty; 185 | constraintsRight.fill = GridBagConstraints.BOTH; 186 | paramBagLayout.setConstraints(paramComponent, constraintsRight); 187 | } 188 | 189 | private void createConstraintsFilterBox(GridBagLayout paramBagLayout, Component paramComponent, int paramx, int paramy, double paramWeightx, double paramWeighty) { 190 | GridBagConstraints constraintsRight = new GridBagConstraints(); 191 | constraintsRight.insets = new Insets(5, 5, 5, 5); 192 | constraintsRight.gridx = paramx; 193 | constraintsRight.gridy = paramy; 194 | constraintsRight.weightx = paramWeightx; 195 | constraintsRight.weighty = paramWeighty; 196 | constraintsRight.fill = GridBagConstraints.HORIZONTAL; 197 | paramBagLayout.setConstraints(paramComponent, constraintsRight); 198 | } 199 | 200 | public void next() { 201 | try { 202 | if (Model.getCurrent().checkIfGrey()) { 203 | String path = Model.getCurrent().saveBMPTemp(); 204 | mainView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 205 | if (path != null) { 206 | try { 207 | String potracePath = SettingsManager.getCurrent().getValue(KEY.POTRACE); 208 | if(potracePath==null || !Files.exists(Paths.get(potracePath))){ 209 | JOptionPane.showMessageDialog(mainView, Dictionary.getCurrent().getString("Potrace.Search")); //$NON-NLS-1$ 210 | potracePath = selectPathForPotrace(); 211 | if(potracePath!=null && Files.exists(Paths.get(potracePath))){ 212 | SettingsManager.getCurrent().setValue(KEY.POTRACE,potracePath); 213 | SettingsManager.getCurrent().save(); 214 | } 215 | } 216 | if(potracePath!=null && Files.exists(Paths.get(potracePath))){ 217 | 218 | if (Model.getCurrent().generateSVGFromBMP(potracePath,path)) { 219 | mainView.previewImage(); 220 | mainView.changePage(mainView.getPreviewPanel()); 221 | }else { 222 | JOptionPane.showConfirmDialog(mainView, Dictionary.getCurrent().getString("SVGConvert.ERROR"), 223 | Dictionary.getCurrent().getString("ERROR"), JOptionPane.CLOSED_OPTION, //$NON-NLS-1$ 224 | JOptionPane.ERROR_MESSAGE); 225 | } 226 | }else { 227 | JOptionPane.showMessageDialog(mainView, Dictionary.getCurrent().getString("Potrace.NotFound")); //$NON-NLS-1$ 228 | } 229 | } finally { 230 | mainView.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 231 | } 232 | } 233 | } else { 234 | JOptionPane.showMessageDialog(mainView, Dictionary.getCurrent().getString("Error.Image.Nogray")); //$NON-NLS-1$ 235 | } 236 | }catch(Exception exc) { 237 | JOptionPane.showMessageDialog(mainView, exc.getMessage()); //$NON-NLS-1$ 238 | } 239 | } 240 | 241 | private String selectPathForPotrace() { 242 | JFileChooser c = new JFileChooser(); 243 | c.setFileFilter(new FileFilter() { 244 | @Override 245 | public String getDescription() { 246 | return "*"; //$NON-NLS-1$ 247 | } 248 | @Override 249 | public boolean accept(File f) { 250 | return !f.isDirectory(); 251 | } 252 | }); 253 | c.setCurrentDirectory(new File(".")); //$NON-NLS-1$ 254 | c.showOpenDialog(mainView); 255 | File file = c.getSelectedFile(); 256 | if(file!=null) { 257 | return file.getAbsolutePath(); 258 | } 259 | return null; 260 | } 261 | 262 | 263 | @Override 264 | public void update() { 265 | filterPanel.validate(); 266 | filterPanel.repaint(); 267 | } 268 | 269 | public ImagePanel getImagePanel() { 270 | return imagePanel; 271 | } 272 | 273 | } 274 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/view/HomePage.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.view; 2 | 3 | import java.awt.GridBagConstraints; 4 | import java.awt.GridBagLayout; 5 | import java.awt.Insets; 6 | 7 | import javax.swing.JPanel; 8 | 9 | public class HomePage extends JPanel { 10 | 11 | private static final long serialVersionUID = 1L; 12 | 13 | public HomePage() { 14 | // Setzt den GridBagLayout als Layoutmanager der HomePage 15 | setLayout(new GridBagLayout()); 16 | 17 | // Linkes Panel 18 | JPanel leftPanel = new JPanel(); 19 | leftPanel.setBackground(MainView.COLOR1); 20 | add(leftPanel, createGbc(0, 0, 3, 1)); 21 | 22 | // Rechtes Panel 23 | JPanel rightPanel = new JPanel(); 24 | rightPanel.setBackground(MainView.COLOR2); 25 | add(rightPanel, createGbc(1, 0, 1, 1)); 26 | } 27 | 28 | /** 29 | * Erstellt und konfiguriert GridBagConstraints. 30 | * 31 | * @param gridx Die Spaltenposition im GridBagLayout. 32 | * @param gridy Die Zeilenposition im GridBagLayout. 33 | * @param weightx Das Gewicht zur Verteilung extra horizontalen Raumes. 34 | * @param weighty Das Gewicht zur Verteilung extra vertikalen Raumes. 35 | * @return Konfiguriertes GridBagConstraints-Objekt. 36 | */ 37 | private GridBagConstraints createGbc(int gridx, int gridy, double weightx, double weighty) { 38 | GridBagConstraints gbc = new GridBagConstraints(); 39 | gbc.gridx = gridx; 40 | gbc.gridy = gridy; 41 | gbc.weightx = weightx; 42 | gbc.weighty = weighty; 43 | gbc.fill = GridBagConstraints.BOTH; 44 | gbc.insets = new Insets(5, 5, 5, 5); 45 | return gbc; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/view/ImagePanel.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.view; 2 | 3 | import java.awt.Graphics; 4 | import java.awt.Image; 5 | 6 | import javax.swing.JPanel; 7 | 8 | import de.revout.pi.vplotter.model.Model; 9 | 10 | public class ImagePanel extends JPanel { 11 | 12 | private static final long serialVersionUID = 1L; 13 | 14 | public ImagePanel() { 15 | super(); 16 | setBackground(MainView.COLOR3); 17 | } 18 | 19 | @Override 20 | protected void paintComponent(Graphics g) { 21 | super.paintComponent(g); 22 | 23 | Image image = Model.getCurrent().getImage(); 24 | if (image == null) { 25 | return; 26 | } 27 | 28 | // Dimensionen des Panels und des Bildes abrufen 29 | int panelWidth = getWidth(); 30 | int panelHeight = getHeight(); 31 | int imageWidth = image.getWidth(null); 32 | int imageHeight = image.getHeight(null); 33 | 34 | // Seitenverhältnis des Bildes und des Panels berechnen 35 | double imageAspect = (double) imageWidth / imageHeight; 36 | double panelAspect = (double) panelWidth / panelHeight; 37 | 38 | // Bestimme die gewünschte Zeichenbreite und -höhe, sodass das Bild passt 39 | int drawWidth, drawHeight; 40 | if (panelAspect > imageAspect) { 41 | // Das Panel ist breiter als das Bild: Höhe als Limit verwenden 42 | drawHeight = panelHeight; 43 | drawWidth = (int) (panelHeight * imageAspect); 44 | } else { 45 | // Das Panel ist schmaler oder gleich proportioniert: Breite als Limit verwenden 46 | drawWidth = panelWidth; 47 | drawHeight = (int) (panelWidth / imageAspect); 48 | } 49 | 50 | // Zentriere das Bild im Panel 51 | int x = (panelWidth - drawWidth) / 2; 52 | int y = (panelHeight - drawHeight) / 2; 53 | 54 | // Zeichne das Bild skaliert und zentriert 55 | g.drawImage(image, x, y, drawWidth, drawHeight, this); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/view/LivePlotterView.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.view; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | import java.awt.Rectangle; 6 | import java.awt.image.BufferedImage; 7 | import java.util.ArrayList; 8 | import javax.swing.JPanel; 9 | import de.revout.pi.vplotter.converter.Pair; 10 | import de.revout.pi.vplotter.main.Driver; 11 | import de.revout.pi.vplotter.main.DriverMoveObserverIf; 12 | 13 | public class LivePlotterView extends JPanel implements DriverMoveObserverIf { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | // Offset (Rand) für die Zeichnung 18 | private final int offset = 2; 19 | // Konstante für den Abzug von der Clip-Größe (vermeidet "Magic Number") 20 | private static final int CLIP_MARGIN = 7; 21 | 22 | // Wird beim ersten Empfang von Bewegungsdaten verwendet, um die Punktliste neu zu initialisieren 23 | private boolean shouldClear = true; 24 | 25 | // Liste der Punktdaten: jedes Element enthält [0] = state, [1] = x, [2] = y 26 | private final ArrayList pointList = new ArrayList<>(); 27 | 28 | // Plotter-Abmessungen (werden bei initialem currentMove aus Driver übernommen) 29 | private double plotterWidth = 1; 30 | private double plotterHeight = 1; 31 | 32 | // Offscreen-BufferedImage als Zeichen-Puffer 33 | private BufferedImage offscreenImage = null; 34 | // Index des letzten Punkts, der in das offscreenImage gezeichnet wurde 35 | private int lastDrawnIndex = -1; 36 | 37 | public LivePlotterView() { 38 | super(); 39 | setBackground(MainView.COLOR3); 40 | // Registriere diesen Beobachter beim Driver 41 | Driver.getCurrent().addDriverMoveObserverIf(this); 42 | } 43 | 44 | @Override 45 | public void currentMove(int state, Pair toPoint, long stepCount, long actualStep) { 46 | synchronized (pointList) { 47 | if (shouldClear) { 48 | pointList.clear(); 49 | shouldClear = false; 50 | double[] plotterSide = Driver.getCurrent().getPlotterSide(); 51 | plotterWidth = plotterSide[0]; 52 | plotterHeight = plotterSide[1]; 53 | // Bei Reset den offscreenBuffer zurücksetzen 54 | offscreenImage = null; 55 | lastDrawnIndex = -1; 56 | } 57 | double[] point = new double[3]; 58 | point[0] = state; 59 | // Transformiere die Koordinaten relativ zum Nullpunkt 60 | point[1] = toPoint.getX() - Driver.getCurrent().getNullPoint().getX(); 61 | point[2] = toPoint.getY() - Driver.getCurrent().getNullPoint().getY(); 62 | pointList.add(point); 63 | } 64 | // Aktualisiere den Offscreen-Buffer inkrementell und repaint() anschließend 65 | updateOffscreenImage(); 66 | repaint(); 67 | } 68 | 69 | /** 70 | * Initialisiert den Offscreen-Puffer in der aktuellen Größe des Panels und füllt ihn mit weißem Hintergrund. 71 | */ 72 | private void initOffscreenImage() { 73 | offscreenImage = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); 74 | Graphics g = offscreenImage.getGraphics(); 75 | g.setColor(Color.WHITE); 76 | g.fillRect(0, 0, getWidth(), getHeight()); 77 | g.dispose(); 78 | lastDrawnIndex = -1; 79 | } 80 | 81 | /** 82 | * Aktualisiert den Offscreen-Puffer, indem nur die neuen Punkte (seit dem letzten Update) 83 | * inkrementell gezeichnet werden. 84 | */ 85 | private void updateOffscreenImage() { 86 | synchronized (pointList) { 87 | // Bei Größenänderung oder falls offscreenImage noch nicht initialisiert ist, neu erstellen 88 | if (offscreenImage == null 89 | || offscreenImage.getWidth() != getWidth() 90 | || offscreenImage.getHeight() != getHeight()) { 91 | initOffscreenImage(); 92 | redrawOffscreenImage(); 93 | return; 94 | } 95 | // Berechne die Skalierung (wie in der Originalvariante) 96 | Rectangle clip = new Rectangle(0, 0, getWidth(), getHeight()); 97 | int clipWidth = clip.width - CLIP_MARGIN; 98 | int clipHeight = clip.height - CLIP_MARGIN; 99 | double scaleX = plotterWidth / clipWidth; 100 | double scaleY = plotterHeight / clipHeight; 101 | double scale = Math.max(scaleX, scaleY); 102 | 103 | Graphics g = offscreenImage.getGraphics(); 104 | g.setColor(Color.BLACK); 105 | int prevX = -1, prevY = -1; 106 | // Hole den letzten gezeichneten Punkt, falls vorhanden 107 | if (lastDrawnIndex >= 0 && lastDrawnIndex < pointList.size()) { 108 | double[] lastPoint = pointList.get(lastDrawnIndex); 109 | prevX = (int) (lastPoint[1] / scale) + offset; 110 | prevY = (int) (lastPoint[2] / scale) + offset; 111 | } 112 | // Zeichne alle neuen Punkte 113 | for (int i = lastDrawnIndex + 1; i < pointList.size(); i++) { 114 | double[] pt = pointList.get(i); 115 | int currentX = (int) (pt[1] / scale) + offset; 116 | int currentY = (int) (pt[2] / scale) + offset; 117 | if (pt[0] == 1 && prevX != -1 && prevY != -1) { 118 | g.drawLine(prevX, prevY, currentX, currentY); 119 | } 120 | prevX = currentX; 121 | prevY = currentY; 122 | lastDrawnIndex = i; 123 | } 124 | g.dispose(); 125 | } 126 | } 127 | 128 | /** 129 | * Redrawt den gesamten Offscreen-Puffer basierend auf allen in pointList gespeicherten Punkten. 130 | * Wird etwa beim Resize oder Neuladen verwendet. 131 | */ 132 | private void redrawOffscreenImage() { 133 | initOffscreenImage(); 134 | int clipWidth = getWidth() - CLIP_MARGIN; 135 | int clipHeight = getHeight() - CLIP_MARGIN; 136 | double scaleX = plotterWidth / clipWidth; 137 | double scaleY = plotterHeight / clipHeight; 138 | double scale = Math.max(scaleX, scaleY); 139 | 140 | Graphics g = offscreenImage.getGraphics(); 141 | g.setColor(Color.BLACK); 142 | int prevX = -1, prevY = -1; 143 | for (double[] pt : pointList) { 144 | int currentX = (int) (pt[1] / scale) + offset; 145 | int currentY = (int) (pt[2] / scale) + offset; 146 | if (pt[0] == 1 && prevX != -1 && prevY != -1) { 147 | g.drawLine(prevX, prevY, currentX, currentY); 148 | } 149 | prevX = currentX; 150 | prevY = currentY; 151 | lastDrawnIndex++; 152 | } 153 | g.dispose(); 154 | } 155 | 156 | @Override 157 | protected void paintComponent(Graphics g) { 158 | super.paintComponent(g); 159 | // Stelle sicher, dass der Offscreen-Puffer existiert und der aktuellen Panel-Größe entspricht 160 | if (offscreenImage == null 161 | || offscreenImage.getWidth() != getWidth() 162 | || offscreenImage.getHeight() != getHeight()) { 163 | initOffscreenImage(); 164 | redrawOffscreenImage(); 165 | } 166 | g.drawImage(offscreenImage, 0, 0, this); 167 | } 168 | 169 | @Override 170 | public void finish() { 171 | shouldClear = true; 172 | } 173 | 174 | @Override 175 | public void init() { 176 | synchronized (pointList) { 177 | pointList.clear(); 178 | } 179 | offscreenImage = null; 180 | lastDrawnIndex = -1; 181 | repaint(); 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/view/LiveView.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.view; 2 | 3 | import java.awt.Color; 4 | import java.awt.Component; 5 | import java.awt.GridBagConstraints; 6 | import java.awt.GridBagLayout; 7 | import java.awt.Insets; 8 | import java.awt.event.ActionEvent; 9 | import java.awt.event.ActionListener; 10 | 11 | import javax.swing.JButton; 12 | import javax.swing.JPanel; 13 | import javax.swing.JProgressBar; 14 | import javax.swing.UIManager; 15 | 16 | import de.revout.pi.vplotter.converter.Pair; 17 | import de.revout.pi.vplotter.lang.Dictionary; 18 | import de.revout.pi.vplotter.main.Driver; 19 | import de.revout.pi.vplotter.main.DriverMoveObserverIf; 20 | import de.revout.pi.vplotter.model.Model; 21 | 22 | public class LiveView extends JPanel implements DriverMoveObserverIf{ 23 | 24 | /** 25 | * 26 | */ 27 | private static final long serialVersionUID = 1L; 28 | private JPanel leftPanel; 29 | private JPanel rightPanel; 30 | private MainView mainView; 31 | private boolean pause; 32 | private JProgressBar progressBar; 33 | private JButton stopButton; 34 | private JButton cancelButton; 35 | private JButton playButton; 36 | 37 | 38 | public LiveView(MainView paramMainview) { 39 | mainView=paramMainview; 40 | UIManager.put("ProgressBar.selectionForeground", Color.BLACK); //$NON-NLS-1$ 41 | UIManager.put("ProgressBar.selectionBackground", Color.BLACK); //$NON-NLS-1$ 42 | 43 | Driver.getCurrent().addDriverMoveObserverIf(this); 44 | 45 | pause = false; 46 | initialize(); 47 | } 48 | 49 | 50 | private void initialize() { 51 | 52 | GridBagLayout filterPanelBagLayout = new GridBagLayout(); 53 | setLayout(filterPanelBagLayout); 54 | 55 | leftPanel = new JPanel(); 56 | leftPanel.setBackground(MainView.COLOR1); 57 | createConstraints(filterPanelBagLayout, leftPanel, 0, 0, 5, 1); 58 | GridBagLayout leftBagLayout = new GridBagLayout(); 59 | leftPanel.setLayout(leftBagLayout); 60 | 61 | rightPanel = new JPanel(); 62 | rightPanel.setBackground(MainView.COLOR2); 63 | createConstraints(filterPanelBagLayout, rightPanel, 1, 0, 1, 1); 64 | GridBagLayout rightBagLayout = new GridBagLayout(); 65 | rightPanel.setLayout(rightBagLayout); 66 | 67 | add(leftPanel); 68 | add(rightPanel); 69 | 70 | LivePlotterView livePlotterView = new LivePlotterView(); 71 | createConstraints(leftBagLayout, livePlotterView, 0, 0, 1, 1); 72 | leftPanel.add(livePlotterView); 73 | 74 | 75 | 76 | JPanel bottomPanel = new JPanel(); 77 | bottomPanel.setBackground(MainView.COLOR2); 78 | createConstraints(rightBagLayout, bottomPanel, 0, 2, 1, 1); 79 | GridBagLayout bottomBagLayout = new GridBagLayout(); 80 | bottomPanel.setLayout(bottomBagLayout); 81 | 82 | progressBar = new JProgressBar(0,100); 83 | progressBar.setStringPainted(true); 84 | progressBar.setForeground(Color.GREEN); 85 | progressBar.setBackground(Color.WHITE); 86 | 87 | stopButton = new JButton(Dictionary.getCurrent().getString("ControlPanel.BtnStop")); //$NON-NLS-1$ 88 | playButton = new JButton(Dictionary.getCurrent().getString("ControlPanel.BtnPause")); //$NON-NLS-1$ 89 | playButton.setEnabled(true); 90 | stopButton.setEnabled(false); 91 | 92 | cancelButton = new JButton(Dictionary.getCurrent().getString("ControlPanel.BtnCancel")); //$NON-NLS-1$ 93 | 94 | stopButton.addActionListener(new ActionListener() { 95 | 96 | @Override 97 | public void actionPerformed(ActionEvent e) { 98 | Driver.getCurrent().stop(); 99 | mainView.changePage(mainView.getFilterPanel()); 100 | stopButton.setEnabled(false); 101 | playButton.setEnabled(true); 102 | playButton.setText(Dictionary.getCurrent().getString("ControlPanel.BtnPause")); //$NON-NLS-1$ 103 | pause = false; 104 | } 105 | }); 106 | 107 | 108 | cancelButton.addActionListener(new ActionListener() { 109 | @Override 110 | public void actionPerformed(ActionEvent e) { 111 | Driver.getCurrent().stop(); 112 | Driver.getCurrent().goTo(Driver.getCurrent().getStartPoint()); 113 | } 114 | }); 115 | 116 | playButton.addActionListener(new ActionListener() { 117 | 118 | @Override 119 | public void actionPerformed(ActionEvent e) { 120 | if(!pause) { 121 | playButton.setText(Dictionary.getCurrent().getString("ControlPanel.BtnContinue")); //$NON-NLS-1$ 122 | stopButton.setEnabled(true); 123 | Driver.getCurrent().setPause(true); 124 | pause = true; 125 | }else { 126 | playButton.setText(Dictionary.getCurrent().getString("ControlPanel.BtnPause")); //$NON-NLS-1$ 127 | Driver.getCurrent().setPause(false); 128 | stopButton.setEnabled(false); 129 | pause = false; 130 | } 131 | 132 | } 133 | }); 134 | 135 | if (Model.getCurrent().getImage()!=null) { 136 | ImagePanel imagePanel = new ImagePanel(); 137 | createConstraints(rightBagLayout, imagePanel, 0, 0, 1, 1,GridBagConstraints.PAGE_START,GridBagConstraints.BOTH); 138 | rightPanel.add(imagePanel); 139 | }else { 140 | PlotterView plotterView = new PlotterView(); 141 | createConstraints(rightBagLayout, plotterView, 0, 0, 1, 1,GridBagConstraints.PAGE_START,GridBagConstraints.BOTH); 142 | rightPanel.add(plotterView); 143 | } 144 | 145 | createConstraints(bottomBagLayout, playButton, 0, 0, 1, 1); 146 | createConstraints(bottomBagLayout, cancelButton, 0, 1, 1, 1); 147 | createConstraints(bottomBagLayout, stopButton, 0, 2, 1, 1); 148 | 149 | createConstraints(rightBagLayout, progressBar, 0, 1, 1, 3,GridBagConstraints.PAGE_END,GridBagConstraints.HORIZONTAL); 150 | 151 | bottomPanel.add(playButton); 152 | bottomPanel.add(cancelButton); 153 | bottomPanel.add(stopButton); 154 | 155 | 156 | rightPanel.add(bottomPanel); 157 | rightPanel.add(progressBar); 158 | } 159 | 160 | @Override 161 | public void init() { 162 | playButton.setEnabled(true); 163 | stopButton.setEnabled(false); 164 | stopButton.setText(Dictionary.getCurrent().getString("ControlPanel.BtnStop")); //$NON-NLS-1$ 165 | progressBar.setValue(0); 166 | } 167 | 168 | @Override 169 | public void currentMove(int paramState, Pair paramToPoint, long paramStepCount, long paramActualStep) { 170 | double progress = ((double)paramActualStep/(double)paramStepCount)*100; 171 | progressBar.setValue((int)progress); 172 | } 173 | 174 | @Override 175 | public void finish() { 176 | progressBar.setValue(101); 177 | stopButton.setText(Dictionary.getCurrent().getString("ControlPanel.BtnFinish")); //$NON-NLS-1$ 178 | playButton.setEnabled(false); 179 | stopButton.setEnabled(true); 180 | } 181 | 182 | 183 | private void createConstraints(GridBagLayout paramBagLayout, Component paramComponent, int paramx, int paramy, 184 | double paramWeightx, double paramWeighty,int paramAnchor,int paramFill) { 185 | GridBagConstraints constraints = new GridBagConstraints(); 186 | constraints.insets = new Insets(5, 5, 5, 5); 187 | constraints.gridx = paramx; 188 | constraints.gridy = paramy; 189 | constraints.weightx = paramWeightx; 190 | constraints.weighty = paramWeighty; 191 | constraints.anchor = paramAnchor; 192 | constraints.fill = paramFill; 193 | paramBagLayout.setConstraints(paramComponent, constraints); 194 | } 195 | 196 | private void createConstraints(GridBagLayout paramBagLayout, Component paramComponent, int paramx, int paramy, 197 | double paramWeightx, double paramWeighty) { 198 | GridBagConstraints constraintsRight = new GridBagConstraints(); 199 | constraintsRight.insets = new Insets(5, 5, 5, 5); 200 | constraintsRight.gridx = paramx; 201 | constraintsRight.gridy = paramy; 202 | constraintsRight.weightx = paramWeightx; 203 | constraintsRight.weighty = paramWeighty; 204 | constraintsRight.fill = GridBagConstraints.BOTH; 205 | paramBagLayout.setConstraints(paramComponent, constraintsRight); 206 | } 207 | 208 | } 209 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/view/MainView.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.view; 2 | 3 | import java.awt.Color; 4 | import java.awt.Cursor; 5 | import java.awt.Desktop; 6 | import java.awt.Graphics; 7 | import java.awt.event.WindowAdapter; 8 | import java.awt.event.WindowEvent; 9 | import java.awt.image.BufferedImage; 10 | import java.io.File; 11 | import java.io.IOException; 12 | import java.util.ArrayList; 13 | import java.util.Arrays; 14 | import java.util.List; 15 | 16 | import javax.imageio.ImageIO; 17 | import javax.swing.JFileChooser; 18 | import javax.swing.JFrame; 19 | import javax.swing.JMenu; 20 | import javax.swing.JMenuBar; 21 | import javax.swing.JMenuItem; 22 | import javax.swing.JOptionPane; 23 | import javax.swing.JPanel; 24 | import javax.swing.event.ChangeListener; 25 | import javax.swing.filechooser.FileFilter; 26 | import javax.swing.filechooser.FileSystemView; 27 | 28 | import de.revout.pi.vplotter.converter.Section; 29 | import de.revout.pi.vplotter.lang.Dictionary; 30 | import de.revout.pi.vplotter.main.Driver; 31 | import de.revout.pi.vplotter.model.Model; 32 | import de.revout.pi.vplotter.saves.SettingsManager; 33 | import de.revout.pi.vplotter.saves.VPlotterPropertiesManager; 34 | import de.revout.pi.vplotter.version.Version; 35 | 36 | public class MainView extends JFrame { 37 | 38 | private static final long serialVersionUID = 1L; 39 | private static final String PROPERTY_SUFFIX = ".plotterconf"; 40 | 41 | public static final Color COLOR1 = new Color(162, 182, 210); 42 | public static final Color COLOR2 = new Color(137, 164, 201); 43 | public static final Color COLOR3 = new Color(171, 198, 222); 44 | 45 | private StackLayout stackLayout; 46 | private JPanel homePage; 47 | private JPanel filterPanel; 48 | private JPanel previewPanel; 49 | private JPanel liveViewPanel; 50 | private JMenuItem loadFileItem; 51 | private JMenuItem newProcessItem; 52 | private JMenuItem goToStartItem; 53 | private JMenu plotterMenu; 54 | private JMenu configMenu; 55 | private JMenu recentFilesMenu; 56 | private JMenu fileMenu; 57 | private List lastFiles; 58 | 59 | public MainView() { 60 | init(); 61 | addWindowListener(new WindowAdapter() { 62 | @Override 63 | public void windowClosing(WindowEvent e) { 64 | Driver.getCurrent().gpioStop(); 65 | } 66 | }); 67 | } 68 | 69 | private void init() { 70 | lastFiles = new ArrayList<>(); 71 | Driver.getCurrent().loadProperty(); 72 | setTitle(Version.number + " " + Dictionary.getCurrent().getString("MainView.TITLE") 73 | + SettingsManager.getCurrent().getValue(SettingsManager.KEY.CONFIG)); 74 | setDefaultCloseOperation(DISPOSE_ON_CLOSE); 75 | setExtendedState(JFrame.MAXIMIZED_BOTH); 76 | createMenu(); 77 | stackLayout = new StackLayout(); 78 | setLayout(stackLayout); 79 | createPages(); 80 | setVisible(true); 81 | } 82 | 83 | private void createPages() { 84 | // Home page 85 | homePage = new HomePage(); 86 | homePage.setBackground(COLOR1); 87 | 88 | // Filter panel 89 | filterPanel = new FilterPanel(this); 90 | filterPanel.setBackground(COLOR1); 91 | 92 | // Preview panel 93 | previewPanel = new PlotterPreview(this); 94 | previewPanel.setBackground(COLOR1); 95 | 96 | // Live view panel 97 | liveViewPanel = new LiveView(this); 98 | liveViewPanel.setBackground(COLOR1); 99 | 100 | // Register pages im StackLayout mit eindeutigen Keys 101 | stackLayout.addLayoutComponent("home", homePage); 102 | stackLayout.addLayoutComponent("filter", filterPanel); 103 | stackLayout.addLayoutComponent("preview", previewPanel); 104 | stackLayout.addLayoutComponent("live", liveViewPanel); 105 | 106 | // Zeige zunächst die Home-Page 107 | changePage(homePage); 108 | } 109 | 110 | public void newProcess() { 111 | Model.getCurrent().newProcess(); 112 | createPages(); 113 | validate(); 114 | repaint(); 115 | } 116 | 117 | public void changePage(JPanel page) { 118 | stackLayout.showComponent(page, this); 119 | boolean used = Driver.getCurrent().isUsed(); 120 | goToStartItem.setEnabled(used); 121 | recentFilesMenu.setEnabled(true); 122 | loadFileItem.setEnabled(true); 123 | newProcessItem.setEnabled(true); 124 | configMenu.setEnabled(true); 125 | plotterMenu.setEnabled(true); 126 | 127 | if (page == homePage) { 128 | newProcessItem.setEnabled(false); 129 | } else { 130 | if (page == filterPanel) { 131 | if (Model.getCurrent().getImage() == null) { 132 | if (Model.getCurrent().getSvgImage() != null) { 133 | changePage(previewPanel); 134 | } else { 135 | changePage(homePage); 136 | } 137 | } 138 | } 139 | recentFilesMenu.setEnabled(false); 140 | loadFileItem.setEnabled(false); 141 | if (page == previewPanel) { 142 | plotterMenu.setEnabled(false); 143 | } 144 | if (page == liveViewPanel) { 145 | configMenu.setEnabled(false); 146 | plotterMenu.setEnabled(false); 147 | } 148 | } 149 | } 150 | 151 | private void createMenu() { 152 | JMenuBar bar = new JMenuBar(); 153 | 154 | fileMenu = new JMenu(Dictionary.getCurrent().getString("MainView.FILE")); 155 | fileMenu.setMnemonic(Dictionary.getCurrent().getString("MainView.Mnemonic.File").charAt(0)); 156 | bar.add(fileMenu); 157 | 158 | configMenu = new JMenu(Dictionary.getCurrent().getString("MainView.CONFIG")); 159 | configMenu.setMnemonic(Dictionary.getCurrent().getString("MainView.Mnemonic.Config").charAt(0)); 160 | bar.add(configMenu); 161 | 162 | plotterMenu = new JMenu(Dictionary.getCurrent().getString("MainView.PLOTTER")); 163 | plotterMenu.setMnemonic(Dictionary.getCurrent().getString("MainView.Mnemonic.Plotter").charAt(0)); 164 | bar.add(plotterMenu); 165 | 166 | // Einfacher Repaint-Listener für alle Menüs 167 | ChangeListener repaintListener = e -> repaint(); 168 | fileMenu.addChangeListener(repaintListener); 169 | configMenu.addChangeListener(repaintListener); 170 | plotterMenu.addChangeListener(repaintListener); 171 | 172 | // Plotter-Menüeinträge 173 | JMenuItem pageLocation = new JMenuItem(Dictionary.getCurrent().getString("MainView.ShowPage")); 174 | pageLocation.addActionListener(e -> { 175 | try { 176 | changePage(getLiveViewPanel()); 177 | Driver.getCurrent().showPageLocation(); 178 | } catch (Exception e1) { 179 | e1.printStackTrace(); 180 | } 181 | goToStartItem.setEnabled(true); 182 | }); 183 | plotterMenu.add(pageLocation); 184 | 185 | JMenuItem testItem = new JMenuItem(Dictionary.getCurrent().getString("MainView.TEST")); 186 | testItem.setMnemonic(Dictionary.getCurrent().getString("MainView.Mnemonic.Test").charAt(0)); 187 | testItem.addActionListener(e -> { 188 | try { 189 | changePage(getLiveViewPanel()); 190 | Driver.getCurrent().test(); 191 | } catch (Exception e1) { 192 | e1.printStackTrace(); 193 | } 194 | goToStartItem.setEnabled(true); 195 | }); 196 | plotterMenu.add(testItem); 197 | 198 | JMenuItem motorsOffItem = new JMenuItem(Dictionary.getCurrent().getString("MainView.OFF")); 199 | motorsOffItem.setMnemonic(Dictionary.getCurrent().getString("MainView.Mnemonic.MotorsOff").charAt(0)); 200 | motorsOffItem.addActionListener(e -> Driver.getCurrent().motorsOff()); 201 | plotterMenu.add(motorsOffItem); 202 | 203 | JMenuItem motorsOnItem = new JMenuItem(Dictionary.getCurrent().getString("MainView.ON")); 204 | motorsOnItem.setMnemonic(Dictionary.getCurrent().getString("MainView.Mnemonic.MotorsOn").charAt(0)); 205 | motorsOnItem.addActionListener(e -> Driver.getCurrent().motorsOn()); 206 | plotterMenu.add(motorsOnItem); 207 | 208 | JMenuItem penAwayItem = new JMenuItem(Dictionary.getCurrent().getString("MainView.PanAway")); 209 | penAwayItem.setMnemonic(Dictionary.getCurrent().getString("MainView.Mnemonic.PanAway").charAt(0)); 210 | penAwayItem.addActionListener(e -> Driver.getCurrent().penAway()); 211 | plotterMenu.add(penAwayItem); 212 | 213 | JMenuItem penDrawItem = new JMenuItem(Dictionary.getCurrent().getString("MainView.PanDraw")); 214 | penDrawItem.setMnemonic(Dictionary.getCurrent().getString("MainView.Mnemonic.PanDraw").charAt(0)); 215 | penDrawItem.addActionListener(e -> Driver.getCurrent().penDraw()); 216 | plotterMenu.add(penDrawItem); 217 | 218 | 219 | goToStartItem = new JMenuItem(Dictionary.getCurrent().getString("MainView.GoToStart")); 220 | goToStartItem.addActionListener(e -> Driver.getCurrent().goTo(Driver.getCurrent().getStartPoint())); 221 | plotterMenu.add(goToStartItem); 222 | goToStartItem.setEnabled(false); 223 | 224 | // File-Menüeinträge 225 | newProcessItem = new JMenuItem(Dictionary.getCurrent().getString("MainView.New")); 226 | newProcessItem.addActionListener(e -> newProcess()); 227 | fileMenu.add(newProcessItem); 228 | 229 | loadFileItem = new JMenuItem(Dictionary.getCurrent().getString("MainView.LoadFile")); 230 | loadFileItem.setMnemonic(Dictionary.getCurrent().getString("MainView.Mnemonic.LoadFile").charAt(0)); 231 | loadFileItem.addActionListener(e -> loadFile()); 232 | fileMenu.add(loadFileItem); 233 | 234 | recentFilesMenu = new JMenu(Dictionary.getCurrent().getString("MainView.RecentUsed")); 235 | recentFilesMenu.setMnemonic(Dictionary.getCurrent().getString("MainView.MnemonicRecentUsed").charAt(0)); 236 | recentFilesMenu.addChangeListener(repaintListener); 237 | fileMenu.add(recentFilesMenu); 238 | 239 | loadRecentFiles(); 240 | 241 | JMenuItem exitItem = new JMenuItem(Dictionary.getCurrent().getString("MainView.EXIT")); 242 | exitItem.setMnemonic(Dictionary.getCurrent().getString("MainView.Mnemonic.Exit").charAt(0)); 243 | exitItem.addActionListener(e -> System.exit(0)); 244 | fileMenu.add(exitItem); 245 | 246 | // Config-Menüeinträge 247 | JMenuItem loadConfigItem = new JMenuItem(Dictionary.getCurrent().getString("MainView.LOAD")); 248 | loadConfigItem.setMnemonic(Dictionary.getCurrent().getString("MainView.Mnemonic.LoadConfig").charAt(0)); 249 | loadConfigItem.addActionListener(e -> loadConfig()); 250 | configMenu.add(loadConfigItem); 251 | 252 | JMenuItem newConfigItem = new JMenuItem(Dictionary.getCurrent().getString("MainView.NEW")); 253 | newConfigItem.setMnemonic(Dictionary.getCurrent().getString("MainView.Mnemonic.NewConfig").charAt(0)); 254 | newConfigItem.addActionListener(e -> newConfig()); 255 | configMenu.add(newConfigItem); 256 | 257 | JMenuItem editConfigItem = new JMenuItem(Dictionary.getCurrent().getString("MainView.EDIT")); 258 | editConfigItem.setMnemonic(Dictionary.getCurrent().getString("MainView.Mnemonic.EditConfig").charAt(0)); 259 | editConfigItem.addActionListener(e -> editConfig()); 260 | configMenu.add(editConfigItem); 261 | 262 | setJMenuBar(bar); 263 | } 264 | 265 | private FileFilter createConfigFileFilter() { 266 | return new FileFilter() { 267 | @Override 268 | public String getDescription() { 269 | return "*" + PROPERTY_SUFFIX; 270 | } 271 | @Override 272 | public boolean accept(File f) { 273 | return f.isDirectory() || f.getName().endsWith(PROPERTY_SUFFIX); 274 | } 275 | }; 276 | } 277 | 278 | private void loadConfig() { 279 | JFileChooser chooser = new JFileChooser(); 280 | chooser.setFileFilter(createConfigFileFilter()); 281 | chooser.setCurrentDirectory(new File("./conf/")); 282 | if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { 283 | File file = chooser.getSelectedFile(); 284 | VPlotterPropertiesManager.getCurrent().load(file); 285 | setTitle(Dictionary.getCurrent().getString("MainView.TITLE") 286 | + SettingsManager.getCurrent().getValue(SettingsManager.KEY.CONFIG)); 287 | } 288 | } 289 | 290 | private void newConfig() { 291 | JFileChooser chooser = new JFileChooser(); 292 | chooser.setFileFilter(createConfigFileFilter()); 293 | chooser.setCurrentDirectory(new File("./conf/")); 294 | if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { 295 | File file = chooser.getSelectedFile(); 296 | if (!file.getName().endsWith(PROPERTY_SUFFIX)) { 297 | file = new File(file.getAbsolutePath() + PROPERTY_SUFFIX); 298 | } 299 | VPlotterPropertiesManager.getCurrent().newConfig(file); 300 | } 301 | } 302 | 303 | private void editConfig() { 304 | JFileChooser chooser = new JFileChooser(); 305 | chooser.setFileFilter(createConfigFileFilter()); 306 | chooser.setCurrentDirectory(new File("./conf/")); 307 | if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { 308 | File file = chooser.getSelectedFile(); 309 | try { 310 | Desktop.getDesktop().open(file); 311 | } catch (IOException ex) { 312 | ex.printStackTrace(); 313 | try { 314 | Runtime.getRuntime().exec("notepad.exe " + file); 315 | } catch (IOException e) { 316 | JOptionPane.showMessageDialog(this, e.getMessage(), 317 | Dictionary.getCurrent().getString("LoadingPanel.Error"), JOptionPane.ERROR_MESSAGE); 318 | e.printStackTrace(); 319 | } 320 | } 321 | } 322 | } 323 | 324 | private void loadFile() { 325 | String oldFile = SettingsManager.getCurrent().getValue(SettingsManager.KEY.FILEPATH); 326 | String filename = getFilePath(); 327 | if (filename == null) { 328 | return; 329 | } 330 | if (!filename.equals(oldFile)) { 331 | if (!lastFiles.contains(filename)) { 332 | lastFiles.add(filename); 333 | saveLastOpenFiles(); 334 | } 335 | Model.getCurrent().setSameFile(false); 336 | } 337 | setImage(filename); 338 | } 339 | 340 | private FileFilter createImageFileFilter() { 341 | return new FileFilter() { 342 | @Override 343 | public String getDescription() { 344 | return Dictionary.getCurrent().getString("LoadingPanel.ChoosePicture"); 345 | } 346 | @Override 347 | public boolean accept(File f) { 348 | String name = f.getName().toLowerCase(); 349 | return f.isDirectory() || name.endsWith(".png") || name.endsWith(".gif") 350 | || name.endsWith(".jpg") || name.endsWith(".jpeg") 351 | || name.endsWith(".bmp") || name.endsWith(".svg"); 352 | } 353 | }; 354 | } 355 | 356 | private String getFilePath() { 357 | JFileChooser chooser = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory()); 358 | String currentPath = SettingsManager.getCurrent().getValue(SettingsManager.KEY.FILEPATH); 359 | if (currentPath != null) { 360 | chooser.setCurrentDirectory(new File(currentPath)); 361 | } 362 | chooser.setFileFilter(createImageFileFilter()); 363 | if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { 364 | File selectedFile = chooser.getSelectedFile(); 365 | try { 366 | SettingsManager.getCurrent().setValue(SettingsManager.KEY.FILEPATH, selectedFile.getPath()); 367 | } catch (IOException e) { 368 | e.printStackTrace(); 369 | } 370 | return selectedFile.getAbsolutePath(); 371 | } 372 | return null; 373 | } 374 | 375 | private void saveLastOpenFiles() { 376 | try { 377 | while (lastFiles.size() > 5) { 378 | lastFiles.remove(0); 379 | } 380 | SettingsManager.getCurrent().setValue(SettingsManager.KEY.LAST_USED, String.join(";", lastFiles)); 381 | SettingsManager.getCurrent().save(); 382 | } catch (IOException e) { 383 | e.printStackTrace(); 384 | } 385 | } 386 | 387 | private void setImage(String filename) { 388 | if (filename.toLowerCase().endsWith(".svg")) { 389 | setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 390 | if (Model.getCurrent().generateDataFromSVG(filename)) { 391 | previewImage(); 392 | changePage(previewPanel); 393 | } 394 | setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 395 | } else { 396 | try { 397 | BufferedImage img = ImageIO.read(new File(filename)); 398 | Model.getCurrent().setImage(img); 399 | Model.getCurrent().setOriginalImage(img); 400 | changePage(filterPanel); 401 | } catch (IOException e) { 402 | e.printStackTrace(); 403 | } 404 | } 405 | } 406 | 407 | private void loadRecentFiles() { 408 | recentFilesMenu.removeAll(); 409 | lastFiles.clear(); 410 | String lastUsed = SettingsManager.getCurrent().getValue(SettingsManager.KEY.LAST_USED); 411 | if (lastUsed != null) { 412 | lastFiles.addAll(Arrays.asList(lastUsed.split(";"))); 413 | } 414 | for (String file : lastFiles) { 415 | JMenuItem item = new JMenuItem(file); 416 | item.addActionListener(e -> setImage(file)); 417 | recentFilesMenu.add(item); 418 | } 419 | } 420 | 421 | public JPanel getHomePage() { 422 | return homePage; 423 | } 424 | 425 | public JPanel getFilterPanel() { 426 | return filterPanel; 427 | } 428 | 429 | public JPanel getPreviewPanel() { 430 | return previewPanel; 431 | } 432 | 433 | public JPanel getLiveViewPanel() { 434 | return liveViewPanel; 435 | } 436 | 437 | public JMenu getPlotterMenu() { 438 | return plotterMenu; 439 | } 440 | 441 | public void previewImage() { 442 | BufferedImage svgImage = Model.getCurrent().getSvgImage(); 443 | if (svgImage == null) return; 444 | Graphics g = svgImage.getGraphics(); 445 | g.setColor(Color.WHITE); 446 | g.fillRect(0, 0, svgImage.getWidth() - 1, svgImage.getHeight() - 1); 447 | g.setColor(Color.BLACK); 448 | Model.getCurrent().setSectionList(Model.getCurrent().createSectionList()); 449 | if (!Model.getCurrent().getSectionList().isEmpty()) { 450 | for (Section sec : Model.getCurrent().getSectionList()) { 451 | int lastX = (int) sec.getX(); 452 | int lastY = (int) sec.getY(); 453 | if (!sec.getLineData().isEmpty()) { 454 | double[] values = Arrays.stream(sec.getLineData().split(" ")) 455 | .mapToDouble(Double::parseDouble) 456 | .toArray(); 457 | for (int i = 0; i < values.length; i += 2) { 458 | int x = (int) values[i]; 459 | int y = (int) values[i + 1]; 460 | g.drawLine(lastX, lastY, x, y); 461 | lastX = x; 462 | lastY = y; 463 | } 464 | } 465 | } 466 | } 467 | g.dispose(); 468 | } 469 | } 470 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/view/PlotterPreview.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.view; 2 | 3 | import java.awt.Component; 4 | import java.awt.GridBagConstraints; 5 | import java.awt.GridBagLayout; 6 | import java.awt.Insets; 7 | import java.awt.event.ActionEvent; 8 | import java.awt.event.ActionListener; 9 | 10 | import javax.swing.JButton; 11 | import javax.swing.JCheckBox; 12 | import javax.swing.JPanel; 13 | import javax.swing.SwingConstants; 14 | 15 | import de.revout.pi.vplotter.converter.VDPConverter; 16 | import de.revout.pi.vplotter.lang.Dictionary; 17 | import de.revout.pi.vplotter.main.Driver; 18 | import de.revout.pi.vplotter.model.Model; 19 | import de.revout.pi.vplotter.saves.SettingsManager; 20 | import de.revout.pi.vplotter.saves.SettingsManager.KEY; 21 | 22 | public class PlotterPreview extends JPanel{ 23 | 24 | /** 25 | * 26 | */ 27 | private static final long serialVersionUID = 1L; 28 | private JPanel leftPanel; 29 | private JPanel rightPanel; 30 | private MainView mainView; 31 | 32 | 33 | public PlotterPreview(MainView paramMainview) { 34 | mainView=paramMainview; 35 | init(); 36 | } 37 | 38 | 39 | private void init() { 40 | 41 | GridBagLayout plotterPreviewBagLayout = new GridBagLayout(); 42 | setLayout(plotterPreviewBagLayout); 43 | 44 | leftPanel = new JPanel(); 45 | leftPanel.setBackground(MainView.COLOR1); 46 | createConstraints(plotterPreviewBagLayout, leftPanel, 0, 0, 5, 1); 47 | GridBagLayout leftBagLayout = new GridBagLayout(); 48 | leftPanel.setLayout(leftBagLayout); 49 | 50 | rightPanel = new JPanel(); 51 | rightPanel.setBackground(MainView.COLOR2); 52 | createConstraints(plotterPreviewBagLayout, rightPanel, 1, 0, 1, 1); 53 | GridBagLayout rightBagLayout = new GridBagLayout(); 54 | rightPanel.setLayout(rightBagLayout); 55 | 56 | add(leftPanel); 57 | add(rightPanel); 58 | 59 | PlotterView plotterView = new PlotterView(); 60 | createConstraints(leftBagLayout, plotterView, 0, 0, 1, 1); 61 | leftPanel.add(plotterView); 62 | 63 | JPanel bottomPanel = new JPanel(); 64 | bottomPanel.setBackground(MainView.COLOR2); 65 | createConstraints(rightBagLayout, bottomPanel, 0, 2, 1, 1); 66 | GridBagLayout bottomBagLayout = new GridBagLayout(); 67 | bottomPanel.setLayout(bottomBagLayout); 68 | 69 | JCheckBox simulationBox = new JCheckBox(Dictionary.getCurrent().getString("OptionPanel.Simulation")); //$NON-NLS-1$ 70 | simulationBox.setBackground(MainView.COLOR2); 71 | simulationBox.setHorizontalAlignment(SwingConstants.CENTER); 72 | simulationBox.addActionListener(new ActionListener() { 73 | @Override 74 | public void actionPerformed(ActionEvent e) { 75 | Driver.getCurrent().setSimulation(simulationBox.isSelected()); 76 | } 77 | }); 78 | 79 | if("true".equals(SettingsManager.getCurrent().getValue(KEY.SIMULATION))) { //$NON-NLS-1$ 80 | simulationBox.setSelected(true); 81 | Driver.getCurrent().setSimulation(true); 82 | }else { 83 | simulationBox.setSelected(false); 84 | Driver.getCurrent().setSimulation(false); 85 | } 86 | 87 | JButton cancelButton = new JButton(Dictionary.getCurrent().getString("OptionPanel.BtnCancel")); //$NON-NLS-1$ 88 | JButton startButton = new JButton(Dictionary.getCurrent().getString("OptionPanel.BtnStart")); //$NON-NLS-1$ 89 | 90 | 91 | startButton.addActionListener(new ActionListener() { 92 | @Override 93 | public void actionPerformed(ActionEvent e) { 94 | try { 95 | Driver.getCurrent().loadProperty(); 96 | mainView.changePage(mainView.getLiveViewPanel()); 97 | Driver.getCurrent().plotte(VDPConverter.buildFromSections(Model.getCurrent().getSectionList())); 98 | 99 | }catch (Exception exc) { 100 | exc.printStackTrace(); 101 | } 102 | } 103 | }); 104 | 105 | cancelButton.addActionListener(new ActionListener() { 106 | @Override 107 | public void actionPerformed(ActionEvent e) { 108 | mainView.changePage(mainView.getFilterPanel()); 109 | } 110 | }); 111 | 112 | createConstraints(bottomBagLayout, startButton, 0, 0, 1, 1); 113 | createConstraints(bottomBagLayout, cancelButton, 0, 1, 1, 1); 114 | createConstraints(rightBagLayout, simulationBox, 0, 1, 1, 4); 115 | 116 | bottomPanel.add(startButton); 117 | bottomPanel.add(cancelButton); 118 | 119 | rightPanel.add(bottomPanel); 120 | rightPanel.add(simulationBox); 121 | } 122 | 123 | 124 | private void createConstraints(GridBagLayout paramBagLayout, Component paramComponent, int paramx, int paramy, 125 | double paramWeightx, double paramWeighty) { 126 | GridBagConstraints constraints = new GridBagConstraints(); 127 | constraints.insets = new Insets(5, 5, 5, 5); 128 | constraints.gridx = paramx; 129 | constraints.gridy = paramy; 130 | constraints.weightx = paramWeightx; 131 | constraints.weighty = paramWeighty; 132 | constraints.fill = GridBagConstraints.BOTH; 133 | paramBagLayout.setConstraints(paramComponent, constraints); 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/view/PlotterView.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.view; 2 | 3 | import java.awt.Graphics; 4 | import java.awt.Image; 5 | import javax.swing.JPanel; 6 | import de.revout.pi.vplotter.model.Model; 7 | 8 | public class PlotterView extends JPanel { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | public PlotterView() { 13 | super(); 14 | setBackground(MainView.COLOR3); 15 | } 16 | 17 | @Override 18 | protected void paintComponent(Graphics g) { 19 | super.paintComponent(g); 20 | 21 | Image svgImage = Model.getCurrent().getSvgImage(); 22 | if (svgImage == null) { 23 | return; 24 | } 25 | 26 | // Abmessungen des Panels und des Bildes abrufen 27 | int panelWidth = getWidth(); 28 | int panelHeight = getHeight(); 29 | int imageWidth = svgImage.getWidth(null); 30 | int imageHeight = svgImage.getHeight(null); 31 | 32 | // Errechne das Seitenverhältnis des Bildes 33 | double imageAspect = (double) imageWidth / imageHeight; 34 | 35 | // Bestimme die Zielabmessungen, sodass das Bild vollständig in das Panel passt 36 | int drawWidth, drawHeight; 37 | if ((double)panelWidth / panelHeight > imageAspect) { 38 | // Höhe ist das begrenzende Element 39 | drawHeight = panelHeight; 40 | drawWidth = (int) (panelHeight * imageAspect); 41 | } else { 42 | // Breite ist das begrenzende Element 43 | drawWidth = panelWidth; 44 | drawHeight = (int) (panelWidth / imageAspect); 45 | } 46 | 47 | // Berechne den Offset zur Zentrierung des Bildes im Panel 48 | int xOffset = (panelWidth - drawWidth) / 2; 49 | int yOffset = (panelHeight - drawHeight) / 2; 50 | 51 | // Zeichne das Bild skaliert und zentriert 52 | g.drawImage(svgImage, xOffset, yOffset, drawWidth, drawHeight, this); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/view/StackLayout.java: -------------------------------------------------------------------------------- 1 | package de.revout.pi.vplotter.view; 2 | 3 | import java.awt.Component; 4 | import java.awt.Container; 5 | import java.awt.Dimension; 6 | import java.awt.Insets; 7 | import java.awt.LayoutManager; 8 | 9 | class StackLayout implements LayoutManager { 10 | 11 | /** Standardgröße für einen leeren Container */ 12 | private static final Dimension EMPTY_SIZE = new Dimension(100, 100); 13 | 14 | /** Aktuell sichtbare Komponente oder null, wenn keine Komponente sichtbar ist */ 15 | private Component visibleComponent = null; 16 | 17 | /** 18 | * Zeigt die übergebene Komponente im Container an. 19 | * Ist der Parameter null, so werden alle enthaltenen Komponenten versteckt. 20 | * 21 | * @param comp die anzuzeigende Komponente 22 | * @param parent der übergeordnete Container 23 | */ 24 | public void showComponent(Component comp, Container parent) { 25 | if (visibleComponent != comp) { 26 | if (comp != null && !parent.isAncestorOf(comp)) { 27 | parent.add(comp); 28 | } 29 | synchronized (parent.getTreeLock()) { 30 | if (visibleComponent != null) { 31 | visibleComponent.setVisible(false); 32 | } 33 | visibleComponent = comp; 34 | if (comp != null) { 35 | comp.setVisible(true); 36 | } 37 | // Aktualisiert das Layout des Containers 38 | parent.validate(); // Alternativ: parent.revalidate(); 39 | } 40 | } 41 | } 42 | 43 | /** 44 | * Liefert die aktuell sichtbare Komponente. 45 | * 46 | * @return die sichtbare Komponente oder null 47 | */ 48 | public Component getVisibleComponent() { 49 | return visibleComponent; 50 | } 51 | 52 | @Override 53 | public void addLayoutComponent(String name, Component comp) { 54 | synchronized (comp.getTreeLock()) { 55 | comp.setVisible(false); 56 | // Wenn diese Komponente bereits als sichtbar markiert war, aufheben 57 | if (comp == visibleComponent) { 58 | visibleComponent = null; 59 | } 60 | } 61 | } 62 | 63 | @Override 64 | public void removeLayoutComponent(Component comp) { 65 | synchronized (comp.getTreeLock()) { 66 | if (comp == visibleComponent) { 67 | visibleComponent = null; 68 | } 69 | // Entfernte Komponente wird wieder sichtbar geschaltet, 70 | // um Problemen mit versteckten Komponenten vorzubeugen. 71 | comp.setVisible(true); 72 | } 73 | } 74 | 75 | @Override 76 | public void layoutContainer(Container parent) { 77 | if (visibleComponent != null) { 78 | synchronized (parent.getTreeLock()) { 79 | Insets insets = parent.getInsets(); 80 | int width = parent.getWidth() - insets.left - insets.right; 81 | int height = parent.getHeight() - insets.top - insets.bottom; 82 | visibleComponent.setBounds(insets.left, insets.top, width, height); 83 | } 84 | } 85 | } 86 | 87 | @Override 88 | public Dimension minimumLayoutSize(Container parent) { 89 | return (visibleComponent == null) ? EMPTY_SIZE : preferredLayoutSize(parent); 90 | } 91 | 92 | @Override 93 | public Dimension preferredLayoutSize(Container parent) { 94 | Dimension currentSize = parent.getSize(); 95 | if (visibleComponent != null) { 96 | Dimension compPrefSize = visibleComponent.getPreferredSize(); 97 | currentSize.width = Math.max(currentSize.width, compPrefSize.width); 98 | currentSize.height = Math.max(currentSize.height, compPrefSize.height); 99 | } else if (currentSize.width == 0 || currentSize.height == 0) { 100 | return EMPTY_SIZE; 101 | } 102 | return currentSize; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/de/revout/pi/vplotter/view/close2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RevoutIT/pivplotter/79397ee6e475511b5be29a30ebae6be5e77efed1/src/main/java/de/revout/pi/vplotter/view/close2.png -------------------------------------------------------------------------------- /src/main/resources/de/revout/pi/vplotter/resources/lang/messages.properties: -------------------------------------------------------------------------------- 1 | ControlPanel.BtnCancel=Cancel 2 | ControlPanel.BtnContinue=Continue 3 | ControlPanel.BtnFinish=Finish 4 | ControlPanel.BtnPause=Pause 5 | ControlPanel.BtnStop=Stop 6 | EdgeDetectionFilter.SettingsName=Threshold 7 | FilterBox.BtnRemove=Remove\! 8 | FilterPanel.BtnCancel=Cancel 9 | FilterPanel.BtnClear=Clear All 10 | FilterPanel.BtnContinue=Continue 11 | FilterPanel.OptionMessage=All filters will be removed. Continue? 12 | FilterPanel.OptionName=Clear Filters 13 | FilterPanel.OptionNo=No 14 | FilterPanel.OptionYes=Yes 15 | GrayscaleFilter.Cut=Cut 16 | GrayscaleFilter.FilterName=Grayscale Filter 17 | GrayscaleFilter.SettingsName=Algorithm 18 | MainView.CONFIG=Configuration 19 | MainView.EDIT=Edit Configuration 20 | MainView.EXIT=Exit 21 | MainView.FILE=File 22 | MainView.Filter=Filter 23 | MainView.LOAD=Load Configuration 24 | MainView.LoadFile=Load File 25 | MainView.New=New 26 | MainView.Mnemonic.Config=k 27 | MainView.Mnemonic.EditConfig=e 28 | MainView.Mnemonic.Exit=x 29 | MainView.Mnemonic.File=f 30 | MainView.Mnemonic.Filter=f 31 | MainView.Mnemonic.LoadConfig=l 32 | MainView.Mnemonic.LoadFile=l 33 | MainView.Mnemonic.MotorsOff=o 34 | MainView.Mnemonic.MotorsOn=e 35 | MainView.Mnemonic.NewConfig=n 36 | MainView.Mnemonic.Picture=p 37 | MainView.Mnemonic.Plotter=p 38 | MainView.Mnemonic.Test=t 39 | MainView.Mnemonic.PanAway=q 40 | MainView.Mnemonic.PanDraw=w 41 | MainView.MnemonicRecentUsed=z 42 | MainView.NEW=New Configuration 43 | MainView.OFF=Turn Motors Off 44 | MainView.ON=Turn Motors On 45 | MainView.PanAway=Pen Up 46 | MainView.PanDraw=Pen Down 47 | MainView.GoToStart=Go to Start Point 48 | MainView.Picture=Picture 49 | MainView.PLOTTER=Plotter 50 | MainView.RecentUsed=Recently Used 51 | MainView.TEST=Test 52 | MainView.ShowPage=Paper Marking 53 | MainView.TITLE=PiVPlotter | Loaded Configuration: 54 | OptionPanel.BtnCancel=Cancel 55 | OptionPanel.BtnStart=Start 56 | OptionPanel.Simulation=Simulation 57 | RotateFilter.FilterName=Rotation Filter 58 | RotateFilter.SettingsName=Rotation Angle 59 | LoadingPanel.ChoosePicture=.png .gif .jpg .jpeg .bmp .svg 60 | Error.Image.Nogray=The image is not a grayscale image. Please apply the grayscale filter! 61 | Potrace.Search=To convert to SVG, the Potrace program is required. In the next window, locate where the program is saved on your computer. 62 | Potrace.NotFound=The Potrace program could not be found. Without it, only SVG images can be processed! 63 | SVGConvert.ERROR=The image could not be converted to SVG. Try applying the grayscale filter! 64 | ERROR=Error 65 | -------------------------------------------------------------------------------- /src/main/resources/de/revout/pi/vplotter/resources/lang/messages_de_DE.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RevoutIT/pivplotter/79397ee6e475511b5be29a30ebae6be5e77efed1/src/main/resources/de/revout/pi/vplotter/resources/lang/messages_de_DE.properties --------------------------------------------------------------------------------