diff options
| author | MenTaLguY <mental@rydia.net> | 2006-01-16 02:36:01 +0000 |
|---|---|---|
| committer | mental <mental@users.sourceforge.net> | 2006-01-16 02:36:01 +0000 |
| commit | 179fa413b047bede6e32109e2ce82437c5fb8d34 (patch) | |
| tree | a5a6ac2c1708bd02288fbd8edb2ff500ff2e0916 /src/extension/dxf2svg | |
| download | inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.tar.gz inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.zip | |
moving trunk for module inkscape
(bzr r1)
Diffstat (limited to 'src/extension/dxf2svg')
| -rw-r--r-- | src/extension/dxf2svg/GPL.txt | 340 | ||||
| -rw-r--r-- | src/extension/dxf2svg/LGPL.txt | 504 | ||||
| -rw-r--r-- | src/extension/dxf2svg/Makefile | 21 | ||||
| -rw-r--r-- | src/extension/dxf2svg/README | 41 | ||||
| -rw-r--r-- | src/extension/dxf2svg/aci2rgb.cpp | 114 | ||||
| -rw-r--r-- | src/extension/dxf2svg/blocks.cpp | 88 | ||||
| -rw-r--r-- | src/extension/dxf2svg/blocks.h | 38 | ||||
| -rw-r--r-- | src/extension/dxf2svg/dxf2svg.cpp | 106 | ||||
| -rw-r--r-- | src/extension/dxf2svg/dxf_input.inx | 16 | ||||
| -rw-r--r-- | src/extension/dxf2svg/dxf_input_windows.inx | 17 | ||||
| -rw-r--r-- | src/extension/dxf2svg/entities.cpp | 1031 | ||||
| -rw-r--r-- | src/extension/dxf2svg/entities.h | 256 | ||||
| -rw-r--r-- | src/extension/dxf2svg/entities2elements.cpp | 681 | ||||
| -rw-r--r-- | src/extension/dxf2svg/entities2elements.h | 53 | ||||
| -rw-r--r-- | src/extension/dxf2svg/read_dxf.cpp | 273 | ||||
| -rw-r--r-- | src/extension/dxf2svg/read_dxf.h | 31 | ||||
| -rw-r--r-- | src/extension/dxf2svg/tables.cpp | 211 | ||||
| -rw-r--r-- | src/extension/dxf2svg/tables.h | 71 | ||||
| -rw-r--r-- | src/extension/dxf2svg/tables2svg_info.cpp | 35 | ||||
| -rw-r--r-- | src/extension/dxf2svg/tables2svg_info.h | 9 | ||||
| -rw-r--r-- | src/extension/dxf2svg/test_dxf.cpp | 99 |
21 files changed, 4035 insertions, 0 deletions
diff --git a/src/extension/dxf2svg/GPL.txt b/src/extension/dxf2svg/GPL.txt new file mode 100644 index 000000000..3912109b5 --- /dev/null +++ b/src/extension/dxf2svg/GPL.txt @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/src/extension/dxf2svg/LGPL.txt b/src/extension/dxf2svg/LGPL.txt new file mode 100644 index 000000000..8add30ad5 --- /dev/null +++ b/src/extension/dxf2svg/LGPL.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + <one line to give the library's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + <signature of Ty Coon>, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/src/extension/dxf2svg/Makefile b/src/extension/dxf2svg/Makefile new file mode 100644 index 000000000..d0f06daf0 --- /dev/null +++ b/src/extension/dxf2svg/Makefile @@ -0,0 +1,21 @@ +objs = read_dxf.o entities.o entities2elements.o tables.o tables2svg_info.o blocks.o +flags = -O1 + +dxf2svg : dxf2svg.cpp $(objs) + g++ $(flags) -o dxf2svg dxf2svg.cpp $(objs) + +test : test_dxf.cpp $(objs) + g++ $(flags) -o test test_dxf.cpp $(objs) + +%.o : %.cpp %.h + g++ $(flags) -c $< + +clean : + rm dxf2svg $(objs) + +install: + echo ****User intervention required**** + echo + echo Copy dxf2svg executable and dxf2svg.inx to share/extension directory + echo Make sure file permissions are set correctly + diff --git a/src/extension/dxf2svg/README b/src/extension/dxf2svg/README new file mode 100644 index 000000000..dbf98d2cc --- /dev/null +++ b/src/extension/dxf2svg/README @@ -0,0 +1,41 @@ +26 Aug 05 + +To use: +I have only gotten this to work with Inkscape under linux (debian sarge). But the converter works from the commandline if you want to test it otherwise. + +1. Run make and copy dxf2svg to somewhere that is looked at by the PATH variable. Or add the current directory to your path +2. Copy the dxf_import.inx to ../Inkscape/share/extensions +3. Run Inkscape +4. Click on open or import and the dxf option should be there + +I have compiled and then succesfully converted dxf files to svg files with the following setups + +WinXP Pro, Cygwin, g++ 3.3.3 +Debian Sarge, AMD x86_64, g++ 4.0.2 +RedHat(?), x86(?), g++ 3.2.3 + +I have weakly tried and failed to compile using +Borland's free compiler bcc32 +MinGW + +What is supported: +polylines, lines, arc, circles, blocks, text, and a little linetypes + +currently not supported but I hope will be in the near future (probably after Sept 05) +layers, colors, trace, splines, dimentions + +If you don't have dxf files of your own, but would like to easily test some I would suggest a few places... + +www.newfocus.com -- look under optomechanics. There are a variety of mounts and such that are posted in dxf and pdf +www.thorlabs.com -- dido what I said about newfocus + +Free CAD programs: +Windows -- A free and not too bad CAD program for windows is CadStd Lite. It exports to dxf and has a variety of samples. +Windows/Linux -- QCad is ok. It has a lot of nice features but when I used it a year ago it would import dxf files but then you couldn't edit what was imported. It is free but with a time limit. My experience is that it can be a little annoying. Because of that and others comments I didn't use their libraries for dxf reading. + + +Matt Squires +squiresm@colorado.edu + +27 Aug 05, Fixed a fair number of bugs, and broken conversions. LWPOLYLINE works now, text rotation is ok but needs multiple transfomations to get it right, can read broken dxf files (w/o dxf EOF information) + diff --git a/src/extension/dxf2svg/aci2rgb.cpp b/src/extension/dxf2svg/aci2rgb.cpp new file mode 100644 index 000000000..57e488bfc --- /dev/null +++ b/src/extension/dxf2svg/aci2rgb.cpp @@ -0,0 +1,114 @@ +#include <iostream> +#include <sstream> +#include <string> + + +char* RGB(double R, double G, double B); +char* RGB(double R, double G, double B){ + int r = int (R); + int g = int (G); + int b = int (B); + + char out[6]; + char *chr_ptr; + string output; + stringstream oss; + + if (r < 16 ){ + oss << 0; + } + oss << hex << r; + + if (g < 16 ){ + oss << 0; + } + oss << hex << g; + + if (b < 16 ){ + oss << 0; + } + oss << hex << b; + + output = oss.str(); + + for (int i = 0; i < 6; i++){ + out[i] = output[i]; + } + chr_ptr = &out; + return chr_ptr; +} + + +float aci_to_rgb(int aci); + +float aci_to_rgb(int aci) + { + aci = abs(aci); // hidden layers have negative color values + if (aci<10 || aci>249) // values of these ranges are special colors + { + switch (aci) + { + case 1: return RGB(255,0,0); // basic colors + case 2: return RGB(255,255,0); + case 3: return RGB(0,255,0); + case 4: return RGB(0,255,255); + case 5: return RGB(0,0,255); + case 6: return RGB(255,0,255); + case 7: return RGB(255,255,255); + case 8: return RGB(128,128,128); + case 9: return RGB(192,192,192); + case 250: return RGB(51,51,51); // grey shades + case 251: return RGB(91,91,91); + case 252: return RGB(132,132,132); + case 253: return RGB(173,173,173); + case 254: return RGB(214,214,214); + case 255: return RGB(255,255,255); + case 256: // "by layer" + // Here you should decide how to handle "by layer" logical color. + // Maybe it is a good idea to return a value like -1. + // The outer code will find what is the color of the layer which + // this entity belongs to. + return -1; + } + } + // for all the rest of ACI codes + float H,S,L, R,G,B; + int remainder = aci % 10; + H = 1.5f * (aci - remainder - 10); // hue in range 0-360 + S = ((aci % 2) ? 0.5f : 1.0f); // odd colors have 50% of saturation, even - 100% + // set lighteness, the last digit of aci code stands for this + if (reminder == 0 || reminder == 1) L = 1.0f; + if (reminder == 2 || reminder == 3) L = 0.8f; + if (reminder == 4 || reminder == 5) L = 0.6f; + if (reminder == 6 || reminder == 7) L = 0.5f; + if (reminder == 8 || reminder == 9) L = 0.3f; + // here we have H,S,L set already + // let's convert it to RGB, first without consideration of S and L + if (H<=120) + { + R = (120-H)/60; + G = H/60; + B = 0; + } + if (H>120 && H<=240) + { + R = 0; + G = (240-H)/60; + B = (H-120)/60; + } + if (H>240 && H<=360) + { + R = (H-240)/60; + G = 0; + B = (360-H)/60; + } + R = min(R, 1); + G = min(G, 1); + B = min(B, 1); + // influence of S and L + float max_value = max(R,max(G,B)); + R = (max_value-S*(max_value-R)) * L * 255; + G = (max_value-S*(max_value-G)) * L * 255; + B = (max_value-S*(max_value-B)) * L * 255; + return RGB(R,G,B); + }
\ No newline at end of file diff --git a/src/extension/dxf2svg/blocks.cpp b/src/extension/dxf2svg/blocks.cpp new file mode 100644 index 000000000..75f348bde --- /dev/null +++ b/src/extension/dxf2svg/blocks.cpp @@ -0,0 +1,88 @@ +/* + * Read Blocks from file and convert to vectors of entities + * + * Author: + * Matt Squires <squiresm@colorado.edu> + * + * Copyright (C) 2005 Matt Squires + * + * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details + */ + + +#include"blocks.h" +#include<iostream> + +block::block(std::vector< std::vector< dxfpair > > sections) : entities( sections ){ + // Inherit most of the functionality of the entitites section + + basic_entity( sections[0] ); + block_info( sections[0] ); +} + +char* block::name(char* string){ + return( strcpy(string,block_name) ); +} + + +void block::block_info( std::vector< dxfpair > info){ + static char string[10000]; + for (int i = 0; i < info.size(); i++){ + switch( info[i].group_code ){ + case 2: // Block name + strcpy( string," "); // Clear the string out + info[i].value_char(string); + strcpy(block_name,string); + break; + } + } +} + + + + + + +blocks::blocks(std::vector< std::vector< dxfpair > > sections){ + // Read the main information about the entities section and then put it in the enetites class + int value; + char string[10000]; + std::vector< dxfpair > single_line; + std::vector< std::vector< dxfpair > > ents; + ents.clear(); + single_line.clear(); + + int n_loop = sections.size(); + n_loop--; + //for(int i = 0; i < (sections.size()-1); i++){ // It is odd but the last value seems to be bad so don't use it + // I am not really sure if I need the -1. I needed it once upon a time to make things work but I don't have time to test it well right now + // But sections.size() is an unsigned int so when you subtract 1 it becomes 4294967295 and tries to run the loop so work around that by making n_loop that is signed + for(int i = 0; i < n_loop; i++){ // It is odd but the last value seems to be bad so don't use it + sections[i][0].value_char(string); + ents.clear(); // First clear out the pline information + + + // Get everything from the start of the BLOCK designation to an ENDBLK value + if ( strncmp(string,"BLOCK",5) == 0 && (i < sections.size())){ + do{ + ents.push_back( sections[i] ); + sections[++i][0].value_char(string); + }while( strncmp(string,"ENDBLK",6) != 0 && (i < sections.size()-1) ); + blocks_blocks.push_back( block( ents ) ); + } + } +} + +block blocks::ret_block(char block_name[10000]){ + int string_len = 0; + char temp[10000]; + + for (int i = 0; i < blocks_blocks.size();i++){ + string_len = strlen(blocks_blocks[i].name(temp)); + if (strncmp(blocks_blocks[i].name(temp),block_name,string_len) == 0 ) return blocks_blocks[i]; + } + return blocks_blocks[0]; +} + + + diff --git a/src/extension/dxf2svg/blocks.h b/src/extension/dxf2svg/blocks.h new file mode 100644 index 000000000..27e0b8be1 --- /dev/null +++ b/src/extension/dxf2svg/blocks.h @@ -0,0 +1,38 @@ +/* Read Blocks from file and convert to vectors of entities +Matt Squires +Google SOC 2005 +*/ + +#ifndef DXF_BLOCKS_H +#define DXF_BLOCKS_H + +#include"read_dxf.h" +#include"entities.h" +#include<vector> + + +class block : public entity, public entities{// : public entities, { + public: + block( std::vector< std::vector< dxfpair > > sections ); // Group all of the blocks as entities + char* name(char* string); + //void blocks_display(); + + + protected: + char block_name[10000]; + double rotation; + + private: + void block_info(std::vector< dxfpair > info); +}; + +class blocks{ + public: + blocks(std::vector< std::vector< dxfpair > > sections); + block ret_block(char block_name[10000]); + + protected: + std::vector< block > blocks_blocks; +}; + +#endif diff --git a/src/extension/dxf2svg/dxf2svg.cpp b/src/extension/dxf2svg/dxf2svg.cpp new file mode 100644 index 000000000..7606e3531 --- /dev/null +++ b/src/extension/dxf2svg/dxf2svg.cpp @@ -0,0 +1,106 @@ +/* + * Build a SVG from an dxf, will support conversion to Inkscape types + * + * Author: + * Matt Squires <squiresm@colorado.edu> + * + * Copyright (C) 2005 Matt Squires + * + * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details + */ + + +#include<fstream> +#include<iostream> +#include"read_dxf.h" +#include"entities.h" +#include"blocks.h" +#include"entities2elements.h" + + + + + + + + +int main(int argc,char *argv[]){ + // Later include options for different conversions like converting as much as possible into paths + int ink = 1; // Assume for now there is no inkscape stuff to add extra + + if(argc > 1){ + double scaling = 90; // converstion from in to pt + + // Read the DXF file + std::vector< std::vector< dxfpair > > output, entities_info, tables_info, blocks_info; + //std::cout << "About to read file \n" << std::endl; + output = dxf_get_sections(argv[1]); + //std::cout << "Finished reading file \n" << std::endl; + + entities_info = separate_parts(output[4]); // Entities is the 5th part of the file. + entities ents(entities_info); // Sort entities into their respective parts + + tables_info = separate_parts(output[2]); // Tables is the 3rd part of a dxf file. + tables tbls(tables_info); // Sort the information in the tables + + blocks_info = separate_parts(output[3]); // Tables is the 4th part of a dxf file. + blocks blks(blocks_info); // Sort the information in the tables + + + + // Get the various file informations + /*std::vector< polyline > plines = ents.ret_plines(); + std::vector< lwpolyline > lwplines = ents.ret_lwplines(); + std::vector< arc > arcs = ents.ret_arcs(); + std::vector< circle > circs = ents.ret_circles(); + std::vector< line > lns = ents.ret_lines(); + std::vector< text > txts = ents.ret_texts(); + std::vector< insert > ins = ents.ret_inserts(); + */ + + + std::vector< layer > layers = tbls.ret_layers(); + + char units[5] = "in"; + char tmp_char[100000]; + char layer_string[500]; + + if (ink < 1){ + // Write a general svg header + std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n\t\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns=\"http://www.w3.org/2000/svg\"\n\txmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"; + std::cout << "\tx=\"0.00000000\"\n\ty=\"0.00000000\"\n\twidth=\"744.09448\"\n\theight=\"-1052.3622\"" << std::endl; + } + else{ + std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" << std::endl; + std::cout << "<!-- Created with dxf2svg -->" << std::endl; + std::cout << "<svg" << std::endl; + std::cout << "\txmlns:dc=\"http://purl.org/dc/elements/1.1/\"" << std::endl; + std::cout << "\txmlns:cc=\"http://web.resource.org/cc/\"" << std::endl; + std::cout << "\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"" << std::endl; + std::cout << "\txmlns:svg=\"http://www.w3.org/2000/svg\"" << std::endl; + std::cout << "\txmlns=\"http://www.w3.org/2000/svg\"" << std::endl; + std::cout << "\txmlns:sodipodi=\"http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd\"" << std::endl; + std::cout << "\txmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"" << std::endl; + std::cout << "\t>" << std::endl; + + } + + + // Now write SVG elements to file + if ( layers.size() < 1 ){ + write_all(0, ents, tbls, blks, scaling, units, tmp_char); + } + else{ + for (int i = 0; i < layers.size(); i++){ + std::cout << "\t<g\n\t\tinkscape:label=\"" << layers[i].name(layer_string) << "\"\n\t\tinkscape:groupmode=\"layer\"\n\t\tid=\"layer" << i+1 << "\">" << std::endl; + write_by_layer(0, ents, tbls, blks, scaling, units, layers[i].name(layer_string), tmp_char); + std::cout << "\t</g>" << std::endl; + } + } + + // Close SVG + std::cout << "</svg>"; + } + + return 0; +} diff --git a/src/extension/dxf2svg/dxf_input.inx b/src/extension/dxf2svg/dxf_input.inx new file mode 100644 index 000000000..b96274ade --- /dev/null +++ b/src/extension/dxf2svg/dxf_input.inx @@ -0,0 +1,16 @@ +<inkscape-extension> + <name>DXF Input</name> + <id>org.inkscape.input.dxf</id> + <dependency type="executable" description="dxf2svg may come with Inkscape, but is also at http://dxf-svg-convert.sourceforge.net/" location="extensions">dxf2svg</dependency> + <dependency type="extension">org.inkscape.input.svg</dependency> + <input> + <extension>.dxf</extension> + <mimetype>image/x-svgz</mimetype> + <filetypename>AutoCAD DXF (*.dxf)</filetypename> + <filetypetooltip>Import AutoCAD's Document Exchange Format</filetypetooltip> + <output_extension>org.inkscape.output.svg</output_extension> + </input> + <script> + <command reldir="extensions">dxf2svg</command> + </script> +</inkscape-extension> diff --git a/src/extension/dxf2svg/dxf_input_windows.inx b/src/extension/dxf2svg/dxf_input_windows.inx new file mode 100644 index 000000000..7dbe6a11b --- /dev/null +++ b/src/extension/dxf2svg/dxf_input_windows.inx @@ -0,0 +1,17 @@ +<inkscape-extension> + <name>DXF Input</name> + <id>org.inkscape.input.dxf</id> + <dependency type="executable" description="dxf2svg may come with Inkscape, but is also at +http://dxf-svg-convert.sourceforge.net/" location="extensions">dxf2svg.exe</dependency> + <dependency type="extension">org.inkscape.input.svg</dependency> + <input> + <extension>.dxf</extension> + <mimetype>image/x-svgz</mimetype> + <filetypename>AutoCAD DXF (*.dxf)</filetypename> + <filetypetooltip>Import AutoCAD's Document Exchange Format</filetypetooltip> + <output_extension>org.inkscape.output.svg</output_extension> + </input> + <script> + <command reldir="extensions">dxf2svg.exe</command> + </script> +</inkscape-extension> diff --git a/src/extension/dxf2svg/entities.cpp b/src/extension/dxf2svg/entities.cpp new file mode 100644 index 000000000..d0d33503e --- /dev/null +++ b/src/extension/dxf2svg/entities.cpp @@ -0,0 +1,1031 @@ +/* + * Class for interpereting the entities found in a DXF file + * + * Author: + * Matt Squires <squiresm@colorado.edu> + * + * Copyright (C) 2005 Matt Squires + * + * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details + */ + + +#include"entities.h" +#include<iostream> +#include<math.h> + +int detmine_entity(char* value){ + // Common Elements as far as I am concerend + if ( strncmp(value,"POLYLINE",8) == 0 ) return 0; + if ( strncmp(value,"ARC",3) == 0 ) return 1; + if ( strncmp(value,"CIRCLE",6) == 0 ) return 2; + if ( strncmp(value,"LINE",4) == 0 ) return 3; + if ( strncmp(value,"SPLINE",6) == 0 ) return 4; + if ( strncmp(value,"XLINE",5) == 0 ) return 5; + if ( strncmp(value,"RAY",3) == 0 ) return 6; + if ( strncmp(value,"DIMENSION",9) == 0 ) return 7; + if ( strncmp(value,"ELLIPSE",7) == 0 ) return 8; + if ( strncmp(value,"INSERT",6) == 0 ) return 9; + if ( strncmp(value,"VERTEX",6) == 0 ) return 10; + if ( strncmp(value,"TEXT",4) == 0 ) return 11; + + // Less Common eletities as far as I am concerend + if ( strncmp(value,"3DSOLID",7) == 0 ) return 12; + if ( strncmp(value,"ACAD_PROXY_ENTITY",17) == 0 ) return 13; + if ( strncmp(value,"ARCALIGNEDTEXT",14) == 0 ) return 14; + if ( strncmp(value,"ATTDEF",6) == 0 ) return 15; + if ( strncmp(value,"ATTRIB",6) == 0 ) return 16; + if ( strncmp(value,"BODY",4) == 0 ) return 17; + if ( strncmp(value,"HATCH",5) == 0 ) return 18; + if ( strncmp(value,"IMAGE",5) == 0 ) return 19; + if ( strncmp(value,"LEADER",6) == 0 ) return 20; + if ( strncmp(value,"LWPOLYLINE",10) == 0 ) return 21; + if ( strncmp(value,"MLINE",5) == 0 ) return 22; + if ( strncmp(value,"MTEXT",5) == 0 ) return 23; + if ( strncmp(value,"OLEFRAME",8) == 0 ) return 24; + if ( strncmp(value,"POINT",5) == 0 ) return 25; + if ( strncmp(value,"REGION",6) == 0 ) return 26; + if ( strncmp(value,"RTEXT",5) == 0 ) return 27; + if ( strncmp(value,"SEQEND",6) == 0 ) return 28; + if ( strncmp(value,"SHAPE",5) == 0 ) return 29; + if ( strncmp(value,"SOLID",5) == 0 ) return 30; + if ( strncmp(value,"3DFACE",6) == 0 ) return 31; + if ( strncmp(value,"TOLERANCE",9) == 0 ) return 32; + if ( strncmp(value,"TRACE",5) == 0 ) return 33; + if ( strncmp(value,"VIEWPORT",8) == 0 ) return 34; + if ( strncmp(value,"WIPEOUT",7) == 0 ) return 35; + else return -1; +} + + +void entity::basic_entity( std::vector< dxfpair > info){ + // Extract all of the typical entity information (e.g. layer name, positions) + static char string[10000]; + for (int i = 0; i < info.size(); i++){ + switch( info[i].group_code ){ + case 6: + strcpy( string," "); // Clear the string out + info[i].value_char(string); + strcpy(linetype,string); + break; + case 8: + strcpy( string," "); // Clear the string out + info[i].value_char(string); + strcpy(layer,string); + break; + case 10: + info[i].value_char(string); + x = atof(string); + if ( x < min_x ){ + min_x = x; + } + if ( x > max_x ){ + max_x = x; + } + break; + case 20: + info[i].value_char(string); + y = atof(string); + if ( y < min_y ){ + min_y = y; + } + if ( y > max_y ){ + max_y = y; + } + break; + case 30: + info[i].value_char(string); + z = atof(string); + break; + } + } + +} + +void entity::entity_display(){ + std::cout << "\tlayer = " << layer << "\n\tlinetype = " << linetype << "\n\tx = " << x << "\ty = " << y << "\tz = " << z << std::flush; +} + +double entity::ret_x(){ + return x; +} + +double entity::ret_y(){ + return y; +} + +double entity::ret_z(){ + return z; +} + + +char* entity::ret_layer_name(char* string){ + return( strcpy(string,layer) ); +} + +char* entity::ret_ltype_name(char* string){ + return( strcpy(string,linetype) ); +} + +double entity::ret_min_x(){ + return min_x; +} + +double entity::ret_max_x(){ + return max_x; +} + +double entity::ret_min_y(){ + return min_y; +} + +double entity::ret_max_y(){ + return max_y; +} + +void entity::test_coord(double x, double y){ + if ( x < min_x ){ + min_x = x; + } + if ( x > max_x ){ + max_x = x; + } + if ( y < min_y ){ + min_y = y; + } + if ( y > max_y ){ + max_y = y; + } +} + + +void entity::reset_extents(){ + min_x = -1e20; + max_x = 1e20; + min_y = -1e20; + max_y = 1e20; +} + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// VERTEX +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +vertex::vertex( std::vector< dxfpair > info){ + // Get the vertex information + + basic_entity( info ); + static char string[10000]; + for (int i = 0; i < info.size(); i++){ + switch( info[i].group_code ){ + case 42: + info[i].value_char(string); + bulge = atof(string); + break; + } + } +} + +double vertex::ret_bulge(){ + return bulge; +} + +void vertex::display(){ + std::cout << "VERTEX\n"; + std::cout << "\tx = " << x << "\ty = " << y << "\tz = " << z << "\tbulge = " << bulge << std::flush; +} + + + + + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// POLYLINE +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +// The polyline is handled a little differently compared to the other entities because a POLYLINE is built from a bunch of VERTEX entities +polyline::polyline( std::vector< std::vector< dxfpair > > sections ){ + reset_extents(); + // get the polyline information + basic_entity( sections[0] ); + points.clear(); + static char string[10000]; + //char string[10000]; + pline_flag = 0; + curves_flag = 0; + for (int i = 0; i < sections[0].size(); i++){ + switch( sections[0][i].group_code ){ + case 70: + sections[0][i].value_char(string); + pline_flag = atoi(string); + break; + case 40: + sections[0][i].value_char(string); + start_width = atoi(string); + break; + case 41: + sections[0][i].value_char(string); + end_width = atoi(string); + break; + case 75: + sections[0][i].value_char(string); + curves_flag = atoi(string); + break; + } + } + // Now add the VERTEX entities to the POLYLINE + for (int i = 1; i < sections.size(); i++){ + points.push_back( vertex( sections[i] ) ); + } +} + + +std::vector< vertex > polyline::ret_points(){ + return points; +} + +double polyline::bulge(int point){ + return points[point].ret_bulge(); +} + +double polyline::bulge_r(int point){ + // Make sure we are not exceeding the bounds of the points vector + if (point >= (points.size()-1)) return 0; + + double dx = points[point+1].ret_x() - points[point].ret_x(); + double dy = points[point+1].ret_y() - points[point].ret_y(); + double bulge = points[point].ret_bulge(); + double l = sqrt(dx*dx + dy*dy); + double r = fabs(l*(bulge*bulge+1)/bulge/4); + + return r; +} + +double polyline::bulge_start_angle(int point){ + // Make sure we are not exceeding the bounds of the points vector + if (point >= (points.size()-1)) return 0; + + double dx = points[point+1].ret_x() - points[point].ret_x(); + double dy = points[point+1].ret_y() - points[point].ret_y(); + double bulge = points[point].ret_bulge(); + double xmid = dx/2 + points[point].ret_x(); + double ymid = dy/2 + points[point].ret_y(); + double l = sqrt(dx*dx + dy*dy); + double r = fabs(l*(bulge*bulge+1)/bulge/4); + + double a = fabs(bulge*l/2); + double sb = bulge/fabs(bulge); //sign of bulge + double theta_p = 4*atan(bulge); + double theta_c; + dx != 0 ? theta_c = atan(dy/dx) : theta_c = 1.57079632679489661923; // Check to make sure that dx is not zero and will give a negative number + if (dx > 0) sb *= -1; // Correct for different point ordering and bulge direction + + double cx = xmid + sb*(r-a)*sin(theta_c); + double cy = ymid - sb*(r-a)*cos(theta_c); + + // Now calculate the angle + double theta = asin(points[point].ret_x()/r); + if (dy < 0) theta = 6.2831853 - theta; // The angle is greater than pi so fix this because max(asin) = pi + + return theta; +} + +double polyline::bulge_end_angle(int point){ + // Make sure we are not exceeding the bounds of the points vector + if (point >= (points.size()-1)) return 0; + + double dx = points[point+1].ret_x() - points[point].ret_x(); + double dy = points[point+1].ret_y() - points[point].ret_y(); + double bulge = points[point].ret_bulge(); + double xmid = dx/2 + points[point].ret_x(); + double ymid = dy/2 + points[point].ret_y(); + double l = sqrt(dx*dx + dy*dy); + double r = fabs(l*(bulge*bulge+1)/bulge/4); + + double a = fabs(bulge*l/2); + double sb = bulge/fabs(bulge); //sign of bulge + double theta_p = 4*atan(bulge); + double theta_c; + dx != 0 ? theta_c = atan(dy/dx) : theta_c = 1.57079632679489661923; // Check to make sure that dx is not zero and will give a negative number + if (dx > 0) sb *= -1; // Correct for different point ordering and bulge direction + + double cx = xmid + sb*(r-a)*sin(theta_c); + double cy = ymid - sb*(r-a)*cos(theta_c); + + // Now calculate the angle + double theta = asin(points[point+1].ret_x()/r); + if (dy < 0) theta = 6.2831853 - theta; // The angle is greater than pi so fix this because max(asin) = pi + + return theta; +} + + +bool polyline::is_closed(){ + // pline-flag holds info about closed pline in the 1 bit. The info is bit wise encoded so use bit wise operators + return bool(pline_flag&1); +} + +void polyline::display(){ + std::cout << "POLYLINE\n"; + entity_display(); + std::cout << std::endl; + for (int i = 0; i < points.size(); i++){ + points[i].display(); + std::cout << std::endl; + } + std::cout << std::endl; +} + + + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// LWPOLYLINE +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +// The lwpolyline is different than the polyline because there are no vertex entities. Use the same basic process as the polyline but parse it out differently +lwpolyline::lwpolyline( std::vector< dxfpair > section ){ + + // First break up the data into the same format that is used by the polyline entity + std::vector< std::vector< dxfpair > > sections; + std::vector< dxfpair > first; + std::vector< dxfpair > others; + + sections.clear(); + first.clear(); + others.clear(); + + int gc; // make a shorter name for group_code; + + int vertex_part; + int already_found = 0; + + for (int i = 0; i < section.size(); i++){ + gc = section[i].group_code; + // Encode bitwise information to keep track of what has been found + vertex_part = 0; + if (gc == 10 ) vertex_part += 1; + if (gc == 20 ) vertex_part += 2; + if (gc == 30 ) vertex_part += 4; + if (gc == 40 ) vertex_part += 8; + if (gc == 41 ) vertex_part += 16; + if (gc == 42 ) vertex_part += 32; + //std::cout << "\n\nvertex_part = " << vertex_part << std::endl << "already_found = " << already_found << std::endl << "(vertex_part&already_found) = " << (vertex_part&already_found) << std::endl; + if ( vertex_part == 0 ){ + // If header stuff has been found save it under first. + // I.E. in a polyline the first set of information is linetype and layer, all of what should be in here + first.push_back( section[i] ); + } + else if ( (vertex_part&already_found) == 0 ){ + // Now work on what would be the vertex information + // New information is still being found so keep saving it + others.push_back( section[i] ); + //std::cout << "add to others" << std::endl; + already_found += vertex_part; // Keep track of what has been found + } + else{ + sections.push_back( others ); + //std::cout << "sections.size() = " << sections.size() << std::endl; + // Now clear the information out and start over + others.clear(); + others.push_back( section[i] ); + already_found = vertex_part; + } + } + + // Now put on the last data that was found + if (others.size() > 0 ){ + sections.push_back( others ); + } + + reset_extents(); + basic_entity( first ); + points.clear(); + static char string[10000]; + //char string[10000]; + pline_flag = 0; + curves_flag = 0; + for (int i = 0; i < first.size(); i++){ + switch( sections[0][i].group_code ){ + case 70: + first[i].value_char(string); + pline_flag = atoi(string); + break; + case 40: + first[i].value_char(string); + start_width = atoi(string); + break; + case 41: + first[i].value_char(string); + end_width = atoi(string); + break; + case 75: + first[i].value_char(string); + curves_flag = atoi(string); + break; + } + } + // Now add the VERTEX entities to the POLYLINE + for (int i = 0; i < sections.size(); i++){ + points.push_back( vertex( sections[i] ) ); + } +} + + + +std::vector< vertex > lwpolyline::ret_points(){ + return points; +} + + +double lwpolyline::bulge(int point){ + return points[point].ret_bulge(); +} + +double lwpolyline::bulge_r(int point){ + // Make sure we are not exceeding the bounds of the points vector + if (point >= (points.size()-1)) return 0; + + double dx = points[point+1].ret_x() - points[point].ret_x(); + double dy = points[point+1].ret_y() - points[point].ret_y(); + double bulge = points[point].ret_bulge(); + double l = sqrt(dx*dx + dy*dy); + double r = fabs(l*(bulge*bulge+1)/bulge/4); + + return r; +} + +double lwpolyline::bulge_start_angle(int point){ + // Make sure we are not exceeding the bounds of the points vector + if (point >= (points.size()-1)) return 0; + + double dx = points[point+1].ret_x() - points[point].ret_x(); + double dy = points[point+1].ret_y() - points[point].ret_y(); + double bulge = points[point].ret_bulge(); + double xmid = dx/2 + points[point].ret_x(); + double ymid = dy/2 + points[point].ret_y(); + double l = sqrt(dx*dx + dy*dy); + double r = fabs(l*(bulge*bulge+1)/bulge/4); + + double a = fabs(bulge*l/2); + double sb = bulge/fabs(bulge); //sign of bulge + double theta_p = 4*atan(bulge); + double theta_c; + dx != 0 ? theta_c = atan(dy/dx) : theta_c = 1.57079632679489661923; // Check to make sure that dx is not zero and will give a negative number + if (dx > 0) sb *= -1; // Correct for different point ordering and bulge direction + + double cx = xmid + sb*(r-a)*sin(theta_c); + double cy = ymid - sb*(r-a)*cos(theta_c); + + // Now calculate the angle + double theta = asin(points[point].ret_x()/r); + if (dy < 0) theta = 6.2831853 - theta; // The angle is greater than pi so fix this because max(asin) = pi + + return theta; +} + +double lwpolyline::bulge_end_angle(int point){ + // Make sure we are not exceeding the bounds of the points vector + if (point >= (points.size()-1)) return 0; + + double dx = points[point+1].ret_x() - points[point].ret_x(); + double dy = points[point+1].ret_y() - points[point].ret_y(); + double bulge = points[point].ret_bulge(); + double xmid = dx/2 + points[point].ret_x(); + double ymid = dy/2 + points[point].ret_y(); + double l = sqrt(dx*dx + dy*dy); + double r = fabs(l*(bulge*bulge+1)/bulge/4); + + double a = fabs(bulge*l/2); + double sb = bulge/fabs(bulge); //sign of bulge + double theta_p = 4*atan(bulge); + double theta_c; + dx != 0 ? theta_c = atan(dy/dx) : theta_c = 1.57079632679489661923; // Check to make sure that dx is not zero and will give a negative number + if (dx > 0) sb *= -1; // Correct for different point ordering and bulge direction + + double cx = xmid + sb*(r-a)*sin(theta_c); + double cy = ymid - sb*(r-a)*cos(theta_c); + + // Now calculate the angle + double theta = asin(points[point+1].ret_x()/r); + if (dy < 0) theta = 6.2831853 - theta; // The angle is greater than pi so fix this because max(asin) = pi + + return theta; +} + +bool lwpolyline::is_closed(){ + // pline-flag holds info about closed pline in the 1 bit. The info is bit wise encoded so use bit wise operators + return bool(pline_flag&1); +} + +void lwpolyline::display(){ + std::cout << "lwpolyline\n"; + entity_display(); + std::cout << std::endl; + for (int i = 0; i < points.size(); i++){ + points[i].display(); + std::cout << std::endl; + } + std::cout << std::endl; +} + + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// ARC +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +arc::arc( std::vector< dxfpair > info){ + + reset_extents(); + basic_entity( info ); + static char string[10000]; + for (int i = 0; i < info.size(); i++){ + switch( info[i].group_code ){ + case 40: + info[i].value_char(string); + radius = atof(string); + test_coord(x+radius,y+radius); + test_coord(x-radius,y-radius); + break; + case 50: + info[i].value_char(string); + start_angle = atof(string); + break; + case 51: + info[i].value_char(string); + end_angle = atof(string); + break; + default: + break; + } + } +} + +double arc::ret_radius(){ + return radius; +} + + +double arc::ret_srt_ang(){ + return start_angle; +} + + +double arc::ret_end_ang(){ + return end_angle; +} + + +void arc::display(){ + std::cout << "ARC\n"; + entity_display(); + std::cout << "\n\tradius = " << radius << "\tstart_angle = " << start_angle << "end_angle = " << end_angle << std::flush; +} + + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// CIRCLE +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +circle::circle( std::vector< dxfpair > info){ + + reset_extents(); + basic_entity( info ); + static char string[10000]; + for (int i = 0; i < info.size(); i++){ + switch( info[i].group_code ){ + case 40: + info[i].value_char(string); + radius = atof(string); + test_coord(x+radius,y+radius); + test_coord(x-radius,y-radius); + break; + } + } +} + +void circle::display(){ + std::cout << "CIRCLE\n"; + entity_display(); + std::cout << "\n\tradius = " << radius << std::flush; +} + + +double circle::ret_radius(){ + return radius; +} + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// LINE +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +line::line( std::vector< dxfpair > info){ + + reset_extents(); + basic_entity( info ); + static char string[10000]; + for (int i = 0; i < info.size(); i++){ + switch( info[i].group_code ){ + case 11: + info[i].value_char(string); + xf = atof(string); + break; + case 21: + info[i].value_char(string); + yf = atof(string); + break; + case 31: + info[i].value_char(string); + zf = atof(string); + break; + } + } + test_coord(xf,yf); + +} + +void line::display(){ + std::cout << "LINE\n"; + entity_display(); + std::cout << "\n\txf = " << xf << "\tyf = " << yf << "\tzf = " << zf << std::flush; +} + + +double line::ret_xf(){ + return xf; +} + +double line::ret_yf(){ + return yf; +} + +double line::ret_zf(){ + return zf; +} + + + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// TEXT +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +text::text( std::vector< dxfpair > info){ + + reset_extents(); + basic_entity( info ); + static char string[10000]; + for (int i = 0; i < info.size(); i++){ + switch( info[i].group_code ){ + case 1: + info[i].value_char(dxf_text); // directly copy the text into a string + break; + case 40: + info[i].value_char(string); + text_height = atof(string); + break; + case 50: + info[i].value_char(string); + text_rotation = atof(string); + break; + } + } +} + +char * text::ret_text(char *string){ + return( strcpy(string,dxf_text) ); +} + +double text::ret_txt_ht(){ + return text_height; +} + +double text::ret_txt_rot(){ + return text_rotation; +} + +void text::display(){ + char tmp[10000]; + std::cout << "TEXT\n"; + entity_display(); + std::cout << "\ndxf_text = " << ret_text(tmp) << std::flush; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// INSERT +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +insert::insert( std::vector< dxfpair > info){ + + basic_entity( info ); + static char string[10000]; + for (int i = 0; i < info.size(); i++){ + switch( info[i].group_code ){ + case 2: + info[i].value_char(block_name); // directly copy the text into a string + break; + case 41: + info[i].value_char(string); + x_scale_factor = atof(string); + break; + case 42: + info[i].value_char(string); + y_scale_factor = atof(string); + break; + case 43: + info[i].value_char(string); + z_scale_factor = atof(string); + break; + case 50: + info[i].value_char(string); + rotation = atof(string); + break; + } + } +} + + +char * insert::name(char *string){ + return( strcpy(string,block_name) ); +} + + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// entities +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + +entities::entities(std::vector< std::vector< dxfpair > > sections){ + // Read the main information about the entities section and then put it in the enetites class + int value; + char string[10000]; + std::vector< dxfpair > single_line; + std::vector< std::vector< dxfpair > > pline; + pline.clear(); + single_line.clear(); + + for(int i = 0; i < sections.size(); i++){ + sections[i][0].value_char(string); + value = detmine_entity(string); + switch( value ){ + case 0: + // Get everything from the start of the polyline designation to an SEQEND value + pline.clear(); // First clear out the pline information + do{ + pline.push_back( sections[i] ); + sections[++i][0].value_char(string); + }while( strncmp(string,"SEQEND",6) != 0 ); + ents_polyline.push_back( polyline( pline ) ); + break; + + case 1: + // ARC + ents_arc.push_back( arc( sections[i] ) ); + break; + + case 2: + // CIRCLE + ents_circle.push_back( circle( sections[i] ) ); + break; + + case 3: + // LINE + ents_line.push_back( line( sections[i] ) ); + break; + case 11: + // TEXT + ents_text.push_back( text( sections[i] ) ); + break; + case 21: + // LWPOLYLINE + ents_lwpolyline.push_back( lwpolyline( sections[i] ) ); + case 9: + // INSERT + ents_insert.push_back( insert( sections[i] ) ); + + //default: + // Nothing here + } + + } + +} + + +// Maybe all of this could be turned into fewer function by using templates, but no time right now. MBS + +std::vector< polyline > entities::ret_plines(){ + std::vector< polyline > pls; + pls.clear(); + for(int i = 0; i < ents_polyline.size();i++){ + pls.push_back( ents_polyline[i] ); + } + return pls; +} + +std::vector< lwpolyline > entities::ret_lwplines(){ + std::vector< lwpolyline > lwpls; + lwpls.clear(); + for(int i = 0; i < ents_lwpolyline.size();i++){ + lwpls.push_back( ents_lwpolyline[i] ); + } + return lwpls; +} + + +std::vector< arc > entities::ret_arcs(){ + std::vector< arc > a; + a.clear(); + for(int i = 0; i < ents_arc.size();i++){ + a.push_back( ents_arc[i] ); + } + return a; +} + +std::vector< circle > entities::ret_circles(){ + std::vector< circle > circs; + circs.clear(); + for(int i = 0; i < ents_circle.size();i++){ + circs.push_back( ents_circle[i] ); + } + return circs; +} + + +std::vector< line > entities::ret_lines(){ + std::vector< line > lns; + lns.clear(); + for(int i = 0; i < ents_line.size();i++){ + lns.push_back( ents_line[i] ); + } + return lns; +} + + +std::vector< text > entities::ret_texts(){ + std::vector< text > txts; + txts.clear(); + for(int i = 0; i < ents_text.size();i++){ + txts.push_back( ents_text[i] ); + } + return txts; +} + + +std::vector< insert > entities::ret_inserts(){ + std::vector< insert > ins; + ins.clear(); + for(int i = 0; i < ents_insert.size();i++){ + ins.push_back( ents_insert[i] ); + } + return ins; +} + + + +// Overload the return function to depend on the layer +std::vector< polyline > entities::ret_plines(char * layer){ + char temp[10000]; + std::vector< polyline > pls; + pls.clear(); + + for(int i = 0; i < ents_polyline.size();i++){ + if ( strcmp( layer,ents_polyline[i].ret_layer_name(temp) ) == 0 ){ + pls.push_back( ents_polyline[i] ); + } + } + return pls; +} + + +std::vector< lwpolyline > entities::ret_lwplines(char * layer){ + char temp[10000]; + std::vector< lwpolyline > lwpls; + lwpls.clear(); + + for(int i = 0; i < ents_lwpolyline.size();i++){ + if ( strcmp( layer,ents_lwpolyline[i].ret_layer_name(temp) ) == 0 ){ + lwpls.push_back( ents_lwpolyline[i] ); + } + } + return lwpls; +} + + +std::vector< circle > entities::ret_circles(char * layer){ + char temp[10000]; + std::vector< circle > circs; + circs.clear(); + + for(int i = 0; i < ents_circle.size();i++){ + if ( strcmp( layer,ents_circle[i].ret_layer_name(temp) ) == 0 ){ + circs.push_back( ents_circle[i] ); + } + } + return circs; +} + + +std::vector< line > entities::ret_lines(char * layer){ + char temp[10000]; + std::vector< line > lns; + lns.clear(); + + for(int i = 0; i < ents_line.size();i++){ + if ( strcmp( layer,ents_line[i].ret_layer_name(temp) ) == 0 ){ + lns.push_back( ents_line[i] ); + } + } + return lns; +} + + +std::vector< text > entities::ret_texts(char * layer){ + char temp[10000]; + std::vector< text > txts; + txts.clear(); + + for(int i = 0; i < ents_text.size();i++){ + if ( strcmp( layer,ents_text[i].ret_layer_name(temp) ) == 0 ){ + txts.push_back( ents_text[i] ); + } + } + return txts; +} + + +/*std::vector< ellipse > entities::ret_ellipses(char * layer){ + char temp[10000]; + std::vector< polyline > pls; + pls.clear(); + + for(int i = 0; i < ents_polyline.size();i++){ + if ( strcmp( layer,ents_polyline[i].ret_layer_name(temp) ) == 0 ){ + pls.push_back( ents_polyline[i] ); + } + } + return pls; +}*/ + + +std::vector< arc > entities::ret_arcs(char * layer){ + char temp[10000]; + std::vector< arc > a; + a.clear(); + + for(int i = 0; i < ents_arc.size();i++){ + if ( strcmp( layer,ents_arc[i].ret_layer_name(temp) ) == 0 ){ + a.push_back( ents_arc[i] ); + } + } + return a; +} + + +std::vector< insert > entities::ret_inserts(char * layer){ + char temp[10000]; + std::vector< insert > ins; + ins.clear(); + + for(int i = 0; i < ents_insert.size();i++){ + if ( strcmp( layer,ents_insert[i].ret_layer_name(temp) ) == 0 ){ + ins.push_back( ents_insert[i] ); + } + } + return ins; +} + + + + +void entities::display_all(){ + for (int i = 0; i < ents_polyline.size(); i++){ + ents_polyline[i].display(); + } + std::cout << std::endl; + for (int i = 0; i < ents_lwpolyline.size(); i++){ + ents_lwpolyline[i].display(); + } + std::cout << std::endl; + for (int i = 0; i < ents_circle.size(); i++){ + ents_circle[i].display(); + } + std::cout << std::endl; + for (int i = 0; i < ents_text.size(); i++){ + ents_text[i].display(); + } +} + + diff --git a/src/extension/dxf2svg/entities.h b/src/extension/dxf2svg/entities.h new file mode 100644 index 000000000..96d863d94 --- /dev/null +++ b/src/extension/dxf2svg/entities.h @@ -0,0 +1,256 @@ +/* Class for interpereting the entities found in a DXF file +Matt Squires +Google SOC +2 July 05 +*/ + +#ifndef DXF_ENTITIES_H +#define DXF_ENTITIES_H + +#include"read_dxf.h" +#include<vector> + + + + +class entity{ + public: + void basic_entity( std::vector< dxfpair > info); // Extract all of the typical entity information (e.g. layer name, positions) + void entity_display(); + double ret_x(); + double ret_y(); + double ret_z(); + char* ret_layer_name(char* string); + char* ret_ltype_name(char* string); + double ret_min_x(); + double ret_max_x(); + double ret_min_y(); + double ret_max_y(); + + + protected: + char layer[10000]; + char linetype[10000]; + double x; + double y; + double z; + double min_x; + double max_x; + double min_y; + double max_y; + void reset_extents(); + void test_coord(double x, double y); +}; + + + + + +class vertex : public entity { + public: + vertex( std::vector< dxfpair > info); + void display(); + double ret_bulge(); + + private: + double bulge; +}; + + + + + +class polyline : public entity { + public: + polyline( std::vector< std::vector< dxfpair > > sections ); + std::vector< vertex > ret_points(); + double bulge(int point); + double bulge_r(int point); + double bulge_start_angle(int point); + double bulge_end_angle(int point); + bool is_closed(); + void display(); + + private: + double buldge; + int pline_flag; // 70 + double start_width; // 40 + double end_width; // 41 + int curves_flag; + std::vector< vertex > points; +}; + +class lwpolyline : public entity { + public: + lwpolyline( std::vector< dxfpair > section ); + std::vector< vertex > ret_points(); + double bulge(int point); + double bulge_r(int point); + double bulge_start_angle(int point); + double bulge_end_angle(int point); + bool is_closed(); + void display(); + + private: + double buldge; + int pline_flag; // 70 + double start_width; // 40 + double end_width; // 41 + int curves_flag; + std::vector< vertex > points; +}; + +class arc : public entity { + public: + arc( std::vector< dxfpair > info); + double ret_radius(); + double ret_srt_ang(); + double ret_end_ang(); + void display(); + + private: + double radius; + double start_angle; + double end_angle; +}; + + + + +class circle : public entity { + public: + circle( std::vector< dxfpair > info); + void display(); + double ret_radius(); + + private: + double radius; +}; + + +class line : public entity { + public: + line( std::vector< dxfpair > info); + void display(); + double ret_xf(); + double ret_yf(); + double ret_zf(); + + private: + double xf; + double yf; + double zf; +}; + +class ellipse : public entity { + public: + ellipse( std::vector< dxfpair > info); + void display(); + double ret_x_ma; + double ret_y_ma; + double ret_z_ma; + double ret_ratio; + double ret_start_p; + double ret_end_p; + + + private: + double x_major_axis; + double y_major_axis; + double z_major_axis; + double ratio; + double start_param; + double end_param; +}; + + + +class text : public entity { + public: + text( std::vector< dxfpair > info); + void display(); + char * ret_text(char *string); + double ret_txt_ht(); + double ret_txt_rot(); + + private: + char dxf_text[10000]; + double text_height; // dxf 40 + double text_rotation; //dxf 50 +}; + + +class insert : public entity { + public: + insert( std::vector< dxfpair > info); + void display(); + char* name(char* string); + double ret_x_sf; + double ret_y_sf; + double ret_z_sf; + double ret_rotation; + + private: + char block_name[10000]; + double x_scale_factor; + double y_scale_factor; + double z_scale_factor; + double rotation; +}; + + + + + + +class entities{ + // Well I said that I would only use STL containers internally, but I would have to use a dynamically linked list, and I haven't done for a long time soo STL is my crutch. + // I also think that there are others in my same boat that prefer stl containers because they are much easier to use + public: + entities(std::vector< std::vector< dxfpair > > sections); // Put the various entities into their respective vectors + void display_all(); + std::vector< polyline > ret_plines(); + std::vector< circle > ret_circles(); + std::vector< line > ret_lines(); + std::vector< text > ret_texts(); + std::vector< ellipse > ret_ellipses(); + std::vector< arc > ret_arcs(); + std::vector< lwpolyline > ret_lwplines(); + std::vector< insert > ret_inserts(); + // Overload the return function to depend on the layer + std::vector< polyline > ret_plines(char * layer); + std::vector< circle > ret_circles(char * layer); + std::vector< line > ret_lines(char * layer); + std::vector< text > ret_texts(char * layer); + std::vector< ellipse > ret_ellipses(char * layer); + std::vector< arc > ret_arcs(char * layer); + std::vector< lwpolyline > ret_lwplines(char * layer); + std::vector< insert > ret_inserts(char * layer); + + int plines_size(); + int circles_size(); + int lines_size(); + int texts_size(); + + + + private: + void add_polyline(polyline pline); + void add_circle(circle circ); + void add_line(line ln); + + std::vector< polyline > ents_polyline; + std::vector< arc > ents_arc; + std::vector< circle > ents_circle; + std::vector< line > ents_line; + std::vector< ellipse > ents_ellipse; + std::vector< text > ents_text; + std::vector< lwpolyline > ents_lwpolyline; + std::vector< insert > ents_insert; + + +}; + + + +#endif diff --git a/src/extension/dxf2svg/entities2elements.cpp b/src/extension/dxf2svg/entities2elements.cpp new file mode 100644 index 000000000..cf42dac32 --- /dev/null +++ b/src/extension/dxf2svg/entities2elements.cpp @@ -0,0 +1,681 @@ +/* + * Code for converting dxf entities to SVG elements + * There are multiple ways for converting different items + * If possible most DXF enetities will be converted to paths because that is the most flexable object + * + * Author: + * Matt Squires <squiresm@colorado.edu> + * + * Copyright (C) 2005 Matt Squires + * + * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details + */ + + + +/* + +Matt Squires +SoC 2005 + +*/ + +#include"entities2elements.h" +#include"tables2svg_info.h" +#include<iostream> +#include<math.h> +// The names indicate the DXF entitiy first and the SVG element last + +// Common elements +char* to_arc(double bulge, double r, double start_ang, double end_ang, int precision,char* delim, char * units, double scaling, char *out){ + // This is used for arcs, polylines, and lwpolylines + char temp[50]; + + // Assume that we are adding to the input and not starting over + strcat(out," A "); + // For arcs there is only one radius + strcat(out,gcvt(scaling*r,precision,temp) ); + strcat(out,","); + strcat(out,gcvt(scaling*r,precision,temp) ); + + strcat(out," 0"); // For arc assume no x-axis rotation. That seems to apply to elipse elements only + // Determine if it is a large arc + if ( (end_ang > start_ang) && ( (end_ang - start_ang) > 180) ){ + //strcat(out," 1,0 "); // Large arc flag...Always use a zero sweep flag + strcat(out," 1, "); // Large arc flag...Always use a zero sweep flag + } + else{ + //strcat(out," 0,0 "); // Small arc flag...Always use a zero sweep flag + strcat(out," 0,"); + } + // This may be easier if I allow r to be plus and minus, but for now this works + if (bulge > 0){ + strcat(out,"0 "); + } + else{ + strcat(out,"1 "); + } +} + +// Build Coordinate +void coord(entity *ent, int precision,char* delim, char * units, double scaling, char *out); // Pairs of coords with units will be used so often build a function +void coord(entity *ent, int precision,char* delim, char * units, double scaling, char *out){ + // Pairs of coords with units will be used so often build a function build a dedicated function for returning such + + char temp[20]; + if (units != NULL) scaling = 1; // If units have been defined then ignore the scaling parameter + strcat(out, gcvt(scaling*ent->ret_x(),precision,temp) ); // There must be a better function for double to ascii conversion that is defined in most libraries + if (units != NULL) strcat(out, units); + strcat(out, delim); + strcat(out, gcvt(-scaling*ent->ret_y(),precision,temp) ); // Because SVG has a the Y-axis pointed down multiply by -1 + if (units != NULL) strcat(out, units); + strcat(out, " "); +} + +// DXF Polyline -> SVG +void pline2svg(polyline pline, int type, int precision, char * units, double scaling, tables plot_info, char *out); // General function for the conversion of a pline to a SVG element. Very similar functions just make accomidations for parts that may not be supported +void pline2svg(polyline pline, int type, int precision, char * units, double scaling, tables plot_info, char *out){ + // 0 is pline2path + // 1 is pline2pline + // 2 is pline2polygon + + + char delim[1]; + double mag_bulge = 0; + double prev_mag_bulge = 0; + + std::vector< vertex >::iterator vver_iter; + std::vector< vertex > points = pline.ret_points(); + + if (type < 1){ + // Put the first Move To at the first, everything else will be a lineto + strcpy(delim," "); + strcat(out, "M "); + coord( &points[0], precision, delim, units, scaling, out ); + prev_mag_bulge = sqrt(pow(points[0].ret_bulge(),2)); // Because the bulge value can be positive or negative calculate the magnitude + if ( prev_mag_bulge > pow(0.1,precision) ){ + to_arc(pline.bulge(0), pline.bulge_r(0), pline.bulge_start_angle(0), pline.bulge_end_angle(0), precision, delim, units, scaling, out); + } + for (int i = 1; i < points.size(); i++){ + if ( prev_mag_bulge < pow(0.1,precision) ){ + // If the previous point was a bulge then don't use a line to + strcat(out, "L "); + } + coord( &points[i], precision, delim, units, scaling, out ); + // If bulge > some precsion then add bulge + mag_bulge = sqrt(pow(points[i].ret_bulge(),2)); + if ( (mag_bulge > pow(0.1,precision)) && (i < (points.size() - 1) )){ + to_arc(pline.bulge(i), pline.bulge_r(i), pline.bulge_start_angle(i), pline.bulge_end_angle(i), precision, delim, units, scaling, out); + } + prev_mag_bulge = mag_bulge; + } + if ( pline.is_closed() ){ + strcat(out,"z"); + } + strcat(out,"\" "); + } + else{ + strcpy(delim,","); + for (int i = 0; i < points.size(); i++){ + coord( &points[i], precision, delim, NULL, scaling, out ); + // If bulge > some precsion then add bulge + } + // if the element is a SVG::pline and the DXF::pline is closed then simulate by adding an extra point + if ( (type == 1) && pline.is_closed() ){ + coord( &points[0], precision, delim, NULL, scaling, out ); + } + } + +} + +char* pline2path(polyline pline, char * units, double scaling, tables plot_info){ + // Convert a dxf polyline to a SVG path. This is the closest conversion of the DXF polyline to an SVG element + char *out_ptr; + char out[10000] = "<path d=\""; + entity *ent_ptr = &pline; + char temp[20]; + int precision = 6; + + pline2svg(pline, 0, precision, units, scaling, plot_info, out); + // Add some line information + strcat(out,"fill=\"none\" stroke=\"black\" stroke-width=\"1\" "); + pattern2dasharray(plot_info.ret_ltype( ent_ptr->ret_ltype_name(temp),ent_ptr->ret_layer_name(temp) ), precision, scaling, out); // Add the linetype information + + strcat(out," />"); + out_ptr = out; + return out_ptr; +} + +char* pline2pline(polyline pline, char * units, double scaling, tables plot_info){ + // Convert a dxf polyline to a SVG polyline. The conversion is not 1:1 because the SVG pline doesn't support closed objects or curves + entity *ent_ptr = &pline; + char temp[2000]; + int precision = 6; + + char out[10000] = "<polyline fill=\"none\" stroke=\"black\" stroke-width=\"1\" "; + ltype linfo = plot_info.ret_ltype(ent_ptr->ret_ltype_name(temp), ent_ptr->ret_layer_name(temp)); + pattern2dasharray(linfo, precision, scaling, out); // Add the linetype information + //strcpy(temp," "); + + strcat(out,"points=\""); + + //strcat(out,"<polyline fill=\"none\" stroke=\"black\" stroke-width=\"1\" points=\""); + pline2svg(pline, 1, precision, units, scaling, plot_info, out); + // Add some line information + // if the DXF pline is closed then add an extra point + + strcat(out,"\"/>"); + char *out_ptr = out; + return out_ptr; +} +char* pline2polygon(polyline pline, char * units, double scaling, tables plot_info){ + // Convert a dxf polyline to a SVG polygon. The conversion is not 1:1 because the SVG polygone assumes a closed path. If the pline is not closed it will be forced closed + //return pline2svg(pline, 2, 6, units, double scaling,out); +} + + +// DXF LWPolyline -> SVG + + +// This could be a template with polyline and lwpolyline but right now it is not that important +void lwpline2svg(lwpolyline pline, int type, int precision, char * units, double scaling, tables plot_info, char *out); // General function for the conversion of a pline to a SVG element. Very similar functions just make accomidations for parts that may not be supported +void lwpline2svg(lwpolyline pline, int type, int precision, char * units, double scaling, tables plot_info, char *out){ + // 0 is pline2path + // 1 is pline2pline + // 2 is pline2polygon + + + char delim[1]; + double mag_bulge = 0; + double prev_mag_bulge = 0; + + std::vector< vertex >::iterator vver_iter; + std::vector< vertex > points = pline.ret_points(); + + if (type < 1){ + // Put the first Move To at the first, everything else will be a lineto + strcpy(delim," "); + strcat(out, "M "); + coord( &points[0], precision, delim, NULL, scaling, out ); + prev_mag_bulge = sqrt(pow(points[0].ret_bulge(),2)); // Because the bulge value can be positive or negative calculate the magnitude + if ( prev_mag_bulge > pow(0.1,precision) ){ + to_arc(pline.bulge(0),pline.bulge_r(0), pline.bulge_start_angle(0), pline.bulge_end_angle(0), precision, delim, NULL, scaling, out); + } + + for (int i = 1; i < points.size(); i++){ + if ( prev_mag_bulge < pow(0.1,precision) ){ + // If the previous point was a bulge then don't use a line to + strcat(out, "L "); + } + coord( &points[i], precision, delim, NULL , scaling, out ); + // If bulge > some precsion then add bulge + mag_bulge = sqrt(pow(points[i].ret_bulge(),2)); + if ( ( mag_bulge > pow(0.1,precision) ) && (i < (points.size() - 1) )){ // Make sure the final point doesn't add a bulge on accident + to_arc(pline.bulge(i), pline.bulge_r(i), pline.bulge_start_angle(i), pline.bulge_end_angle(i), precision, delim, units, scaling, out); + } + prev_mag_bulge = mag_bulge; + } + if ( pline.is_closed() ){ + strcat(out,"z"); + } + strcat(out,"\" "); + } + else{ + strcpy(delim,","); + for (int i = 0; i < points.size(); i++){ + coord( &points[i], precision, delim, units, scaling, out ); + // If bulge > some precsion then add bulge + } + // if the element is a SVG::pline and the DXF::pline is closed then simulate by adding an extra point + if ( (type == 1) && pline.is_closed() ){ + coord( &points[0], precision, delim, units, scaling, out ); + } + } + +} + +char* lwpline2path(lwpolyline pline, char * units, double scaling, tables plot_info){ + // Convert a dxf polyline to a SVG path. This is the closest conversion of the DXF polyline to an SVG element + char *out_ptr; + char out[10000] = "<path d=\""; + entity *ent_ptr = &pline; + char temp[20]; + int precision = 6; + + lwpline2svg(pline, 0, precision, units, scaling, plot_info, out); + // Add some line information + strcat(out,"fill=\"none\" stroke=\"black\" stroke-width=\"1\" "); + pattern2dasharray(plot_info.ret_ltype( ent_ptr->ret_ltype_name(temp),ent_ptr->ret_layer_name(temp) ), precision, scaling, out); // Add the linetype information + + strcat(out," />"); + out_ptr = out; + return out_ptr; +} + +// DXF ARC -> SVG +char* arc2path(arc a, int precision, char * units, double scaling, tables plot_info, char *out){ + // So far this appears to be the only way to convert arcs into something recognized by SVG + char *out_ptr; + char temp[20]; + entity *ent_ptr = &a; + + strcpy(out,"<path d=\"M"); + // Calculate the starting point from the center and the start angle. As far as I can tell the rotation is CCW in the dxf notation and it in degrees + strcat(out,gcvt(scaling*(ent_ptr->ret_x()+a.ret_radius()*cos( a.ret_srt_ang()*3.14159/180 )),precision,temp) ); + strcat(out," "); + strcat(out,gcvt(-1*scaling*(ent_ptr->ret_y()+a.ret_radius()*sin( a.ret_srt_ang()*3.14159/180 )),precision,temp) ); + strcat(out," A "); + // For arcs there is only one radius + strcat(out,gcvt(scaling*a.ret_radius(),precision,temp) ); + strcat(out,","); + strcat(out,gcvt(scaling*a.ret_radius(),precision,temp) ); + + strcat(out," 0"); // For arc assume no x-axis rotation. That seems to apply to elipse elements only + // Determine if it is a large arc + if ( (a.ret_end_ang() > a.ret_srt_ang()) && ( (a.ret_end_ang() - a.ret_srt_ang()) > 180) ){ + strcat(out," 1,0 "); // Large arc flag...Always use a zero sweep flag + } + else{ + strcat(out," 0,0 "); // Small arc flag...Always use a zero sweep flag + } + + //The final point + strcat(out,gcvt(scaling*(ent_ptr->ret_x()+a.ret_radius()*cos( a.ret_end_ang()*3.14159/180 )),precision,temp) ); + strcat(out,","); + strcat(out,gcvt(-1*scaling*(ent_ptr->ret_y()+a.ret_radius()*sin( a.ret_end_ang()*3.14159/180 )),precision,temp) ); + strcat(out,"\" fill=\"none\" stroke=\"black\" stroke-width=\"1\" "); + ltype linfo = plot_info.ret_ltype(ent_ptr->ret_ltype_name(temp), ent_ptr->ret_layer_name(temp)); + pattern2dasharray(linfo, precision, scaling, out); // Add the linetype information + strcat(out, " />"); + + + out_ptr = out; + return out_ptr; + +} + + +// DXF Circle -> SVG +char* circle2circle(circle circ, int precision, char * units, double scaling, tables plot_info, char *out){ + // Direct conversion of DXF circle to SVG circle + char *out_ptr; + char temp[1000]="\" cy=\""; + entity *ent_ptr = ˆ + strcpy(out,"<circle cx=\""); + coord(ent_ptr, precision,temp, units, scaling, out); + strcat(out,"\" r=\""); + strcat(out,gcvt(circ.ret_radius(),precision,temp) ); + strcat(out,units); + strcat(out,"\" fill=\"none\" stroke=\"black\" stroke-width=\"1\" "); + ltype linfo = plot_info.ret_ltype(ent_ptr->ret_ltype_name(temp), ent_ptr->ret_layer_name(temp)); + //plot_info.ret_ltype(ent_ptr->ret_ltype_name(temp), ent_ptr->ret_layer_name(temp)); + pattern2dasharray(linfo, precision, scaling, out); // Add the linetype information + //pattern2dasharray(plot_info.ret_ltype(ent_ptr->ret_ltype_name(temp), ent_ptr->ret_layer_name(temp)), precision, scaling, out); // Add the linetype information + strcat(out, " />"); + out_ptr = out; + return out_ptr; +} + +char* circle2path(circle circ, int precision, char * units, double scaling, tables plot_info, char *out){ + // Conversion of DXF circle to SVG circle assuming the path will represent the circle + + char *out_ptr; + char temp[20]=","; + entity *ent_ptr = ˆ + + strcpy(out,"<path d=\"M"); + // The starting point is x-r,y so subtract off the radius from the x coord + strcat(out,gcvt(ent_ptr->ret_x()-circ.ret_radius(),precision,temp) ); + strcat(out," "); + strcat(out,gcvt(ent_ptr->ret_y(),precision,temp) ); + + strcat(out," a"); + strcat(out,gcvt(circ.ret_radius(),precision,temp) ); + strcat(out,","); + strcat(out,gcvt(circ.ret_radius(),precision,temp) ); + strcat(out,"0 0,0 0,0\" fill=\"none\" stroke=\"black\" stroke-width=\"1\""); + + out_ptr = out; + return out_ptr; +} + + +// DXF Line -> SVG +char* line2line(line ln, int precision, char * units, double scaling, tables plot_info, char *out){ + // Directly convert DXF to SVG because it works + char *out_ptr; + char temp[20]; + entity *ent_ptr = &ln; + + strcpy(out,"<line x1=\""); + strcat(out,gcvt(ent_ptr->ret_x(),precision,temp) ); + strcat(out,units); + strcat(out,"\" y1=\""); + strcat(out,gcvt(-1*ent_ptr->ret_y(),precision,temp) ); // Put in an extra minus because of the way SVG has defined the axis + strcat(out,units); + + strcat(out,"\" x2=\""); + strcat(out,gcvt(ln.ret_xf(),precision,temp) ); + strcat(out,units); + strcat(out,"\" y2=\""); + strcat(out,gcvt(-1*ln.ret_yf(),precision,temp) ); // Put in an extra minus because of the way SVG has defined the axis + strcat(out,units); + strcat(out,"\" stroke-width=\"1\" stroke=\"black\" "); + ltype linfo = plot_info.ret_ltype(ent_ptr->ret_ltype_name(temp), ent_ptr->ret_layer_name(temp)); + pattern2dasharray(linfo, precision, scaling, out); // Add the linetype information + strcat(out, " />"); + + out_ptr = out; + return out_ptr; +} + + +char* line2path(line ln, int precision, char * units, double scaling, tables plot_info, char *out){ + // Convert DXF line to SVG path + + char *out_ptr; + char temp[20]; + entity *ent_ptr = &ln; + + strcpy(out,"<path d=\"M"); + strcat(out,gcvt(scaling*ent_ptr->ret_x(),precision,temp) ); + strcat(out," "); + strcat(out,gcvt(scaling*ent_ptr->ret_y(),precision,temp) ); + + strcat(out," L"); + strcat(out,gcvt(scaling*ln.ret_xf(),precision,temp) ); + strcat(out," "); + strcat(out,gcvt(scaling*ln.ret_yf(),precision,temp) ); + strcat(out,"\" fill=\"none\" stroke=\"black\" stroke-width=\"1\" /"); + + out_ptr = out; + return out_ptr; +} + +// DXF Text -> SVG +char* text2text(text txt, int precision, char * units, double scaling, tables plot_info, char *out){ + // Directly convert DXF to SVG because it works + char *out_ptr; + char temp[10000]; + entity *ent_ptr = &txt; + + // If the text is rotated use the transform matrix + + if ( txt.ret_txt_rot() > precision ){ + double ca = cos(0.017453*txt.ret_txt_rot()); // ca = cosine(a) + double sa = sin(-0.017453*txt.ret_txt_rot()); // sa = sine(a) + double tx = ent_ptr->ret_x()*scaling; + double ty = -ent_ptr->ret_y()*scaling; + // Apply a translation to the orgin, then a rotation, then a translation back to the original position + double a = ca; + double b = sa; + double c = -sa; + double d = ca; + double e = -1*(tx*ca-ty*sa-tx); + double f = -1*(tx*sa+ty*ca-ty); + + strcpy(out, "<g transform=\"matrix("); + strcat(out,gcvt(a,precision,temp) ); + strcat(out," "); + strcat(out,gcvt(b,precision,temp) ); + strcat(out," "); + strcat(out,gcvt(c,precision,temp) ); + strcat(out," "); + strcat(out,gcvt(d,precision,temp) ); + strcat(out," "); + strcat(out,gcvt(e,precision,temp) ); + strcat(out," "); + strcat(out,gcvt(f,precision,temp) ); + strcat(out,")\" >\n<text x=\""); + } + else{ + strcpy(out,"<text x=\""); + } + /* + strcat(out,gcvt(ent_ptr->ret_x(),precision,temp) ); + strcat(out,units); + strcat(out,"\" y=\"-"); // Put in an extra minus because of the way SVG has defined the axis + strcat(out,gcvt(ent_ptr->ret_y(),precision,temp) ); + strcat(out,units); + */ + strcat(out,gcvt(ent_ptr->ret_x()*scaling,precision,temp) ); + //strcat(out,units); + strcat(out,"\" y=\"-"); // Put in an extra minus because of the way SVG has defined the axis + strcat(out,gcvt(ent_ptr->ret_y()*scaling,precision,temp) ); + //strcat(out,units); + strcat(out,"\" font-family=\"Verdana\" font-size=\""); + strcat(out,gcvt(scaling*txt.ret_txt_ht(),precision,temp) ); + strcat(out,"\" Fill=\"black\""); + + strcat(out," >"); + // Now put in the text + strcat(out,txt.ret_text(temp)); + + // Now close the text element + strcat(out,"</text>"); + // If the text was rotated finish off the tranform group + if ( txt.ret_txt_rot() > precision ){ + strcat(out,"</g>"); + } + + out_ptr = out; + return out_ptr; +} + + + +// DXF Insert -> SVG +char* insert2group(insert in, int precision, char * units, double scaling, tables plot_info, blocks blks, char *out){ + char *out_ptr; + char tmp_char[100000]; + + // get the block using the name from the insert information + block blk = blks.ret_block(in.name(tmp_char)); + + entity *ent_ptr = ∈ + entities *ents_ptr = &blk; + // For now just translations MBS 22 Aug 05 + strcpy(out, "<g transform=\"matrix(1,0,0,1,"); + strcat(out,gcvt(scaling*ent_ptr->ret_x(),precision,tmp_char) ); + strcat(out,","); + strcat(out,gcvt(-scaling*ent_ptr->ret_y(),precision,tmp_char) ); + strcat(out,")\" >\n"); + + + // Now convert the entities in the block + std::vector< polyline > plines = ents_ptr->ret_plines(); + std::vector< lwpolyline > lwplines = ents_ptr->ret_lwplines(); + std::vector< arc > arcs = ents_ptr->ret_arcs(); + std::vector< circle > circs = ents_ptr->ret_circles(); + std::vector< line > lns = ents_ptr->ret_lines(); + std::vector< text > txts = ents_ptr->ret_texts(); + + + + for(int i = 0; i < plines.size();i++){ + strcat( out,pline2pline(plines[i], units, scaling, plot_info ) ); + strcat( out, "\n" ); + } + for(int i = 0; i < lwplines.size();i++){ + strcat( out,lwpline2path(lwplines[i], units, scaling, plot_info ) ); + strcat( out, "\n" ); + } + for(int i = 0; i < arcs.size();i++){ + strcat( out, arc2path(arcs[i], 6,units, scaling, plot_info, tmp_char ) ); + strcat( out, "\n" ); + } + for(int i = 0; i < circs.size();i++){ + strcat( out, circle2circle(circs[i], 6, units, scaling, plot_info, tmp_char) ); + strcat( out, "\n" ); + } + for(int i = 0; i < lns.size();i++){ + strcat( out, line2line(lns[i], 6, units, scaling, plot_info, tmp_char) ); + strcat( out, "\n" ); + } + for(int i = 0; i < txts.size();i++){ + strcat( out, text2text(txts[i], 6, units, scaling, plot_info, tmp_char) ); + strcat( out, "\n" ); + } + // End the group + strcat(out,"</g>"); + + out_ptr = out; + return out_ptr; +} + + + +char* write_by_layer(int output_type, entities &ents, tables &tbls, blocks &blks, double scaling, char * units, char * layer, char * out){ + // output_type = 0 is to std:out + // output_type = 1 is to the input filename but with .dxf on the end + + // For now everything will go to stdout later may directed to other places + + // Get the various file informations as dependent on the layer type + std::vector< polyline > plines = ents.ret_plines(layer); + std::vector< lwpolyline > lwplines = ents.ret_lwplines(layer); + std::vector< arc > arcs = ents.ret_arcs(layer); + std::vector< circle > circs = ents.ret_circles(layer); + std::vector< line > lns = ents.ret_lines(layer); + std::vector< text > txts = ents.ret_texts(layer); + std::vector< insert > ins = ents.ret_inserts(layer); + + // It would be better to redirect stdout to different places. That would make the code cleaner but I don't think it will work better + char tmp_char[100000]; + for(int i = 0; i < plines.size();i++){ + if (output_type == 0){ + std::cout << "\t" << pline2path(plines[i], NULL, scaling, tbls ) << std::endl; + } + else if (output_type == 1){ + std::cout << "\t" << pline2path(plines[i], NULL, scaling, tbls ) << std::endl; + } + } + for(int i = 0; i < lwplines.size();i++){ + if (output_type == 0){ + std::cout << "\t" << lwpline2path(lwplines[i], units, scaling, tbls ) << std::endl; + } + else if (output_type == 1){ + std::cout << "\t" << lwpline2path(lwplines[i], units, scaling, tbls ) << std::endl; + } + } + for(int i = 0; i < arcs.size();i++){ + if (output_type == 0){ + std::cout << "\t" << arc2path(arcs[i], 6,units, scaling, tbls, tmp_char ) << std::endl; + } + else if (output_type == 1){ + std::cout << "\t" << arc2path(arcs[i], 6,units, scaling, tbls, tmp_char ) << std::endl; + } + } + for(int i = 0; i < circs.size();i++){ + if (output_type == 0){ + std::cout << "\t" << circle2circle(circs[i], 6, units, scaling, tbls, tmp_char) << std::endl; + } + else if (output_type == 1){ + std::cout << "\t" << circle2circle(circs[i], 6, units, scaling, tbls, tmp_char) << std::endl; + } + } + for(int i = 0; i < lns.size();i++){ + if (output_type == 0){ + std::cout << "\t" << line2line(lns[i], 6, units, scaling, tbls, tmp_char) << std::endl; + } + else if (output_type == 1){ + std::cout << "\t" << line2line(lns[i], 6, units, scaling, tbls, tmp_char) << std::endl; + } + } + for(int i = 0; i < txts.size();i++){ + if (output_type == 0){ + std::cout << "\t" << text2text(txts[i], 6, units, scaling, tbls, tmp_char) << std::endl; + } + else if (output_type == 1){ + std::cout << "\t" << text2text(txts[i], 6, units, scaling, tbls, tmp_char) << std::endl; + } + } + for(int i = 0; i < ins.size();i++){ + if (output_type == 0){ + std::cout << "\t" << insert2group(ins[i], 6, units, scaling, tbls, blks, tmp_char) << std::endl; + } + else if (output_type == 1){ + std::cout << "\t" << insert2group(ins[i], 6, units, scaling, tbls, blks, tmp_char) << std::endl; + } + } +} + + + +char* write_all(int output_type, entities &ents, tables &tbls, blocks &blks, double scaling, char * units, char * out){ + // output_type = 0 is to std:out + // output_type = 1 is to the input filename but with .dxf on the end + + // For now everything will go to stdout later may directed to other places + + // Get the various file informations as dependent on the layer type + std::vector< polyline > plines = ents.ret_plines(); + std::vector< lwpolyline > lwplines = ents.ret_lwplines(); + std::vector< arc > arcs = ents.ret_arcs(); + std::vector< circle > circs = ents.ret_circles(); + std::vector< line > lns = ents.ret_lines(); + std::vector< text > txts = ents.ret_texts(); + std::vector< insert > ins = ents.ret_inserts(); + + // It would be better to redirect stdout to different places. That would make the code cleaner but I don't think it will work better + char tmp_char[100000]; + for(int i = 0; i < plines.size();i++){ + if (output_type == 0){ + std::cout << "\t" << pline2path(plines[i], NULL, scaling, tbls ) << std::endl; + } + else if (output_type == 1){ + std::cout << "\t" << pline2path(plines[i], NULL, scaling, tbls ) << std::endl; + } + } + for(int i = 0; i < lwplines.size();i++){ + if (output_type == 0){ + std::cout << "\t" << lwpline2path(lwplines[i], units, scaling, tbls ) << std::endl; + } + else if (output_type == 1){ + std::cout << "\t" << lwpline2path(lwplines[i], units, scaling, tbls ) << std::endl; + } + } + for(int i = 0; i < arcs.size();i++){ + if (output_type == 0){ + std::cout << "\t" << arc2path(arcs[i], 6,units, scaling, tbls, tmp_char ) << std::endl; + } + else if (output_type == 1){ + std::cout << "\t" << arc2path(arcs[i], 6,units, scaling, tbls, tmp_char ) << std::endl; + } + } + for(int i = 0; i < circs.size();i++){ + if (output_type == 0){ + std::cout << "\t" << circle2circle(circs[i], 6, units, scaling, tbls, tmp_char) << std::endl; + } + else if (output_type == 1){ + std::cout << "\t" << circle2circle(circs[i], 6, units, scaling, tbls, tmp_char) << std::endl; + } + } + for(int i = 0; i < lns.size();i++){ + if (output_type == 0){ + std::cout << "\t" << line2line(lns[i], 6, units, scaling, tbls, tmp_char) << std::endl; + } + else if (output_type == 1){ + std::cout << "\t" << line2line(lns[i], 6, units, scaling, tbls, tmp_char) << std::endl; + } + } + for(int i = 0; i < txts.size();i++){ + if (output_type == 0){ + std::cout << "\t" << text2text(txts[i], 6, units, scaling, tbls, tmp_char) << std::endl; + } + else if (output_type == 1){ + std::cout << "\t" << text2text(txts[i], 6, units, scaling, tbls, tmp_char) << std::endl; + } + } + for(int i = 0; i < ins.size();i++){ + if (output_type == 0){ + std::cout << "\t" << insert2group(ins[i], 6, units, scaling, tbls, blks, tmp_char) << std::endl; + } + else if (output_type == 1){ + std::cout << "\t" << insert2group(ins[i], 6, units, scaling, tbls, blks, tmp_char) << std::endl; + } + } +} + + + diff --git a/src/extension/dxf2svg/entities2elements.h b/src/extension/dxf2svg/entities2elements.h new file mode 100644 index 000000000..cceefcf15 --- /dev/null +++ b/src/extension/dxf2svg/entities2elements.h @@ -0,0 +1,53 @@ +/* Method for converting dxf entities to SVG elements +There are multiple ways for converting different items + +If possible most DXF enetities will be converted to paths because that is the most flexable object + +Matt Squires +SoC 2005 + +*/ + +#include"entities.h" +#include"tables.h" +#include"blocks.h" + +// The names indicate the DXF entitiy first and the SVG element last + +// Common elements +char* to_arc(double bulge, double r, double start_ang, double end_ang, int precision,char* delim, char * units, double scaling, char *out); // This is used for arcs, polylines, and lwpolylines + +// DXF Polyline -> SVG + +char* pline2path(polyline pline, char * units, double scaling, tables plot_info); // Convert a dxf polyline to a SVG path. This is the closest conversion of the DXF polyline to an SVG element +char* pline2pline(polyline pline, char * units, double scaling, tables plot_info); // Convert a dxf polyline to a SVG polyline. The conversion is not 1:1 because the SVG pline doesn't support closed objects or curves +char* pline2polygon(polyline pline, char * units, double scaling, tables plot_info); // Convert a dxf polyline to a SVG polygon. The conversion is not 1:1 because the SVG polygone assumes a closed path. If the pline is not closed it will be forced closed + +// DXF LWPolyline -> SVG +char* lwpline2path(lwpolyline pline, char * units, double scaling, tables plot_info); // Convert a dxf polyline to a SVG path. This is the closest conversion of the DXF polyline to an SVG element + +// DXF ARC -> SVG +char* arc2path(arc a, int precision, char * units, double scaling, tables plot_info, char *out); // So far this appears to be the only way to convert arcs into something recognized by SVG + + +// DXF Circle -> SVG +char* circle2circle(circle circ, int precision, char * units, double scaling, tables plot_info, char *out); // Direct conversion of DXF circle to SVG circle +char* circle2path(circle circ, int precision, char * units, double scaling, tables plot_info, char *out); // Conversion of DXF circle to SVG circle assuming the path will represent the circle + + +// DXF Line -> SVG +char* line2line(line ln, int precision, char * units, double scaling, tables plot_info, char *out); // Directly convert DXF to SVG because it works +char* line2path(line ln, int precision, char * units, double scaling, tables plot_info, char *out); // Convert DXF line to SVG path + +// DXF Text -> SVG +char* text2text(text txt, int precision, char * units, double scaling, tables plot_info, char *out); // Directly convert DXF to SVF assuming VERANDA font + +// DXF Insert -> SVG +char* insert2group(insert in, int precision, char * units, double scaling, tables plot_info, blocks blks, char *out); + +// Write all of the possible enties with a variety of options + +char* write_by_layer(int output_type, entities &ents, tables &tbls, blocks &blks, double scaling, char * units, char * layer, char * out); // Write out the entities by layer designation +char* write_all(int output_type, entities &ents, tables &tbls, blocks &blks, double scaling, char * units, char * out); + + diff --git a/src/extension/dxf2svg/read_dxf.cpp b/src/extension/dxf2svg/read_dxf.cpp new file mode 100644 index 000000000..8a6a6d6ac --- /dev/null +++ b/src/extension/dxf2svg/read_dxf.cpp @@ -0,0 +1,273 @@ +/* + * For reading and slight parsing of dxf files + * + * Author: + * Matt Squires <squiresm@colorado.edu> + * + * Copyright (C) 2005 Matt Squires + * + * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details + */ + + + +#include<fstream> +#include<string> +#include"read_dxf.h" + +#include<iostream> +using namespace std; + + +int MAX_STR_LN = 10000; + +int section(char* value){ + if ( strncmp(value,"HEADER",6) == 0 ) return 0; + if ( strncmp(value,"CLASSES",7) == 0 ) return 1; + if ( strncmp(value,"TABLES",6) == 0 ) return 2; + if ( strncmp(value,"BLOCKS",6) == 0 ) return 3; + if ( strncmp(value,"ENTITIES",8) == 0 ) return 4; + if ( strncmp(value,"OBJECTS",7) == 0 ) return 5; + if ( strncmp(value,"THUMBNAILIMAGE",14) == 0 ) return 6; +} + + +dxfpair::dxfpair(int gcode, char val[10000]){ + group_code = gcode; + // Dynamically save the strings, otherwise the memory uses is bad + + for (int i = 0; i < strlen(val); i++){ + value.push_back(val[i]); + } +} + + +dxfpair::~dxfpair(){ + //delete [] value; +} + +char * dxfpair::value_char(char *string){ + int size = value.size(); + while( ( size > 0 ) && int(value[size-1]) < 33){ + // Strip off any control characters and spaces off the end of the string + size--; + } + for(int i = 0; i < size; i++){ + string[i] = value[i]; + } + string[size]=0; +} + +std::vector< std::vector< dxfpair > > dxf_get_sections(char* filename){ + // In the dxf format information is paired into group codes that indicate the information that follows on the next line. The information on the next line is called the value + + int n =0; + + int group_code; + char value[MAX_STR_LN]; + + int section_num; + + + + + std::vector< std::vector< dxfpair > > out; + + std::vector< dxfpair > header; + std::vector< dxfpair > classes; + std::vector< dxfpair > tables; + std::vector< dxfpair > blocks; + std::vector< dxfpair > entities; + std::vector< dxfpair > objects; + std::vector< dxfpair > thumbnailimage; + + header.clear(); + classes.clear(); + tables.clear(); + blocks.clear(); + entities.clear(); + objects.clear(); + thumbnailimage.clear(); + + + // Open dxf file for reading + std::ifstream file(filename); + + if (!file.is_open()){ + exit (1); // Change this to an exception + } + + // Find the first SECTION header + + while ( (!file.eof()) ){ + n++; + + // get the first group code and value + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + + do{ + + // TO DO set all the chars to be caps for later comparison + + // Find the SECTION codes + if ( (group_code == 0 ) && ( strncmp(value,"SECTION",7) == 0 ) ){ + // Directly after a section value is the type of section ( e.g. HEADER, TABLES ) + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + section_num = section( value ); + if ( group_code == 2 ){ + // Make sure the the group code is 2 for the SECTION name + // This is a big block of mostly repetitive code, it will result in larger code, but would be faster than putting the switch in another while loop. If I still live in a time when file size mattered alot I would change it + //std::cout << "section_num = " << section_num << std::endl; + switch ( section_num ){ + case 0: + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + do{ + header.push_back( dxfpair( group_code, value ) ); + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + }while( ( (group_code != 0) || strncmp(value,"ENDSEC",6) != 0 ) && (!file.eof()) ); // I put in the (group_code != 0) in the hope that it will be a faster bool compare than the string compare. Test this later + break; + case 1: + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + if ( (group_code != 0) || (strncmp(value,"ENDSEC",6) != 0) ){ + // Some dxf files have blank sections. These are not handled by the do/while loop so break about if needed + do{ + classes.push_back( dxfpair( group_code, value ) ); + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + }while( ( (group_code != 0) || strncmp(value,"ENDSEC",6) != 0 ) && (!file.eof()) ); // I put in the (group_code != 0) in the hope that it will be a faster bool compare than the string compare. Test this later + } + break; + case 2: + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + do{ + tables.push_back( dxfpair( group_code, value ) ); + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + }while( ( (group_code != 0) || strncmp(value,"ENDSEC",6) != 0 ) && (!file.eof()) ); + break; + case 3: + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + do{ + blocks.push_back( dxfpair( group_code, value ) ); + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + }while( ( (group_code != 0) || strncmp(value,"ENDSEC",6) != 0 ) && (!file.eof()) ); // I put in the (group_code != 0) in the hope that it will be a faster bool compare than the string compare. Test this later + break; + case 4: + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + do{ + entities.push_back( dxfpair( group_code, value ) ); + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + }while( ( (group_code != 0) || strncmp(value,"ENDSEC",6) != 0 ) && (!file.eof()) ); // I put in the (group_code != 0) in the hope that it will be a faster bool compare than the string compare. Test this later + break; + case 5: + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + do{ + objects.push_back( dxfpair( group_code, value ) ); + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + }while( ( (group_code != 0) || strncmp(value,"ENDSEC",6) != 0 ) && (!file.eof()) ); // I put in the (group_code != 0) in the hope that it will be a faster bool compare than the string compare. Test this later + break; + case 6: + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + do{ + thumbnailimage.push_back( dxfpair( group_code, value ) ); + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + }while( ( (group_code != 0) || strncmp(value,"ENDSEC",6) != 0 ) && (!file.eof()) ); // I put in the (group_code != 0) in the hope that it will be a faster bool compare than the string compare. Test this later + break; + default: + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + } + } + } + file.getline(value,MAX_STR_LN); + group_code = atoi(value); + file.getline(value,MAX_STR_LN); + + n++; + }while( ( strncmp(value,"EOF",3) != 0 ) && (!file.eof()) ); + } + + out.push_back(header); + out.push_back(classes); + out.push_back(tables); + out.push_back(blocks); + out.push_back(entities); + out.push_back(objects); + out.push_back(thumbnailimage); + + return out; +} + + +std::vector< std::vector< dxfpair > > separate_parts( std::vector< dxfpair > section){ + //std::cout << "1" << std::endl; + //std::cout << "section.size() = " << section.size() << std::endl; + // Find where the major sections are and break into smaller parts + // Major section is defined as anything beween group_code 0 to 0 + std::vector< dxfpair > inner; + std::vector< std::vector< dxfpair > > outer; + //std::cout << "2" << std::endl; + for (int i = 0; i < section.size(); i++){ + //std::cout << "i = " << i << std::endl; + //std::cout << "section[i].value.size() = " << section[i].value.size() << std::endl; + + // Make sure no control codes like LF or CR are making it past this section + if ( (section[i].value.size() > 0) && int(section[i].value.back()) < 32 ){ + section[i].value.pop_back(); + } + //for(int j = 0;j < section[i].value.size();j++ ) std::cout << section[i].value[j]; + //std::cout << std::endl; + + inner.push_back( section[i] ); + + // If the next group code is 0 then push the previously found info on outer and start looking for data again + if (section[i+1].group_code == 0){ + //std::cout << "inner.push_back" << std::endl; + outer.push_back( inner ); + inner.clear(); + } + } + // Because putting the data on outer depends on find a GC=0 the last bit of data may be left behind so it inner has data in it put it on outer + if ( inner.size() > 0 ){ + outer.push_back( inner ); + inner.clear(); + } + //std::cout << "3" << std::endl; + if (section.back().group_code == 0){ + //outer.push_back( inner ); // Put the last part on if there is information, but I don't think it needs to. + } + + return outer; +} + diff --git a/src/extension/dxf2svg/read_dxf.h b/src/extension/dxf2svg/read_dxf.h new file mode 100644 index 000000000..0708b6ce1 --- /dev/null +++ b/src/extension/dxf2svg/read_dxf.h @@ -0,0 +1,31 @@ +/* Header file for reading dxf information and basic parsing. Interprting information is found in other files +*/ + +#ifndef READ_DXF_H +#define READ_DXF_H + +#include<vector> + + + +class dxfpair{ + public: + dxfpair(int gcode, char val[10000]); + ~dxfpair(); + char * value_char(char *string); + + // Leave this data public + int group_code; + std::vector< char > value; +}; + + + + +int section(char* value); // Convert the section titles into integers + +std::vector< std::vector< dxfpair > > dxf_get_sections(char* filename); + +std::vector< std::vector< dxfpair > > separate_parts( std::vector< dxfpair > section ); // Find where the major sections are and break into smaller parts + +#endif diff --git a/src/extension/dxf2svg/tables.cpp b/src/extension/dxf2svg/tables.cpp new file mode 100644 index 000000000..fcaff33c0 --- /dev/null +++ b/src/extension/dxf2svg/tables.cpp @@ -0,0 +1,211 @@ +/* + * Code for the conversion of DXF information in the TABLES section + * + * Author: + * Matt Squires <squiresm@colorado.edu> + * + * Copyright (C) 2005 Matt Squires + * + * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details + */ + +#include"tables.h" +#include<iostream> + + + + +int determine_table(char* value){ + // Common Elements as far as I am concerend + if ( strncmp(value,"LAYER",5) == 0 ) return 0; + if ( strncmp(value,"LTYPE",5) == 0 ) return 1; + if ( strncmp(value,"STYLE",5) == 0 ) return 2; + if ( strncmp(value,"UCS",3) == 0 ) return 3; + if ( strncmp(value,"VIEW",4) == 0 ) return 4; + if ( strncmp(value,"VPORT",4) == 0 ) return 5; + if ( strncmp(value,"APPID",5) == 0 ) return 6; + if ( strncmp(value,"BLOCK_RECORD",12) == 0 ) return 7; + else return -1; +} + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// TABLE +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +int table::ret_maxN(){ + return max_number; +} + + + + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// LAYER +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +layer::layer( std::vector< dxfpair > info){ + // Get the vertex information + + //basic_entity( info ); + //static char string[10000]; + char string[10000]; + for (int i = 0; i < info.size(); i++){ + switch( info[i].group_code ){ + case 2: + info[i].value_char(layer_name); + break; + case 6: + info[i].value_char(ltype_name); + break; + + case 62: + info[i].value_char(string); + color_number = atoi(string); + //std::cout << "I found a color and its number = " << color_number << std::endl; + break; + case 290: + info[i].value_char(string); + plotting_flag = atoi(string); + break; + } + } +} + +void layer::display(){ + std::cout << "LAYER\n"; + //std::cout << "\tx = " << x << "\ty = " << y << "\tz = " << z << "\tbulge = " << bulge << std::flush; +} + +char* layer::name(char* string){ + return( strcpy(string,layer_name) ); +} + + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// LTYPE +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +ltype::ltype( std::vector< dxfpair > info){ + // Get the linetype information + + //static char string[10000]; + char string[10000]; + for (int i = 0; i < info.size(); i++){ + switch( info[i].group_code ){ + case 2: + info[i].value_char(ltype_name); + break; + case 3: + info[i].value_char(descriptive_txt); + break; + case 73: + info[i].value_char(string); + num_elements = atoi(string); + break; + case 40: + info[i].value_char(string); + pattern_length = atof(string); + break; + case 49: + info[i].value_char(string); + pattern.push_back( atof(string) ); + break; + } + } +} + + + +char* ltype::name(char* string){ + return( strcpy(string,ltype_name) ); +} + + +std::vector< double > ltype::ret_pattern(){ + return pattern; +} + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// tables +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + +tables::tables(std::vector< std::vector< dxfpair > > sections){ + // Read the main information about the entities section and then put it in the enetites class + int value; + char string[10000]; + + for(int i = 0; i < sections.size(); i++){ + //std::cout << "start" << std::endl; + sections[i][0].value_char(string); + value = determine_table(string); + //std::cout << "sections.size() = " << sections.size() << std::endl << "i = " << i << std::endl << "string = " << string << std::endl; + switch( value ){ + case 0: + // LAYER + //std::cout << "tables start layer " << std::endl; + tables_layer.push_back( layer( sections[i] ) ); + //std::cout << "tables end layer " << std::endl; + break; + + case 1: + // LTYPE + //std::cout << "tables start ltype " << std::endl; + tables_ltype.push_back( ltype( sections[i] ) ); + //std::cout << "tables end ltype " << std::endl; + break; + + //case 3: + // break; + + default: + break; + // Nothing here + } + + } + +} + + + + +ltype tables::ret_ltype(char ltype_name[10000], char layer_name[10000]){ + int string_len = 0; + char name[10000]; + char temp[10000]; + // The ltype information may be given in the entitity or in the layer information + // Assume that if there is a name defined in the linetype that it trumps any other layer information + if ( strlen(ltype_name) > 0 ) strcpy(name,ltype_name); + else strcpy(name,layer_name); + for (int i = 0; i < tables_ltype.size();i++){ + string_len = strlen(tables_ltype[i].name(temp)); + if (strncmp(tables_ltype[i].name(temp),name,string_len) == 0 ) return tables_ltype[i]; + } + return tables_ltype[0]; +} + + +layer tables::ret_layer(char layer_name[10000]){ + int string_len = 0; + char temp[10000]; + + for (int i = 0; i < tables_layer.size();i++){ + string_len = strlen(tables_layer[i].name(temp)); + if (strncmp(tables_layer[i].name(temp),layer_name,string_len) == 0 ) return tables_layer[i]; + } + return tables_layer[0]; +} + + +std::vector< layer > tables::ret_layers(){ + return tables_layer; +} diff --git a/src/extension/dxf2svg/tables.h b/src/extension/dxf2svg/tables.h new file mode 100644 index 000000000..f63122eaf --- /dev/null +++ b/src/extension/dxf2svg/tables.h @@ -0,0 +1,71 @@ +/* Code for the conversion of DXF information in the TABLES section +Matt Squires +SoC +2005*/ + +#ifndef DXF_TABLES_H +#define DXF_TABLES_H + +#include<vector> +#include"read_dxf.h" + +class table{ + public: + int ret_maxN(); + private: + int max_number; +}; + + +class layer : public table{ + public: + layer( std::vector< dxfpair > info); + void display(); + char* name(char* string); + private: + char layer_name[10000]; + char ltype_name[10000]; // The layer may also hold the ltype infomation + int color_number; + int plotting_flag; + +}; + + +class ltype : public table{ + public: + ltype( std::vector< dxfpair > info); + char* name(char* string); + std::vector< double > ret_pattern(); + private: + char ltype_name[10000]; + char descriptive_txt[10000]; + int num_elements; + double pattern_length; + std::vector< double > pattern; + +}; + + +class tables{ + // Well I said that I would only use STL containers internally, but I would have to use a dynamically linked list, and I haven't done for a long time soo STL is my crutch. + public: + tables(std::vector< std::vector< dxfpair > > sections); // Put the various entities into their respective vectors + void display_all(); + + ltype ret_ltype(char ltype_name[10000], char layer_name[10000]); + layer ret_layer(char layer_name[10000]); + + std::vector< layer > ret_layers(); + + + private: + //void add_dimstyle(polyline pline); + void add_layer(layer layr); + void add_ltype(ltype line_type); + + std::vector< layer > tables_layer; + std::vector< ltype > tables_ltype; +}; + + +#endif diff --git a/src/extension/dxf2svg/tables2svg_info.cpp b/src/extension/dxf2svg/tables2svg_info.cpp new file mode 100644 index 000000000..17bc47beb --- /dev/null +++ b/src/extension/dxf2svg/tables2svg_info.cpp @@ -0,0 +1,35 @@ +/* + * Convert DXF table information to a format that is recognized by SVG + * + * Author: + * Matt Squires <squiresm@colorado.edu> + * + * Copyright (C) 2005 Matt Squires + * + * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details + */ + + +#include"tables2svg_info.h" +#include<math.h> +#include<iostream> + +char* pattern2dasharray(ltype info, int precision, double scaling, char* out){ + std::vector< double > pattern = info.ret_pattern(); + char temp[50]; + char *out_ptr; + + + if (pattern.size() > 0){ + strcat(out," stroke-dasharray=\""); + for(int i = 0; i < pattern.size()-1;i++){ + strcat(out,gcvt(scaling*sqrt(pow(pattern[i],2)),precision,temp) ); + strcat(out,","); + } + strcat( out,gcvt(scaling*sqrt(pow(pattern[pattern.size()-1],2)),precision,temp) ); + strcat(out,"\" "); + } + + out_ptr = out; + return out_ptr; +} diff --git a/src/extension/dxf2svg/tables2svg_info.h b/src/extension/dxf2svg/tables2svg_info.h new file mode 100644 index 000000000..2c99f034e --- /dev/null +++ b/src/extension/dxf2svg/tables2svg_info.h @@ -0,0 +1,9 @@ +/* Convert DXF table information to a format that is recognized by SVG +Matt Squires +SOC 2005 +*/ + + +#include"tables.h" + +char* pattern2dasharray(ltype info, int precision, double scaling, char* temp); diff --git a/src/extension/dxf2svg/test_dxf.cpp b/src/extension/dxf2svg/test_dxf.cpp new file mode 100644 index 000000000..62969ca6e --- /dev/null +++ b/src/extension/dxf2svg/test_dxf.cpp @@ -0,0 +1,99 @@ +/* test read_dxf */ +#include"read_dxf.h" +#include"entities.h" +#include"blocks.h" +#include"tables.h" +#include<iostream> +#include"entities2elements.h" + +using namespace std; + +int main(){ + std::vector< std::vector< dxfpair > > output, entities_info, blocks_info, tables_info; + //output = dxf_get_sections("circ_sqr.dxf"); + //output = dxf_get_sections("Labjack.dxf"); + //output = dxf_get_sections("mini_post.dxf"); + //output = dxf_get_sections("../8599-E0W.dxf"); + //output = dxf_get_sections("../bulged_lwpoly.dxf"); + //output = dxf_get_sections("../aspheric_lens.dxf"); + output = dxf_get_sections("../layers_colors.dxf"); + /*std::vector< dxfpair > header; + std::vector< dxfpair > classes; + std::vector< dxfpair > tables; + std::vector< dxfpair > blocks; + std::vector< dxfpair > entities; + std::vector< dxfpair > objects; + std::vector< dxfpair > thumbnailimage; + */ + + + //dxf_get_sections("circ_sqr.dxf",header,classes,tables,blocks,entities,objects,thumbnailimage); + //dxf_get_sections("mini_post.dxf",header,classes,tables,blocks,entities,objects,thumbnailimage); + + //cout << entities.size() << endl; + for (int i=0;i<output.size();i++) cout << "output[i].size()" << i << " = " << output[i].size() << endl; + //cout << endl; + //for (int i=0;i<output[0].size();i++) cout << output[0][i].group_code << "\t" << output[0][i].value << endl; + //cout << endl; + //for (int i=0;i<output[4].size();i++) cout << output[4][i].group_code << "\t" << output[4][i].value << endl; + + // Now display the different parts of the entities section + //cout << endl; + for (int i=0;i < output[4].size();i++){ + //cout << output[4][i].group_code << " " << output[4][i].value[0] << output[4][i].value[1] << endl; + } + cout << endl; + entities_info = separate_parts(output[4]); + cout << "entities_info.size() = " << entities_info.size() << endl; + + for (int i=0;i < entities_info.size();i++){ + //for (int j=0;j < entities_info[i].size();j++) cout << entities_info[i][j].group_code << " " << entities_info[i][j].value[0] << entities_info[i][j].value[1] << entities_info[i][j].value[2] << entities_info[i][j].value[3] << entities_info[i][j].value[4] << "\n"; + //cout << endl << endl << endl; + } + + cout << "blocks separate parts" << endl; + blocks_info = separate_parts(output[3]); // Tables is the 4th part of a dxf file. + cout << "sort separated parts" << endl; + blocks blks(blocks_info); // Sort the information in the tables + cout << "blocks_info.size() = " << blocks_info.size() << endl; + + for (int i=0;i < blocks_info.size();i++){ + //for (int j=0;j < blocks_info[i].size();j++) cout << blocks_info[i][j].group_code << " " << blocks_info[i][j].value[0] << blocks_info[i][j].value[1] << blocks_info[i][j].value[2] << blocks_info[i][j].value[3] << blocks_info[i][j].value[4] << "\n"; + //cout << endl << endl << endl; + } + + + tables_info = separate_parts(output[2]); // Tables is the 3rd part of a dxf file. + cout << "tables_info.size() = " << tables_info.size() << endl; + for (int i=0;i < tables_info.size();i++){ + //for (int j=0;j < tables_info[i].size();j++) cout << tables_info[i][j].group_code << " " << tables_info[i][j].value[0] << tables_info[i][j].value[1] << tables_info[i][j].value[2] << tables_info[i][j].value[3] << tables_info[i][j].value[4] << "\n"; + //cout << "i = " << i << endl << endl; + } + tables tbls(tables_info); // Sort the information in the tables + + + + cout << "This should change \n"; + + cout << "\n\nNow display all parsed info \n"; + entities ents(entities_info); + ents.display_all(); + + //char units[5] = "in"; + char units[5] = ""; + + cout << "\nNow for the begining of the SVG...\n\n"; + + cout << "Polyline conversion\n"; + //std::vector< polyline > pl_tmp= ents.ret_plines(); + //cout << "pline2pline\n" << pline2pline(pl_tmp[0], units ) << endl; + //cout << "pline2pline\n" << pline2pline(ents.ret_plines()[0], units ) << endl; + //cout << "pline2path\n" << pline2path(ents.ret_plines()[0], units ); + + char tmp_char[10000]; + + cout << "\nCircle conversion\n"; + //cout << "circle2circle\n" << circle2circle(ents.ret_circles()[0], 3, units, tmp_char) << endl; + + return 0; +} |
