Merge lp:~valavanisalex/ubuntu/utopic/inkscape/fix-1358863 into lp:ubuntu/utopic/inkscape
- Utopic (14.10)
- fix-1358863
- Merge into utopic
Proposed by
Alex Valavanis
Status: | Merged | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 87 | ||||||||||||||||||||||||||||
Proposed branch: | lp:~valavanisalex/ubuntu/utopic/inkscape/fix-1358863 | ||||||||||||||||||||||||||||
Merge into: | lp:ubuntu/utopic/inkscape | ||||||||||||||||||||||||||||
Diff against target: |
83978 lines (+9530/-59871) 289 files modified
.pc/0001-Fix_Datamatrix_UI_issue.patch/share/extensions/render_barcode_datamatrix.inx (+0/-20) .pc/0001-Fix_Datamatrix_UI_issue.patch/share/extensions/render_barcode_datamatrix.py (+0/-654) .pc/0002-Drop_PS_and_PDF_support_in_MimeType.patch/inkscape.desktop.in (+0/-14) .pc/0003-Fix_LP_-911146.patch/src/extension/implementation/script.cpp (+0/-1034) .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/connector-context.cpp (+0/-2041) .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/extension/effect.cpp (+0/-409) .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/gradient-drag.cpp (+0/-2216) .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/libavoid/vpsc.cpp (+0/-1301) .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/libcola/straightener.cpp (+0/-361) .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/libcroco/cr-parser.c (+0/-4409) .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/libvpsc/block.cpp (+0/-422) .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/widgets/desktop-widget.h (+0/-268) .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/widgets/toolbox.cpp (+0/-8503) .pc/0005-Fix_FreeType_include.patch/src/libnrtype/FontFactory.h (+0/-163) .pc/0006-Fix_FTBFS_on_poppler-0.26.patch/configure.ac (+0/-1065) .pc/0006-Fix_FTBFS_on_poppler-0.26.patch/src/extension/internal/pdfinput/pdf-parser.cpp (+0/-3399) .pc/0006_add_unity_quicklist_support.patch/inkscape.desktop.in (+0/-14) .pc/applied-patches (+0/-8) .pc/librevenge.patch/configure.ac (+0/-1070) .pc/librevenge.patch/src/extension/internal/wpg-input.cpp (+0/-145) ChangeLog (+775/-10714) Info.plist (+3/-3) Info.plist.in (+1/-1) Makefile.in (+183/-167) NEWS (+9/-17) aclocal.m4 (+406/-348) build.xml (+1/-1) compile (+68/-31) config.guess (+106/-78) config.h.in (+3/-3) config.sub (+66/-48) configure (+520/-358) configure.ac (+28/-38) debian/changelog (+55/-0) debian/control (+3/-3) debian/patches/0004-Fix_FTBFS_on_gcc-4.8.patch (+10/-139) debian/patches/0005-Fix_FTBFS_due_to_tests.patch (+482/-0) debian/patches/0005-Fix_FreeType_include.patch (+0/-23) debian/patches/0006-Fix_FTBFS_on_poppler-0.26.patch (+0/-150) debian/patches/0006-Update_to_new_libwpg.patch (+111/-0) debian/patches/librevenge.patch (+0/-80) debian/patches/series (+2/-3) debian/rules (+2/-2) depcomp (+296/-193) doc/Makefile.in (+75/-37) inkscape.1 (+51/-42) inkscape.desktop.in (+1/-7) inkscape.el.1 (+74/-65) inkscape.fr.1 (+63/-54) inkscape.ja.1 (+33/-24) inkscape.sk.1 (+58/-49) inkscape.spec (+1/-1) inkscape.zh_TW.1 (+31/-22) install-sh (+7/-7) missing (+159/-275) mkinstalldirs (+2/-2) packaging/macosx/Resources/MenuBar.nib/classes.nib (+0/-4) packaging/macosx/Resources/MenuBar.nib/info.nib (+0/-23) packaging/macosx/Resources/MenuBar.nib/objects.xib (+0/-73) packaging/macosx/Resources/ProgressWindow.nib/classes.nib (+0/-4) packaging/macosx/Resources/ProgressWindow.nib/info.nib (+0/-18) packaging/macosx/Resources/ProgressWindow.nib/objects.xib (+0/-53) packaging/macosx/Resources/bin/getdisplay.sh (+0/-9) packaging/macosx/Resources/bin/inkscape (+0/-158) packaging/macosx/Resources/etc/fonts/fonts.conf (+0/-155) packaging/macosx/Resources/openDoc (+0/-17) packaging/macosx/Resources/script (+0/-54) packaging/macosx/Resources/themes/Clearlooks-Quicksilver-OSX/gtk-2.0/Scrollbars_1/copy-slider.sh (+0/-7) packaging/macosx/Resources/themes/Clearlooks-Quicksilver-OSX/gtk-2.0/Scrollbars_6/copy-slider.sh (+0/-7) packaging/macosx/Resources/themes/Clearlooks-Quicksilver-OSX/gtk-2.0/pre_gtkrc (+0/-547) packaging/macosx/ScriptExec/English.lproj/main.nib/classes.nib (+0/-4) packaging/macosx/ScriptExec/English.lproj/main.nib/info.nib (+0/-19) packaging/macosx/ScriptExec/English.lproj/main.nib/objects.xib (+0/-271) packaging/macosx/ScriptExec/Info.plist (+0/-39) packaging/macosx/ScriptExec/MenuBar.nib/classes.nib (+0/-4) packaging/macosx/ScriptExec/MenuBar.nib/info.nib (+0/-23) packaging/macosx/ScriptExec/MenuBar.nib/objects.xib (+0/-73) packaging/macosx/ScriptExec/ScriptExec.xcode/project.pbxproj (+0/-451) packaging/macosx/ScriptExec/ScriptExec.xcodeproj/project.pbxproj (+0/-351) packaging/macosx/ScriptExec/ScriptExec_Prefix.pch (+0/-5) packaging/macosx/ScriptExec/main.c (+0/-789) packaging/macosx/ScriptExec/openDoc (+0/-4) packaging/macosx/ScriptExec/script (+0/-4) packaging/macosx/ScriptExec/version.plist (+0/-16) packaging/macosx/osx-app.sh (+0/-499) packaging/macosx/osx-build.sh (+0/-410) packaging/macosx/osx-dmg.sh (+0/-178) packaging/win32/AdvUninstLog.nsh (+0/-437) packaging/win32/AdvUninstLog.txt (+0/-121) packaging/win32/MessageBox.txt (+0/-186) packaging/win32/RequireLatestNSIS.nsh (+0/-9) packaging/win32/VersionCompleteXXXX.nsh (+0/-47) packaging/win32/header.svg (+0/-516) packaging/win32/ifexist.nsh (+0/-21) packaging/win32/inkscape.nsi (+0/-1032) packaging/win32/inkscape.nsi.uninstall (+0/-20) packaging/win32/languages/Breton.nsh (+0/-113) packaging/win32/languages/Catalan.nsh (+0/-113) packaging/win32/languages/Czech.nsh (+0/-113) packaging/win32/languages/Dutch.nsh (+0/-113) packaging/win32/languages/English.nsh (+0/-113) packaging/win32/languages/Finnish.nsh (+0/-113) packaging/win32/languages/French.nsh (+0/-113) packaging/win32/languages/Galician.nsh (+0/-113) packaging/win32/languages/German.nsh (+0/-113) packaging/win32/languages/Indonesian.nsh (+0/-113) packaging/win32/languages/Italian.nsh (+0/-113) packaging/win32/languages/Japanese.nsh (+0/-113) packaging/win32/languages/Polish.nsh (+0/-113) packaging/win32/languages/Romanian.nsh (+0/-113) packaging/win32/languages/Russian.nsh (+0/-113) packaging/win32/languages/SimpChinese.nsh (+0/-113) packaging/win32/languages/Slovak.nsh (+0/-113) packaging/win32/languages/Slovenian.nsh (+0/-113) packaging/win32/languages/Spanish.nsh (+0/-113) packaging/win32/languages/TradChinese.nsh (+0/-113) packaging/win32/languages/Ukrainian.nsh (+0/-113) packaging/win32/md5dll.txt (+0/-68) packaging/win32/portable/App/AppInfo/appinfo.ini (+0/-26) packaging/win32/portable/App/AppInfo/installer.ini (+0/-15) packaging/win32/portable/App/readme.txt (+0/-1) packaging/win32/portable/Other/Source/InkscapePortable.ini (+0/-6) packaging/win32/portable/Other/Source/InkscapePortable.nsi (+0/-130) packaging/win32/portable/Other/Source/License.txt (+0/-344) packaging/win32/portable/Other/Source/PortableApps.comInstallerCustom.nsh (+0/-12) packaging/win32/portable/Other/Source/PortableApps.comLauncherLANG_ENGLISH.nsh (+0/-6) packaging/win32/portable/Other/Source/Readme.txt (+0/-67) packaging/win32/portable/Other/Source/ReplaceInFileWithTextReplace.nsh (+0/-64) packaging/win32/portable/help.html (+0/-178) packaging/win32/portable/readme.packaging.txt (+0/-29) packaging/win32/welcomefinish.svg (+0/-3510) po/fi.po (+1866/-2720) po/nl.po (+2/-2) share/Makefile.in (+145/-126) share/clipart/Makefile.am (+0/-1) share/clipart/Makefile.in (+75/-38) share/clipart/inkscape.logo.svg (+0/-9) share/examples/Makefile.in (+75/-37) share/examples/blend_modes.svg (+12/-12) share/examples/lighting_filters.svg (+12/-12) share/extensions/Barcode/Makefile.in (+75/-37) share/extensions/Makefile.in (+147/-128) share/extensions/Poly3DObjects/Makefile.in (+76/-39) share/extensions/alphabet_soup/Makefile.in (+76/-39) share/extensions/dxf_outlines.py (+6/-1) share/extensions/inkex.py (+8/-2) share/extensions/inkscape_help_reportabug.inx (+1/-1) share/extensions/printing-marks.inx (+5/-5) share/extensions/render_barcode_datamatrix.inx (+4/-34) share/extensions/render_barcode_datamatrix.py (+3/-46) share/extensions/scour.py (+6/-3) share/extensions/simplestyle.py (+1/-1) share/extensions/test/Makefile.in (+75/-37) share/extensions/text_braille.py (+1/-1) share/extensions/xaml2svg/Makefile.in (+76/-39) share/extensions/yocto_css.py (+6/-3) share/filters/Makefile.in (+76/-38) share/fonts/Makefile.in (+76/-38) share/gradients/Makefile.in (+76/-38) share/icons/Makefile.in (+146/-127) share/icons/application/16x16/Makefile.in (+76/-38) share/icons/application/22x22/Makefile.in (+76/-38) share/icons/application/24x24/Makefile.in (+76/-38) share/icons/application/256x256/Makefile.in (+76/-38) share/icons/application/32x32/Makefile.in (+76/-38) share/icons/application/48x48/Makefile.in (+76/-38) share/icons/application/Makefile.in (+147/-128) share/icons/inkscape.file.svg (+14/-16) share/icons/inkscape.svg (+14/-16) share/keys/Makefile.in (+76/-38) share/keys/right-handed-illustration.xml (+0/-1) share/keys/xara.xml (+0/-1) share/markers/Makefile.in (+76/-38) share/palettes/Makefile.in (+76/-38) share/palettes/Tango-Palette.gpl (+2/-0) share/patterns/Makefile.in (+76/-38) share/screens/Makefile.in (+76/-38) share/templates/Makefile.in (+75/-37) share/tutorials/Makefile.in (+75/-37) share/ui/Makefile.in (+76/-38) src/2geom/basic-intersection.cpp (+11/-1) src/2geom/interval.h (+1/-1) src/2geom/rect.h (+1/-1) src/2geom/sbasis.h (+24/-6) src/2geom/solve-bezier-parametric.cpp (+22/-5) src/Makefile.am (+1/-5) src/Makefile.in (+574/-817) src/box3d-context.cpp (+1/-1) src/color-profile.cpp (+8/-10) src/cxxtests.cpp (+62/-62) src/dialogs/export.cpp (+1/-1) src/dialogs/spellcheck.cpp (+1/-1) src/display/canvas-grid.cpp (+5/-0) src/display/nr-filter-gaussian.cpp (+2/-2) src/display/sodipodi-ctrl.cpp (+7/-2) src/display/sp-canvas.cpp (+9/-7) src/dom/io/uristream.cpp (+24/-25) src/dom/io/uristream.h (+38/-38) src/dom/svgimpl.cpp (+3/-3) src/dropper-context.cpp (+1/-1) src/extension/effect.cpp (+1/-1) src/extension/implementation/script.cpp (+1/-8) src/extension/init.cpp (+1/-1) src/extension/internal/cairo-renderer.cpp (+1/-1) src/extension/internal/filter/filter-file.cpp (+1/-1) src/extension/internal/filter/filter.cpp (+1/-1) src/extension/internal/pdfinput/svg-builder.cpp (+13/-13) src/extension/internal/wpg-input.cpp (+17/-10) src/extension/system.cpp (+2/-1) src/file.cpp (+1/-1) src/gc-core.h (+1/-1) src/gc.cpp (+13/-5) src/gradient-drag.cpp (+1/-1) src/helper/pixbuf-ops.cpp (+1/-1) src/helper/sp-marshal.cpp (+7/-7) src/helper/sp-marshal.h (+6/-6) src/inkscape-version.cpp (+1/-1) src/inkscape.rc (+5/-5) src/inkview.rc (+5/-5) src/interface.cpp (+11/-9) src/io/inkjar.cpp (+17/-9) src/io/inkjar.h (+4/-2) src/io/inkscapestream.h (+1/-0) src/io/uristream.cpp (+29/-31) src/io/uristream.h (+40/-40) src/io/xsltstream.cpp (+8/-11) src/io/xsltstream.h (+19/-21) src/libavoid/vpsc.cpp (+1/-1) src/libcola/straightener.cpp (+3/-3) src/libcroco/cr-parser.c (+1/-1) src/libcroco/cr-rgb.c (+2/-2) src/libgdl/gdl-dock-object.c (+1/-1) src/libgdl/gdl-dock-object.h (+2/-2) src/libgdl/gdl-tools.h (+1/-1) src/libnrtype/FontFactory.cpp (+1/-1) src/libnrtype/Layout-TNG-OutIter.cpp (+26/-5) src/libvpsc/Makefile_insert (+0/-2) src/libvpsc/block.cpp (+1/-1) src/libvpsc/csolve_VPSC.cpp (+0/-126) src/libvpsc/csolve_VPSC.h (+0/-60) src/live_effects/lpe-bendpath.cpp (+6/-3) src/live_effects/lpe-perp_bisector.h (+2/-2) src/main.cpp (+3/-0) src/pencil-context.cpp (+16/-9) src/preferences.cpp (+3/-0) src/prefix.cpp (+0/-3) src/registrytool.cpp (+1/-1) src/remove-last.h (+3/-2) src/select-context.cpp (+2/-2) src/selection-chemistry.cpp (+1/-1) src/selection.cpp (+2/-0) src/seltrans.cpp (+1/-1) src/sp-conn-end.cpp (+1/-1) src/sp-flowregion.cpp (+2/-2) src/sp-guide.cpp (+4/-4) src/sp-image.cpp (+4/-6) src/sp-item-group.cpp (+2/-0) src/sp-item-rm-unsatisfied-cns.cpp (+2/-2) src/sp-namedview.cpp (+4/-4) src/sp-polygon.cpp (+7/-4) src/splivarot.cpp (+15/-5) src/spray-context.cpp (+22/-32) src/trace/imagemap-gdk.cpp (+8/-6) src/trace/imagemap-gdk.h (+2/-2) src/trace/siox.cpp (+3/-12) src/trace/siox.h (+1/-11) src/trace/trace.cpp (+2/-2) src/tweak-context.cpp (+1/-1) src/ui/dialog/filedialogimpl-gtkmm.cpp (+10/-5) src/ui/dialog/filedialogimpl-win32.cpp (+10/-12) src/ui/dialog/filedialogimpl-win32.h (+12/-0) src/ui/dialog/inkscape-preferences.cpp (+5/-2) src/ui/dialog/layers.cpp (+4/-3) src/ui/dialog/print.cpp (+4/-3) src/ui/tool/multi-path-manipulator.cpp (+13/-3) src/ui/tool/node-tool.cpp (+4/-0) src/ui/tool/node.h (+8/-0) src/ui/tool/path-manipulator.cpp (+5/-1) src/ui/tool/transform-handle-set.cpp (+1/-1) src/ui/widget/registered-widget.h (+0/-3) src/verbs.cpp (+5/-0) src/widgets/desktop-widget.cpp (+12/-14) src/widgets/eek-preview.cpp (+1/-1) src/widgets/ege-paint-def.cpp (+1/-1) src/widgets/sp-color-icc-selector.cpp (+3/-3) src/widgets/toolbox.cpp (+1/-1) src/xml/repr-io.cpp (+75/-15) src/xml/repr-util.cpp (+3/-3) test-driver (+139/-0) |
||||||||||||||||||||||||||||
To merge this branch: | bzr merge lp:~valavanisalex/ubuntu/utopic/inkscape/fix-1358863 | ||||||||||||||||||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel Holbach (community) | Approve | ||
Review via email: mp+231439@code.launchpad.net |
Commit message
Description of the change
Merge upstream bugfix version 0.48.5 from Debian Unstable/Testing
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === removed directory '.pc/0001-Fix_Datamatrix_UI_issue.patch' | |||
2 | === removed directory '.pc/0001-Fix_Datamatrix_UI_issue.patch/share' | |||
3 | === removed directory '.pc/0001-Fix_Datamatrix_UI_issue.patch/share/extensions' | |||
4 | === removed file '.pc/0001-Fix_Datamatrix_UI_issue.patch/share/extensions/render_barcode_datamatrix.inx' | |||
5 | --- .pc/0001-Fix_Datamatrix_UI_issue.patch/share/extensions/render_barcode_datamatrix.inx 2013-07-02 17:25:52 +0000 | |||
6 | +++ .pc/0001-Fix_Datamatrix_UI_issue.patch/share/extensions/render_barcode_datamatrix.inx 1970-01-01 00:00:00 +0000 | |||
7 | @@ -1,20 +0,0 @@ | |||
8 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
9 | 2 | <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> | ||
10 | 3 | <_name>Barcode - Datamatrix</_name> | ||
11 | 4 | <id>il.datamatrix</id> | ||
12 | 5 | <dependency type="executable" location="extensions">render_barcode_datamatrix.py</dependency> | ||
13 | 6 | <dependency type="executable" location="extensions">inkex.py</dependency> | ||
14 | 7 | <param name="text" type="string" _gui-text="Text">Inkscape</param> | ||
15 | 8 | <param name="rows" type="int" min="8" max="144" _gui-text="Rows">10</param> | ||
16 | 9 | <param name="cols" type="int" min="10" max="144" _gui-text="Cols">10</param> | ||
17 | 10 | <param name="size" type="int" min="1" max="1000" _gui-text="Square Size / px">4</param> | ||
18 | 11 | <effect> | ||
19 | 12 | <object-type>all</object-type> | ||
20 | 13 | <effects-menu> | ||
21 | 14 | <submenu _name="Render"/> | ||
22 | 15 | </effects-menu> | ||
23 | 16 | </effect> | ||
24 | 17 | <script> | ||
25 | 18 | <command reldir="extensions" interpreter="python">render_barcode_datamatrix.py</command> | ||
26 | 19 | </script> | ||
27 | 20 | </inkscape-extension> | ||
28 | 21 | 0 | ||
29 | === removed file '.pc/0001-Fix_Datamatrix_UI_issue.patch/share/extensions/render_barcode_datamatrix.py' | |||
30 | --- .pc/0001-Fix_Datamatrix_UI_issue.patch/share/extensions/render_barcode_datamatrix.py 2013-07-02 17:25:52 +0000 | |||
31 | +++ .pc/0001-Fix_Datamatrix_UI_issue.patch/share/extensions/render_barcode_datamatrix.py 1970-01-01 00:00:00 +0000 | |||
32 | @@ -1,654 +0,0 @@ | |||
33 | 1 | #!/usr/bin/env python | ||
34 | 2 | # -*- coding: UTF-8 -*- | ||
35 | 3 | ''' | ||
36 | 4 | Copyright (C) 2009 John Beard john.j.beard@gmail.com | ||
37 | 5 | |||
38 | 6 | ######DESCRIPTION###### | ||
39 | 7 | |||
40 | 8 | This extension renders a DataMatrix 2D barcode, as specified in | ||
41 | 9 | BS ISO/IEC 16022:2006. Only ECC200 codes are considered, as these are the only | ||
42 | 10 | ones recommended for an "open" system. | ||
43 | 11 | |||
44 | 12 | The size of the DataMatrix is variable between 10x10 to 144x144 | ||
45 | 13 | |||
46 | 14 | The absolute size of the DataMatrix modules (the little squares) is also | ||
47 | 15 | variable. | ||
48 | 16 | |||
49 | 17 | If more data is given than can be contained in one DataMatrix, | ||
50 | 18 | more than one DataMatrices will be produced. | ||
51 | 19 | |||
52 | 20 | Text is encoded as ASCII (the standard provides for other options, but these are | ||
53 | 21 | not implemented). Consecutive digits are encoded in a compressed form, halving | ||
54 | 22 | the space required to store them. | ||
55 | 23 | |||
56 | 24 | The basis processing flow is; | ||
57 | 25 | * Convert input string to codewords (modified ASCII and compressed digits) | ||
58 | 26 | * Split codewords into blocks of the right size for Reed-Solomon coding | ||
59 | 27 | * Interleave the blocks if required | ||
60 | 28 | * Apply Reed-Solomon coding | ||
61 | 29 | * De-interleave the blocks if required | ||
62 | 30 | * Place the codewords into the matrix bit by bit | ||
63 | 31 | * Render the modules in the matrix as squares | ||
64 | 32 | |||
65 | 33 | ######LICENCE####### | ||
66 | 34 | This program is free software; you can redistribute it and/or modify | ||
67 | 35 | it under the terms of the GNU General Public License as published by | ||
68 | 36 | the Free Software Foundation; either version 2 of the License, or | ||
69 | 37 | (at your option) any later version. | ||
70 | 38 | |||
71 | 39 | This program is distributed in the hope that it will be useful, | ||
72 | 40 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
73 | 41 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
74 | 42 | GNU General Public License for more details. | ||
75 | 43 | |||
76 | 44 | You should have received a copy of the GNU General Public License | ||
77 | 45 | along with this program; if not, write to the Free Software | ||
78 | 46 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
79 | 47 | |||
80 | 48 | ######VERSION HISTORY##### | ||
81 | 49 | Ver. Date Notes | ||
82 | 50 | |||
83 | 51 | 0.50 2009-10-25 Full functionality, up to 144x144. | ||
84 | 52 | ASCII and compressed digit encoding only. | ||
85 | 53 | ''' | ||
86 | 54 | |||
87 | 55 | import inkex, simplestyle | ||
88 | 56 | |||
89 | 57 | import gettext | ||
90 | 58 | _ = gettext.gettext | ||
91 | 59 | |||
92 | 60 | #ENCODING ROUTINES =================================================== | ||
93 | 61 | # Take an input string and convert it to a sequence (or sequences) | ||
94 | 62 | # of codewords as specified in ISO/IEC 16022:2006 (section 5.2.3) | ||
95 | 63 | #===================================================================== | ||
96 | 64 | |||
97 | 65 | #create a 2d list corresponding to the 1's and 0s of the DataMatrix | ||
98 | 66 | def encode(text, (nrow, ncol) ): | ||
99 | 67 | #retreive the parameters of this size of DataMatrix | ||
100 | 68 | data_nrow, data_ncol, reg_row, reg_col, nd, nc, inter = get_parameters( nrow, ncol ) | ||
101 | 69 | |||
102 | 70 | if not ((nrow == 144) and (ncol == 144)): #we have a regular datamatrix | ||
103 | 71 | size144 = False | ||
104 | 72 | else: #special handling will be required by get_codewords() | ||
105 | 73 | size144 = True | ||
106 | 74 | |||
107 | 75 | #generate the codewords including padding and ECC | ||
108 | 76 | codewords = get_codewords( text, nd, nc, inter, size144 ) | ||
109 | 77 | |||
110 | 78 | # break up into separate arrays if more than one DataMatrix is needed | ||
111 | 79 | module_arrays = [] | ||
112 | 80 | for codeword_stream in codewords: #for each datamatrix | ||
113 | 81 | bit_array = place_bits(codeword_stream, (data_nrow*reg_row, data_ncol*reg_col)) #place the codewords' bits across the array as modules | ||
114 | 82 | module_arrays.append(add_finder_pattern( bit_array, data_nrow, data_ncol, reg_row, reg_col )) #add finder patterns around the modules | ||
115 | 83 | |||
116 | 84 | return module_arrays | ||
117 | 85 | |||
118 | 86 | #return parameters for the selected datamatrix size | ||
119 | 87 | # data_nrow number of rows in each data region | ||
120 | 88 | # data_ncol number of cols in each data region | ||
121 | 89 | # reg_row number of rows of data regions | ||
122 | 90 | # reg_col number of cols of data regions | ||
123 | 91 | # nd number of data codewords per reed-solomon block | ||
124 | 92 | # nc number of ECC codewords per reed-solomon block | ||
125 | 93 | # inter number of interleaved Reed-Solomon blocks | ||
126 | 94 | def get_parameters(nrow, ncol): | ||
127 | 95 | |||
128 | 96 | #SQUARE SYMBOLS | ||
129 | 97 | if ( nrow == 10 and ncol == 10 ): | ||
130 | 98 | return 8, 8, 1, 1, 3, 5, 1 | ||
131 | 99 | elif ( nrow == 12 and ncol == 12 ): | ||
132 | 100 | return 10, 10, 1, 1, 5, 7, 1 | ||
133 | 101 | elif ( nrow == 14 and ncol == 14 ): | ||
134 | 102 | return 12, 12, 1, 1, 8, 10, 1 | ||
135 | 103 | elif ( nrow == 16 and ncol == 16 ): | ||
136 | 104 | return 14, 14, 1, 1, 12, 12, 1 | ||
137 | 105 | elif ( nrow == 18 and ncol == 18 ): | ||
138 | 106 | return 16, 16, 1, 1, 18, 14, 1 | ||
139 | 107 | elif ( nrow == 20 and ncol == 20 ): | ||
140 | 108 | return 18, 18, 1, 1, 22, 18, 1 | ||
141 | 109 | elif ( nrow == 22 and ncol == 22 ): | ||
142 | 110 | return 18, 18, 1, 1, 30, 20, 1 | ||
143 | 111 | elif ( nrow == 24 and ncol == 24 ): | ||
144 | 112 | return 22, 22, 1, 1, 36, 24, 1 | ||
145 | 113 | elif ( nrow == 26 and ncol == 26 ): | ||
146 | 114 | return 24, 24, 1, 1, 44, 28, 1 | ||
147 | 115 | elif ( nrow == 32 and ncol == 32 ): | ||
148 | 116 | return 14, 14, 2, 2, 62, 36, 1 | ||
149 | 117 | elif ( nrow == 36 and ncol == 36 ): | ||
150 | 118 | return 16, 16, 2, 2, 86, 42, 1 | ||
151 | 119 | elif ( nrow == 40 and ncol == 40): | ||
152 | 120 | return 18, 18, 2, 2, 114, 48, 1 | ||
153 | 121 | elif ( nrow == 44 and ncol == 44): | ||
154 | 122 | return 20, 20, 2, 2, 144, 56, 1 | ||
155 | 123 | elif ( nrow == 48 and ncol == 48 ): | ||
156 | 124 | return 22, 22, 2, 2, 174, 68, 1 | ||
157 | 125 | |||
158 | 126 | elif ( nrow == 52 and ncol == 52 ): | ||
159 | 127 | return 24, 24, 2, 2, 102, 42, 2 | ||
160 | 128 | elif ( nrow == 64 and ncol == 64 ): | ||
161 | 129 | return 16, 16, 4, 4, 140, 56, 2 | ||
162 | 130 | |||
163 | 131 | elif ( nrow == 72 and ncol == 72 ): | ||
164 | 132 | return 16, 16, 4, 4, 92, 36, 4 | ||
165 | 133 | elif ( nrow == 80 and ncol == 80 ): | ||
166 | 134 | return 18, 18, 4, 4, 114, 48, 4 | ||
167 | 135 | elif ( nrow == 88 and ncol == 88 ): | ||
168 | 136 | return 20, 20, 4, 4, 144, 56, 4 | ||
169 | 137 | elif ( nrow == 96 and ncol == 96 ): | ||
170 | 138 | return 22, 22, 4, 4, 174, 68, 4 | ||
171 | 139 | |||
172 | 140 | elif ( nrow == 104 and ncol == 104 ): | ||
173 | 141 | return 24, 24, 4, 4, 136, 56, 6 | ||
174 | 142 | elif ( nrow == 120 and ncol == 120): | ||
175 | 143 | return 18, 18, 6, 6, 175, 68, 6 | ||
176 | 144 | |||
177 | 145 | elif ( nrow == 132 and ncol == 132): | ||
178 | 146 | return 20, 20, 6, 6, 163, 62, 8 | ||
179 | 147 | |||
180 | 148 | elif (nrow == 144 and ncol == 144): | ||
181 | 149 | return 22, 22, 6, 6, 0, 0, 0 #there are two separate sections of the data matrix with | ||
182 | 150 | #different interleaving and reed-solomon parameters. | ||
183 | 151 | #this will be handled separately | ||
184 | 152 | |||
185 | 153 | #RECTANGULAR SYMBOLS | ||
186 | 154 | elif ( nrow == 8 and ncol == 18 ): | ||
187 | 155 | return 6, 16, 1, 1, 5, 7, 1 | ||
188 | 156 | elif ( nrow == 8 and ncol == 32 ): | ||
189 | 157 | return 6, 14, 1, 2, 10, 11, 1 | ||
190 | 158 | elif ( nrow == 12 and ncol == 26 ): | ||
191 | 159 | return 10, 24, 1, 1, 16, 14, 1 | ||
192 | 160 | elif ( nrow == 12 and ncol == 36 ): | ||
193 | 161 | return 10, 16, 1, 2, 22, 18, 1 | ||
194 | 162 | elif ( nrow == 16 and ncol == 36 ): | ||
195 | 163 | return 14, 16, 1, 2, 32, 24, 1 | ||
196 | 164 | elif ( nrow == 16 and ncol == 48 ): | ||
197 | 165 | return 14, 22, 1, 2, 49, 28, 1 | ||
198 | 166 | |||
199 | 167 | #RETURN ERROR | ||
200 | 168 | else: | ||
201 | 169 | inkex.errormsg(_('Unrecognised DataMatrix size')) | ||
202 | 170 | |||
203 | 171 | return None | ||
204 | 172 | |||
205 | 173 | # CODEWORD STREAM GENERATION ========================================= | ||
206 | 174 | #take the text input and return the codewords, | ||
207 | 175 | #including the Reed-Solomon error-correcting codes. | ||
208 | 176 | #===================================================================== | ||
209 | 177 | |||
210 | 178 | def get_codewords( text, nd, nc, inter, size144 ): | ||
211 | 179 | #convert the data to the codewords | ||
212 | 180 | data = encode_to_ascii( text ) | ||
213 | 181 | |||
214 | 182 | if not size144: #render a "normal" datamatrix | ||
215 | 183 | data_blocks = partition_data(data, nd*inter) #partition into data blocks of length nd*inter -> inter Reed-Solomon block | ||
216 | 184 | |||
217 | 185 | data_blocks = interleave( data_blocks, inter) # interleave consecutive inter blocks if required | ||
218 | 186 | |||
219 | 187 | data_blocks = reed_solomon(data_blocks, nd, nc) #generate and append the Reed-Solomon codewords | ||
220 | 188 | |||
221 | 189 | data_blocks = combine_interleaved(data_blocks, inter, nd, nc, False) #concatenate Reed-Solomon blocks bound for the same datamatrix | ||
222 | 190 | |||
223 | 191 | else: #we have a 144x144 datamatrix | ||
224 | 192 | data_blocks = partition_data(data, 1558) #partition the data into datamtrix-sized chunks (1558 =156*8 + 155*2 ) | ||
225 | 193 | |||
226 | 194 | for i in range(len(data_blocks)): #for each datamtrix | ||
227 | 195 | |||
228 | 196 | |||
229 | 197 | inter = 8 | ||
230 | 198 | nd = 156 | ||
231 | 199 | nc = 62 | ||
232 | 200 | block1 = data_blocks[i][0:156*8] | ||
233 | 201 | block1 = interleave( [block1], inter) # interleave into 8 blocks | ||
234 | 202 | block1 = reed_solomon(block1, nd, nc) #generate and append the Reed-Solomon codewords | ||
235 | 203 | |||
236 | 204 | inter = 2 | ||
237 | 205 | nd = 155 | ||
238 | 206 | nc = 62 | ||
239 | 207 | block2 = data_blocks[i][156*8:] | ||
240 | 208 | block2 = interleave( [block2], inter) # interleave into 2 blocks | ||
241 | 209 | block2 = reed_solomon(block2, nd, nc) #generate and append the Reed-Solomon codewords | ||
242 | 210 | |||
243 | 211 | blocks = block1 | ||
244 | 212 | blocks.extend(block2) | ||
245 | 213 | |||
246 | 214 | blocks = combine_interleaved(blocks, 10, nd, nc, True) | ||
247 | 215 | |||
248 | 216 | data_blocks[i] = blocks[0] | ||
249 | 217 | |||
250 | 218 | |||
251 | 219 | return data_blocks | ||
252 | 220 | |||
253 | 221 | |||
254 | 222 | #Takes a codeword stream and splits up into "inter" blocks. | ||
255 | 223 | #eg interleave( [1,2,3,4,5,6], 2 ) -> [1,3,5], [2,4,6] | ||
256 | 224 | def interleave( blocks, inter): | ||
257 | 225 | |||
258 | 226 | if inter == 1: # if we don't have to interleave, just return the blocks | ||
259 | 227 | return blocks | ||
260 | 228 | else: | ||
261 | 229 | result = [] | ||
262 | 230 | for block in blocks: #for each codeword block in the stream | ||
263 | 231 | block_length = len(block)/inter #length of each interleaved block | ||
264 | 232 | inter_blocks = [[0] * block_length for i in xrange(inter)] #the interleaved blocks | ||
265 | 233 | |||
266 | 234 | for i in range(block_length): #for each element in the interleaved blocks | ||
267 | 235 | for j in range(inter): #for each interleaved block | ||
268 | 236 | inter_blocks[j][i] = block[ i*inter + j ] | ||
269 | 237 | |||
270 | 238 | result.extend(inter_blocks) #add the interleaved blocks to the output | ||
271 | 239 | |||
272 | 240 | return result | ||
273 | 241 | |||
274 | 242 | #Combine interleaved blocks into the groups for the same datamatrix | ||
275 | 243 | # | ||
276 | 244 | #e.g combine_interleaved( [[d1, d3, d5, e1, e3, e5], [d2, d4, d6, e2, e4, e6]], 2, 3, 3 ) | ||
277 | 245 | # --> [[d1, d2, d3, d4, d5, d6, e1, e2, e3, e4, e5, e6]] | ||
278 | 246 | def combine_interleaved( blocks, inter, nd, nc, size144): | ||
279 | 247 | if inter == 1: #the blocks aren't interleaved | ||
280 | 248 | return blocks | ||
281 | 249 | else: | ||
282 | 250 | result = [] | ||
283 | 251 | for i in range( len(blocks) / inter ): #for each group of "inter" blocks -> one full datamatrix | ||
284 | 252 | data_codewords = [] #interleaved data blocks | ||
285 | 253 | |||
286 | 254 | if size144: | ||
287 | 255 | nd_range = 1558 #1558 = 156*8 + 155*2 | ||
288 | 256 | nc_range = 620 #620 = 62*8 + 62*2 | ||
289 | 257 | else: | ||
290 | 258 | nd_range = nd*inter | ||
291 | 259 | nc_range = nc*inter | ||
292 | 260 | |||
293 | 261 | for j in range(nd_range): #for each codeword in the final list | ||
294 | 262 | data_codewords.append( blocks[i*inter + j%inter][j/inter] ) | ||
295 | 263 | |||
296 | 264 | for j in range(nc_range): #for each block, add the ecc codewords | ||
297 | 265 | data_codewords.append( blocks[i*inter + j%inter][nd + j/inter] ) | ||
298 | 266 | |||
299 | 267 | result.append(data_codewords) | ||
300 | 268 | return result | ||
301 | 269 | |||
302 | 270 | #checks if an ASCII character is a digit from 0 - 9 | ||
303 | 271 | def is_digit( char ): | ||
304 | 272 | |||
305 | 273 | if ord(char) >= 48 and ord(char) <= 57: | ||
306 | 274 | return True | ||
307 | 275 | else: | ||
308 | 276 | return False | ||
309 | 277 | |||
310 | 278 | def encode_to_ascii( text): | ||
311 | 279 | |||
312 | 280 | ascii = [] | ||
313 | 281 | i = 0 | ||
314 | 282 | while i < len(text): | ||
315 | 283 | #check for double digits | ||
316 | 284 | if is_digit( text[i] ) and ( i < len(text)-1) and is_digit( text[i+1] ): #if the next char is also a digit | ||
317 | 285 | |||
318 | 286 | codeword = int( text[i] + text[i+1] ) + 130 | ||
319 | 287 | ascii.append( codeword ) | ||
320 | 288 | i = i + 2 #move on 2 characters | ||
321 | 289 | else: #encode as a normal ascii, | ||
322 | 290 | ascii.append( ord(text[i] ) + 1 ) #codeword is ASCII value + 1 (ISO 16022:2006 5.2.3) | ||
323 | 291 | i = i + 1 #next character | ||
324 | 292 | |||
325 | 293 | return ascii | ||
326 | 294 | |||
327 | 295 | |||
328 | 296 | #partition data into blocks of the appropriate size to suit the | ||
329 | 297 | #Reed-Solomon block being used. | ||
330 | 298 | #e.g. partition_data([1,2,3,4,5], 3) -> [[1,2,3],[4,5,PAD]] | ||
331 | 299 | def partition_data( data , rs_data): | ||
332 | 300 | |||
333 | 301 | PAD_VAL = 129 # PAD codeword (ISO 16022:2006 5.2.3) | ||
334 | 302 | data_blocks = [] | ||
335 | 303 | i = 0 | ||
336 | 304 | while i < len(data): | ||
337 | 305 | if len(data) >= i+rs_data: #we have a whole block in our data | ||
338 | 306 | data_blocks.append( data[i:i+rs_data] ) | ||
339 | 307 | i = i + rs_data | ||
340 | 308 | else: #pad out with the pad codeword | ||
341 | 309 | data_block = data[i:len(data)] #add any remaining data | ||
342 | 310 | pad_pos = len(data) | ||
343 | 311 | padded = False | ||
344 | 312 | while len(data_block) < rs_data:#and then pad with randomised pad codewords | ||
345 | 313 | if not padded: | ||
346 | 314 | data_block.append( PAD_VAL ) #add a normal pad codeword | ||
347 | 315 | padded = True | ||
348 | 316 | else: | ||
349 | 317 | data_block.append( randomise_pad_253( PAD_VAL, pad_pos) ) | ||
350 | 318 | pad_pos = pad_pos + 1 | ||
351 | 319 | data_blocks.append( data_block) | ||
352 | 320 | break | ||
353 | 321 | |||
354 | 322 | return data_blocks | ||
355 | 323 | |||
356 | 324 | #Pad character randomisation, to prevent regular patterns appearing | ||
357 | 325 | #in the data matrix | ||
358 | 326 | def randomise_pad_253(pad_value, pad_position ): | ||
359 | 327 | pseudo_random_number = ( ( 149 * pad_position ) % 253 )+ 1 | ||
360 | 328 | randomised = pad_value + pseudo_random_number | ||
361 | 329 | if ( randomised <= 254 ): | ||
362 | 330 | return randomised | ||
363 | 331 | else: | ||
364 | 332 | return randomised - 254 | ||
365 | 333 | |||
366 | 334 | # REED-SOLOMON ENCODING ROUTINES ===================================== | ||
367 | 335 | |||
368 | 336 | # "prod(x,y,log,alog,gf)" returns the product "x" times "y" | ||
369 | 337 | def prod(x, y, log, alog, gf): | ||
370 | 338 | |||
371 | 339 | if ( x==0 or y==0): | ||
372 | 340 | return 0 | ||
373 | 341 | else: | ||
374 | 342 | result = alog[ ( log[x] + log[y] ) % (gf - 1) ] | ||
375 | 343 | return result | ||
376 | 344 | |||
377 | 345 | # generate the log & antilog lists: | ||
378 | 346 | def gen_log_alog(gf, pp): | ||
379 | 347 | log = [0]*gf | ||
380 | 348 | alog = [0]*gf | ||
381 | 349 | |||
382 | 350 | log[0] = 1-gf | ||
383 | 351 | alog[0] = 1 | ||
384 | 352 | |||
385 | 353 | for i in range(1,gf): | ||
386 | 354 | alog[i] = alog[i-1] * 2 | ||
387 | 355 | |||
388 | 356 | if (alog[i] >= gf): | ||
389 | 357 | alog[i] = alog[i] ^ pp | ||
390 | 358 | |||
391 | 359 | log[alog[i]] = i | ||
392 | 360 | |||
393 | 361 | return log, alog | ||
394 | 362 | |||
395 | 363 | # generate the generator polynomial coefficients: | ||
396 | 364 | def gen_poly_coeffs(nc, log, alog, gf): | ||
397 | 365 | c = [0] * (nc+1) | ||
398 | 366 | c[0] = 1 | ||
399 | 367 | |||
400 | 368 | for i in range(1,nc+1): | ||
401 | 369 | c[i] = c[i-1] | ||
402 | 370 | |||
403 | 371 | j = i-1 | ||
404 | 372 | while j >= 1: | ||
405 | 373 | c[j] = c[j-1] ^ prod(c[j],alog[i],log,alog,gf) | ||
406 | 374 | j = j - 1 | ||
407 | 375 | |||
408 | 376 | c[0] = prod(c[0],alog[i],log,alog,gf) | ||
409 | 377 | |||
410 | 378 | return c | ||
411 | 379 | |||
412 | 380 | # "ReedSolomon(wd,nd,nc)" takes "nd" data codeword values in wd[] | ||
413 | 381 | # and adds on "nc" check codewords, all within GF(gf) where "gf" is a | ||
414 | 382 | # power of 2 and "pp" is the value of its prime modulus polynomial */ | ||
415 | 383 | def reed_solomon(data, nd, nc): | ||
416 | 384 | #parameters of the polynomial arithmetic | ||
417 | 385 | gf = 256 #operating on 8-bit codewords -> Galois field = 2^8 = 256 | ||
418 | 386 | pp = 301 #prime modulus polynomial for ECC-200 is 0b100101101 = 301 (ISO 16022:2006 5.7.1) | ||
419 | 387 | |||
420 | 388 | log, alog = gen_log_alog(gf,pp) | ||
421 | 389 | c = gen_poly_coeffs(nc, log, alog, gf) | ||
422 | 390 | |||
423 | 391 | for block in data: #for each block of data codewords | ||
424 | 392 | |||
425 | 393 | block.extend( [0]*(nc+1) ) #extend to make space for the error codewords | ||
426 | 394 | |||
427 | 395 | #generate "nc" checkwords in the list block | ||
428 | 396 | for i in range(0, nd): | ||
429 | 397 | k = block[nd] ^ block[i] | ||
430 | 398 | |||
431 | 399 | for j in range(0,nc): | ||
432 | 400 | block[nd+j] = block[nd+j+1] ^ prod(k,c[nc-j-1],log, alog,gf) | ||
433 | 401 | |||
434 | 402 | block.pop() | ||
435 | 403 | |||
436 | 404 | return data | ||
437 | 405 | |||
438 | 406 | #MODULE PLACEMENT ROUTINES=========================================== | ||
439 | 407 | # These routines take a steam of codewords, and place them into the | ||
440 | 408 | # DataMatrix in accordance with Annex F of BS ISO/IEC 16022:2006 | ||
441 | 409 | |||
442 | 410 | # bit() returns the bit'th bit of the byte | ||
443 | 411 | def bit(byte, bit): | ||
444 | 412 | #the MSB is bit 1, LSB is bit 8 | ||
445 | 413 | return ( byte >> (8-bit) ) %2 | ||
446 | 414 | |||
447 | 415 | # "module" places a given bit with appropriate wrapping within array | ||
448 | 416 | def module(array, nrow, ncol, row, col, bit) : | ||
449 | 417 | if (row < 0) : | ||
450 | 418 | row = row + nrow | ||
451 | 419 | col = col + 4 - ((nrow+4)%8) | ||
452 | 420 | |||
453 | 421 | if (col < 0): | ||
454 | 422 | col = col + ncol | ||
455 | 423 | row = row + 4 - ((ncol+4)%8) | ||
456 | 424 | |||
457 | 425 | array[row][col] = bit | ||
458 | 426 | |||
459 | 427 | def corner1(array, nrow, ncol, char): | ||
460 | 428 | module(array, nrow, ncol, nrow-1, 0, bit(char,1)); | ||
461 | 429 | module(array, nrow, ncol, nrow-1, 1, bit(char,2)); | ||
462 | 430 | module(array, nrow, ncol, nrow-1, 2, bit(char,3)); | ||
463 | 431 | module(array, nrow, ncol, 0, ncol-2, bit(char,4)); | ||
464 | 432 | module(array, nrow, ncol, 0, ncol-1, bit(char,5)); | ||
465 | 433 | module(array, nrow, ncol, 1, ncol-1, bit(char,6)); | ||
466 | 434 | module(array, nrow, ncol, 2, ncol-1, bit(char,7)); | ||
467 | 435 | module(array, nrow, ncol, 3, ncol-1, bit(char,8)); | ||
468 | 436 | |||
469 | 437 | def corner2(array, nrow, ncol, char): | ||
470 | 438 | module(array, nrow, ncol, nrow-3, 0, bit(char,1)); | ||
471 | 439 | module(array, nrow, ncol, nrow-2, 0, bit(char,2)); | ||
472 | 440 | module(array, nrow, ncol, nrow-1, 0, bit(char,3)); | ||
473 | 441 | module(array, nrow, ncol, 0, ncol-4, bit(char,4)); | ||
474 | 442 | module(array, nrow, ncol, 0, ncol-3, bit(char,5)); | ||
475 | 443 | module(array, nrow, ncol, 0, ncol-2, bit(char,6)); | ||
476 | 444 | module(array, nrow, ncol, 0, ncol-1, bit(char,7)); | ||
477 | 445 | module(array, nrow, ncol, 1, ncol-1, bit(char,8)); | ||
478 | 446 | |||
479 | 447 | def corner3(array, nrow, ncol, char): | ||
480 | 448 | module(array, nrow, ncol, nrow-3, 0, bit(char,1)); | ||
481 | 449 | module(array, nrow, ncol, nrow-2, 0, bit(char,2)); | ||
482 | 450 | module(array, nrow, ncol, nrow-1, 0, bit(char,3)); | ||
483 | 451 | module(array, nrow, ncol, 0, ncol-2, bit(char,4)); | ||
484 | 452 | module(array, nrow, ncol, 0, ncol-1, bit(char,5)); | ||
485 | 453 | module(array, nrow, ncol, 1, ncol-1, bit(char,6)); | ||
486 | 454 | module(array, nrow, ncol, 2, ncol-1, bit(char,7)); | ||
487 | 455 | module(array, nrow, ncol, 3, ncol-1, bit(char,8)); | ||
488 | 456 | |||
489 | 457 | def corner4(array, nrow, ncol, char): | ||
490 | 458 | module(array, nrow, ncol, nrow-1, 0, bit(char,1)); | ||
491 | 459 | module(array, nrow, ncol, nrow-1, ncol-1, bit(char,2)); | ||
492 | 460 | module(array, nrow, ncol, 0, ncol-3, bit(char,3)); | ||
493 | 461 | module(array, nrow, ncol, 0, ncol-2, bit(char,4)); | ||
494 | 462 | module(array, nrow, ncol, 0, ncol-1, bit(char,5)); | ||
495 | 463 | module(array, nrow, ncol, 1, ncol-3, bit(char,6)); | ||
496 | 464 | module(array, nrow, ncol, 1, ncol-2, bit(char,7)); | ||
497 | 465 | module(array, nrow, ncol, 1, ncol-1, bit(char,8)); | ||
498 | 466 | |||
499 | 467 | #"utah" places the 8 bits of a utah-shaped symbol character in ECC200 | ||
500 | 468 | def utah(array, nrow, ncol, row, col, char): | ||
501 | 469 | module(array, nrow, ncol,row-2, col-2, bit(char,1)) | ||
502 | 470 | module(array, nrow, ncol,row-2, col-1, bit(char,2)) | ||
503 | 471 | module(array, nrow, ncol,row-1, col-2, bit(char,3)) | ||
504 | 472 | module(array, nrow, ncol,row-1, col-1, bit(char,4)) | ||
505 | 473 | module(array, nrow, ncol,row-1, col, bit(char,5)) | ||
506 | 474 | module(array, nrow, ncol,row, col-2, bit(char,6)) | ||
507 | 475 | module(array, nrow, ncol,row, col-1, bit(char,7)) | ||
508 | 476 | module(array, nrow, ncol,row, col, bit(char,8)) | ||
509 | 477 | |||
510 | 478 | #"place_bits" fills an nrow x ncol array with the bits from the | ||
511 | 479 | # codewords in data. | ||
512 | 480 | def place_bits(data, (nrow, ncol)): | ||
513 | 481 | # First, fill the array[] with invalid entries */ | ||
514 | 482 | INVALID = 2 | ||
515 | 483 | array = [[INVALID] * ncol for i in xrange(nrow)] #initialise and fill with -1's (invalid value) | ||
516 | 484 | # Starting in the correct location for character #1, bit 8,... | ||
517 | 485 | char = 0 | ||
518 | 486 | row = 4 | ||
519 | 487 | col = 0 | ||
520 | 488 | while True: | ||
521 | 489 | |||
522 | 490 | #first check for one of the special corner cases, then... | ||
523 | 491 | if ((row == nrow) and (col == 0)): | ||
524 | 492 | corner1(array, nrow, ncol, data[char]) | ||
525 | 493 | char = char + 1 | ||
526 | 494 | if ((row == nrow-2) and (col == 0) and (ncol%4)) : | ||
527 | 495 | corner2(array, nrow, ncol, data[char]) | ||
528 | 496 | char = char + 1 | ||
529 | 497 | if ((row == nrow-2) and (col == 0) and (ncol%8 == 4)): | ||
530 | 498 | corner3(array, nrow, ncol, data[char]) | ||
531 | 499 | char = char + 1 | ||
532 | 500 | if ((row == nrow+4) and (col == 2) and ((ncol%8) == 0)): | ||
533 | 501 | corner4(array, nrow, ncol, data[char]) | ||
534 | 502 | char = char + 1 | ||
535 | 503 | |||
536 | 504 | #sweep upward diagonally, inserting successive characters,... | ||
537 | 505 | while True: | ||
538 | 506 | if ((row < nrow) and (col >= 0) and (array[row][col] == INVALID)) : | ||
539 | 507 | utah(array, nrow, ncol,row,col,data[char]) | ||
540 | 508 | char = char+1 | ||
541 | 509 | row = row - 2 | ||
542 | 510 | col = col + 2 | ||
543 | 511 | |||
544 | 512 | if not((row >= 0) and (col < ncol)): | ||
545 | 513 | break | ||
546 | 514 | |||
547 | 515 | row = row + 1 | ||
548 | 516 | col = col + 3 | ||
549 | 517 | |||
550 | 518 | # & then sweep downward diagonally, inserting successive characters,... | ||
551 | 519 | while True: | ||
552 | 520 | if ((row >= 0) and (col < ncol) and (array[row][col] == INVALID)) : | ||
553 | 521 | utah(array, nrow, ncol,row,col,data[char]) | ||
554 | 522 | char = char + 1 | ||
555 | 523 | row = row + 2 | ||
556 | 524 | col = col - 2 | ||
557 | 525 | |||
558 | 526 | if not((row < nrow) and (col >= 0)): | ||
559 | 527 | break | ||
560 | 528 | |||
561 | 529 | row = row + 3 | ||
562 | 530 | col = col + 1 | ||
563 | 531 | |||
564 | 532 | #... until the entire array is scanned | ||
565 | 533 | if not((row < nrow) or (col < ncol)): | ||
566 | 534 | break | ||
567 | 535 | |||
568 | 536 | # Lastly, if the lower righthand corner is untouched, fill in fixed pattern */ | ||
569 | 537 | if (array[nrow-1][ncol-1] == INVALID): | ||
570 | 538 | array[nrow-1][ncol-2] = 0 | ||
571 | 539 | array[nrow-1][ncol-1] = 1 | ||
572 | 540 | array[nrow-2][ncol-1] = 0 | ||
573 | 541 | array[nrow-2][ncol-2] = 1 | ||
574 | 542 | |||
575 | 543 | return array #return the array of 1's and 0's | ||
576 | 544 | |||
577 | 545 | |||
578 | 546 | def add_finder_pattern( array, data_nrow, data_ncol, reg_row, reg_col ): | ||
579 | 547 | |||
580 | 548 | #get the total size of the datamatrix | ||
581 | 549 | nrow = (data_nrow+2) * reg_row | ||
582 | 550 | ncol = (data_ncol+2) * reg_col | ||
583 | 551 | |||
584 | 552 | datamatrix = [[0] * ncol for i in xrange(nrow)] #initialise and fill with 0's | ||
585 | 553 | |||
586 | 554 | for i in range( reg_col ): #for each column of data regions | ||
587 | 555 | for j in range(nrow): | ||
588 | 556 | datamatrix[j][i*(data_ncol+2)] = 1 #vertical black bar on left | ||
589 | 557 | datamatrix[j][i*(data_ncol+2)+data_ncol+1] = (j)%2 # alternating blocks | ||
590 | 558 | |||
591 | 559 | for i in range( reg_row): # for each row of data regions | ||
592 | 560 | for j in range(ncol): | ||
593 | 561 | datamatrix[i*(data_nrow+2)+data_nrow+1][j] = 1 #horizontal black bar at bottom | ||
594 | 562 | datamatrix[i*(data_nrow+2)][j] = (j+1)%2 # alternating blocks | ||
595 | 563 | |||
596 | 564 | for i in range( data_nrow*reg_row ): | ||
597 | 565 | for j in range( data_ncol* reg_col ): | ||
598 | 566 | dest_col = j + 1 + 2*(j/(data_ncol)) #offset by 1, plus two for every addition block | ||
599 | 567 | dest_row = i + 1 + 2*(i/(data_nrow)) | ||
600 | 568 | |||
601 | 569 | datamatrix[dest_row][dest_col] = array[i][j] #transfer from the plain bit array | ||
602 | 570 | |||
603 | 571 | return datamatrix | ||
604 | 572 | |||
605 | 573 | #RENDERING ROUTINES ================================================== | ||
606 | 574 | # Take the array of 1's and 0's and render as a series of black | ||
607 | 575 | # squares. A binary 1 is a filled square | ||
608 | 576 | #===================================================================== | ||
609 | 577 | |||
610 | 578 | #SVG element generation routine | ||
611 | 579 | def draw_SVG_square((w,h), (x,y), parent): | ||
612 | 580 | |||
613 | 581 | style = { 'stroke' : 'none', | ||
614 | 582 | 'stroke-width' : '1', | ||
615 | 583 | 'fill' : '#000000' | ||
616 | 584 | } | ||
617 | 585 | |||
618 | 586 | attribs = { | ||
619 | 587 | 'style' :simplestyle.formatStyle(style), | ||
620 | 588 | 'height' : str(h), | ||
621 | 589 | 'width' : str(w), | ||
622 | 590 | 'x' : str(x), | ||
623 | 591 | 'y' : str(y) | ||
624 | 592 | } | ||
625 | 593 | circ = inkex.etree.SubElement(parent, inkex.addNS('rect','svg'), attribs ) | ||
626 | 594 | |||
627 | 595 | #turn a 2D array of 1's and 0's into a set of black squares | ||
628 | 596 | def render_data_matrix( module_arrays, size, spacing, parent): | ||
629 | 597 | |||
630 | 598 | for i in range(len(module_arrays)): #for each data matrix | ||
631 | 599 | |||
632 | 600 | height = len(module_arrays[i]) | ||
633 | 601 | width = len(module_arrays[i][0] ) | ||
634 | 602 | |||
635 | 603 | for y in range(height): #loop over all the modules in the datamatrix | ||
636 | 604 | for x in range(width): | ||
637 | 605 | |||
638 | 606 | if module_arrays[i][y][x] == 1: #A binary 1 is a filled square | ||
639 | 607 | draw_SVG_square((size,size), (x*size + i*spacing,y*size), parent) | ||
640 | 608 | elif module_arrays[i][y][x] != 0: #we have an invalid bit value | ||
641 | 609 | inkex.errormsg(_('Invalid bit value, this is a bug!')) | ||
642 | 610 | |||
643 | 611 | class DataMatrix(inkex.Effect): | ||
644 | 612 | def __init__(self): | ||
645 | 613 | inkex.Effect.__init__(self) | ||
646 | 614 | |||
647 | 615 | #PARSE OPTIONS | ||
648 | 616 | self.OptionParser.add_option("--text", | ||
649 | 617 | action="store", type="string", | ||
650 | 618 | dest="TEXT", default='Inkscape') | ||
651 | 619 | self.OptionParser.add_option("--rows", | ||
652 | 620 | action="store", type="int", | ||
653 | 621 | dest="ROWS", default=10) | ||
654 | 622 | self.OptionParser.add_option("--cols", | ||
655 | 623 | action="store", type="int", | ||
656 | 624 | dest="COLS", default=10) | ||
657 | 625 | self.OptionParser.add_option("--size", | ||
658 | 626 | action="store", type="int", | ||
659 | 627 | dest="SIZE", default=4) | ||
660 | 628 | |||
661 | 629 | def effect(self): | ||
662 | 630 | |||
663 | 631 | so = self.options | ||
664 | 632 | |||
665 | 633 | if so.TEXT == '': #abort if converting blank text | ||
666 | 634 | inkex.errormsg(_('Please enter an input string')) | ||
667 | 635 | else: | ||
668 | 636 | |||
669 | 637 | #INKSCAPE GROUP TO CONTAIN EVERYTHING | ||
670 | 638 | |||
671 | 639 | centre = self.view_center #Put in in the centre of the current view | ||
672 | 640 | grp_transform = 'translate' + str( centre ) | ||
673 | 641 | grp_name = 'DataMatrix' | ||
674 | 642 | grp_attribs = {inkex.addNS('label','inkscape'):grp_name, | ||
675 | 643 | 'transform':grp_transform } | ||
676 | 644 | grp = inkex.etree.SubElement(self.current_layer, 'g', grp_attribs)#the group to put everything in | ||
677 | 645 | |||
678 | 646 | #GENERATE THE DATAMATRIX | ||
679 | 647 | encoded = encode( so.TEXT, (so.ROWS, so.COLS) ) #get the pattern of squares | ||
680 | 648 | render_data_matrix( encoded, so.SIZE, so.COLS*so.SIZE*1.5, grp ) # generate the SVG elements | ||
681 | 649 | |||
682 | 650 | if __name__ == '__main__': | ||
683 | 651 | e = DataMatrix() | ||
684 | 652 | e.affect() | ||
685 | 653 | |||
686 | 654 | # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99 | ||
687 | 655 | 0 | ||
688 | === removed directory '.pc/0002-Drop_PS_and_PDF_support_in_MimeType.patch' | |||
689 | === removed file '.pc/0002-Drop_PS_and_PDF_support_in_MimeType.patch/inkscape.desktop.in' | |||
690 | --- .pc/0002-Drop_PS_and_PDF_support_in_MimeType.patch/inkscape.desktop.in 2013-07-02 17:25:52 +0000 | |||
691 | +++ .pc/0002-Drop_PS_and_PDF_support_in_MimeType.patch/inkscape.desktop.in 1970-01-01 00:00:00 +0000 | |||
692 | @@ -1,14 +0,0 @@ | |||
693 | 1 | [Desktop Entry] | ||
694 | 2 | Version=1.0 | ||
695 | 3 | _Name=Inkscape | ||
696 | 4 | _GenericName=Vector Graphics Editor | ||
697 | 5 | _X-GNOME-FullName=Inkscape Vector Graphics Editor | ||
698 | 6 | _Comment=Create and edit Scalable Vector Graphics images | ||
699 | 7 | Type=Application | ||
700 | 8 | Categories=Graphics;VectorGraphics;GTK; | ||
701 | 9 | MimeType=image/svg+xml;image/svg+xml-compressed;application/vnd.corel-draw;application/pdf;application/postscript;image/x-eps;application/illustrator; | ||
702 | 10 | Exec=inkscape %F | ||
703 | 11 | TryExec=inkscape | ||
704 | 12 | Terminal=false | ||
705 | 13 | StartupNotify=true | ||
706 | 14 | Icon=inkscape | ||
707 | 15 | 0 | ||
708 | === removed directory '.pc/0003-Fix_LP_-911146.patch' | |||
709 | === removed directory '.pc/0003-Fix_LP_-911146.patch/src' | |||
710 | === removed directory '.pc/0003-Fix_LP_-911146.patch/src/extension' | |||
711 | === removed directory '.pc/0003-Fix_LP_-911146.patch/src/extension/implementation' | |||
712 | === removed file '.pc/0003-Fix_LP_-911146.patch/src/extension/implementation/script.cpp' | |||
713 | --- .pc/0003-Fix_LP_-911146.patch/src/extension/implementation/script.cpp 2013-07-02 17:25:52 +0000 | |||
714 | +++ .pc/0003-Fix_LP_-911146.patch/src/extension/implementation/script.cpp 1970-01-01 00:00:00 +0000 | |||
715 | @@ -1,1034 +0,0 @@ | |||
716 | 1 | /** \file | ||
717 | 2 | * Code for handling extensions (i.e.\ scripts). | ||
718 | 3 | */ | ||
719 | 4 | /* | ||
720 | 5 | * Authors: | ||
721 | 6 | * Bryce Harrington <bryce@osdl.org> | ||
722 | 7 | * Ted Gould <ted@gould.cx> | ||
723 | 8 | * Jon A. Cruz <jon@joncruz.org> | ||
724 | 9 | * | ||
725 | 10 | * Copyright (C) 2002-2005,2007 Authors | ||
726 | 11 | * | ||
727 | 12 | * Released under GNU GPL, read the file 'COPYING' for more information | ||
728 | 13 | */ | ||
729 | 14 | |||
730 | 15 | #define __INKSCAPE_EXTENSION_IMPLEMENTATION_SCRIPT_C__ | ||
731 | 16 | |||
732 | 17 | #ifdef HAVE_CONFIG_H | ||
733 | 18 | # include <config.h> | ||
734 | 19 | #endif | ||
735 | 20 | |||
736 | 21 | #include <unistd.h> | ||
737 | 22 | |||
738 | 23 | #include <errno.h> | ||
739 | 24 | #include <glib.h> | ||
740 | 25 | #include <glib/gstdio.h> | ||
741 | 26 | #include <gtkmm.h> | ||
742 | 27 | |||
743 | 28 | #include "ui/view/view.h" | ||
744 | 29 | #include "desktop-handles.h" | ||
745 | 30 | #include "desktop.h" | ||
746 | 31 | #include "selection.h" | ||
747 | 32 | #include "sp-namedview.h" | ||
748 | 33 | #include "io/sys.h" | ||
749 | 34 | #include "preferences.h" | ||
750 | 35 | #include "../system.h" | ||
751 | 36 | #include "extension/effect.h" | ||
752 | 37 | #include "extension/output.h" | ||
753 | 38 | #include "extension/input.h" | ||
754 | 39 | #include "extension/db.h" | ||
755 | 40 | #include "script.h" | ||
756 | 41 | #include "dialogs/dialog-events.h" | ||
757 | 42 | #include "application/application.h" | ||
758 | 43 | #include "xml/node.h" | ||
759 | 44 | #include "xml/attribute-record.h" | ||
760 | 45 | |||
761 | 46 | #include "util/glib-list-iterators.h" | ||
762 | 47 | #include "path-prefix.h" | ||
763 | 48 | |||
764 | 49 | |||
765 | 50 | #ifdef WIN32 | ||
766 | 51 | #include <windows.h> | ||
767 | 52 | #include <sys/stat.h> | ||
768 | 53 | #include "registrytool.h" | ||
769 | 54 | #endif | ||
770 | 55 | |||
771 | 56 | |||
772 | 57 | |||
773 | 58 | /** This is the command buffer that gets allocated from the stack */ | ||
774 | 59 | #define BUFSIZE (255) | ||
775 | 60 | |||
776 | 61 | |||
777 | 62 | |||
778 | 63 | /* Namespaces */ | ||
779 | 64 | namespace Inkscape { | ||
780 | 65 | namespace Extension { | ||
781 | 66 | namespace Implementation { | ||
782 | 67 | |||
783 | 68 | /** \brief Make GTK+ events continue to come through a little bit | ||
784 | 69 | |||
785 | 70 | This just keeps coming the events through so that we'll make the GUI | ||
786 | 71 | update and look pretty. | ||
787 | 72 | */ | ||
788 | 73 | void Script::pump_events (void) { | ||
789 | 74 | while ( Gtk::Main::events_pending() ) { | ||
790 | 75 | Gtk::Main::iteration(); | ||
791 | 76 | } | ||
792 | 77 | return; | ||
793 | 78 | } | ||
794 | 79 | |||
795 | 80 | |||
796 | 81 | /** \brief A table of what interpreters to call for a given language | ||
797 | 82 | |||
798 | 83 | This table is used to keep track of all the programs to execute a | ||
799 | 84 | given script. It also tracks the preference to use to overwrite | ||
800 | 85 | the given interpreter to a custom one per user. | ||
801 | 86 | */ | ||
802 | 87 | Script::interpreter_t const Script::interpreterTab[] = { | ||
803 | 88 | {"perl", "perl-interpreter", "perl" }, | ||
804 | 89 | #ifdef WIN32 | ||
805 | 90 | {"python", "python-interpreter", "pythonw" }, | ||
806 | 91 | #else | ||
807 | 92 | {"python", "python-interpreter", "python" }, | ||
808 | 93 | #endif | ||
809 | 94 | {"ruby", "ruby-interpreter", "ruby" }, | ||
810 | 95 | {"shell", "shell-interpreter", "sh" }, | ||
811 | 96 | { NULL, NULL, NULL } | ||
812 | 97 | }; | ||
813 | 98 | |||
814 | 99 | |||
815 | 100 | |||
816 | 101 | /** \brief Look up an interpreter name, and translate to something that | ||
817 | 102 | is executable | ||
818 | 103 | \param interpNameArg The name of the interpreter that we're looking | ||
819 | 104 | for, should be an entry in interpreterTab | ||
820 | 105 | */ | ||
821 | 106 | std::string Script::resolveInterpreterExecutable(const Glib::ustring &interpNameArg) | ||
822 | 107 | { | ||
823 | 108 | interpreter_t const *interp = 0; | ||
824 | 109 | bool foundInterp = false; | ||
825 | 110 | for (interp = interpreterTab ; interp->identity ; interp++ ){ | ||
826 | 111 | if (interpNameArg == interp->identity) { | ||
827 | 112 | foundInterp = true; | ||
828 | 113 | break; | ||
829 | 114 | } | ||
830 | 115 | } | ||
831 | 116 | |||
832 | 117 | // Do we have a supported interpreter type? | ||
833 | 118 | if (!foundInterp) { | ||
834 | 119 | return ""; | ||
835 | 120 | } | ||
836 | 121 | std::string interpreter_path = Glib::filename_from_utf8(interp->defaultval); | ||
837 | 122 | |||
838 | 123 | // 1. Check preferences for an override. | ||
839 | 124 | // Note: this must be an absolute path. | ||
840 | 125 | Inkscape::Preferences *prefs = Inkscape::Preferences::get(); | ||
841 | 126 | Glib::ustring prefInterp = prefs->getString("/extensions/" + Glib::ustring(interp->prefstring)); | ||
842 | 127 | |||
843 | 128 | if (!prefInterp.empty()) { | ||
844 | 129 | interpreter_path = Glib::filename_from_utf8(prefInterp); | ||
845 | 130 | } | ||
846 | 131 | |||
847 | 132 | // 2. Search the path. | ||
848 | 133 | // Do this on all systems, for consistency. | ||
849 | 134 | // PATH is set up to contain the Python and Perl binary directories | ||
850 | 135 | // on Windows, so no extra code is necessary. | ||
851 | 136 | if (!Glib::path_is_absolute(interpreter_path)) { | ||
852 | 137 | interpreter_path = Glib::find_program_in_path(interpreter_path); | ||
853 | 138 | } | ||
854 | 139 | return interpreter_path; | ||
855 | 140 | } | ||
856 | 141 | |||
857 | 142 | /** \brief This function creates a script object and sets up the | ||
858 | 143 | variables. | ||
859 | 144 | \return A script object | ||
860 | 145 | |||
861 | 146 | This function just sets the command to NULL. It should get built | ||
862 | 147 | officially in the load function. This allows for less allocation | ||
863 | 148 | of memory in the unloaded state. | ||
864 | 149 | */ | ||
865 | 150 | Script::Script() : | ||
866 | 151 | Implementation() | ||
867 | 152 | { | ||
868 | 153 | } | ||
869 | 154 | |||
870 | 155 | /** | ||
871 | 156 | * brief Destructor | ||
872 | 157 | */ | ||
873 | 158 | Script::~Script() | ||
874 | 159 | { | ||
875 | 160 | } | ||
876 | 161 | |||
877 | 162 | |||
878 | 163 | |||
879 | 164 | /** | ||
880 | 165 | \return A string with the complete string with the relative directory expanded | ||
881 | 166 | \brief This function takes in a Repr that contains a reldir entry | ||
882 | 167 | and returns that data with the relative directory expanded. | ||
883 | 168 | Mostly it is here so that relative directories all get used | ||
884 | 169 | the same way. | ||
885 | 170 | \param reprin The Inkscape::XML::Node with the reldir in it. | ||
886 | 171 | |||
887 | 172 | Basically this function looks at an attribute of the Repr, and makes | ||
888 | 173 | a decision based on that. Currently, it is only working with the | ||
889 | 174 | 'extensions' relative directory, but there will be more of them. | ||
890 | 175 | One thing to notice is that this function always returns an allocated | ||
891 | 176 | string. This means that the caller of this function can always | ||
892 | 177 | free what they are given (and should do it too!). | ||
893 | 178 | */ | ||
894 | 179 | std::string | ||
895 | 180 | Script::solve_reldir(Inkscape::XML::Node *reprin) { | ||
896 | 181 | |||
897 | 182 | gchar const *s = reprin->attribute("reldir"); | ||
898 | 183 | |||
899 | 184 | // right now the only recognized relative directory is "extensions" | ||
900 | 185 | if (!s || Glib::ustring(s) != "extensions") { | ||
901 | 186 | Glib::ustring str = sp_repr_children(reprin)->content(); | ||
902 | 187 | return str; | ||
903 | 188 | } | ||
904 | 189 | |||
905 | 190 | Glib::ustring reldir = s; | ||
906 | 191 | for (unsigned int i=0; | ||
907 | 192 | i < Inkscape::Extension::Extension::search_path.size(); | ||
908 | 193 | i++) { | ||
909 | 194 | |||
910 | 195 | gchar * fname = g_build_filename( | ||
911 | 196 | Inkscape::Extension::Extension::search_path[i], | ||
912 | 197 | sp_repr_children(reprin)->content(), | ||
913 | 198 | NULL); | ||
914 | 199 | Glib::ustring filename = fname; | ||
915 | 200 | g_free(fname); | ||
916 | 201 | //printf("Filename: %s\n", filename.c_str()); | ||
917 | 202 | if ( Inkscape::IO::file_test(filename.c_str(), G_FILE_TEST_EXISTS) ) { | ||
918 | 203 | return Glib::filename_from_utf8(filename); | ||
919 | 204 | } | ||
920 | 205 | } | ||
921 | 206 | |||
922 | 207 | return ""; | ||
923 | 208 | } | ||
924 | 209 | |||
925 | 210 | |||
926 | 211 | |||
927 | 212 | /** | ||
928 | 213 | \return Whether the command given exists, including in the path | ||
929 | 214 | \brief This function is used to find out if something exists for | ||
930 | 215 | the check command. It can look in the path if required. | ||
931 | 216 | \param command The command or file that should be looked for | ||
932 | 217 | |||
933 | 218 | The first thing that this function does is check to see if the | ||
934 | 219 | incoming file name has a directory delimiter in it. This would | ||
935 | 220 | mean that it wants to control the directories, and should be | ||
936 | 221 | used directly. | ||
937 | 222 | |||
938 | 223 | If not, the path is used. Each entry in the path is stepped through, | ||
939 | 224 | attached to the string, and then tested. If the file is found | ||
940 | 225 | then a TRUE is returned. If we get all the way through the path | ||
941 | 226 | then a FALSE is returned, the command could not be found. | ||
942 | 227 | */ | ||
943 | 228 | bool Script::check_existence(const std::string &command) | ||
944 | 229 | { | ||
945 | 230 | // Check the simple case first | ||
946 | 231 | if (command.empty()) { | ||
947 | 232 | return false; | ||
948 | 233 | } | ||
949 | 234 | |||
950 | 235 | //Don't search when it is an absolute path. */ | ||
951 | 236 | if (Glib::path_is_absolute(command)) { | ||
952 | 237 | if (Glib::file_test(command, Glib::FILE_TEST_EXISTS)) { | ||
953 | 238 | return true; | ||
954 | 239 | } else { | ||
955 | 240 | return false; | ||
956 | 241 | } | ||
957 | 242 | } | ||
958 | 243 | |||
959 | 244 | // First search in the current directory | ||
960 | 245 | std::string path = G_SEARCHPATH_SEPARATOR_S; | ||
961 | 246 | path.append(";"); | ||
962 | 247 | // And then in the PATH environment variable. | ||
963 | 248 | path.append(Glib::getenv("PATH")); | ||
964 | 249 | |||
965 | 250 | std::string::size_type pos = 0; | ||
966 | 251 | std::string::size_type pos2 = 0; | ||
967 | 252 | while ( pos < path.size() ) { | ||
968 | 253 | |||
969 | 254 | std::string localPath; | ||
970 | 255 | |||
971 | 256 | pos2 = path.find(G_SEARCHPATH_SEPARATOR, pos); | ||
972 | 257 | if (pos2 == path.npos) { | ||
973 | 258 | localPath = path.substr(pos); | ||
974 | 259 | pos = path.size(); | ||
975 | 260 | } else { | ||
976 | 261 | localPath = path.substr(pos, pos2-pos); | ||
977 | 262 | pos = pos2+1; | ||
978 | 263 | } | ||
979 | 264 | |||
980 | 265 | //printf("### %s\n", localPath.c_str()); | ||
981 | 266 | std::string candidatePath = | ||
982 | 267 | Glib::build_filename(localPath, command); | ||
983 | 268 | |||
984 | 269 | if (Glib::file_test(candidatePath, | ||
985 | 270 | Glib::FILE_TEST_EXISTS)) { | ||
986 | 271 | return true; | ||
987 | 272 | } | ||
988 | 273 | |||
989 | 274 | } | ||
990 | 275 | |||
991 | 276 | return false; | ||
992 | 277 | } | ||
993 | 278 | |||
994 | 279 | |||
995 | 280 | |||
996 | 281 | |||
997 | 282 | |||
998 | 283 | /** | ||
999 | 284 | \return none | ||
1000 | 285 | \brief This function 'loads' an extention, basically it determines | ||
1001 | 286 | the full command for the extention and stores that. | ||
1002 | 287 | \param module The extention to be loaded. | ||
1003 | 288 | |||
1004 | 289 | The most difficult part about this function is finding the actual | ||
1005 | 290 | command through all of the Reprs. Basically it is hidden down a | ||
1006 | 291 | couple of layers, and so the code has to move down too. When | ||
1007 | 292 | the command is actually found, it has its relative directory | ||
1008 | 293 | solved. | ||
1009 | 294 | |||
1010 | 295 | At that point all of the loops are exited, and there is an | ||
1011 | 296 | if statement to make sure they didn't exit because of not finding | ||
1012 | 297 | the command. If that's the case, the extention doesn't get loaded | ||
1013 | 298 | and should error out at a higher level. | ||
1014 | 299 | */ | ||
1015 | 300 | |||
1016 | 301 | bool Script::load(Inkscape::Extension::Extension *module) | ||
1017 | 302 | { | ||
1018 | 303 | if (module->loaded()) { | ||
1019 | 304 | return true; | ||
1020 | 305 | } | ||
1021 | 306 | |||
1022 | 307 | helper_extension = ""; | ||
1023 | 308 | |||
1024 | 309 | /* This should probably check to find the executable... */ | ||
1025 | 310 | Inkscape::XML::Node *child_repr = sp_repr_children(module->get_repr()); | ||
1026 | 311 | while (child_repr != NULL) { | ||
1027 | 312 | if (!strcmp(child_repr->name(), INKSCAPE_EXTENSION_NS "script")) { | ||
1028 | 313 | child_repr = sp_repr_children(child_repr); | ||
1029 | 314 | while (child_repr != NULL) { | ||
1030 | 315 | if (!strcmp(child_repr->name(), INKSCAPE_EXTENSION_NS "command")) { | ||
1031 | 316 | const gchar *interpretstr = child_repr->attribute("interpreter"); | ||
1032 | 317 | if (interpretstr != NULL) { | ||
1033 | 318 | std::string interpString = resolveInterpreterExecutable(interpretstr); | ||
1034 | 319 | command.insert(command.end(), interpString); | ||
1035 | 320 | } | ||
1036 | 321 | command.insert(command.end(), solve_reldir(child_repr)); | ||
1037 | 322 | } | ||
1038 | 323 | if (!strcmp(child_repr->name(), INKSCAPE_EXTENSION_NS "helper_extension")) { | ||
1039 | 324 | helper_extension = sp_repr_children(child_repr)->content(); | ||
1040 | 325 | } | ||
1041 | 326 | child_repr = sp_repr_next(child_repr); | ||
1042 | 327 | } | ||
1043 | 328 | |||
1044 | 329 | break; | ||
1045 | 330 | } | ||
1046 | 331 | child_repr = sp_repr_next(child_repr); | ||
1047 | 332 | } | ||
1048 | 333 | |||
1049 | 334 | //g_return_val_if_fail(command.length() > 0, false); | ||
1050 | 335 | |||
1051 | 336 | return true; | ||
1052 | 337 | } | ||
1053 | 338 | |||
1054 | 339 | |||
1055 | 340 | /** | ||
1056 | 341 | \return None. | ||
1057 | 342 | \brief Unload this puppy! | ||
1058 | 343 | \param module Extension to be unloaded. | ||
1059 | 344 | |||
1060 | 345 | This function just sets the module to unloaded. It free's the | ||
1061 | 346 | command if it has been allocated. | ||
1062 | 347 | */ | ||
1063 | 348 | void Script::unload(Inkscape::Extension::Extension */*module*/) | ||
1064 | 349 | { | ||
1065 | 350 | command.clear(); | ||
1066 | 351 | helper_extension = ""; | ||
1067 | 352 | } | ||
1068 | 353 | |||
1069 | 354 | |||
1070 | 355 | |||
1071 | 356 | |||
1072 | 357 | /** | ||
1073 | 358 | \return Whether the check passed or not | ||
1074 | 359 | \brief Check every dependency that was given to make sure we should keep this extension | ||
1075 | 360 | \param module The Extension in question | ||
1076 | 361 | |||
1077 | 362 | */ | ||
1078 | 363 | bool | ||
1079 | 364 | Script::check(Inkscape::Extension::Extension *module) | ||
1080 | 365 | { | ||
1081 | 366 | int script_count = 0; | ||
1082 | 367 | Inkscape::XML::Node *child_repr = sp_repr_children(module->get_repr()); | ||
1083 | 368 | while (child_repr != NULL) { | ||
1084 | 369 | if (!strcmp(child_repr->name(), INKSCAPE_EXTENSION_NS "script")) { | ||
1085 | 370 | script_count++; | ||
1086 | 371 | child_repr = sp_repr_children(child_repr); | ||
1087 | 372 | while (child_repr != NULL) { | ||
1088 | 373 | if (!strcmp(child_repr->name(), INKSCAPE_EXTENSION_NS "check")) { | ||
1089 | 374 | std::string command_text = solve_reldir(child_repr); | ||
1090 | 375 | if (!command_text.empty()) { | ||
1091 | 376 | /* I've got the command */ | ||
1092 | 377 | bool existance = check_existence(command_text); | ||
1093 | 378 | if (!existance) { | ||
1094 | 379 | return false; | ||
1095 | 380 | } | ||
1096 | 381 | } else { | ||
1097 | 382 | return false; | ||
1098 | 383 | } | ||
1099 | 384 | } | ||
1100 | 385 | |||
1101 | 386 | if (!strcmp(child_repr->name(), INKSCAPE_EXTENSION_NS "helper_extension")) { | ||
1102 | 387 | gchar const *helper = sp_repr_children(child_repr)->content(); | ||
1103 | 388 | if (Inkscape::Extension::db.get(helper) == NULL) { | ||
1104 | 389 | return false; | ||
1105 | 390 | } | ||
1106 | 391 | } | ||
1107 | 392 | |||
1108 | 393 | child_repr = sp_repr_next(child_repr); | ||
1109 | 394 | } | ||
1110 | 395 | |||
1111 | 396 | break; | ||
1112 | 397 | } | ||
1113 | 398 | child_repr = sp_repr_next(child_repr); | ||
1114 | 399 | } | ||
1115 | 400 | |||
1116 | 401 | if (script_count == 0) { | ||
1117 | 402 | return false; | ||
1118 | 403 | } | ||
1119 | 404 | |||
1120 | 405 | return true; | ||
1121 | 406 | } | ||
1122 | 407 | |||
1123 | 408 | class ScriptDocCache : public ImplementationDocumentCache { | ||
1124 | 409 | friend class Script; | ||
1125 | 410 | protected: | ||
1126 | 411 | std::string _filename; | ||
1127 | 412 | int _tempfd; | ||
1128 | 413 | public: | ||
1129 | 414 | ScriptDocCache (Inkscape::UI::View::View * view); | ||
1130 | 415 | ~ScriptDocCache ( ); | ||
1131 | 416 | }; | ||
1132 | 417 | |||
1133 | 418 | ScriptDocCache::ScriptDocCache (Inkscape::UI::View::View * view) : | ||
1134 | 419 | ImplementationDocumentCache(view), | ||
1135 | 420 | _filename(""), | ||
1136 | 421 | _tempfd(0) | ||
1137 | 422 | { | ||
1138 | 423 | try { | ||
1139 | 424 | _tempfd = Inkscape::IO::file_open_tmp(_filename, "ink_ext_XXXXXX.svg"); | ||
1140 | 425 | } catch (...) { | ||
1141 | 426 | /// \todo Popup dialog here | ||
1142 | 427 | return; | ||
1143 | 428 | } | ||
1144 | 429 | |||
1145 | 430 | SPDesktop *desktop = (SPDesktop *) view; | ||
1146 | 431 | sp_namedview_document_from_window(desktop); | ||
1147 | 432 | |||
1148 | 433 | Inkscape::Extension::save( | ||
1149 | 434 | Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE), | ||
1150 | 435 | view->doc(), _filename.c_str(), false, false, false, Inkscape::Extension::FILE_SAVE_METHOD_TEMPORARY); | ||
1151 | 436 | |||
1152 | 437 | return; | ||
1153 | 438 | } | ||
1154 | 439 | |||
1155 | 440 | ScriptDocCache::~ScriptDocCache ( ) | ||
1156 | 441 | { | ||
1157 | 442 | close(_tempfd); | ||
1158 | 443 | unlink(_filename.c_str()); | ||
1159 | 444 | } | ||
1160 | 445 | |||
1161 | 446 | ImplementationDocumentCache *Script::newDocCache( Inkscape::Extension::Extension * /*ext*/, Inkscape::UI::View::View * view ) { | ||
1162 | 447 | return new ScriptDocCache(view); | ||
1163 | 448 | } | ||
1164 | 449 | |||
1165 | 450 | |||
1166 | 451 | /** | ||
1167 | 452 | \return A dialog for preferences | ||
1168 | 453 | \brief A stub funtion right now | ||
1169 | 454 | \param module Module who's preferences need getting | ||
1170 | 455 | \param filename Hey, the file you're getting might be important | ||
1171 | 456 | |||
1172 | 457 | This function should really do something, right now it doesn't. | ||
1173 | 458 | */ | ||
1174 | 459 | Gtk::Widget *Script::prefs_input(Inkscape::Extension::Input *module, | ||
1175 | 460 | const gchar */*filename*/) | ||
1176 | 461 | { | ||
1177 | 462 | return module->autogui(NULL, NULL); | ||
1178 | 463 | } | ||
1179 | 464 | |||
1180 | 465 | |||
1181 | 466 | |||
1182 | 467 | /** | ||
1183 | 468 | \return A dialog for preferences | ||
1184 | 469 | \brief A stub funtion right now | ||
1185 | 470 | \param module Module whose preferences need getting | ||
1186 | 471 | |||
1187 | 472 | This function should really do something, right now it doesn't. | ||
1188 | 473 | */ | ||
1189 | 474 | Gtk::Widget *Script::prefs_output(Inkscape::Extension::Output *module) | ||
1190 | 475 | { | ||
1191 | 476 | return module->autogui(NULL, NULL); | ||
1192 | 477 | } | ||
1193 | 478 | |||
1194 | 479 | /** | ||
1195 | 480 | \return A new document that has been opened | ||
1196 | 481 | \brief This function uses a filename that is put in, and calls | ||
1197 | 482 | the extension's command to create an SVG file which is | ||
1198 | 483 | returned. | ||
1199 | 484 | \param module Extension to use. | ||
1200 | 485 | \param filename File to open. | ||
1201 | 486 | |||
1202 | 487 | First things first, this function needs a temporary file name. To | ||
1203 | 488 | create on of those the function g_file_open_tmp is used with | ||
1204 | 489 | the header of ink_ext_. | ||
1205 | 490 | |||
1206 | 491 | The extension is then executed using the 'execute' function | ||
1207 | 492 | with the filname coming in, and the temporary filename. After | ||
1208 | 493 | That executing, the SVG should be in the temporary file. | ||
1209 | 494 | |||
1210 | 495 | Finally, the temporary file is opened using the SVG input module and | ||
1211 | 496 | a document is returned. That document has its filename set to | ||
1212 | 497 | the incoming filename (so that it's not the temporary filename). | ||
1213 | 498 | That document is then returned from this function. | ||
1214 | 499 | */ | ||
1215 | 500 | SPDocument *Script::open(Inkscape::Extension::Input *module, | ||
1216 | 501 | const gchar *filenameArg) | ||
1217 | 502 | { | ||
1218 | 503 | std::list<std::string> params; | ||
1219 | 504 | module->paramListString(params); | ||
1220 | 505 | |||
1221 | 506 | std::string tempfilename_out; | ||
1222 | 507 | int tempfd_out = 0; | ||
1223 | 508 | try { | ||
1224 | 509 | tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX.svg"); | ||
1225 | 510 | } catch (...) { | ||
1226 | 511 | /// \todo Popup dialog here | ||
1227 | 512 | return NULL; | ||
1228 | 513 | } | ||
1229 | 514 | |||
1230 | 515 | std::string lfilename = Glib::filename_from_utf8(filenameArg); | ||
1231 | 516 | |||
1232 | 517 | file_listener fileout; | ||
1233 | 518 | int data_read = execute(command, params, lfilename, fileout); | ||
1234 | 519 | fileout.toFile(tempfilename_out); | ||
1235 | 520 | |||
1236 | 521 | SPDocument * mydoc = NULL; | ||
1237 | 522 | if (data_read > 10) { | ||
1238 | 523 | if (helper_extension.size()==0) { | ||
1239 | 524 | mydoc = Inkscape::Extension::open( | ||
1240 | 525 | Inkscape::Extension::db.get(SP_MODULE_KEY_INPUT_SVG), | ||
1241 | 526 | tempfilename_out.c_str()); | ||
1242 | 527 | } else { | ||
1243 | 528 | mydoc = Inkscape::Extension::open( | ||
1244 | 529 | Inkscape::Extension::db.get(helper_extension.c_str()), | ||
1245 | 530 | tempfilename_out.c_str()); | ||
1246 | 531 | } | ||
1247 | 532 | } // data_read | ||
1248 | 533 | |||
1249 | 534 | if (mydoc != NULL) { | ||
1250 | 535 | g_free(mydoc->base); | ||
1251 | 536 | mydoc->base = NULL; | ||
1252 | 537 | sp_document_change_uri_and_hrefs(mydoc, filenameArg); | ||
1253 | 538 | } | ||
1254 | 539 | |||
1255 | 540 | // make sure we don't leak file descriptors from g_file_open_tmp | ||
1256 | 541 | close(tempfd_out); | ||
1257 | 542 | |||
1258 | 543 | unlink(tempfilename_out.c_str()); | ||
1259 | 544 | |||
1260 | 545 | return mydoc; | ||
1261 | 546 | } // open | ||
1262 | 547 | |||
1263 | 548 | |||
1264 | 549 | |||
1265 | 550 | /** | ||
1266 | 551 | \return none | ||
1267 | 552 | \brief This function uses an extention to save a document. It first | ||
1268 | 553 | creates an SVG file of the document, and then runs it through | ||
1269 | 554 | the script. | ||
1270 | 555 | \param module Extention to be used | ||
1271 | 556 | \param doc Document to be saved | ||
1272 | 557 | \param filename The name to save the final file as | ||
1273 | 558 | \return false in case of any failure writing the file, otherwise true | ||
1274 | 559 | |||
1275 | 560 | Well, at some point people need to save - it is really what makes | ||
1276 | 561 | the entire application useful. And, it is possible that someone | ||
1277 | 562 | would want to use an extetion for this, so we need a function to | ||
1278 | 563 | do that eh? | ||
1279 | 564 | |||
1280 | 565 | First things first, the document is saved to a temporary file that | ||
1281 | 566 | is an SVG file. To get the temporary filename g_file_open_tmp is used with | ||
1282 | 567 | ink_ext_ as a prefix. Don't worry, this file gets deleted at the | ||
1283 | 568 | end of the function. | ||
1284 | 569 | |||
1285 | 570 | After we have the SVG file, then extention_execute is called with | ||
1286 | 571 | the temporary file name and the final output filename. This should | ||
1287 | 572 | put the output of the script into the final output file. We then | ||
1288 | 573 | delete the temporary file. | ||
1289 | 574 | */ | ||
1290 | 575 | void Script::save(Inkscape::Extension::Output *module, | ||
1291 | 576 | SPDocument *doc, | ||
1292 | 577 | const gchar *filenameArg) | ||
1293 | 578 | { | ||
1294 | 579 | std::list<std::string> params; | ||
1295 | 580 | module->paramListString(params); | ||
1296 | 581 | |||
1297 | 582 | std::string tempfilename_in; | ||
1298 | 583 | int tempfd_in = 0; | ||
1299 | 584 | try { | ||
1300 | 585 | tempfd_in = Inkscape::IO::file_open_tmp(tempfilename_in, "ink_ext_XXXXXX.svg"); | ||
1301 | 586 | } catch (...) { | ||
1302 | 587 | /// \todo Popup dialog here | ||
1303 | 588 | throw Inkscape::Extension::Output::save_failed(); | ||
1304 | 589 | } | ||
1305 | 590 | |||
1306 | 591 | if (helper_extension.size() == 0) { | ||
1307 | 592 | Inkscape::Extension::save( | ||
1308 | 593 | Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE), | ||
1309 | 594 | doc, tempfilename_in.c_str(), false, false, false, | ||
1310 | 595 | Inkscape::Extension::FILE_SAVE_METHOD_TEMPORARY); | ||
1311 | 596 | } else { | ||
1312 | 597 | Inkscape::Extension::save( | ||
1313 | 598 | Inkscape::Extension::db.get(helper_extension.c_str()), | ||
1314 | 599 | doc, tempfilename_in.c_str(), false, false, false, | ||
1315 | 600 | Inkscape::Extension::FILE_SAVE_METHOD_TEMPORARY); | ||
1316 | 601 | } | ||
1317 | 602 | |||
1318 | 603 | |||
1319 | 604 | file_listener fileout; | ||
1320 | 605 | execute(command, params, tempfilename_in, fileout); | ||
1321 | 606 | |||
1322 | 607 | std::string lfilename = Glib::filename_from_utf8(filenameArg); | ||
1323 | 608 | bool success = fileout.toFile(lfilename); | ||
1324 | 609 | |||
1325 | 610 | // make sure we don't leak file descriptors from g_file_open_tmp | ||
1326 | 611 | close(tempfd_in); | ||
1327 | 612 | // FIXME: convert to utf8 (from "filename encoding") and unlink_utf8name | ||
1328 | 613 | unlink(tempfilename_in.c_str()); | ||
1329 | 614 | |||
1330 | 615 | if (success == false) { | ||
1331 | 616 | throw Inkscape::Extension::Output::save_failed(); | ||
1332 | 617 | } | ||
1333 | 618 | |||
1334 | 619 | return; | ||
1335 | 620 | } | ||
1336 | 621 | |||
1337 | 622 | |||
1338 | 623 | |||
1339 | 624 | /** | ||
1340 | 625 | \return none | ||
1341 | 626 | \brief This function uses an extention as a effect on a document. | ||
1342 | 627 | \param module Extention to effect with. | ||
1343 | 628 | \param doc Document to run through the effect. | ||
1344 | 629 | |||
1345 | 630 | This function is a little bit trickier than the previous two. It | ||
1346 | 631 | needs two temporary files to get it's work done. Both of these | ||
1347 | 632 | files have random names created for them using the g_file_open_temp function | ||
1348 | 633 | with the ink_ext_ prefix in the temporary directory. Like the other | ||
1349 | 634 | functions, the temporary files are deleted at the end. | ||
1350 | 635 | |||
1351 | 636 | To save/load the two temporary documents (both are SVG) the internal | ||
1352 | 637 | modules for SVG load and save are used. They are both used through | ||
1353 | 638 | the module system function by passing their keys into the functions. | ||
1354 | 639 | |||
1355 | 640 | The command itself is built a little bit differently than in other | ||
1356 | 641 | functions because the effect support selections. So on the command | ||
1357 | 642 | line a list of all the ids that are selected is included. Currently, | ||
1358 | 643 | this only works for a single selected object, but there will be more. | ||
1359 | 644 | The command string is filled with the data, and then after the execution | ||
1360 | 645 | it is freed. | ||
1361 | 646 | |||
1362 | 647 | The execute function is used at the core of this function | ||
1363 | 648 | to execute the Script on the two SVG documents (actually only one | ||
1364 | 649 | exists at the time, the other is created by that script). At that | ||
1365 | 650 | point both should be full, and the second one is loaded. | ||
1366 | 651 | */ | ||
1367 | 652 | void Script::effect(Inkscape::Extension::Effect *module, | ||
1368 | 653 | Inkscape::UI::View::View *doc, | ||
1369 | 654 | ImplementationDocumentCache * docCache) | ||
1370 | 655 | { | ||
1371 | 656 | if (docCache == NULL) { | ||
1372 | 657 | docCache = newDocCache(module, doc); | ||
1373 | 658 | } | ||
1374 | 659 | ScriptDocCache * dc = dynamic_cast<ScriptDocCache *>(docCache); | ||
1375 | 660 | if (dc == NULL) { | ||
1376 | 661 | printf("TOO BAD TO LIVE!!!"); | ||
1377 | 662 | exit(1); | ||
1378 | 663 | } | ||
1379 | 664 | |||
1380 | 665 | SPDesktop *desktop = (SPDesktop *)doc; | ||
1381 | 666 | sp_namedview_document_from_window(desktop); | ||
1382 | 667 | |||
1383 | 668 | std::list<std::string> params; | ||
1384 | 669 | module->paramListString(params); | ||
1385 | 670 | |||
1386 | 671 | if (module->no_doc) { | ||
1387 | 672 | // this is a no-doc extension, e.g. a Help menu command; | ||
1388 | 673 | // just run the command without any files, ignoring errors | ||
1389 | 674 | |||
1390 | 675 | Glib::ustring empty; | ||
1391 | 676 | file_listener outfile; | ||
1392 | 677 | execute(command, params, empty, outfile); | ||
1393 | 678 | |||
1394 | 679 | return; | ||
1395 | 680 | } | ||
1396 | 681 | |||
1397 | 682 | std::string tempfilename_out; | ||
1398 | 683 | int tempfd_out = 0; | ||
1399 | 684 | try { | ||
1400 | 685 | tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX.svg"); | ||
1401 | 686 | } catch (...) { | ||
1402 | 687 | /// \todo Popup dialog here | ||
1403 | 688 | return; | ||
1404 | 689 | } | ||
1405 | 690 | |||
1406 | 691 | if (desktop != NULL) { | ||
1407 | 692 | Inkscape::Util::GSListConstIterator<SPItem *> selected = | ||
1408 | 693 | sp_desktop_selection(desktop)->itemList(); | ||
1409 | 694 | while ( selected != NULL ) { | ||
1410 | 695 | Glib::ustring selected_id; | ||
1411 | 696 | selected_id += "--id="; | ||
1412 | 697 | selected_id += (*selected)->getId(); | ||
1413 | 698 | params.insert(params.begin(), selected_id); | ||
1414 | 699 | ++selected; | ||
1415 | 700 | } | ||
1416 | 701 | } | ||
1417 | 702 | |||
1418 | 703 | file_listener fileout; | ||
1419 | 704 | int data_read = execute(command, params, dc->_filename, fileout); | ||
1420 | 705 | fileout.toFile(tempfilename_out); | ||
1421 | 706 | |||
1422 | 707 | pump_events(); | ||
1423 | 708 | |||
1424 | 709 | SPDocument * mydoc = NULL; | ||
1425 | 710 | if (data_read > 10) { | ||
1426 | 711 | mydoc = Inkscape::Extension::open( | ||
1427 | 712 | Inkscape::Extension::db.get(SP_MODULE_KEY_INPUT_SVG), | ||
1428 | 713 | tempfilename_out.c_str()); | ||
1429 | 714 | } // data_read | ||
1430 | 715 | |||
1431 | 716 | pump_events(); | ||
1432 | 717 | |||
1433 | 718 | // make sure we don't leak file descriptors from g_file_open_tmp | ||
1434 | 719 | close(tempfd_out); | ||
1435 | 720 | |||
1436 | 721 | g_unlink(tempfilename_out.c_str()); | ||
1437 | 722 | |||
1438 | 723 | /* Do something with mydoc.... */ | ||
1439 | 724 | if (mydoc) { | ||
1440 | 725 | doc->doc()->emitReconstructionStart(); | ||
1441 | 726 | copy_doc(doc->doc()->rroot, mydoc->rroot); | ||
1442 | 727 | doc->doc()->emitReconstructionFinish(); | ||
1443 | 728 | SPObject *layer = NULL; | ||
1444 | 729 | |||
1445 | 730 | // Getting the named view from the document generated by the extension | ||
1446 | 731 | SPNamedView *nv = sp_document_namedview(mydoc, NULL); | ||
1447 | 732 | |||
1448 | 733 | //Check if it has a default layer set up | ||
1449 | 734 | if ( nv != NULL){ | ||
1450 | 735 | if( nv->default_layer_id != 0 ) { | ||
1451 | 736 | SPDocument *document = desktop->doc(); | ||
1452 | 737 | //If so, get that layer | ||
1453 | 738 | layer = document->getObjectById(g_quark_to_string(nv->default_layer_id)); | ||
1454 | 739 | } | ||
1455 | 740 | } | ||
1456 | 741 | |||
1457 | 742 | sp_namedview_update_layers_from_document(desktop); | ||
1458 | 743 | //If that layer exists, | ||
1459 | 744 | if (layer) { | ||
1460 | 745 | //set the current layer | ||
1461 | 746 | desktop->setCurrentLayer(layer); | ||
1462 | 747 | } | ||
1463 | 748 | mydoc->release(); | ||
1464 | 749 | } | ||
1465 | 750 | |||
1466 | 751 | return; | ||
1467 | 752 | } | ||
1468 | 753 | |||
1469 | 754 | |||
1470 | 755 | |||
1471 | 756 | /** | ||
1472 | 757 | \brief A function to take all the svg elements from one document | ||
1473 | 758 | and put them in another. | ||
1474 | 759 | \param oldroot The root node of the document to be replaced | ||
1475 | 760 | \param newroot The root node of the document to replace it with | ||
1476 | 761 | |||
1477 | 762 | This function first deletes all of the data in the old document. It | ||
1478 | 763 | does this by creating a list of what needs to be deleted, and then | ||
1479 | 764 | goes through the list. This two pass approach removes issues with | ||
1480 | 765 | the list being change while parsing through it. Lots of nasty bugs. | ||
1481 | 766 | |||
1482 | 767 | Then, it goes through the new document, duplicating all of the | ||
1483 | 768 | elements and putting them into the old document. The copy | ||
1484 | 769 | is then complete. | ||
1485 | 770 | */ | ||
1486 | 771 | void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newroot) | ||
1487 | 772 | { | ||
1488 | 773 | std::vector<Inkscape::XML::Node *> delete_list; | ||
1489 | 774 | Inkscape::XML::Node * oldroot_namedview = NULL; | ||
1490 | 775 | |||
1491 | 776 | for (Inkscape::XML::Node * child = oldroot->firstChild(); | ||
1492 | 777 | child != NULL; | ||
1493 | 778 | child = child->next()) { | ||
1494 | 779 | if (!strcmp("sodipodi:namedview", child->name())) { | ||
1495 | 780 | oldroot_namedview = child; | ||
1496 | 781 | for (Inkscape::XML::Node * oldroot_namedview_child = child->firstChild(); | ||
1497 | 782 | oldroot_namedview_child != NULL; | ||
1498 | 783 | oldroot_namedview_child = oldroot_namedview_child->next()) { | ||
1499 | 784 | delete_list.push_back(oldroot_namedview_child); | ||
1500 | 785 | } | ||
1501 | 786 | } else { | ||
1502 | 787 | delete_list.push_back(child); | ||
1503 | 788 | } | ||
1504 | 789 | } | ||
1505 | 790 | for (unsigned int i = 0; i < delete_list.size(); i++) { | ||
1506 | 791 | sp_repr_unparent(delete_list[i]); | ||
1507 | 792 | } | ||
1508 | 793 | |||
1509 | 794 | for (Inkscape::XML::Node * child = newroot->firstChild(); | ||
1510 | 795 | child != NULL; | ||
1511 | 796 | child = child->next()) { | ||
1512 | 797 | if (!strcmp("sodipodi:namedview", child->name())) { | ||
1513 | 798 | if (oldroot_namedview != NULL) { | ||
1514 | 799 | for (Inkscape::XML::Node * newroot_namedview_child = child->firstChild(); | ||
1515 | 800 | newroot_namedview_child != NULL; | ||
1516 | 801 | newroot_namedview_child = newroot_namedview_child->next()) { | ||
1517 | 802 | oldroot_namedview->appendChild(newroot_namedview_child->duplicate(oldroot->document())); | ||
1518 | 803 | } | ||
1519 | 804 | } | ||
1520 | 805 | } else { | ||
1521 | 806 | oldroot->appendChild(child->duplicate(oldroot->document())); | ||
1522 | 807 | } | ||
1523 | 808 | } | ||
1524 | 809 | |||
1525 | 810 | { | ||
1526 | 811 | using Inkscape::Util::List; | ||
1527 | 812 | using Inkscape::XML::AttributeRecord; | ||
1528 | 813 | std::vector<gchar const *> attribs; | ||
1529 | 814 | |||
1530 | 815 | // Make a list of all attributes of the old root node. | ||
1531 | 816 | for (List<AttributeRecord const> iter = oldroot->attributeList(); iter; ++iter) { | ||
1532 | 817 | attribs.push_back(g_quark_to_string(iter->key)); | ||
1533 | 818 | } | ||
1534 | 819 | |||
1535 | 820 | // Delete the attributes of the old root nodes. | ||
1536 | 821 | for (std::vector<gchar const *>::const_iterator it = attribs.begin(); it != attribs.end(); it++) { | ||
1537 | 822 | oldroot->setAttribute(*it, NULL); | ||
1538 | 823 | } | ||
1539 | 824 | |||
1540 | 825 | // Set the new attributes. | ||
1541 | 826 | for (List<AttributeRecord const> iter = newroot->attributeList(); iter; ++iter) { | ||
1542 | 827 | gchar const *name = g_quark_to_string(iter->key); | ||
1543 | 828 | oldroot->setAttribute(name, newroot->attribute(name)); | ||
1544 | 829 | } | ||
1545 | 830 | } | ||
1546 | 831 | |||
1547 | 832 | /** \todo Restore correct layer */ | ||
1548 | 833 | /** \todo Restore correct selection */ | ||
1549 | 834 | } | ||
1550 | 835 | |||
1551 | 836 | /** \brief This function checks the stderr file, and if it has data, | ||
1552 | 837 | shows it in a warning dialog to the user | ||
1553 | 838 | \param filename Filename of the stderr file | ||
1554 | 839 | */ | ||
1555 | 840 | void Script::checkStderr (const Glib::ustring &data, | ||
1556 | 841 | Gtk::MessageType type, | ||
1557 | 842 | const Glib::ustring &message) | ||
1558 | 843 | { | ||
1559 | 844 | Gtk::MessageDialog warning(message, false, type, Gtk::BUTTONS_OK, true); | ||
1560 | 845 | warning.set_resizable(true); | ||
1561 | 846 | GtkWidget *dlg = GTK_WIDGET(warning.gobj()); | ||
1562 | 847 | sp_transientize(dlg); | ||
1563 | 848 | |||
1564 | 849 | Gtk::VBox * vbox = warning.get_vbox(); | ||
1565 | 850 | |||
1566 | 851 | /* Gtk::TextView * textview = new Gtk::TextView(Gtk::TextBuffer::create()); */ | ||
1567 | 852 | Gtk::TextView * textview = new Gtk::TextView(); | ||
1568 | 853 | textview->set_editable(false); | ||
1569 | 854 | textview->set_wrap_mode(Gtk::WRAP_WORD); | ||
1570 | 855 | textview->show(); | ||
1571 | 856 | |||
1572 | 857 | // Remove the last character | ||
1573 | 858 | char *errormsg = (char*) data.c_str(); | ||
1574 | 859 | while (*errormsg != '\0') errormsg++; | ||
1575 | 860 | errormsg -= 1; | ||
1576 | 861 | *errormsg = '\0'; | ||
1577 | 862 | |||
1578 | 863 | textview->get_buffer()->set_text(_(data.c_str())); | ||
1579 | 864 | |||
1580 | 865 | Gtk::ScrolledWindow * scrollwindow = new Gtk::ScrolledWindow(); | ||
1581 | 866 | scrollwindow->add(*textview); | ||
1582 | 867 | scrollwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); | ||
1583 | 868 | scrollwindow->set_shadow_type(Gtk::SHADOW_IN); | ||
1584 | 869 | scrollwindow->show(); | ||
1585 | 870 | scrollwindow->set_size_request(0, 60); | ||
1586 | 871 | |||
1587 | 872 | vbox->pack_start(*scrollwindow, true, true, 5 /* fix these */); | ||
1588 | 873 | |||
1589 | 874 | warning.run(); | ||
1590 | 875 | |||
1591 | 876 | return; | ||
1592 | 877 | } | ||
1593 | 878 | |||
1594 | 879 | bool Script::cancelProcessing (void) { | ||
1595 | 880 | _canceled = true; | ||
1596 | 881 | _main_loop->quit(); | ||
1597 | 882 | Glib::spawn_close_pid(_pid); | ||
1598 | 883 | |||
1599 | 884 | return true; | ||
1600 | 885 | } | ||
1601 | 886 | |||
1602 | 887 | |||
1603 | 888 | /** \brief This is the core of the extension file as it actually does | ||
1604 | 889 | the execution of the extension. | ||
1605 | 890 | \param in_command The command to be executed | ||
1606 | 891 | \param filein Filename coming in | ||
1607 | 892 | \param fileout Filename of the out file | ||
1608 | 893 | \return Number of bytes that were read into the output file. | ||
1609 | 894 | |||
1610 | 895 | The first thing that this function does is build the command to be | ||
1611 | 896 | executed. This consists of the first string (in_command) and then | ||
1612 | 897 | the filename for input (filein). This file is put on the command | ||
1613 | 898 | line. | ||
1614 | 899 | |||
1615 | 900 | The next thing is that this function does is open a pipe to the | ||
1616 | 901 | command and get the file handle in the ppipe variable. It then | ||
1617 | 902 | opens the output file with the output file handle. Both of these | ||
1618 | 903 | operations are checked extensively for errors. | ||
1619 | 904 | |||
1620 | 905 | After both are opened, then the data is copied from the output | ||
1621 | 906 | of the pipe into the file out using fread and fwrite. These two | ||
1622 | 907 | functions are used because of their primitive nature they make | ||
1623 | 908 | no assumptions about the data. A buffer is used in the transfer, | ||
1624 | 909 | but the output of fread is stored so the exact number of bytes | ||
1625 | 910 | is handled gracefully. | ||
1626 | 911 | |||
1627 | 912 | At the very end (after the data has been copied) both of the files | ||
1628 | 913 | are closed, and we return to what we were doing. | ||
1629 | 914 | */ | ||
1630 | 915 | int Script::execute (const std::list<std::string> &in_command, | ||
1631 | 916 | const std::list<std::string> &in_params, | ||
1632 | 917 | const Glib::ustring &filein, | ||
1633 | 918 | file_listener &fileout) | ||
1634 | 919 | { | ||
1635 | 920 | g_return_val_if_fail(!in_command.empty(), 0); | ||
1636 | 921 | // printf("Executing\n"); | ||
1637 | 922 | |||
1638 | 923 | std::vector<std::string> argv; | ||
1639 | 924 | |||
1640 | 925 | bool interpreted = (in_command.size() == 2); | ||
1641 | 926 | std::string program = in_command.front(); | ||
1642 | 927 | std::string script = interpreted ? in_command.back() : ""; | ||
1643 | 928 | std::string working_directory = ""; | ||
1644 | 929 | |||
1645 | 930 | // Use Glib::find_program_in_path instead of the equivalent | ||
1646 | 931 | // Glib::spawn_* functionality, because _wspawnp is broken on Windows: | ||
1647 | 932 | // it doesn't work when PATH contains Unicode directories | ||
1648 | 933 | if (!Glib::path_is_absolute(program)) { | ||
1649 | 934 | program = Glib::find_program_in_path(program); | ||
1650 | 935 | } | ||
1651 | 936 | argv.push_back(program); | ||
1652 | 937 | |||
1653 | 938 | if (interpreted) { | ||
1654 | 939 | // On Windows, Python garbles Unicode command line parameters | ||
1655 | 940 | // in an useless way. This means extensions fail when Inkscape | ||
1656 | 941 | // is run from an Unicode directory. | ||
1657 | 942 | // As a workaround, we set the working directory to the one | ||
1658 | 943 | // containing the script. | ||
1659 | 944 | working_directory = Glib::path_get_dirname(script); | ||
1660 | 945 | script = Glib::path_get_basename(script); | ||
1661 | 946 | #ifdef G_OS_WIN32 | ||
1662 | 947 | // ANNOYING: glibmm does not wrap g_win32_locale_filename_from_utf8 | ||
1663 | 948 | gchar *workdir_s = g_win32_locale_filename_from_utf8(working_directory.data()); | ||
1664 | 949 | working_directory = workdir_s; | ||
1665 | 950 | g_free(workdir_s); | ||
1666 | 951 | #endif | ||
1667 | 952 | |||
1668 | 953 | argv.push_back(script); | ||
1669 | 954 | } | ||
1670 | 955 | |||
1671 | 956 | // assemble the rest of argv | ||
1672 | 957 | std::copy(in_params.begin(), in_params.end(), std::back_inserter(argv)); | ||
1673 | 958 | if (!filein.empty()) { | ||
1674 | 959 | argv.push_back(filein); | ||
1675 | 960 | } | ||
1676 | 961 | |||
1677 | 962 | int stdout_pipe, stderr_pipe; | ||
1678 | 963 | |||
1679 | 964 | try { | ||
1680 | 965 | Glib::spawn_async_with_pipes(working_directory, // working directory | ||
1681 | 966 | argv, // arg v | ||
1682 | 967 | static_cast<Glib::SpawnFlags>(0), // no flags | ||
1683 | 968 | sigc::slot<void>(), | ||
1684 | 969 | &_pid, // Pid | ||
1685 | 970 | NULL, // STDIN | ||
1686 | 971 | &stdout_pipe, // STDOUT | ||
1687 | 972 | &stderr_pipe); // STDERR | ||
1688 | 973 | } catch (Glib::Error e) { | ||
1689 | 974 | printf("Can't Spawn!!! spawn returns: %s\n", e.what().data()); | ||
1690 | 975 | return 0; | ||
1691 | 976 | } | ||
1692 | 977 | |||
1693 | 978 | _main_loop = Glib::MainLoop::create(false); | ||
1694 | 979 | |||
1695 | 980 | file_listener fileerr; | ||
1696 | 981 | fileout.init(stdout_pipe, _main_loop); | ||
1697 | 982 | fileerr.init(stderr_pipe, _main_loop); | ||
1698 | 983 | |||
1699 | 984 | _canceled = false; | ||
1700 | 985 | _main_loop->run(); | ||
1701 | 986 | |||
1702 | 987 | // Ensure all the data is out of the pipe | ||
1703 | 988 | while (!fileout.isDead()) { | ||
1704 | 989 | fileout.read(Glib::IO_IN); | ||
1705 | 990 | } | ||
1706 | 991 | while (!fileerr.isDead()) { | ||
1707 | 992 | fileerr.read(Glib::IO_IN); | ||
1708 | 993 | } | ||
1709 | 994 | |||
1710 | 995 | if (_canceled) { | ||
1711 | 996 | // std::cout << "Script Canceled" << std::endl; | ||
1712 | 997 | return 0; | ||
1713 | 998 | } | ||
1714 | 999 | |||
1715 | 1000 | Glib::ustring stderr_data = fileerr.string(); | ||
1716 | 1001 | if (stderr_data.length() != 0 && | ||
1717 | 1002 | Inkscape::NSApplication::Application::getUseGui() | ||
1718 | 1003 | ) { | ||
1719 | 1004 | checkStderr(stderr_data, Gtk::MESSAGE_INFO, | ||
1720 | 1005 | _("Inkscape has received additional data from the script executed. " | ||
1721 | 1006 | "The script did not return an error, but this may indicate the results will not be as expected.")); | ||
1722 | 1007 | } | ||
1723 | 1008 | |||
1724 | 1009 | Glib::ustring stdout_data = fileout.string(); | ||
1725 | 1010 | if (stdout_data.length() == 0) { | ||
1726 | 1011 | return 0; | ||
1727 | 1012 | } | ||
1728 | 1013 | |||
1729 | 1014 | // std::cout << "Finishing Execution." << std::endl; | ||
1730 | 1015 | return stdout_data.length(); | ||
1731 | 1016 | } | ||
1732 | 1017 | |||
1733 | 1018 | |||
1734 | 1019 | |||
1735 | 1020 | |||
1736 | 1021 | } // namespace Implementation | ||
1737 | 1022 | } // namespace Extension | ||
1738 | 1023 | } // namespace Inkscape | ||
1739 | 1024 | |||
1740 | 1025 | /* | ||
1741 | 1026 | Local Variables: | ||
1742 | 1027 | mode:c++ | ||
1743 | 1028 | c-file-style:"stroustrup" | ||
1744 | 1029 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) | ||
1745 | 1030 | indent-tabs-mode:nil | ||
1746 | 1031 | fill-column:99 | ||
1747 | 1032 | End: | ||
1748 | 1033 | */ | ||
1749 | 1034 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : | ||
1750 | 1035 | 0 | ||
1751 | === removed directory '.pc/0004-Fix_FTBFS_on_gcc-4.8.patch' | |||
1752 | === removed directory '.pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src' | |||
1753 | === removed file '.pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/connector-context.cpp' | |||
1754 | --- .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/connector-context.cpp 2013-07-02 17:25:52 +0000 | |||
1755 | +++ .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/connector-context.cpp 1970-01-01 00:00:00 +0000 | |||
1756 | @@ -1,2041 +0,0 @@ | |||
1757 | 1 | /* | ||
1758 | 2 | * Connector creation tool | ||
1759 | 3 | * | ||
1760 | 4 | * Authors: | ||
1761 | 5 | * Michael Wybrow <mjwybrow@users.sourceforge.net> | ||
1762 | 6 | * | ||
1763 | 7 | * Copyright (C) 2005-2008 Michael Wybrow | ||
1764 | 8 | * Copyright (C) 2009 Monash University | ||
1765 | 9 | * | ||
1766 | 10 | * Released under GNU GPL, read the file 'COPYING' for more information | ||
1767 | 11 | * | ||
1768 | 12 | * TODO: | ||
1769 | 13 | * o Show a visual indicator for objects with the 'avoid' property set. | ||
1770 | 14 | * o Allow user to change a object between a path and connector through | ||
1771 | 15 | * the interface. | ||
1772 | 16 | * o Create an interface for setting markers (arrow heads). | ||
1773 | 17 | * o Better distinguish between paths and connectors to prevent problems | ||
1774 | 18 | * in the node tool and paths accidentally being turned into connectors | ||
1775 | 19 | * in the connector tool. Perhaps have a way to convert between. | ||
1776 | 20 | * o Only call libavoid's updateEndPoint as required. Currently we do it | ||
1777 | 21 | * for both endpoints, even if only one is moving. | ||
1778 | 22 | * o Allow user-placeable connection points. | ||
1779 | 23 | * o Deal sanely with connectors with both endpoints attached to the | ||
1780 | 24 | * same connection point, and drawing of connectors attaching | ||
1781 | 25 | * overlapping shapes (currently tries to adjust connector to be | ||
1782 | 26 | * outside both bounding boxes). | ||
1783 | 27 | * o Fix many special cases related to connectors updating, | ||
1784 | 28 | * e.g., copying a couple of shapes and a connector that are | ||
1785 | 29 | * attached to each other. | ||
1786 | 30 | * e.g., detach connector when it is moved or transformed in | ||
1787 | 31 | * one of the other contexts. | ||
1788 | 32 | * o Cope with shapes whose ids change when they have attached | ||
1789 | 33 | * connectors. | ||
1790 | 34 | * o During dragging motion, gobble up to and use the final motion event. | ||
1791 | 35 | * Gobbling away all duplicates after the current can occasionally result | ||
1792 | 36 | * in the path lagging behind the mouse cursor if it is no longer being | ||
1793 | 37 | * dragged. | ||
1794 | 38 | * o Fix up libavoid's representation after undo actions. It doesn't see | ||
1795 | 39 | * any transform signals and hence doesn't know shapes have moved back to | ||
1796 | 40 | * there earlier positions. | ||
1797 | 41 | * o Decide whether drawing/editing mode should be an Inkscape preference | ||
1798 | 42 | * or the connector tool should always start in drawing mode. | ||
1799 | 43 | * o Correct the problem with switching to the select tool when pressing | ||
1800 | 44 | * space bar (there are moments when it refuses to do so). | ||
1801 | 45 | * | ||
1802 | 46 | * ---------------------------------------------------------------------------- | ||
1803 | 47 | * | ||
1804 | 48 | * mjwybrow's observations on acracan's Summer of Code connector work: | ||
1805 | 49 | * | ||
1806 | 50 | * - GUI comments: | ||
1807 | 51 | * | ||
1808 | 52 | * - Buttons for adding and removing user-specified connection | ||
1809 | 53 | * points should probably have "+" and "-" symbols on them so they | ||
1810 | 54 | * are consistent with the similar buttons for the node tool. | ||
1811 | 55 | * - Controls on the connector tool be should be reordered logically, | ||
1812 | 56 | * possibly as follows: | ||
1813 | 57 | * | ||
1814 | 58 | * *Connector*: [Polyline-radio-button] [Orthgonal-radio-button] | ||
1815 | 59 | * [Curvature-control] | *Shape*: [Avoid-button] [Dont-avoid-button] | ||
1816 | 60 | * [Spacing-control] | *Connection pts*: [Edit-mode] [Add-pt] [Rm-pt] | ||
1817 | 61 | * | ||
1818 | 62 | * I think that the network layout controls be moved to the | ||
1819 | 63 | * Align and Distribute dialog (there is already the layout button | ||
1820 | 64 | * there, but no options are exposed). | ||
1821 | 65 | * | ||
1822 | 66 | * I think that the style change between polyline and orthogonal | ||
1823 | 67 | * would be much clearer with two buttons (radio behaviour -- just | ||
1824 | 68 | * one is true). | ||
1825 | 69 | * | ||
1826 | 70 | * The other tools show a label change from "New:" to "Change:" | ||
1827 | 71 | * depending on whether an object is selected. We could consider | ||
1828 | 72 | * this but there may not be space. | ||
1829 | 73 | * | ||
1830 | 74 | * The Add-pt and Rm-pt buttons should be greyed out (inactive) if | ||
1831 | 75 | * we are not in connection point editing mode. And probably also | ||
1832 | 76 | * if there is no shape selected, i.e. at the times they have no | ||
1833 | 77 | * effect when clicked. | ||
1834 | 78 | * | ||
1835 | 79 | * Likewise for the avoid/ignore shapes buttons. These should be | ||
1836 | 80 | * inactive when a shape is not selected in the connector context. | ||
1837 | 81 | * | ||
1838 | 82 | * - When creating/editing connection points: | ||
1839 | 83 | * | ||
1840 | 84 | * - Strange things can happen if you have connectors selected, or | ||
1841 | 85 | * try rerouting connectors by dragging their endpoints when in | ||
1842 | 86 | * connection point editing mode. | ||
1843 | 87 | * | ||
1844 | 88 | * - Possibly the selected shape's connection points should always | ||
1845 | 89 | * be shown (i.e., have knots) when in editing mode. | ||
1846 | 90 | * | ||
1847 | 91 | * - It is a little strange to be able to place connection points | ||
1848 | 92 | * competely outside shapes. Especially when you later can't draw | ||
1849 | 93 | * connectors to them since the knots are only visible when you | ||
1850 | 94 | * are over the shape. I think that you should only be able to | ||
1851 | 95 | * place connection points inside or on the boundary of the shape | ||
1852 | 96 | * itself. | ||
1853 | 97 | * | ||
1854 | 98 | * - The intended ability to place a new point at the current cursor | ||
1855 | 99 | * position by pressing RETURN does not seem to work. | ||
1856 | 100 | * | ||
1857 | 101 | * - The Status bar tooltip should change to reflect editing mode | ||
1858 | 102 | * and tell the user about RETURN and how to use the tool. | ||
1859 | 103 | * | ||
1860 | 104 | * - Connection points general: | ||
1861 | 105 | * | ||
1862 | 106 | * - Connection points that were inside the shape can end up outside | ||
1863 | 107 | * after a rotation is applied to the shape in the select tool. | ||
1864 | 108 | * It doesn't seem like the correct transform is being applied to | ||
1865 | 109 | * these, or it is being applied at the wrong time. I'd expect | ||
1866 | 110 | * connection points to rotate with the shape, and stay at the | ||
1867 | 111 | * same position "on the shape" | ||
1868 | 112 | * | ||
1869 | 113 | * - I was able to make the connectors attached to a shape fall off | ||
1870 | 114 | * the shape after scaling it. Not sure the exact cause, but may | ||
1871 | 115 | * require more investigation/debugging. | ||
1872 | 116 | * | ||
1873 | 117 | * - The user-defined connection points should be either absolute | ||
1874 | 118 | * (as the current ones are) or defined as a percentage of the | ||
1875 | 119 | * shape. These would be based on a toggle setting on the | ||
1876 | 120 | * toolbar, and they would be placed in exactly the same way by | ||
1877 | 121 | * the user. The only difference would be that they would be | ||
1878 | 122 | * store as percentage positions in the SVG connection-points | ||
1879 | 123 | * property and that they would update/move automatically if the | ||
1880 | 124 | * object was resized or scaled. | ||
1881 | 125 | * | ||
1882 | 126 | * - Thinking more, I think you always want to store and think about | ||
1883 | 127 | * the positions of connection points to be pre-transform, but | ||
1884 | 128 | * obviously the shape transform is applied to them. That way, | ||
1885 | 129 | * they will rotate and scale automatically with the shape, when | ||
1886 | 130 | * the shape transform is altered. The Percentage version would | ||
1887 | 131 | * compute their position from the pre-transform dimensions and | ||
1888 | 132 | * then have the transform applied to them, for example. | ||
1889 | 133 | * | ||
1890 | 134 | * - The connection points in the test_connection_points.svg file | ||
1891 | 135 | * seem to follow the shape when it is moved, but connection | ||
1892 | 136 | * points I add to new shapes, do not follow the shape, either | ||
1893 | 137 | * when the shape is just moved or transformed. There is | ||
1894 | 138 | * something wrong here. What exactly should the behaviour be | ||
1895 | 139 | * currently? | ||
1896 | 140 | * | ||
1897 | 141 | * - I see that connection points are specified at absolute canvas | ||
1898 | 142 | * positions. I really think that they should be specified in | ||
1899 | 143 | * shape coordinated relative to the shapes. There may be | ||
1900 | 144 | * transforms applied to layers and the canvas which would make | ||
1901 | 145 | * specifying them quite difficult. I'd expect a position of 0, 0 | ||
1902 | 146 | * to be on the shape in question or very close to it, for example. | ||
1903 | 147 | * | ||
1904 | 148 | */ | ||
1905 | 149 | |||
1906 | 150 | |||
1907 | 151 | |||
1908 | 152 | #include <gdk/gdkkeysyms.h> | ||
1909 | 153 | #include <string> | ||
1910 | 154 | #include <cstring> | ||
1911 | 155 | |||
1912 | 156 | #include "connector-context.h" | ||
1913 | 157 | #include "pixmaps/cursor-connector.xpm" | ||
1914 | 158 | #include "pixmaps/cursor-node.xpm" | ||
1915 | 159 | //#include "pixmaps/cursor-node-m.xpm" | ||
1916 | 160 | //#include "pixmaps/cursor-node-d.xpm" | ||
1917 | 161 | #include "xml/node-event-vector.h" | ||
1918 | 162 | #include "xml/repr.h" | ||
1919 | 163 | #include "svg/svg.h" | ||
1920 | 164 | #include "desktop.h" | ||
1921 | 165 | #include "desktop-style.h" | ||
1922 | 166 | #include "desktop-handles.h" | ||
1923 | 167 | #include "document.h" | ||
1924 | 168 | #include "message-context.h" | ||
1925 | 169 | #include "message-stack.h" | ||
1926 | 170 | #include "selection.h" | ||
1927 | 171 | #include "inkscape.h" | ||
1928 | 172 | #include "preferences.h" | ||
1929 | 173 | #include "sp-path.h" | ||
1930 | 174 | #include "display/canvas-bpath.h" | ||
1931 | 175 | #include "display/sodipodi-ctrl.h" | ||
1932 | 176 | #include <glibmm/i18n.h> | ||
1933 | 177 | #include <glibmm/stringutils.h> | ||
1934 | 178 | #include "snap.h" | ||
1935 | 179 | #include "knot.h" | ||
1936 | 180 | #include "sp-conn-end.h" | ||
1937 | 181 | #include "sp-conn-end-pair.h" | ||
1938 | 182 | #include "conn-avoid-ref.h" | ||
1939 | 183 | #include "libavoid/vertices.h" | ||
1940 | 184 | #include "libavoid/router.h" | ||
1941 | 185 | #include "context-fns.h" | ||
1942 | 186 | #include "sp-namedview.h" | ||
1943 | 187 | #include "sp-text.h" | ||
1944 | 188 | #include "sp-flowtext.h" | ||
1945 | 189 | #include "display/curve.h" | ||
1946 | 190 | |||
1947 | 191 | static void sp_connector_context_class_init(SPConnectorContextClass *klass); | ||
1948 | 192 | static void sp_connector_context_init(SPConnectorContext *conn_context); | ||
1949 | 193 | static void sp_connector_context_dispose(GObject *object); | ||
1950 | 194 | |||
1951 | 195 | static void sp_connector_context_setup(SPEventContext *ec); | ||
1952 | 196 | static void sp_connector_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val); | ||
1953 | 197 | static void sp_connector_context_finish(SPEventContext *ec); | ||
1954 | 198 | static gint sp_connector_context_root_handler(SPEventContext *ec, GdkEvent *event); | ||
1955 | 199 | static gint sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event); | ||
1956 | 200 | |||
1957 | 201 | // Stuff borrowed from DrawContext | ||
1958 | 202 | static void spcc_connector_set_initial_point(SPConnectorContext *cc, Geom::Point const p); | ||
1959 | 203 | static void spcc_connector_set_subsequent_point(SPConnectorContext *cc, Geom::Point const p); | ||
1960 | 204 | static void spcc_connector_finish_segment(SPConnectorContext *cc, Geom::Point p); | ||
1961 | 205 | static void spcc_reset_colors(SPConnectorContext *cc); | ||
1962 | 206 | static void spcc_connector_finish(SPConnectorContext *cc); | ||
1963 | 207 | static void spcc_concat_colors_and_flush(SPConnectorContext *cc); | ||
1964 | 208 | static void spcc_flush_white(SPConnectorContext *cc, SPCurve *gc); | ||
1965 | 209 | |||
1966 | 210 | // Context event handlers | ||
1967 | 211 | static gint connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const &bevent); | ||
1968 | 212 | static gint connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion const &mevent); | ||
1969 | 213 | static gint connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton const &revent); | ||
1970 | 214 | static gint connector_handle_key_press(SPConnectorContext *const cc, guint const keyval); | ||
1971 | 215 | |||
1972 | 216 | static void cc_active_shape_add_knot(SPDesktop* desktop, SPItem* item, ConnectionPointMap &cphandles, ConnectionPoint& cp); | ||
1973 | 217 | static void cc_set_active_shape(SPConnectorContext *cc, SPItem *item); | ||
1974 | 218 | static void cc_clear_active_shape(SPConnectorContext *cc); | ||
1975 | 219 | static void cc_set_active_conn(SPConnectorContext *cc, SPItem *item); | ||
1976 | 220 | static void cc_clear_active_conn(SPConnectorContext *cc); | ||
1977 | 221 | static bool conn_pt_handle_test(SPConnectorContext *cc, Geom::Point& p, gchar **href, gchar **cpid); | ||
1978 | 222 | static void cc_select_handle(SPKnot* knot); | ||
1979 | 223 | static void cc_deselect_handle(SPKnot* knot); | ||
1980 | 224 | static bool cc_item_is_shape(SPItem *item); | ||
1981 | 225 | static void cc_selection_changed(Inkscape::Selection *selection, gpointer data); | ||
1982 | 226 | static void cc_connector_rerouting_finish(SPConnectorContext *const cc, | ||
1983 | 227 | Geom::Point *const p); | ||
1984 | 228 | |||
1985 | 229 | static void shape_event_attr_deleted(Inkscape::XML::Node *repr, | ||
1986 | 230 | Inkscape::XML::Node *child, Inkscape::XML::Node *ref, gpointer data); | ||
1987 | 231 | static void shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name, | ||
1988 | 232 | gchar const *old_value, gchar const *new_value, bool is_interactive, | ||
1989 | 233 | gpointer data); | ||
1990 | 234 | |||
1991 | 235 | |||
1992 | 236 | static char* cc_knot_tips[] = { _("<b>Connection point</b>: click or drag to create a new connector"), | ||
1993 | 237 | _("<b>Connection point</b>: click to select, drag to move") }; | ||
1994 | 238 | |||
1995 | 239 | /*static Geom::Point connector_drag_origin_w(0, 0); | ||
1996 | 240 | static bool connector_within_tolerance = false;*/ | ||
1997 | 241 | static SPEventContextClass *parent_class; | ||
1998 | 242 | |||
1999 | 243 | |||
2000 | 244 | static Inkscape::XML::NodeEventVector shape_repr_events = { | ||
2001 | 245 | NULL, /* child_added */ | ||
2002 | 246 | NULL, /* child_added */ | ||
2003 | 247 | shape_event_attr_changed, | ||
2004 | 248 | NULL, /* content_changed */ | ||
2005 | 249 | NULL /* order_changed */ | ||
2006 | 250 | }; | ||
2007 | 251 | |||
2008 | 252 | static Inkscape::XML::NodeEventVector layer_repr_events = { | ||
2009 | 253 | NULL, /* child_added */ | ||
2010 | 254 | shape_event_attr_deleted, | ||
2011 | 255 | NULL, /* child_added */ | ||
2012 | 256 | NULL, /* content_changed */ | ||
2013 | 257 | NULL /* order_changed */ | ||
2014 | 258 | }; | ||
2015 | 259 | |||
2016 | 260 | |||
2017 | 261 | GType | ||
2018 | 262 | sp_connector_context_get_type(void) | ||
2019 | 263 | { | ||
2020 | 264 | static GType type = 0; | ||
2021 | 265 | if (!type) { | ||
2022 | 266 | GTypeInfo info = { | ||
2023 | 267 | sizeof(SPConnectorContextClass), | ||
2024 | 268 | NULL, NULL, | ||
2025 | 269 | (GClassInitFunc) sp_connector_context_class_init, | ||
2026 | 270 | NULL, NULL, | ||
2027 | 271 | sizeof(SPConnectorContext), | ||
2028 | 272 | 4, | ||
2029 | 273 | (GInstanceInitFunc) sp_connector_context_init, | ||
2030 | 274 | NULL, /* value_table */ | ||
2031 | 275 | }; | ||
2032 | 276 | type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPConnectorContext", &info, (GTypeFlags)0); | ||
2033 | 277 | } | ||
2034 | 278 | return type; | ||
2035 | 279 | } | ||
2036 | 280 | |||
2037 | 281 | static void | ||
2038 | 282 | sp_connector_context_class_init(SPConnectorContextClass *klass) | ||
2039 | 283 | { | ||
2040 | 284 | GObjectClass *object_class; | ||
2041 | 285 | SPEventContextClass *event_context_class; | ||
2042 | 286 | |||
2043 | 287 | object_class = (GObjectClass *) klass; | ||
2044 | 288 | event_context_class = (SPEventContextClass *) klass; | ||
2045 | 289 | |||
2046 | 290 | parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass); | ||
2047 | 291 | |||
2048 | 292 | object_class->dispose = sp_connector_context_dispose; | ||
2049 | 293 | |||
2050 | 294 | event_context_class->setup = sp_connector_context_setup; | ||
2051 | 295 | event_context_class->set = sp_connector_context_set; | ||
2052 | 296 | event_context_class->finish = sp_connector_context_finish; | ||
2053 | 297 | event_context_class->root_handler = sp_connector_context_root_handler; | ||
2054 | 298 | event_context_class->item_handler = sp_connector_context_item_handler; | ||
2055 | 299 | } | ||
2056 | 300 | |||
2057 | 301 | |||
2058 | 302 | static void | ||
2059 | 303 | sp_connector_context_init(SPConnectorContext *cc) | ||
2060 | 304 | { | ||
2061 | 305 | SPEventContext *ec = SP_EVENT_CONTEXT(cc); | ||
2062 | 306 | |||
2063 | 307 | ec->cursor_shape = cursor_connector_xpm; | ||
2064 | 308 | ec->hot_x = 1; | ||
2065 | 309 | ec->hot_y = 1; | ||
2066 | 310 | ec->xp = 0; | ||
2067 | 311 | ec->yp = 0; | ||
2068 | 312 | |||
2069 | 313 | cc->mode = SP_CONNECTOR_CONTEXT_DRAWING_MODE; | ||
2070 | 314 | cc->knot_tip = 0; | ||
2071 | 315 | |||
2072 | 316 | cc->red_color = 0xff00007f; | ||
2073 | 317 | |||
2074 | 318 | cc->newconn = NULL; | ||
2075 | 319 | cc->newConnRef = NULL; | ||
2076 | 320 | cc->curvature = 0.0; | ||
2077 | 321 | |||
2078 | 322 | cc->sel_changed_connection = sigc::connection(); | ||
2079 | 323 | |||
2080 | 324 | cc->active_shape = NULL; | ||
2081 | 325 | cc->active_shape_repr = NULL; | ||
2082 | 326 | cc->active_shape_layer_repr = NULL; | ||
2083 | 327 | |||
2084 | 328 | cc->active_conn = NULL; | ||
2085 | 329 | cc->active_conn_repr = NULL; | ||
2086 | 330 | |||
2087 | 331 | cc->active_handle = NULL; | ||
2088 | 332 | |||
2089 | 333 | cc->selected_handle = NULL; | ||
2090 | 334 | |||
2091 | 335 | cc->clickeditem = NULL; | ||
2092 | 336 | cc->clickedhandle = NULL; | ||
2093 | 337 | |||
2094 | 338 | new (&cc->connpthandles) ConnectionPointMap(); | ||
2095 | 339 | |||
2096 | 340 | for (int i = 0; i < 2; ++i) { | ||
2097 | 341 | cc->endpt_handle[i] = NULL; | ||
2098 | 342 | cc->endpt_handler_id[i] = 0; | ||
2099 | 343 | } | ||
2100 | 344 | cc->shref = NULL; | ||
2101 | 345 | cc->scpid = NULL; | ||
2102 | 346 | cc->ehref = NULL; | ||
2103 | 347 | cc->ecpid = NULL; | ||
2104 | 348 | cc->npoints = 0; | ||
2105 | 349 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2106 | 350 | } | ||
2107 | 351 | |||
2108 | 352 | |||
2109 | 353 | static void | ||
2110 | 354 | sp_connector_context_dispose(GObject *object) | ||
2111 | 355 | { | ||
2112 | 356 | SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(object); | ||
2113 | 357 | |||
2114 | 358 | cc->sel_changed_connection.disconnect(); | ||
2115 | 359 | |||
2116 | 360 | if (!cc->connpthandles.empty()) { | ||
2117 | 361 | for (ConnectionPointMap::iterator it = cc->connpthandles.begin(); | ||
2118 | 362 | it != cc->connpthandles.end(); ++it) { | ||
2119 | 363 | g_object_unref(it->first); | ||
2120 | 364 | } | ||
2121 | 365 | cc->connpthandles.clear(); | ||
2122 | 366 | } | ||
2123 | 367 | cc->connpthandles.~ConnectionPointMap(); | ||
2124 | 368 | for (int i = 0; i < 2; ++i) { | ||
2125 | 369 | if (cc->endpt_handle[1]) { | ||
2126 | 370 | g_object_unref(cc->endpt_handle[i]); | ||
2127 | 371 | cc->endpt_handle[i] = NULL; | ||
2128 | 372 | } | ||
2129 | 373 | } | ||
2130 | 374 | if (cc->shref) { | ||
2131 | 375 | g_free(cc->shref); | ||
2132 | 376 | cc->shref = NULL; | ||
2133 | 377 | } | ||
2134 | 378 | if (cc->scpid) { | ||
2135 | 379 | g_free(cc->scpid); | ||
2136 | 380 | cc->scpid = NULL; | ||
2137 | 381 | } | ||
2138 | 382 | if (cc->ehref) { | ||
2139 | 383 | g_free(cc->shref); | ||
2140 | 384 | cc->shref = NULL; | ||
2141 | 385 | } | ||
2142 | 386 | if (cc->ecpid) { | ||
2143 | 387 | g_free(cc->scpid); | ||
2144 | 388 | cc->scpid = NULL; | ||
2145 | 389 | } | ||
2146 | 390 | g_assert( cc->newConnRef == NULL ); | ||
2147 | 391 | |||
2148 | 392 | G_OBJECT_CLASS(parent_class)->dispose(object); | ||
2149 | 393 | } | ||
2150 | 394 | |||
2151 | 395 | |||
2152 | 396 | static void | ||
2153 | 397 | sp_connector_context_setup(SPEventContext *ec) | ||
2154 | 398 | { | ||
2155 | 399 | SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec); | ||
2156 | 400 | SPDesktop *dt = ec->desktop; | ||
2157 | 401 | |||
2158 | 402 | if (((SPEventContextClass *) parent_class)->setup) { | ||
2159 | 403 | ((SPEventContextClass *) parent_class)->setup(ec); | ||
2160 | 404 | } | ||
2161 | 405 | |||
2162 | 406 | cc->selection = sp_desktop_selection(dt); | ||
2163 | 407 | |||
2164 | 408 | cc->sel_changed_connection.disconnect(); | ||
2165 | 409 | cc->sel_changed_connection = cc->selection->connectChanged( | ||
2166 | 410 | sigc::bind(sigc::ptr_fun(&cc_selection_changed), | ||
2167 | 411 | (gpointer) cc)); | ||
2168 | 412 | |||
2169 | 413 | /* Create red bpath */ | ||
2170 | 414 | cc->red_bpath = sp_canvas_bpath_new(sp_desktop_sketch(ec->desktop), NULL); | ||
2171 | 415 | sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cc->red_bpath), cc->red_color, | ||
2172 | 416 | 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); | ||
2173 | 417 | sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cc->red_bpath), 0x00000000, | ||
2174 | 418 | SP_WIND_RULE_NONZERO); | ||
2175 | 419 | /* Create red curve */ | ||
2176 | 420 | cc->red_curve = new SPCurve(); | ||
2177 | 421 | |||
2178 | 422 | /* Create green curve */ | ||
2179 | 423 | cc->green_curve = new SPCurve(); | ||
2180 | 424 | |||
2181 | 425 | // Notice the initial selection. | ||
2182 | 426 | cc_selection_changed(cc->selection, (gpointer) cc); | ||
2183 | 427 | |||
2184 | 428 | cc->within_tolerance = false; | ||
2185 | 429 | |||
2186 | 430 | sp_event_context_read(ec, "curvature"); | ||
2187 | 431 | sp_event_context_read(ec, "orthogonal"); | ||
2188 | 432 | sp_event_context_read(ec, "mode"); | ||
2189 | 433 | cc->knot_tip = cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE ? cc_knot_tips[0] : cc_knot_tips[1]; | ||
2190 | 434 | Inkscape::Preferences *prefs = Inkscape::Preferences::get(); | ||
2191 | 435 | if (prefs->getBool("/tools/connector/selcue", 0)) { | ||
2192 | 436 | ec->enableSelectionCue(); | ||
2193 | 437 | } | ||
2194 | 438 | |||
2195 | 439 | // Make sure we see all enter events for canvas items, | ||
2196 | 440 | // even if a mouse button is depressed. | ||
2197 | 441 | dt->canvas->gen_all_enter_events = true; | ||
2198 | 442 | } | ||
2199 | 443 | |||
2200 | 444 | |||
2201 | 445 | static void | ||
2202 | 446 | sp_connector_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) | ||
2203 | 447 | { | ||
2204 | 448 | SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec); | ||
2205 | 449 | |||
2206 | 450 | /* fixme: Proper error handling for non-numeric data. Use a locale-independent function like | ||
2207 | 451 | * g_ascii_strtod (or a thin wrapper that does the right thing for invalid values inf/nan). */ | ||
2208 | 452 | Glib::ustring name = val->getEntryName(); | ||
2209 | 453 | if ( name == "curvature" ) { | ||
2210 | 454 | cc->curvature = val->getDoubleLimited(); // prevents NaN and +/-Inf from messing up | ||
2211 | 455 | } | ||
2212 | 456 | else if ( name == "orthogonal" ) { | ||
2213 | 457 | cc->isOrthogonal = val->getBool(); | ||
2214 | 458 | } | ||
2215 | 459 | else if ( name == "mode") | ||
2216 | 460 | { | ||
2217 | 461 | sp_connector_context_switch_mode(ec, val->getBool() ? SP_CONNECTOR_CONTEXT_EDITING_MODE : SP_CONNECTOR_CONTEXT_DRAWING_MODE); | ||
2218 | 462 | } | ||
2219 | 463 | } | ||
2220 | 464 | |||
2221 | 465 | void sp_connector_context_switch_mode(SPEventContext* ec, unsigned int newMode) | ||
2222 | 466 | { | ||
2223 | 467 | SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec); | ||
2224 | 468 | |||
2225 | 469 | cc->mode = newMode; | ||
2226 | 470 | if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE ) | ||
2227 | 471 | { | ||
2228 | 472 | ec->cursor_shape = cursor_connector_xpm; | ||
2229 | 473 | cc->knot_tip = cc_knot_tips[0]; | ||
2230 | 474 | if (cc->selected_handle) | ||
2231 | 475 | cc_deselect_handle( cc->selected_handle ); | ||
2232 | 476 | cc->selected_handle = NULL; | ||
2233 | 477 | // Show all default connection points | ||
2234 | 478 | |||
2235 | 479 | } | ||
2236 | 480 | else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE ) | ||
2237 | 481 | { | ||
2238 | 482 | ec->cursor_shape = cursor_node_xpm; | ||
2239 | 483 | cc->knot_tip = cc_knot_tips[1]; | ||
2240 | 484 | /* if (cc->active_shape) | ||
2241 | 485 | { | ||
2242 | 486 | cc->selection->set( SP_OBJECT( cc->active_shape ) ); | ||
2243 | 487 | } | ||
2244 | 488 | else | ||
2245 | 489 | { | ||
2246 | 490 | SPItem* item = cc->selection->singleItem(); | ||
2247 | 491 | if ( item ) | ||
2248 | 492 | { | ||
2249 | 493 | cc_set_active_shape(cc, item); | ||
2250 | 494 | cc->selection->set( SP_OBJECT( item ) ); | ||
2251 | 495 | } | ||
2252 | 496 | }*/ | ||
2253 | 497 | } | ||
2254 | 498 | sp_event_context_update_cursor(ec); | ||
2255 | 499 | |||
2256 | 500 | } | ||
2257 | 501 | |||
2258 | 502 | |||
2259 | 503 | static void | ||
2260 | 504 | sp_connector_context_finish(SPEventContext *ec) | ||
2261 | 505 | { | ||
2262 | 506 | SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec); | ||
2263 | 507 | |||
2264 | 508 | spcc_connector_finish(cc); | ||
2265 | 509 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2266 | 510 | |||
2267 | 511 | if (((SPEventContextClass *) parent_class)->finish) { | ||
2268 | 512 | ((SPEventContextClass *) parent_class)->finish(ec); | ||
2269 | 513 | } | ||
2270 | 514 | |||
2271 | 515 | if (cc->selection) { | ||
2272 | 516 | cc->selection = NULL; | ||
2273 | 517 | } | ||
2274 | 518 | cc_clear_active_shape(cc); | ||
2275 | 519 | cc_clear_active_conn(cc); | ||
2276 | 520 | |||
2277 | 521 | // Restore the default event generating behaviour. | ||
2278 | 522 | SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(ec); | ||
2279 | 523 | desktop->canvas->gen_all_enter_events = false; | ||
2280 | 524 | } | ||
2281 | 525 | |||
2282 | 526 | |||
2283 | 527 | //----------------------------------------------------------------------------- | ||
2284 | 528 | |||
2285 | 529 | |||
2286 | 530 | static void | ||
2287 | 531 | cc_clear_active_shape(SPConnectorContext *cc) | ||
2288 | 532 | { | ||
2289 | 533 | if (cc->active_shape == NULL) { | ||
2290 | 534 | return; | ||
2291 | 535 | } | ||
2292 | 536 | g_assert( cc->active_shape_repr ); | ||
2293 | 537 | g_assert( cc->active_shape_layer_repr ); | ||
2294 | 538 | |||
2295 | 539 | cc->active_shape = NULL; | ||
2296 | 540 | |||
2297 | 541 | if (cc->active_shape_repr) { | ||
2298 | 542 | sp_repr_remove_listener_by_data(cc->active_shape_repr, cc); | ||
2299 | 543 | Inkscape::GC::release(cc->active_shape_repr); | ||
2300 | 544 | cc->active_shape_repr = NULL; | ||
2301 | 545 | |||
2302 | 546 | sp_repr_remove_listener_by_data(cc->active_shape_layer_repr, cc); | ||
2303 | 547 | Inkscape::GC::release(cc->active_shape_layer_repr); | ||
2304 | 548 | cc->active_shape_layer_repr = NULL; | ||
2305 | 549 | } | ||
2306 | 550 | |||
2307 | 551 | // Hide the connection points if they exist. | ||
2308 | 552 | if (cc->connpthandles.size()) { | ||
2309 | 553 | for (ConnectionPointMap::iterator it = cc->connpthandles.begin(); | ||
2310 | 554 | it != cc->connpthandles.end(); ++it) { | ||
2311 | 555 | sp_knot_hide(it->first); | ||
2312 | 556 | } | ||
2313 | 557 | } | ||
2314 | 558 | } | ||
2315 | 559 | |||
2316 | 560 | |||
2317 | 561 | static void | ||
2318 | 562 | cc_clear_active_conn(SPConnectorContext *cc) | ||
2319 | 563 | { | ||
2320 | 564 | if (cc->active_conn == NULL) { | ||
2321 | 565 | return; | ||
2322 | 566 | } | ||
2323 | 567 | g_assert( cc->active_conn_repr ); | ||
2324 | 568 | |||
2325 | 569 | cc->active_conn = NULL; | ||
2326 | 570 | |||
2327 | 571 | if (cc->active_conn_repr) { | ||
2328 | 572 | sp_repr_remove_listener_by_data(cc->active_conn_repr, cc); | ||
2329 | 573 | Inkscape::GC::release(cc->active_conn_repr); | ||
2330 | 574 | cc->active_conn_repr = NULL; | ||
2331 | 575 | } | ||
2332 | 576 | |||
2333 | 577 | // Hide the endpoint handles. | ||
2334 | 578 | for (int i = 0; i < 2; ++i) { | ||
2335 | 579 | if (cc->endpt_handle[i]) { | ||
2336 | 580 | sp_knot_hide(cc->endpt_handle[i]); | ||
2337 | 581 | } | ||
2338 | 582 | } | ||
2339 | 583 | } | ||
2340 | 584 | |||
2341 | 585 | |||
2342 | 586 | static bool | ||
2343 | 587 | conn_pt_handle_test(SPConnectorContext *cc, Geom::Point& p, gchar **href, gchar **cpid) | ||
2344 | 588 | { | ||
2345 | 589 | // TODO: this will need to change when there are more connection | ||
2346 | 590 | // points available for each shape. | ||
2347 | 591 | |||
2348 | 592 | if (cc->active_handle && (cc->connpthandles.find(cc->active_handle) != cc->connpthandles.end())) | ||
2349 | 593 | { | ||
2350 | 594 | p = cc->active_handle->pos; | ||
2351 | 595 | const ConnectionPoint& cp = cc->connpthandles[cc->active_handle]; | ||
2352 | 596 | *href = g_strdup_printf("#%s", cc->active_shape->getId()); | ||
2353 | 597 | *cpid = g_strdup_printf("%c%d", cp.type == ConnPointDefault ? 'd' : 'u' , cp.id); | ||
2354 | 598 | return true; | ||
2355 | 599 | } | ||
2356 | 600 | *href = NULL; | ||
2357 | 601 | *cpid = NULL; | ||
2358 | 602 | return false; | ||
2359 | 603 | } | ||
2360 | 604 | |||
2361 | 605 | static void | ||
2362 | 606 | cc_select_handle(SPKnot* knot) | ||
2363 | 607 | { | ||
2364 | 608 | knot->setShape(SP_KNOT_SHAPE_SQUARE); | ||
2365 | 609 | knot->setSize(10); | ||
2366 | 610 | knot->setAnchor(GTK_ANCHOR_CENTER); | ||
2367 | 611 | knot->setFill(0x0000ffff, 0x0000ffff, 0x0000ffff); | ||
2368 | 612 | sp_knot_update_ctrl(knot); | ||
2369 | 613 | } | ||
2370 | 614 | |||
2371 | 615 | static void | ||
2372 | 616 | cc_deselect_handle(SPKnot* knot) | ||
2373 | 617 | { | ||
2374 | 618 | knot->setShape(SP_KNOT_SHAPE_SQUARE); | ||
2375 | 619 | knot->setSize(8); | ||
2376 | 620 | knot->setAnchor(GTK_ANCHOR_CENTER); | ||
2377 | 621 | knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff); | ||
2378 | 622 | sp_knot_update_ctrl(knot); | ||
2379 | 623 | } | ||
2380 | 624 | |||
2381 | 625 | static gint | ||
2382 | 626 | sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event) | ||
2383 | 627 | { | ||
2384 | 628 | gint ret = FALSE; | ||
2385 | 629 | |||
2386 | 630 | SPDesktop *desktop = event_context->desktop; | ||
2387 | 631 | |||
2388 | 632 | SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(event_context); | ||
2389 | 633 | |||
2390 | 634 | Geom::Point p(event->button.x, event->button.y); | ||
2391 | 635 | |||
2392 | 636 | switch (event->type) { | ||
2393 | 637 | case GDK_BUTTON_RELEASE: | ||
2394 | 638 | if (event->button.button == 1 && !event_context->space_panning) { | ||
2395 | 639 | if ((cc->state == SP_CONNECTOR_CONTEXT_DRAGGING) && | ||
2396 | 640 | (event_context->within_tolerance)) | ||
2397 | 641 | { | ||
2398 | 642 | spcc_reset_colors(cc); | ||
2399 | 643 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2400 | 644 | } | ||
2401 | 645 | if (cc->state != SP_CONNECTOR_CONTEXT_IDLE) { | ||
2402 | 646 | // Doing something else like rerouting. | ||
2403 | 647 | break; | ||
2404 | 648 | } | ||
2405 | 649 | // find out clicked item, honoring Alt | ||
2406 | 650 | SPItem *item = sp_event_context_find_item(desktop, | ||
2407 | 651 | p, event->button.state & GDK_MOD1_MASK, FALSE); | ||
2408 | 652 | |||
2409 | 653 | if (event->button.state & GDK_SHIFT_MASK) { | ||
2410 | 654 | cc->selection->toggle(item); | ||
2411 | 655 | } else { | ||
2412 | 656 | cc->selection->set(item); | ||
2413 | 657 | if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE && cc->selected_handle ) | ||
2414 | 658 | { | ||
2415 | 659 | cc_deselect_handle( cc->selected_handle ); | ||
2416 | 660 | cc->selected_handle = NULL; | ||
2417 | 661 | } | ||
2418 | 662 | /* When selecting a new item, | ||
2419 | 663 | do not allow showing connection points | ||
2420 | 664 | on connectors. (yet?) | ||
2421 | 665 | */ | ||
2422 | 666 | if ( item != cc->active_shape && !cc_item_is_connector( item ) ) | ||
2423 | 667 | cc_set_active_shape( cc, item ); | ||
2424 | 668 | } | ||
2425 | 669 | ret = TRUE; | ||
2426 | 670 | |||
2427 | 671 | } | ||
2428 | 672 | break; | ||
2429 | 673 | case GDK_ENTER_NOTIFY: | ||
2430 | 674 | { | ||
2431 | 675 | if (cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE || (cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE && !cc->selected_handle)) | ||
2432 | 676 | { | ||
2433 | 677 | if (cc_item_is_shape(item)) { | ||
2434 | 678 | |||
2435 | 679 | // I don't really understand what the above does, | ||
2436 | 680 | // so I commented it. | ||
2437 | 681 | // This is a shape, so show connection point(s). | ||
2438 | 682 | /* if (!(cc->active_shape) | ||
2439 | 683 | // Don't show handle for another handle. | ||
2440 | 684 | // || (cc->connpthandles.find((SPKnot*) item) != cc->connpthandles.end()) | ||
2441 | 685 | ) | ||
2442 | 686 | { | ||
2443 | 687 | cc_set_active_shape(cc, item); | ||
2444 | 688 | }*/ | ||
2445 | 689 | cc_set_active_shape(cc, item); | ||
2446 | 690 | } | ||
2447 | 691 | ret = TRUE; | ||
2448 | 692 | } | ||
2449 | 693 | break; | ||
2450 | 694 | } | ||
2451 | 695 | default: | ||
2452 | 696 | break; | ||
2453 | 697 | } | ||
2454 | 698 | |||
2455 | 699 | return ret; | ||
2456 | 700 | } | ||
2457 | 701 | |||
2458 | 702 | |||
2459 | 703 | gint | ||
2460 | 704 | sp_connector_context_root_handler(SPEventContext *ec, GdkEvent *event) | ||
2461 | 705 | { | ||
2462 | 706 | SPConnectorContext *const cc = SP_CONNECTOR_CONTEXT(ec); | ||
2463 | 707 | |||
2464 | 708 | gint ret = FALSE; | ||
2465 | 709 | |||
2466 | 710 | switch (event->type) { | ||
2467 | 711 | case GDK_BUTTON_PRESS: | ||
2468 | 712 | ret = connector_handle_button_press(cc, event->button); | ||
2469 | 713 | break; | ||
2470 | 714 | |||
2471 | 715 | case GDK_MOTION_NOTIFY: | ||
2472 | 716 | ret = connector_handle_motion_notify(cc, event->motion); | ||
2473 | 717 | break; | ||
2474 | 718 | |||
2475 | 719 | case GDK_BUTTON_RELEASE: | ||
2476 | 720 | ret = connector_handle_button_release(cc, event->button); | ||
2477 | 721 | break; | ||
2478 | 722 | case GDK_KEY_PRESS: | ||
2479 | 723 | ret = connector_handle_key_press(cc, get_group0_keyval (&event->key)); | ||
2480 | 724 | break; | ||
2481 | 725 | |||
2482 | 726 | default: | ||
2483 | 727 | break; | ||
2484 | 728 | } | ||
2485 | 729 | |||
2486 | 730 | if (!ret) { | ||
2487 | 731 | gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) | ||
2488 | 732 | = ((SPEventContextClass *) parent_class)->root_handler; | ||
2489 | 733 | if (parent_root_handler) { | ||
2490 | 734 | ret = parent_root_handler(ec, event); | ||
2491 | 735 | } | ||
2492 | 736 | } | ||
2493 | 737 | |||
2494 | 738 | return ret; | ||
2495 | 739 | } | ||
2496 | 740 | |||
2497 | 741 | |||
2498 | 742 | static gint | ||
2499 | 743 | connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const &bevent) | ||
2500 | 744 | { | ||
2501 | 745 | Geom::Point const event_w(bevent.x, bevent.y); | ||
2502 | 746 | /* Find desktop coordinates */ | ||
2503 | 747 | Geom::Point p = cc->desktop->w2d(event_w); | ||
2504 | 748 | SPEventContext *event_context = SP_EVENT_CONTEXT(cc); | ||
2505 | 749 | |||
2506 | 750 | gint ret = FALSE; | ||
2507 | 751 | if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE ) | ||
2508 | 752 | { | ||
2509 | 753 | if ( bevent.button == 1 && !event_context->space_panning ) { | ||
2510 | 754 | |||
2511 | 755 | SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc); | ||
2512 | 756 | |||
2513 | 757 | if (Inkscape::have_viable_layer(desktop, cc->_message_context) == false) { | ||
2514 | 758 | return TRUE; | ||
2515 | 759 | } | ||
2516 | 760 | |||
2517 | 761 | Geom::Point const event_w(bevent.x, | ||
2518 | 762 | bevent.y); | ||
2519 | 763 | // connector_drag_origin_w = event_w; | ||
2520 | 764 | cc->xp = bevent.x; | ||
2521 | 765 | cc->yp = bevent.y; | ||
2522 | 766 | cc->within_tolerance = true; | ||
2523 | 767 | |||
2524 | 768 | Geom::Point const event_dt = cc->desktop->w2d(event_w); | ||
2525 | 769 | |||
2526 | 770 | SnapManager &m = cc->desktop->namedview->snap_manager; | ||
2527 | 771 | m.setup(cc->desktop); | ||
2528 | 772 | |||
2529 | 773 | switch (cc->state) { | ||
2530 | 774 | case SP_CONNECTOR_CONTEXT_STOP: | ||
2531 | 775 | /* This is allowed, if we just canceled curve */ | ||
2532 | 776 | case SP_CONNECTOR_CONTEXT_IDLE: | ||
2533 | 777 | { | ||
2534 | 778 | if ( cc->npoints == 0 ) { | ||
2535 | 779 | cc_clear_active_conn(cc); | ||
2536 | 780 | |||
2537 | 781 | SP_EVENT_CONTEXT_DESKTOP(cc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new connector")); | ||
2538 | 782 | |||
2539 | 783 | /* Set start anchor */ | ||
2540 | 784 | /* Create green anchor */ | ||
2541 | 785 | Geom::Point p = event_dt; | ||
2542 | 786 | |||
2543 | 787 | // Test whether we clicked on a connection point | ||
2544 | 788 | bool found = conn_pt_handle_test(cc, p, &cc->shref, &cc->scpid); | ||
2545 | 789 | |||
2546 | 790 | if (!found) { | ||
2547 | 791 | // This is the first point, so just snap it to the grid | ||
2548 | 792 | // as there's no other points to go off. | ||
2549 | 793 | m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); | ||
2550 | 794 | } | ||
2551 | 795 | spcc_connector_set_initial_point(cc, p); | ||
2552 | 796 | |||
2553 | 797 | } | ||
2554 | 798 | cc->state = SP_CONNECTOR_CONTEXT_DRAGGING; | ||
2555 | 799 | ret = TRUE; | ||
2556 | 800 | break; | ||
2557 | 801 | } | ||
2558 | 802 | case SP_CONNECTOR_CONTEXT_DRAGGING: | ||
2559 | 803 | { | ||
2560 | 804 | // This is the second click of a connector creation. | ||
2561 | 805 | m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); | ||
2562 | 806 | |||
2563 | 807 | spcc_connector_set_subsequent_point(cc, p); | ||
2564 | 808 | spcc_connector_finish_segment(cc, p); | ||
2565 | 809 | // Test whether we clicked on a connection point | ||
2566 | 810 | /*bool found = */conn_pt_handle_test(cc, p, &cc->ehref, &cc->ecpid); | ||
2567 | 811 | if (cc->npoints != 0) { | ||
2568 | 812 | spcc_connector_finish(cc); | ||
2569 | 813 | } | ||
2570 | 814 | cc_set_active_conn(cc, cc->newconn); | ||
2571 | 815 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2572 | 816 | ret = TRUE; | ||
2573 | 817 | break; | ||
2574 | 818 | } | ||
2575 | 819 | case SP_CONNECTOR_CONTEXT_CLOSE: | ||
2576 | 820 | { | ||
2577 | 821 | g_warning("Button down in CLOSE state"); | ||
2578 | 822 | break; | ||
2579 | 823 | } | ||
2580 | 824 | default: | ||
2581 | 825 | break; | ||
2582 | 826 | } | ||
2583 | 827 | } else if (bevent.button == 3) { | ||
2584 | 828 | if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) { | ||
2585 | 829 | // A context menu is going to be triggered here, | ||
2586 | 830 | // so end the rerouting operation. | ||
2587 | 831 | cc_connector_rerouting_finish(cc, &p); | ||
2588 | 832 | |||
2589 | 833 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2590 | 834 | |||
2591 | 835 | // Don't set ret to TRUE, so we drop through to the | ||
2592 | 836 | // parent handler which will open the context menu. | ||
2593 | 837 | } | ||
2594 | 838 | else if (cc->npoints != 0) { | ||
2595 | 839 | spcc_connector_finish(cc); | ||
2596 | 840 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2597 | 841 | ret = TRUE; | ||
2598 | 842 | } | ||
2599 | 843 | } | ||
2600 | 844 | } | ||
2601 | 845 | else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE ) | ||
2602 | 846 | { | ||
2603 | 847 | if ( bevent.button == 1 && !event_context->space_panning ) | ||
2604 | 848 | { | ||
2605 | 849 | // Initialize variables in case of dragging | ||
2606 | 850 | |||
2607 | 851 | SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc); | ||
2608 | 852 | |||
2609 | 853 | if (Inkscape::have_viable_layer(desktop, cc->_message_context) == false) { | ||
2610 | 854 | return TRUE; | ||
2611 | 855 | } | ||
2612 | 856 | |||
2613 | 857 | cc->xp = bevent.x; | ||
2614 | 858 | cc->yp = bevent.y; | ||
2615 | 859 | cc->within_tolerance = true; | ||
2616 | 860 | |||
2617 | 861 | ConnectionPointMap::iterator const& active_knot_it = cc->connpthandles.find( cc->active_handle ); | ||
2618 | 862 | |||
2619 | 863 | switch (cc->state) | ||
2620 | 864 | { | ||
2621 | 865 | case SP_CONNECTOR_CONTEXT_IDLE: | ||
2622 | 866 | if ( active_knot_it != cc->connpthandles.end() ) | ||
2623 | 867 | { | ||
2624 | 868 | // We do not allow selecting and, thereby, moving default knots | ||
2625 | 869 | if ( active_knot_it->second.type != ConnPointDefault) | ||
2626 | 870 | { | ||
2627 | 871 | if (cc->selected_handle != cc->active_handle) | ||
2628 | 872 | { | ||
2629 | 873 | if ( cc->selected_handle ) | ||
2630 | 874 | cc_deselect_handle( cc->selected_handle ); | ||
2631 | 875 | cc->selected_handle = cc->active_handle; | ||
2632 | 876 | cc_select_handle( cc->selected_handle ); | ||
2633 | 877 | } | ||
2634 | 878 | } | ||
2635 | 879 | else | ||
2636 | 880 | // Just ignore the default connection point | ||
2637 | 881 | return FALSE; | ||
2638 | 882 | } | ||
2639 | 883 | else | ||
2640 | 884 | if ( cc->selected_handle ) | ||
2641 | 885 | { | ||
2642 | 886 | cc_deselect_handle( cc->selected_handle ); | ||
2643 | 887 | cc->selected_handle = NULL; | ||
2644 | 888 | } | ||
2645 | 889 | |||
2646 | 890 | if ( cc->selected_handle ) | ||
2647 | 891 | { | ||
2648 | 892 | cc->state = SP_CONNECTOR_CONTEXT_DRAGGING; | ||
2649 | 893 | cc->selection->set( SP_OBJECT( cc->active_shape ) ); | ||
2650 | 894 | } | ||
2651 | 895 | |||
2652 | 896 | ret = TRUE; | ||
2653 | 897 | break; | ||
2654 | 898 | // Dragging valid because of the way we create | ||
2655 | 899 | // new connection points. | ||
2656 | 900 | case SP_CONNECTOR_CONTEXT_DRAGGING: | ||
2657 | 901 | // Do nothing. | ||
2658 | 902 | ret = TRUE; | ||
2659 | 903 | break; | ||
2660 | 904 | } | ||
2661 | 905 | } | ||
2662 | 906 | } | ||
2663 | 907 | return ret; | ||
2664 | 908 | } | ||
2665 | 909 | |||
2666 | 910 | |||
2667 | 911 | static gint | ||
2668 | 912 | connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion const &mevent) | ||
2669 | 913 | { | ||
2670 | 914 | gint ret = FALSE; | ||
2671 | 915 | SPEventContext *event_context = SP_EVENT_CONTEXT(cc); | ||
2672 | 916 | Inkscape::Preferences *prefs = Inkscape::Preferences::get(); | ||
2673 | 917 | |||
2674 | 918 | if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { | ||
2675 | 919 | // allow middle-button scrolling | ||
2676 | 920 | return FALSE; | ||
2677 | 921 | } | ||
2678 | 922 | |||
2679 | 923 | Geom::Point const event_w(mevent.x, mevent.y); | ||
2680 | 924 | |||
2681 | 925 | if (cc->within_tolerance) { | ||
2682 | 926 | cc->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); | ||
2683 | 927 | if ( ( abs( (gint) mevent.x - cc->xp ) < cc->tolerance ) && | ||
2684 | 928 | ( abs( (gint) mevent.y - cc->yp ) < cc->tolerance ) ) { | ||
2685 | 929 | return FALSE; // Do not drag if we're within tolerance from origin. | ||
2686 | 930 | } | ||
2687 | 931 | } | ||
2688 | 932 | // Once the user has moved farther than tolerance from the original location | ||
2689 | 933 | // (indicating they intend to move the object, not click), then always process | ||
2690 | 934 | // the motion notify coordinates as given (no snapping back to origin) | ||
2691 | 935 | cc->within_tolerance = false; | ||
2692 | 936 | |||
2693 | 937 | SPDesktop *const dt = cc->desktop; | ||
2694 | 938 | |||
2695 | 939 | /* Find desktop coordinates */ | ||
2696 | 940 | Geom::Point p = dt->w2d(event_w); | ||
2697 | 941 | |||
2698 | 942 | if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE ) | ||
2699 | 943 | { | ||
2700 | 944 | SnapManager &m = dt->namedview->snap_manager; | ||
2701 | 945 | m.setup(dt); | ||
2702 | 946 | |||
2703 | 947 | switch (cc->state) { | ||
2704 | 948 | case SP_CONNECTOR_CONTEXT_DRAGGING: | ||
2705 | 949 | { | ||
2706 | 950 | gobble_motion_events(mevent.state); | ||
2707 | 951 | // This is movement during a connector creation. | ||
2708 | 952 | if ( cc->npoints > 0 ) { | ||
2709 | 953 | m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); | ||
2710 | 954 | cc->selection->clear(); | ||
2711 | 955 | spcc_connector_set_subsequent_point(cc, p); | ||
2712 | 956 | ret = TRUE; | ||
2713 | 957 | } | ||
2714 | 958 | break; | ||
2715 | 959 | } | ||
2716 | 960 | case SP_CONNECTOR_CONTEXT_REROUTING: | ||
2717 | 961 | { | ||
2718 | 962 | gobble_motion_events(GDK_BUTTON1_MASK); | ||
2719 | 963 | g_assert( SP_IS_PATH(cc->clickeditem)); | ||
2720 | 964 | |||
2721 | 965 | m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); | ||
2722 | 966 | |||
2723 | 967 | // Update the hidden path | ||
2724 | 968 | Geom::Matrix i2d = sp_item_i2d_affine(cc->clickeditem); | ||
2725 | 969 | Geom::Matrix d2i = i2d.inverse(); | ||
2726 | 970 | SPPath *path = SP_PATH(cc->clickeditem); | ||
2727 | 971 | SPCurve *curve = path->original_curve ? path->original_curve : path->curve; | ||
2728 | 972 | if (cc->clickedhandle == cc->endpt_handle[0]) { | ||
2729 | 973 | Geom::Point o = cc->endpt_handle[1]->pos; | ||
2730 | 974 | curve->stretch_endpoints(p * d2i, o * d2i); | ||
2731 | 975 | } | ||
2732 | 976 | else { | ||
2733 | 977 | Geom::Point o = cc->endpt_handle[0]->pos; | ||
2734 | 978 | curve->stretch_endpoints(o * d2i, p * d2i); | ||
2735 | 979 | } | ||
2736 | 980 | sp_conn_reroute_path_immediate(path); | ||
2737 | 981 | |||
2738 | 982 | // Copy this to the temporary visible path | ||
2739 | 983 | cc->red_curve = path->original_curve ? | ||
2740 | 984 | path->original_curve->copy() : path->curve->copy(); | ||
2741 | 985 | cc->red_curve->transform(i2d); | ||
2742 | 986 | |||
2743 | 987 | sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve); | ||
2744 | 988 | ret = TRUE; | ||
2745 | 989 | break; | ||
2746 | 990 | } | ||
2747 | 991 | case SP_CONNECTOR_CONTEXT_STOP: | ||
2748 | 992 | /* This is perfectly valid */ | ||
2749 | 993 | break; | ||
2750 | 994 | default: | ||
2751 | 995 | if (!sp_event_context_knot_mouseover(cc)) { | ||
2752 | 996 | m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE)); | ||
2753 | 997 | } | ||
2754 | 998 | break; | ||
2755 | 999 | } | ||
2756 | 1000 | } | ||
2757 | 1001 | else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE ) | ||
2758 | 1002 | { | ||
2759 | 1003 | switch ( cc->state ) | ||
2760 | 1004 | { | ||
2761 | 1005 | case SP_CONNECTOR_CONTEXT_DRAGGING: | ||
2762 | 1006 | sp_knot_set_position(cc->selected_handle, p, 0); | ||
2763 | 1007 | ret = TRUE; | ||
2764 | 1008 | break; | ||
2765 | 1009 | case SP_CONNECTOR_CONTEXT_NEWCONNPOINT: | ||
2766 | 1010 | sp_knot_set_position(cc->selected_handle, p, 0); | ||
2767 | 1011 | ret = TRUE; | ||
2768 | 1012 | break; | ||
2769 | 1013 | } | ||
2770 | 1014 | } | ||
2771 | 1015 | |||
2772 | 1016 | return ret; | ||
2773 | 1017 | } | ||
2774 | 1018 | |||
2775 | 1019 | |||
2776 | 1020 | static gint | ||
2777 | 1021 | connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton const &revent) | ||
2778 | 1022 | { | ||
2779 | 1023 | gint ret = FALSE; | ||
2780 | 1024 | SPEventContext *event_context = SP_EVENT_CONTEXT(cc); | ||
2781 | 1025 | if ( revent.button == 1 && !event_context->space_panning ) { | ||
2782 | 1026 | |||
2783 | 1027 | SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc); | ||
2784 | 1028 | SPDocument *doc = sp_desktop_document(desktop); | ||
2785 | 1029 | |||
2786 | 1030 | SnapManager &m = desktop->namedview->snap_manager; | ||
2787 | 1031 | m.setup(desktop); | ||
2788 | 1032 | |||
2789 | 1033 | Geom::Point const event_w(revent.x, revent.y); | ||
2790 | 1034 | |||
2791 | 1035 | /* Find desktop coordinates */ | ||
2792 | 1036 | Geom::Point p = cc->desktop->w2d(event_w); | ||
2793 | 1037 | if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE ) | ||
2794 | 1038 | { | ||
2795 | 1039 | switch (cc->state) { | ||
2796 | 1040 | //case SP_CONNECTOR_CONTEXT_POINT: | ||
2797 | 1041 | case SP_CONNECTOR_CONTEXT_DRAGGING: | ||
2798 | 1042 | { | ||
2799 | 1043 | m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); | ||
2800 | 1044 | |||
2801 | 1045 | if (cc->within_tolerance) | ||
2802 | 1046 | { | ||
2803 | 1047 | spcc_connector_finish_segment(cc, p); | ||
2804 | 1048 | return TRUE; | ||
2805 | 1049 | } | ||
2806 | 1050 | // Connector has been created via a drag, end it now. | ||
2807 | 1051 | spcc_connector_set_subsequent_point(cc, p); | ||
2808 | 1052 | spcc_connector_finish_segment(cc, p); | ||
2809 | 1053 | // Test whether we clicked on a connection point | ||
2810 | 1054 | /*bool found = */conn_pt_handle_test(cc, p, &cc->ehref, &cc->ecpid); | ||
2811 | 1055 | if (cc->npoints != 0) { | ||
2812 | 1056 | spcc_connector_finish(cc); | ||
2813 | 1057 | } | ||
2814 | 1058 | cc_set_active_conn(cc, cc->newconn); | ||
2815 | 1059 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2816 | 1060 | break; | ||
2817 | 1061 | } | ||
2818 | 1062 | case SP_CONNECTOR_CONTEXT_REROUTING: | ||
2819 | 1063 | { | ||
2820 | 1064 | m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); | ||
2821 | 1065 | cc_connector_rerouting_finish(cc, &p); | ||
2822 | 1066 | |||
2823 | 1067 | sp_document_ensure_up_to_date(doc); | ||
2824 | 1068 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2825 | 1069 | return TRUE; | ||
2826 | 1070 | break; | ||
2827 | 1071 | } | ||
2828 | 1072 | case SP_CONNECTOR_CONTEXT_STOP: | ||
2829 | 1073 | /* This is allowed, if we just cancelled curve */ | ||
2830 | 1074 | break; | ||
2831 | 1075 | default: | ||
2832 | 1076 | break; | ||
2833 | 1077 | } | ||
2834 | 1078 | ret = TRUE; | ||
2835 | 1079 | } | ||
2836 | 1080 | else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE ) | ||
2837 | 1081 | { | ||
2838 | 1082 | switch ( cc->state ) | ||
2839 | 1083 | { | ||
2840 | 1084 | case SP_CONNECTOR_CONTEXT_DRAGGING: | ||
2841 | 1085 | |||
2842 | 1086 | if (!cc->within_tolerance) | ||
2843 | 1087 | { | ||
2844 | 1088 | m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); | ||
2845 | 1089 | sp_knot_set_position(cc->selected_handle, p, 0); | ||
2846 | 1090 | ConnectionPoint& cp = cc->connpthandles[cc->selected_handle]; | ||
2847 | 1091 | cp.pos = p * sp_item_dt2i_affine(cc->active_shape); | ||
2848 | 1092 | cc->active_shape->avoidRef->updateConnectionPoint(cp); | ||
2849 | 1093 | } | ||
2850 | 1094 | |||
2851 | 1095 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2852 | 1096 | ret = TRUE; | ||
2853 | 1097 | break; | ||
2854 | 1098 | |||
2855 | 1099 | |||
2856 | 1100 | case SP_CONNECTOR_CONTEXT_NEWCONNPOINT: | ||
2857 | 1101 | m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); | ||
2858 | 1102 | |||
2859 | 1103 | sp_knot_set_position(cc->selected_handle, p, 0); | ||
2860 | 1104 | |||
2861 | 1105 | ConnectionPoint cp; | ||
2862 | 1106 | cp.type = ConnPointUserDefined; | ||
2863 | 1107 | cp.pos = p * sp_item_dt2i_affine(cc->active_shape); | ||
2864 | 1108 | cp.dir = Avoid::ConnDirAll; | ||
2865 | 1109 | g_object_unref(cc->selected_handle); | ||
2866 | 1110 | cc->active_shape->avoidRef->addConnectionPoint(cp); | ||
2867 | 1111 | sp_document_ensure_up_to_date(doc); | ||
2868 | 1112 | for (ConnectionPointMap::iterator it = cc->connpthandles.begin(); it != cc->connpthandles.end(); ++it) | ||
2869 | 1113 | if (it->second.type == ConnPointUserDefined && it->second.id == cp.id) | ||
2870 | 1114 | { | ||
2871 | 1115 | cc->selected_handle = it->first; | ||
2872 | 1116 | break; | ||
2873 | 1117 | } | ||
2874 | 1118 | cc_select_handle( cc->selected_handle ); | ||
2875 | 1119 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2876 | 1120 | ret = TRUE; | ||
2877 | 1121 | break; | ||
2878 | 1122 | } | ||
2879 | 1123 | } | ||
2880 | 1124 | } | ||
2881 | 1125 | |||
2882 | 1126 | |||
2883 | 1127 | return ret; | ||
2884 | 1128 | } | ||
2885 | 1129 | |||
2886 | 1130 | |||
2887 | 1131 | static gint | ||
2888 | 1132 | connector_handle_key_press(SPConnectorContext *const cc, guint const keyval) | ||
2889 | 1133 | { | ||
2890 | 1134 | gint ret = FALSE; | ||
2891 | 1135 | /* fixme: */ | ||
2892 | 1136 | if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE ) | ||
2893 | 1137 | { | ||
2894 | 1138 | switch (keyval) { | ||
2895 | 1139 | case GDK_Return: | ||
2896 | 1140 | case GDK_KP_Enter: | ||
2897 | 1141 | if (cc->npoints != 0) { | ||
2898 | 1142 | spcc_connector_finish(cc); | ||
2899 | 1143 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2900 | 1144 | ret = TRUE; | ||
2901 | 1145 | } | ||
2902 | 1146 | break; | ||
2903 | 1147 | case GDK_Escape: | ||
2904 | 1148 | if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) { | ||
2905 | 1149 | |||
2906 | 1150 | SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc); | ||
2907 | 1151 | SPDocument *doc = sp_desktop_document(desktop); | ||
2908 | 1152 | |||
2909 | 1153 | cc_connector_rerouting_finish(cc, NULL); | ||
2910 | 1154 | |||
2911 | 1155 | sp_document_undo(doc); | ||
2912 | 1156 | |||
2913 | 1157 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2914 | 1158 | desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE, | ||
2915 | 1159 | _("Connector endpoint drag cancelled.")); | ||
2916 | 1160 | ret = TRUE; | ||
2917 | 1161 | } | ||
2918 | 1162 | else if (cc->npoints != 0) { | ||
2919 | 1163 | // if drawing, cancel, otherwise pass it up for deselecting | ||
2920 | 1164 | cc->state = SP_CONNECTOR_CONTEXT_STOP; | ||
2921 | 1165 | spcc_reset_colors(cc); | ||
2922 | 1166 | ret = TRUE; | ||
2923 | 1167 | } | ||
2924 | 1168 | break; | ||
2925 | 1169 | default: | ||
2926 | 1170 | break; | ||
2927 | 1171 | } | ||
2928 | 1172 | } | ||
2929 | 1173 | else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE ) | ||
2930 | 1174 | { | ||
2931 | 1175 | switch ( cc->state ) | ||
2932 | 1176 | { | ||
2933 | 1177 | case SP_CONNECTOR_CONTEXT_DRAGGING: | ||
2934 | 1178 | if ( keyval == GDK_Escape ) | ||
2935 | 1179 | { | ||
2936 | 1180 | // Cancel connection point dragging | ||
2937 | 1181 | |||
2938 | 1182 | // Obtain original position | ||
2939 | 1183 | ConnectionPoint const& cp = cc->connpthandles[cc->selected_handle]; | ||
2940 | 1184 | SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc); | ||
2941 | 1185 | const Geom::Matrix& i2doc = sp_item_i2doc_affine(cc->active_shape); | ||
2942 | 1186 | sp_knot_set_position(cc->selected_handle, cp.pos * i2doc * desktop->doc2dt(), 0); | ||
2943 | 1187 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2944 | 1188 | desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE, | ||
2945 | 1189 | _("Connection point drag cancelled.")); | ||
2946 | 1190 | ret = TRUE; | ||
2947 | 1191 | } | ||
2948 | 1192 | else if ( keyval == GDK_Return || keyval == GDK_KP_Enter ) | ||
2949 | 1193 | { | ||
2950 | 1194 | // Put connection point at current position | ||
2951 | 1195 | |||
2952 | 1196 | SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc); | ||
2953 | 1197 | SnapManager &m = desktop->namedview->snap_manager; | ||
2954 | 1198 | m.setup(desktop); | ||
2955 | 1199 | Geom::Point p = cc->selected_handle->pos; | ||
2956 | 1200 | // SPEventContext* event_context = SP_EVENT_CONTEXT( cc ); | ||
2957 | 1201 | |||
2958 | 1202 | if (!cc->within_tolerance) | ||
2959 | 1203 | { | ||
2960 | 1204 | m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); | ||
2961 | 1205 | sp_knot_set_position(cc->selected_handle, p, 0); | ||
2962 | 1206 | ConnectionPoint& cp = cc->connpthandles[cc->selected_handle]; | ||
2963 | 1207 | cp.pos = p * sp_item_dt2i_affine(cc->active_shape); | ||
2964 | 1208 | cc->active_shape->avoidRef->updateConnectionPoint(cp); | ||
2965 | 1209 | } | ||
2966 | 1210 | |||
2967 | 1211 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2968 | 1212 | ret = TRUE; | ||
2969 | 1213 | } | ||
2970 | 1214 | break; | ||
2971 | 1215 | case SP_CONNECTOR_CONTEXT_NEWCONNPOINT: | ||
2972 | 1216 | if ( keyval == GDK_Escape ) | ||
2973 | 1217 | { | ||
2974 | 1218 | // Just destroy the knot | ||
2975 | 1219 | g_object_unref( cc->selected_handle ); | ||
2976 | 1220 | cc->selected_handle = NULL; | ||
2977 | 1221 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
2978 | 1222 | ret = TRUE; | ||
2979 | 1223 | } | ||
2980 | 1224 | else if ( keyval == GDK_Return || keyval == GDK_KP_Enter ) | ||
2981 | 1225 | { | ||
2982 | 1226 | SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc); | ||
2983 | 1227 | SPDocument *doc = sp_desktop_document(desktop); | ||
2984 | 1228 | SnapManager &m = desktop->namedview->snap_manager; | ||
2985 | 1229 | m.setup(desktop); | ||
2986 | 1230 | Geom::Point p = cc->selected_handle->pos; | ||
2987 | 1231 | |||
2988 | 1232 | m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); | ||
2989 | 1233 | |||
2990 | 1234 | sp_knot_set_position(cc->selected_handle, p, 0); | ||
2991 | 1235 | |||
2992 | 1236 | ConnectionPoint cp; | ||
2993 | 1237 | cp.type = ConnPointUserDefined; | ||
2994 | 1238 | cp.pos = p * sp_item_dt2i_affine(cc->active_shape); | ||
2995 | 1239 | cp.dir = Avoid::ConnDirAll; | ||
2996 | 1240 | g_object_unref(cc->selected_handle); | ||
2997 | 1241 | cc->active_shape->avoidRef->addConnectionPoint(cp); | ||
2998 | 1242 | sp_document_ensure_up_to_date(doc); | ||
2999 | 1243 | for (ConnectionPointMap::iterator it = cc->connpthandles.begin(); it != cc->connpthandles.end(); ++it) | ||
3000 | 1244 | if (it->second.type == ConnPointUserDefined && it->second.id == cp.id) | ||
3001 | 1245 | { | ||
3002 | 1246 | cc->selected_handle = it->first; | ||
3003 | 1247 | break; | ||
3004 | 1248 | } | ||
3005 | 1249 | cc_select_handle( cc->selected_handle ); | ||
3006 | 1250 | cc->state = SP_CONNECTOR_CONTEXT_IDLE; | ||
3007 | 1251 | ret = TRUE; | ||
3008 | 1252 | } | ||
3009 | 1253 | |||
3010 | 1254 | break; | ||
3011 | 1255 | case SP_CONNECTOR_CONTEXT_IDLE: | ||
3012 | 1256 | if ( keyval == GDK_Delete && cc->selected_handle ) | ||
3013 | 1257 | { | ||
3014 | 1258 | cc->active_shape->avoidRef->deleteConnectionPoint(cc->connpthandles[cc->selected_handle]); | ||
3015 | 1259 | cc->selected_handle = NULL; | ||
3016 | 1260 | ret = TRUE; | ||
3017 | 1261 | } | ||
3018 | 1262 | |||
3019 | 1263 | break; | ||
3020 | 1264 | } | ||
3021 | 1265 | } | ||
3022 | 1266 | |||
3023 | 1267 | return ret; | ||
3024 | 1268 | } | ||
3025 | 1269 | |||
3026 | 1270 | |||
3027 | 1271 | static void | ||
3028 | 1272 | cc_connector_rerouting_finish(SPConnectorContext *const cc, Geom::Point *const p) | ||
3029 | 1273 | { | ||
3030 | 1274 | SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc); | ||
3031 | 1275 | SPDocument *doc = sp_desktop_document(desktop); | ||
3032 | 1276 | |||
3033 | 1277 | // Clear the temporary path: | ||
3034 | 1278 | cc->red_curve->reset(); | ||
3035 | 1279 | sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL); | ||
3036 | 1280 | |||
3037 | 1281 | if (p != NULL) | ||
3038 | 1282 | { | ||
3039 | 1283 | // Test whether we clicked on a connection point | ||
3040 | 1284 | gchar *shape_label, *cpid; | ||
3041 | 1285 | bool found = conn_pt_handle_test(cc, *p, &shape_label, &cpid); | ||
3042 | 1286 | |||
3043 | 1287 | if (found) { | ||
3044 | 1288 | if (cc->clickedhandle == cc->endpt_handle[0]) { | ||
3045 | 1289 | sp_object_setAttribute(cc->clickeditem, | ||
3046 | 1290 | "inkscape:connection-start", shape_label, false); | ||
3047 | 1291 | sp_object_setAttribute(cc->clickeditem, | ||
3048 | 1292 | "inkscape:connection-start-point", cpid, false); | ||
3049 | 1293 | } | ||
3050 | 1294 | else { | ||
3051 | 1295 | sp_object_setAttribute(cc->clickeditem, | ||
3052 | 1296 | "inkscape:connection-end", shape_label, false); | ||
3053 | 1297 | sp_object_setAttribute(cc->clickeditem, | ||
3054 | 1298 | "inkscape:connection-end-point", cpid, false); | ||
3055 | 1299 | } | ||
3056 | 1300 | g_free(shape_label); | ||
3057 | 1301 | } | ||
3058 | 1302 | } | ||
3059 | 1303 | cc->clickeditem->setHidden(false); | ||
3060 | 1304 | sp_conn_reroute_path_immediate(SP_PATH(cc->clickeditem)); | ||
3061 | 1305 | cc->clickeditem->updateRepr(); | ||
3062 | 1306 | sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR, | ||
3063 | 1307 | _("Reroute connector")); | ||
3064 | 1308 | cc_set_active_conn(cc, cc->clickeditem); | ||
3065 | 1309 | } | ||
3066 | 1310 | |||
3067 | 1311 | |||
3068 | 1312 | static void | ||
3069 | 1313 | spcc_reset_colors(SPConnectorContext *cc) | ||
3070 | 1314 | { | ||
3071 | 1315 | /* Red */ | ||
3072 | 1316 | cc->red_curve->reset(); | ||
3073 | 1317 | sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL); | ||
3074 | 1318 | |||
3075 | 1319 | cc->green_curve->reset(); | ||
3076 | 1320 | cc->npoints = 0; | ||
3077 | 1321 | } | ||
3078 | 1322 | |||
3079 | 1323 | |||
3080 | 1324 | static void | ||
3081 | 1325 | spcc_connector_set_initial_point(SPConnectorContext *const cc, Geom::Point const p) | ||
3082 | 1326 | { | ||
3083 | 1327 | g_assert( cc->npoints == 0 ); | ||
3084 | 1328 | |||
3085 | 1329 | cc->p[0] = p; | ||
3086 | 1330 | cc->p[1] = p; | ||
3087 | 1331 | cc->npoints = 2; | ||
3088 | 1332 | sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL); | ||
3089 | 1333 | } | ||
3090 | 1334 | |||
3091 | 1335 | |||
3092 | 1336 | static void | ||
3093 | 1337 | spcc_connector_set_subsequent_point(SPConnectorContext *const cc, Geom::Point const p) | ||
3094 | 1338 | { | ||
3095 | 1339 | g_assert( cc->npoints != 0 ); | ||
3096 | 1340 | |||
3097 | 1341 | SPDesktop *dt = cc->desktop; | ||
3098 | 1342 | Geom::Point o = dt->dt2doc(cc->p[0]); | ||
3099 | 1343 | Geom::Point d = dt->dt2doc(p); | ||
3100 | 1344 | Avoid::Point src(o[Geom::X], o[Geom::Y]); | ||
3101 | 1345 | Avoid::Point dst(d[Geom::X], d[Geom::Y]); | ||
3102 | 1346 | |||
3103 | 1347 | if (!cc->newConnRef) { | ||
3104 | 1348 | Avoid::Router *router = sp_desktop_document(dt)->router; | ||
3105 | 1349 | cc->newConnRef = new Avoid::ConnRef(router); | ||
3106 | 1350 | cc->newConnRef->setEndpoint(Avoid::VertID::src, src); | ||
3107 | 1351 | if (cc->isOrthogonal) | ||
3108 | 1352 | cc->newConnRef->setRoutingType(Avoid::ConnType_Orthogonal); | ||
3109 | 1353 | else | ||
3110 | 1354 | cc->newConnRef->setRoutingType(Avoid::ConnType_PolyLine); | ||
3111 | 1355 | } | ||
3112 | 1356 | // Set new endpoint. | ||
3113 | 1357 | cc->newConnRef->setEndpoint(Avoid::VertID::tar, dst); | ||
3114 | 1358 | // Immediately generate new routes for connector. | ||
3115 | 1359 | cc->newConnRef->makePathInvalid(); | ||
3116 | 1360 | cc->newConnRef->router()->processTransaction(); | ||
3117 | 1361 | // Recreate curve from libavoid route. | ||
3118 | 1362 | recreateCurve( cc->red_curve, cc->newConnRef, cc->curvature ); | ||
3119 | 1363 | cc->red_curve->transform(dt->doc2dt()); | ||
3120 | 1364 | sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve); | ||
3121 | 1365 | } | ||
3122 | 1366 | |||
3123 | 1367 | |||
3124 | 1368 | /** | ||
3125 | 1369 | * Concats red, blue and green. | ||
3126 | 1370 | * If any anchors are defined, process these, optionally removing curves from white list | ||
3127 | 1371 | * Invoke _flush_white to write result back to object. | ||
3128 | 1372 | */ | ||
3129 | 1373 | static void | ||
3130 | 1374 | spcc_concat_colors_and_flush(SPConnectorContext *cc) | ||
3131 | 1375 | { | ||
3132 | 1376 | SPCurve *c = cc->green_curve; | ||
3133 | 1377 | cc->green_curve = new SPCurve(); | ||
3134 | 1378 | |||
3135 | 1379 | cc->red_curve->reset(); | ||
3136 | 1380 | sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL); | ||
3137 | 1381 | |||
3138 | 1382 | if (c->is_empty()) { | ||
3139 | 1383 | c->unref(); | ||
3140 | 1384 | return; | ||
3141 | 1385 | } | ||
3142 | 1386 | |||
3143 | 1387 | spcc_flush_white(cc, c); | ||
3144 | 1388 | |||
3145 | 1389 | c->unref(); | ||
3146 | 1390 | } | ||
3147 | 1391 | |||
3148 | 1392 | |||
3149 | 1393 | /* | ||
3150 | 1394 | * Flushes white curve(s) and additional curve into object | ||
3151 | 1395 | * | ||
3152 | 1396 | * No cleaning of colored curves - this has to be done by caller | ||
3153 | 1397 | * No rereading of white data, so if you cannot rely on ::modified, do it in caller | ||
3154 | 1398 | * | ||
3155 | 1399 | */ | ||
3156 | 1400 | |||
3157 | 1401 | static void | ||
3158 | 1402 | spcc_flush_white(SPConnectorContext *cc, SPCurve *gc) | ||
3159 | 1403 | { | ||
3160 | 1404 | SPCurve *c; | ||
3161 | 1405 | |||
3162 | 1406 | if (gc) { | ||
3163 | 1407 | c = gc; | ||
3164 | 1408 | c->ref(); | ||
3165 | 1409 | } else { | ||
3166 | 1410 | return; | ||
3167 | 1411 | } | ||
3168 | 1412 | |||
3169 | 1413 | /* Now we have to go back to item coordinates at last */ | ||
3170 | 1414 | c->transform(SP_EVENT_CONTEXT_DESKTOP(cc)->dt2doc()); | ||
3171 | 1415 | |||
3172 | 1416 | SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc); | ||
3173 | 1417 | SPDocument *doc = sp_desktop_document(desktop); | ||
3174 | 1418 | Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); | ||
3175 | 1419 | |||
3176 | 1420 | if ( c && !c->is_empty() ) { | ||
3177 | 1421 | /* We actually have something to write */ | ||
3178 | 1422 | |||
3179 | 1423 | Inkscape::XML::Node *repr = xml_doc->createElement("svg:path"); | ||
3180 | 1424 | /* Set style */ | ||
3181 | 1425 | sp_desktop_apply_style_tool(desktop, repr, "/tools/connector", false); | ||
3182 | 1426 | |||
3183 | 1427 | gchar *str = sp_svg_write_path( c->get_pathvector() ); | ||
3184 | 1428 | g_assert( str != NULL ); | ||
3185 | 1429 | repr->setAttribute("d", str); | ||
3186 | 1430 | g_free(str); | ||
3187 | 1431 | |||
3188 | 1432 | /* Attach repr */ | ||
3189 | 1433 | cc->newconn = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr)); | ||
3190 | 1434 | cc->newconn->transform = sp_item_i2doc_affine(SP_ITEM(desktop->currentLayer())).inverse(); | ||
3191 | 1435 | |||
3192 | 1436 | bool connection = false; | ||
3193 | 1437 | sp_object_setAttribute(cc->newconn, "inkscape:connector-type", | ||
3194 | 1438 | cc->isOrthogonal ? "orthogonal" : "polyline", false); | ||
3195 | 1439 | sp_object_setAttribute(cc->newconn, "inkscape:connector-curvature", | ||
3196 | 1440 | Glib::Ascii::dtostr(cc->curvature).c_str(), false); | ||
3197 | 1441 | if (cc->shref) | ||
3198 | 1442 | { | ||
3199 | 1443 | sp_object_setAttribute(cc->newconn, "inkscape:connection-start", | ||
3200 | 1444 | cc->shref, false); | ||
3201 | 1445 | if (cc->scpid) | ||
3202 | 1446 | sp_object_setAttribute(cc->newconn, "inkscape:connection-start-point", | ||
3203 | 1447 | cc->scpid, false); | ||
3204 | 1448 | connection = true; | ||
3205 | 1449 | } | ||
3206 | 1450 | |||
3207 | 1451 | if (cc->ehref) | ||
3208 | 1452 | { | ||
3209 | 1453 | sp_object_setAttribute(cc->newconn, "inkscape:connection-end", | ||
3210 | 1454 | cc->ehref, false); | ||
3211 | 1455 | if (cc->ecpid) | ||
3212 | 1456 | sp_object_setAttribute(cc->newconn, "inkscape:connection-end-point", | ||
3213 | 1457 | cc->ecpid, false); | ||
3214 | 1458 | connection = true; | ||
3215 | 1459 | } | ||
3216 | 1460 | // Process pending updates. | ||
3217 | 1461 | cc->newconn->updateRepr(); | ||
3218 | 1462 | sp_document_ensure_up_to_date(doc); | ||
3219 | 1463 | |||
3220 | 1464 | if (connection) { | ||
3221 | 1465 | // Adjust endpoints to shape edge. | ||
3222 | 1466 | sp_conn_reroute_path_immediate(SP_PATH(cc->newconn)); | ||
3223 | 1467 | cc->newconn->updateRepr(); | ||
3224 | 1468 | } | ||
3225 | 1469 | |||
3226 | 1470 | // Only set the selection after we are finished with creating the attributes of | ||
3227 | 1471 | // the connector. Otherwise, the selection change may alter the defaults for | ||
3228 | 1472 | // values like curvature in the connector context, preventing subsequent lookup | ||
3229 | 1473 | // of their original values. | ||
3230 | 1474 | cc->selection->set(repr); | ||
3231 | 1475 | Inkscape::GC::release(repr); | ||
3232 | 1476 | } | ||
3233 | 1477 | |||
3234 | 1478 | c->unref(); | ||
3235 | 1479 | |||
3236 | 1480 | sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR, _("Create connector")); | ||
3237 | 1481 | } | ||
3238 | 1482 | |||
3239 | 1483 | |||
3240 | 1484 | static void | ||
3241 | 1485 | spcc_connector_finish_segment(SPConnectorContext *const cc, Geom::Point const /*p*/) | ||
3242 | 1486 | { | ||
3243 | 1487 | if (!cc->red_curve->is_empty()) { | ||
3244 | 1488 | cc->green_curve->append_continuous(cc->red_curve, 0.0625); | ||
3245 | 1489 | |||
3246 | 1490 | cc->p[0] = cc->p[3]; | ||
3247 | 1491 | cc->p[1] = cc->p[4]; | ||
3248 | 1492 | cc->npoints = 2; | ||
3249 | 1493 | |||
3250 | 1494 | cc->red_curve->reset(); | ||
3251 | 1495 | } | ||
3252 | 1496 | } | ||
3253 | 1497 | |||
3254 | 1498 | |||
3255 | 1499 | static void | ||
3256 | 1500 | spcc_connector_finish(SPConnectorContext *const cc) | ||
3257 | 1501 | { | ||
3258 | 1502 | SPDesktop *const desktop = cc->desktop; | ||
3259 | 1503 | desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing connector")); | ||
3260 | 1504 | |||
3261 | 1505 | cc->red_curve->reset(); | ||
3262 | 1506 | spcc_concat_colors_and_flush(cc); | ||
3263 | 1507 | |||
3264 | 1508 | cc->npoints = 0; | ||
3265 | 1509 | |||
3266 | 1510 | if (cc->newConnRef) { | ||
3267 | 1511 | cc->newConnRef->removeFromGraph(); | ||
3268 | 1512 | delete cc->newConnRef; | ||
3269 | 1513 | cc->newConnRef = NULL; | ||
3270 | 1514 | } | ||
3271 | 1515 | } | ||
3272 | 1516 | |||
3273 | 1517 | |||
3274 | 1518 | static gboolean | ||
3275 | 1519 | cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot) | ||
3276 | 1520 | { | ||
3277 | 1521 | g_assert (knot != NULL); | ||
3278 | 1522 | |||
3279 | 1523 | g_object_ref(knot); | ||
3280 | 1524 | |||
3281 | 1525 | SPConnectorContext *cc = SP_CONNECTOR_CONTEXT( | ||
3282 | 1526 | knot->desktop->event_context); | ||
3283 | 1527 | |||
3284 | 1528 | gboolean consumed = FALSE; | ||
3285 | 1529 | |||
3286 | 1530 | gchar* knot_tip = knot->tip ? knot->tip : cc->knot_tip; | ||
3287 | 1531 | switch (event->type) { | ||
3288 | 1532 | case GDK_ENTER_NOTIFY: | ||
3289 | 1533 | sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, TRUE); | ||
3290 | 1534 | |||
3291 | 1535 | cc->active_handle = knot; | ||
3292 | 1536 | if (knot_tip) | ||
3293 | 1537 | { | ||
3294 | 1538 | knot->desktop->event_context->defaultMessageContext()->set( | ||
3295 | 1539 | Inkscape::NORMAL_MESSAGE, knot_tip); | ||
3296 | 1540 | } | ||
3297 | 1541 | |||
3298 | 1542 | consumed = TRUE; | ||
3299 | 1543 | break; | ||
3300 | 1544 | case GDK_LEAVE_NOTIFY: | ||
3301 | 1545 | sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, FALSE); | ||
3302 | 1546 | |||
3303 | 1547 | cc->active_handle = NULL; | ||
3304 | 1548 | |||
3305 | 1549 | if (knot_tip) { | ||
3306 | 1550 | knot->desktop->event_context->defaultMessageContext()->clear(); | ||
3307 | 1551 | } | ||
3308 | 1552 | |||
3309 | 1553 | consumed = TRUE; | ||
3310 | 1554 | break; | ||
3311 | 1555 | default: | ||
3312 | 1556 | break; | ||
3313 | 1557 | } | ||
3314 | 1558 | |||
3315 | 1559 | g_object_unref(knot); | ||
3316 | 1560 | |||
3317 | 1561 | return consumed; | ||
3318 | 1562 | } | ||
3319 | 1563 | |||
3320 | 1564 | |||
3321 | 1565 | static gboolean | ||
3322 | 1566 | endpt_handler(SPKnot */*knot*/, GdkEvent *event, SPConnectorContext *cc) | ||
3323 | 1567 | { | ||
3324 | 1568 | g_assert( SP_IS_CONNECTOR_CONTEXT(cc) ); | ||
3325 | 1569 | |||
3326 | 1570 | gboolean consumed = FALSE; | ||
3327 | 1571 | |||
3328 | 1572 | switch (event->type) { | ||
3329 | 1573 | case GDK_BUTTON_PRESS: | ||
3330 | 1574 | g_assert( (cc->active_handle == cc->endpt_handle[0]) || | ||
3331 | 1575 | (cc->active_handle == cc->endpt_handle[1]) ); | ||
3332 | 1576 | if (cc->state == SP_CONNECTOR_CONTEXT_IDLE) { | ||
3333 | 1577 | cc->clickeditem = cc->active_conn; | ||
3334 | 1578 | cc->clickedhandle = cc->active_handle; | ||
3335 | 1579 | cc_clear_active_conn(cc); | ||
3336 | 1580 | cc->state = SP_CONNECTOR_CONTEXT_REROUTING; | ||
3337 | 1581 | |||
3338 | 1582 | // Disconnect from attached shape | ||
3339 | 1583 | unsigned ind = (cc->active_handle == cc->endpt_handle[0]) ? 0 : 1; | ||
3340 | 1584 | sp_conn_end_detach(cc->clickeditem, ind); | ||
3341 | 1585 | |||
3342 | 1586 | Geom::Point origin; | ||
3343 | 1587 | if (cc->clickedhandle == cc->endpt_handle[0]) { | ||
3344 | 1588 | origin = cc->endpt_handle[1]->pos; | ||
3345 | 1589 | } | ||
3346 | 1590 | else { | ||
3347 | 1591 | origin = cc->endpt_handle[0]->pos; | ||
3348 | 1592 | } | ||
3349 | 1593 | |||
3350 | 1594 | // Show the red path for dragging. | ||
3351 | 1595 | cc->red_curve = SP_PATH(cc->clickeditem)->original_curve ? SP_PATH(cc->clickeditem)->original_curve->copy() : SP_PATH(cc->clickeditem)->curve->copy(); | ||
3352 | 1596 | Geom::Matrix i2d = sp_item_i2d_affine(cc->clickeditem); | ||
3353 | 1597 | cc->red_curve->transform(i2d); | ||
3354 | 1598 | sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve); | ||
3355 | 1599 | |||
3356 | 1600 | cc->clickeditem->setHidden(true); | ||
3357 | 1601 | |||
3358 | 1602 | // The rest of the interaction rerouting the connector is | ||
3359 | 1603 | // handled by the context root handler. | ||
3360 | 1604 | consumed = TRUE; | ||
3361 | 1605 | } | ||
3362 | 1606 | break; | ||
3363 | 1607 | default: | ||
3364 | 1608 | break; | ||
3365 | 1609 | } | ||
3366 | 1610 | |||
3367 | 1611 | return consumed; | ||
3368 | 1612 | } | ||
3369 | 1613 | |||
3370 | 1614 | static void cc_active_shape_add_knot(SPDesktop* desktop, SPItem* item, ConnectionPointMap &cphandles, ConnectionPoint& cp) | ||
3371 | 1615 | { | ||
3372 | 1616 | SPKnot *knot = sp_knot_new(desktop, 0); | ||
3373 | 1617 | |||
3374 | 1618 | knot->setShape(SP_KNOT_SHAPE_SQUARE); | ||
3375 | 1619 | knot->setSize(8); | ||
3376 | 1620 | knot->setAnchor(GTK_ANCHOR_CENTER); | ||
3377 | 1621 | knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff); | ||
3378 | 1622 | sp_knot_update_ctrl(knot); | ||
3379 | 1623 | |||
3380 | 1624 | // We don't want to use the standard knot handler. | ||
3381 | 1625 | g_signal_handler_disconnect(G_OBJECT(knot->item), | ||
3382 | 1626 | knot->_event_handler_id); | ||
3383 | 1627 | knot->_event_handler_id = 0; | ||
3384 | 1628 | |||
3385 | 1629 | gtk_signal_connect(GTK_OBJECT(knot->item), "event", | ||
3386 | 1630 | GTK_SIGNAL_FUNC(cc_generic_knot_handler), knot); | ||
3387 | 1631 | sp_knot_set_position(knot, item->avoidRef->getConnectionPointPos(cp.type, cp.id) * desktop->doc2dt(), 0); | ||
3388 | 1632 | sp_knot_show(knot); | ||
3389 | 1633 | cphandles[knot] = cp; | ||
3390 | 1634 | } | ||
3391 | 1635 | |||
3392 | 1636 | static void cc_set_active_shape(SPConnectorContext *cc, SPItem *item) | ||
3393 | 1637 | { | ||
3394 | 1638 | g_assert(item != NULL ); | ||
3395 | 1639 | |||
3396 | 1640 | std::map<int, ConnectionPoint>* connpts = &item->avoidRef->connection_points; | ||
3397 | 1641 | |||
3398 | 1642 | if (cc->active_shape != item) | ||
3399 | 1643 | { | ||
3400 | 1644 | // The active shape has changed | ||
3401 | 1645 | // Rebuild everything | ||
3402 | 1646 | cc->active_shape = item; | ||
3403 | 1647 | // Remove existing active shape listeners | ||
3404 | 1648 | if (cc->active_shape_repr) { | ||
3405 | 1649 | sp_repr_remove_listener_by_data(cc->active_shape_repr, cc); | ||
3406 | 1650 | Inkscape::GC::release(cc->active_shape_repr); | ||
3407 | 1651 | |||
3408 | 1652 | sp_repr_remove_listener_by_data(cc->active_shape_layer_repr, cc); | ||
3409 | 1653 | Inkscape::GC::release(cc->active_shape_layer_repr); | ||
3410 | 1654 | } | ||
3411 | 1655 | |||
3412 | 1656 | // Listen in case the active shape changes | ||
3413 | 1657 | cc->active_shape_repr = SP_OBJECT_REPR(item); | ||
3414 | 1658 | if (cc->active_shape_repr) { | ||
3415 | 1659 | Inkscape::GC::anchor(cc->active_shape_repr); | ||
3416 | 1660 | sp_repr_add_listener(cc->active_shape_repr, &shape_repr_events, cc); | ||
3417 | 1661 | |||
3418 | 1662 | cc->active_shape_layer_repr = cc->active_shape_repr->parent(); | ||
3419 | 1663 | Inkscape::GC::anchor(cc->active_shape_layer_repr); | ||
3420 | 1664 | sp_repr_add_listener(cc->active_shape_layer_repr, &layer_repr_events, cc); | ||
3421 | 1665 | } | ||
3422 | 1666 | |||
3423 | 1667 | |||
3424 | 1668 | // Set the connection points. | ||
3425 | 1669 | if ( cc->connpthandles.size() ) | ||
3426 | 1670 | // destroy the old list | ||
3427 | 1671 | while (! cc->connpthandles.empty() ) | ||
3428 | 1672 | { | ||
3429 | 1673 | g_object_unref(cc->connpthandles.begin()->first); | ||
3430 | 1674 | cc->connpthandles.erase(cc->connpthandles.begin()); | ||
3431 | 1675 | } | ||
3432 | 1676 | // build the new one | ||
3433 | 1677 | if ( connpts->size() ) | ||
3434 | 1678 | for (std::map<int, ConnectionPoint>::iterator it = connpts->begin(); it != connpts->end(); ++it) | ||
3435 | 1679 | cc_active_shape_add_knot(cc->desktop, item, cc->connpthandles, it->second); | ||
3436 | 1680 | |||
3437 | 1681 | // Also add default connection points | ||
3438 | 1682 | // For now, only centre default connection point will | ||
3439 | 1683 | // be available | ||
3440 | 1684 | ConnectionPoint centre; | ||
3441 | 1685 | centre.type = ConnPointDefault; | ||
3442 | 1686 | centre.id = ConnPointPosCC; | ||
3443 | 1687 | cc_active_shape_add_knot(cc->desktop, item, cc->connpthandles, centre); | ||
3444 | 1688 | } | ||
3445 | 1689 | else | ||
3446 | 1690 | { | ||
3447 | 1691 | // The active shape didn't change | ||
3448 | 1692 | // Update only the connection point knots | ||
3449 | 1693 | |||
3450 | 1694 | // Ensure the item's connection_points map | ||
3451 | 1695 | // has been updated | ||
3452 | 1696 | sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item)); | ||
3453 | 1697 | |||
3454 | 1698 | std::set<int> seen; | ||
3455 | 1699 | for ( ConnectionPointMap::iterator it = cc->connpthandles.begin(); it != cc->connpthandles.end() ;) | ||
3456 | 1700 | { | ||
3457 | 1701 | bool removed = false; | ||
3458 | 1702 | if ( it->second.type == ConnPointUserDefined ) | ||
3459 | 1703 | { | ||
3460 | 1704 | std::map<int, ConnectionPoint>::iterator p = connpts->find(it->second.id); | ||
3461 | 1705 | if (p != connpts->end()) | ||
3462 | 1706 | { | ||
3463 | 1707 | if ( it->second != p->second ) | ||
3464 | 1708 | // Connection point position has changed | ||
3465 | 1709 | // Update knot position | ||
3466 | 1710 | sp_knot_set_position(it->first, | ||
3467 | 1711 | item->avoidRef->getConnectionPointPos(it->second.type, it->second.id) * cc->desktop->doc2dt(), 0); | ||
3468 | 1712 | seen.insert(it->second.id); | ||
3469 | 1713 | sp_knot_show(it->first); | ||
3470 | 1714 | } | ||
3471 | 1715 | else | ||
3472 | 1716 | { | ||
3473 | 1717 | // This connection point does no longer exist, | ||
3474 | 1718 | // remove the knot | ||
3475 | 1719 | ConnectionPointMap::iterator curr = it; | ||
3476 | 1720 | ++it; | ||
3477 | 1721 | g_object_unref( curr->first ); | ||
3478 | 1722 | cc->connpthandles.erase(curr); | ||
3479 | 1723 | removed = true; | ||
3480 | 1724 | } | ||
3481 | 1725 | } | ||
3482 | 1726 | else | ||
3483 | 1727 | { | ||
3484 | 1728 | // It's a default connection point | ||
3485 | 1729 | // Just make sure it's position is correct | ||
3486 | 1730 | sp_knot_set_position(it->first, | ||
3487 | 1731 | item->avoidRef->getConnectionPointPos(it->second.type, it->second.id) * cc->desktop->doc2dt(), 0); | ||
3488 | 1732 | sp_knot_show(it->first); | ||
3489 | 1733 | |||
3490 | 1734 | } | ||
3491 | 1735 | if ( !removed ) | ||
3492 | 1736 | ++it; | ||
3493 | 1737 | } | ||
3494 | 1738 | // Add knots for new connection points. | ||
3495 | 1739 | if (connpts->size()) | ||
3496 | 1740 | for ( std::map<int, ConnectionPoint>::iterator it = connpts->begin(); it != connpts->end(); ++it ) | ||
3497 | 1741 | if ( seen.find(it->first) == seen.end() ) | ||
3498 | 1742 | // A new connection point has been added | ||
3499 | 1743 | // to the shape. Add a knot for it. | ||
3500 | 1744 | cc_active_shape_add_knot(cc->desktop, item, cc->connpthandles, it->second); | ||
3501 | 1745 | } | ||
3502 | 1746 | } | ||
3503 | 1747 | |||
3504 | 1748 | |||
3505 | 1749 | static void | ||
3506 | 1750 | cc_set_active_conn(SPConnectorContext *cc, SPItem *item) | ||
3507 | 1751 | { | ||
3508 | 1752 | g_assert( SP_IS_PATH(item) ); | ||
3509 | 1753 | |||
3510 | 1754 | SPCurve *curve = SP_PATH(item)->original_curve ? SP_PATH(item)->original_curve : SP_PATH(item)->curve; | ||
3511 | 1755 | Geom::Matrix i2d = sp_item_i2d_affine(item); | ||
3512 | 1756 | |||
3513 | 1757 | if (cc->active_conn == item) | ||
3514 | 1758 | { | ||
3515 | 1759 | if (curve->is_empty()) | ||
3516 | 1760 | { | ||
3517 | 1761 | // Connector is invisible because it is clipped to the boundary of | ||
3518 | 1762 | // two overlpapping shapes. | ||
3519 | 1763 | sp_knot_hide(cc->endpt_handle[0]); | ||
3520 | 1764 | sp_knot_hide(cc->endpt_handle[1]); | ||
3521 | 1765 | } | ||
3522 | 1766 | else | ||
3523 | 1767 | { | ||
3524 | 1768 | // Just adjust handle positions. | ||
3525 | 1769 | Geom::Point startpt = *(curve->first_point()) * i2d; | ||
3526 | 1770 | sp_knot_set_position(cc->endpt_handle[0], startpt, 0); | ||
3527 | 1771 | |||
3528 | 1772 | Geom::Point endpt = *(curve->last_point()) * i2d; | ||
3529 | 1773 | sp_knot_set_position(cc->endpt_handle[1], endpt, 0); | ||
3530 | 1774 | } | ||
3531 | 1775 | |||
3532 | 1776 | return; | ||
3533 | 1777 | } | ||
3534 | 1778 | |||
3535 | 1779 | cc->active_conn = item; | ||
3536 | 1780 | |||
3537 | 1781 | // Remove existing active conn listeners | ||
3538 | 1782 | if (cc->active_conn_repr) { | ||
3539 | 1783 | sp_repr_remove_listener_by_data(cc->active_conn_repr, cc); | ||
3540 | 1784 | Inkscape::GC::release(cc->active_conn_repr); | ||
3541 | 1785 | cc->active_conn_repr = NULL; | ||
3542 | 1786 | } | ||
3543 | 1787 | |||
3544 | 1788 | // Listen in case the active conn changes | ||
3545 | 1789 | cc->active_conn_repr = SP_OBJECT_REPR(item); | ||
3546 | 1790 | if (cc->active_conn_repr) { | ||
3547 | 1791 | Inkscape::GC::anchor(cc->active_conn_repr); | ||
3548 | 1792 | sp_repr_add_listener(cc->active_conn_repr, &shape_repr_events, cc); | ||
3549 | 1793 | } | ||
3550 | 1794 | |||
3551 | 1795 | for (int i = 0; i < 2; ++i) { | ||
3552 | 1796 | |||
3553 | 1797 | // Create the handle if it doesn't exist | ||
3554 | 1798 | if ( cc->endpt_handle[i] == NULL ) { | ||
3555 | 1799 | SPKnot *knot = sp_knot_new(cc->desktop, | ||
3556 | 1800 | _("<b>Connector endpoint</b>: drag to reroute or connect to new shapes")); | ||
3557 | 1801 | |||
3558 | 1802 | knot->setShape(SP_KNOT_SHAPE_SQUARE); | ||
3559 | 1803 | knot->setSize(7); | ||
3560 | 1804 | knot->setAnchor(GTK_ANCHOR_CENTER); | ||
3561 | 1805 | knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff); | ||
3562 | 1806 | knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff); | ||
3563 | 1807 | sp_knot_update_ctrl(knot); | ||
3564 | 1808 | |||
3565 | 1809 | // We don't want to use the standard knot handler, | ||
3566 | 1810 | // since we don't want this knot to be draggable. | ||
3567 | 1811 | g_signal_handler_disconnect(G_OBJECT(knot->item), | ||
3568 | 1812 | knot->_event_handler_id); | ||
3569 | 1813 | knot->_event_handler_id = 0; | ||
3570 | 1814 | |||
3571 | 1815 | gtk_signal_connect(GTK_OBJECT(knot->item), "event", | ||
3572 | 1816 | GTK_SIGNAL_FUNC(cc_generic_knot_handler), knot); | ||
3573 | 1817 | |||
3574 | 1818 | cc->endpt_handle[i] = knot; | ||
3575 | 1819 | } | ||
3576 | 1820 | |||
3577 | 1821 | // Remove any existing handlers | ||
3578 | 1822 | if (cc->endpt_handler_id[i]) { | ||
3579 | 1823 | g_signal_handlers_disconnect_by_func( | ||
3580 | 1824 | G_OBJECT(cc->endpt_handle[i]->item), | ||
3581 | 1825 | (void*)G_CALLBACK(endpt_handler), (gpointer) cc ); | ||
3582 | 1826 | cc->endpt_handler_id[i] = 0; | ||
3583 | 1827 | } | ||
3584 | 1828 | |||
3585 | 1829 | // Setup handlers for connector endpoints, this is | ||
3586 | 1830 | // is as 'after' so that cc_generic_knot_handler is | ||
3587 | 1831 | // triggered first for any endpoint. | ||
3588 | 1832 | cc->endpt_handler_id[i] = g_signal_connect_after( | ||
3589 | 1833 | G_OBJECT(cc->endpt_handle[i]->item), "event", | ||
3590 | 1834 | G_CALLBACK(endpt_handler), cc); | ||
3591 | 1835 | } | ||
3592 | 1836 | |||
3593 | 1837 | if (curve->is_empty()) | ||
3594 | 1838 | { | ||
3595 | 1839 | // Connector is invisible because it is clipped to the boundary | ||
3596 | 1840 | // of two overlpapping shapes. So, it doesn't need endpoints. | ||
3597 | 1841 | return; | ||
3598 | 1842 | } | ||
3599 | 1843 | |||
3600 | 1844 | Geom::Point startpt = *(curve->first_point()) * i2d; | ||
3601 | 1845 | sp_knot_set_position(cc->endpt_handle[0], startpt, 0); | ||
3602 | 1846 | |||
3603 | 1847 | Geom::Point endpt = *(curve->last_point()) * i2d; | ||
3604 | 1848 | sp_knot_set_position(cc->endpt_handle[1], endpt, 0); | ||
3605 | 1849 | |||
3606 | 1850 | sp_knot_show(cc->endpt_handle[0]); | ||
3607 | 1851 | sp_knot_show(cc->endpt_handle[1]); | ||
3608 | 1852 | } | ||
3609 | 1853 | |||
3610 | 1854 | void cc_create_connection_point(SPConnectorContext* cc) | ||
3611 | 1855 | { | ||
3612 | 1856 | if (cc->active_shape && cc->state == SP_CONNECTOR_CONTEXT_IDLE) | ||
3613 | 1857 | { | ||
3614 | 1858 | if (cc->selected_handle) | ||
3615 | 1859 | { | ||
3616 | 1860 | cc_deselect_handle( cc->selected_handle ); | ||
3617 | 1861 | } | ||
3618 | 1862 | SPKnot *knot = sp_knot_new(cc->desktop, 0); | ||
3619 | 1863 | // We do not process events on this knot. | ||
3620 | 1864 | g_signal_handler_disconnect(G_OBJECT(knot->item), | ||
3621 | 1865 | knot->_event_handler_id); | ||
3622 | 1866 | knot->_event_handler_id = 0; | ||
3623 | 1867 | |||
3624 | 1868 | cc_select_handle( knot ); | ||
3625 | 1869 | cc->selected_handle = knot; | ||
3626 | 1870 | sp_knot_show(cc->selected_handle); | ||
3627 | 1871 | cc->state = SP_CONNECTOR_CONTEXT_NEWCONNPOINT; | ||
3628 | 1872 | } | ||
3629 | 1873 | } | ||
3630 | 1874 | |||
3631 | 1875 | void cc_remove_connection_point(SPConnectorContext* cc) | ||
3632 | 1876 | { | ||
3633 | 1877 | if (cc->selected_handle && cc->state == SP_CONNECTOR_CONTEXT_IDLE ) | ||
3634 | 1878 | { | ||
3635 | 1879 | cc->active_shape->avoidRef->deleteConnectionPoint(cc->connpthandles[cc->selected_handle]); | ||
3636 | 1880 | cc->selected_handle = NULL; | ||
3637 | 1881 | } | ||
3638 | 1882 | } | ||
3639 | 1883 | |||
3640 | 1884 | static bool cc_item_is_shape(SPItem *item) | ||
3641 | 1885 | { | ||
3642 | 1886 | if (SP_IS_PATH(item)) { | ||
3643 | 1887 | SPCurve *curve = (SP_SHAPE(item))->curve; | ||
3644 | 1888 | if ( curve && !(curve->is_closed()) ) { | ||
3645 | 1889 | // Open paths are connectors. | ||
3646 | 1890 | return false; | ||
3647 | 1891 | } | ||
3648 | 1892 | } | ||
3649 | 1893 | else if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { | ||
3650 | 1894 | Inkscape::Preferences *prefs = Inkscape::Preferences::get(); | ||
3651 | 1895 | if (prefs->getBool("/tools/connector/ignoretext", true)) { | ||
3652 | 1896 | // Don't count text as a shape we can connect connector to. | ||
3653 | 1897 | return false; | ||
3654 | 1898 | } | ||
3655 | 1899 | } | ||
3656 | 1900 | return true; | ||
3657 | 1901 | } | ||
3658 | 1902 | |||
3659 | 1903 | |||
3660 | 1904 | bool cc_item_is_connector(SPItem *item) | ||
3661 | 1905 | { | ||
3662 | 1906 | if (SP_IS_PATH(item)) { | ||
3663 | 1907 | bool closed = SP_PATH(item)->original_curve ? SP_PATH(item)->original_curve->is_closed() : SP_PATH(item)->curve->is_closed(); | ||
3664 | 1908 | if (SP_PATH(item)->connEndPair.isAutoRoutingConn() && !closed) { | ||
3665 | 1909 | // To be considered a connector, an object must be a non-closed | ||
3666 | 1910 | // path that is marked with a "inkscape:connector-type" attribute. | ||
3667 | 1911 | return true; | ||
3668 | 1912 | } | ||
3669 | 1913 | } | ||
3670 | 1914 | return false; | ||
3671 | 1915 | } | ||
3672 | 1916 | |||
3673 | 1917 | |||
3674 | 1918 | void cc_selection_set_avoid(bool const set_avoid) | ||
3675 | 1919 | { | ||
3676 | 1920 | SPDesktop *desktop = inkscape_active_desktop(); | ||
3677 | 1921 | if (desktop == NULL) { | ||
3678 | 1922 | return; | ||
3679 | 1923 | } | ||
3680 | 1924 | |||
3681 | 1925 | SPDocument *document = sp_desktop_document(desktop); | ||
3682 | 1926 | |||
3683 | 1927 | Inkscape::Selection *selection = sp_desktop_selection(desktop); | ||
3684 | 1928 | |||
3685 | 1929 | GSList *l = (GSList *) selection->itemList(); | ||
3686 | 1930 | |||
3687 | 1931 | int changes = 0; | ||
3688 | 1932 | |||
3689 | 1933 | while (l) { | ||
3690 | 1934 | SPItem *item = (SPItem *) l->data; | ||
3691 | 1935 | |||
3692 | 1936 | char const *value = (set_avoid) ? "true" : NULL; | ||
3693 | 1937 | |||
3694 | 1938 | if (cc_item_is_shape(item)) { | ||
3695 | 1939 | sp_object_setAttribute(item, "inkscape:connector-avoid", | ||
3696 | 1940 | value, false); | ||
3697 | 1941 | item->avoidRef->handleSettingChange(); | ||
3698 | 1942 | changes++; | ||
3699 | 1943 | } | ||
3700 | 1944 | |||
3701 | 1945 | l = l->next; | ||
3702 | 1946 | } | ||
3703 | 1947 | |||
3704 | 1948 | if (changes == 0) { | ||
3705 | 1949 | desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, | ||
3706 | 1950 | _("Select <b>at least one non-connector object</b>.")); | ||
3707 | 1951 | return; | ||
3708 | 1952 | } | ||
3709 | 1953 | |||
3710 | 1954 | char *event_desc = (set_avoid) ? | ||
3711 | 1955 | _("Make connectors avoid selected objects") : | ||
3712 | 1956 | _("Make connectors ignore selected objects"); | ||
3713 | 1957 | sp_document_done(document, SP_VERB_CONTEXT_CONNECTOR, event_desc); | ||
3714 | 1958 | } | ||
3715 | 1959 | |||
3716 | 1960 | |||
3717 | 1961 | static void | ||
3718 | 1962 | cc_selection_changed(Inkscape::Selection *selection, gpointer data) | ||
3719 | 1963 | { | ||
3720 | 1964 | SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data); | ||
3721 | 1965 | //SPEventContext *ec = SP_EVENT_CONTEXT(cc); | ||
3722 | 1966 | |||
3723 | 1967 | SPItem *item = selection->singleItem(); | ||
3724 | 1968 | |||
3725 | 1969 | if (cc->active_conn == item) | ||
3726 | 1970 | { | ||
3727 | 1971 | // Nothing to change. | ||
3728 | 1972 | return; | ||
3729 | 1973 | } | ||
3730 | 1974 | if (item == NULL) | ||
3731 | 1975 | { | ||
3732 | 1976 | cc_clear_active_conn(cc); | ||
3733 | 1977 | return; | ||
3734 | 1978 | } | ||
3735 | 1979 | |||
3736 | 1980 | if (cc_item_is_connector(item)) { | ||
3737 | 1981 | cc_set_active_conn(cc, item); | ||
3738 | 1982 | } | ||
3739 | 1983 | } | ||
3740 | 1984 | |||
3741 | 1985 | |||
3742 | 1986 | static void | ||
3743 | 1987 | shape_event_attr_deleted(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *child, | ||
3744 | 1988 | Inkscape::XML::Node */*ref*/, gpointer data) | ||
3745 | 1989 | { | ||
3746 | 1990 | g_assert(data); | ||
3747 | 1991 | SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data); | ||
3748 | 1992 | |||
3749 | 1993 | if (child == cc->active_shape_repr) { | ||
3750 | 1994 | // The active shape has been deleted. Clear active shape. | ||
3751 | 1995 | cc_clear_active_shape(cc); | ||
3752 | 1996 | } | ||
3753 | 1997 | } | ||
3754 | 1998 | |||
3755 | 1999 | |||
3756 | 2000 | static void | ||
3757 | 2001 | shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name, | ||
3758 | 2002 | gchar const */*old_value*/, gchar const */*new_value*/, | ||
3759 | 2003 | bool /*is_interactive*/, gpointer data) | ||
3760 | 2004 | { | ||
3761 | 2005 | g_assert(data); | ||
3762 | 2006 | SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data); | ||
3763 | 2007 | |||
3764 | 2008 | // Look for changes that result in onscreen movement. | ||
3765 | 2009 | if (!strcmp(name, "d") || !strcmp(name, "x") || !strcmp(name, "y") || | ||
3766 | 2010 | !strcmp(name, "width") || !strcmp(name, "height") || | ||
3767 | 2011 | !strcmp(name, "transform")) | ||
3768 | 2012 | { | ||
3769 | 2013 | if (repr == cc->active_shape_repr) { | ||
3770 | 2014 | // Active shape has moved. Clear active shape. | ||
3771 | 2015 | cc_clear_active_shape(cc); | ||
3772 | 2016 | } | ||
3773 | 2017 | else if (repr == cc->active_conn_repr) { | ||
3774 | 2018 | // The active conn has been moved. | ||
3775 | 2019 | // Set it again, which just sets new handle positions. | ||
3776 | 2020 | cc_set_active_conn(cc, cc->active_conn); | ||
3777 | 2021 | } | ||
3778 | 2022 | } | ||
3779 | 2023 | else | ||
3780 | 2024 | if ( !strcmp(name, "inkscape:connection-points") ) | ||
3781 | 2025 | if (repr == cc->active_shape_repr) | ||
3782 | 2026 | // The connection points of the active shape | ||
3783 | 2027 | // have changed. Update them. | ||
3784 | 2028 | cc_set_active_shape(cc, cc->active_shape); | ||
3785 | 2029 | } | ||
3786 | 2030 | |||
3787 | 2031 | |||
3788 | 2032 | /* | ||
3789 | 2033 | Local Variables: | ||
3790 | 2034 | mode:c++ | ||
3791 | 2035 | c-file-style:"stroustrup" | ||
3792 | 2036 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) | ||
3793 | 2037 | indent-tabs-mode:nil | ||
3794 | 2038 | fill-column:99 | ||
3795 | 2039 | End: | ||
3796 | 2040 | */ | ||
3797 | 2041 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : | ||
3798 | 2042 | 0 | ||
3799 | === removed directory '.pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/extension' | |||
3800 | === removed file '.pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/extension/effect.cpp' | |||
3801 | --- .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/extension/effect.cpp 2013-07-02 17:25:52 +0000 | |||
3802 | +++ .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/extension/effect.cpp 1970-01-01 00:00:00 +0000 | |||
3803 | @@ -1,409 +0,0 @@ | |||
3804 | 1 | /* | ||
3805 | 2 | * Authors: | ||
3806 | 3 | * Ted Gould <ted@gould.cx> | ||
3807 | 4 | * | ||
3808 | 5 | * Copyright (C) 2002-2007 Authors | ||
3809 | 6 | * | ||
3810 | 7 | * Released under GNU GPL, read the file 'COPYING' for more information | ||
3811 | 8 | */ | ||
3812 | 9 | |||
3813 | 10 | #include "inkscape-private.h" | ||
3814 | 11 | #include "helper/action.h" | ||
3815 | 12 | #include "ui/view/view.h" | ||
3816 | 13 | #include "desktop-handles.h" | ||
3817 | 14 | #include "selection.h" | ||
3818 | 15 | #include "sp-namedview.h" | ||
3819 | 16 | #include "desktop.h" | ||
3820 | 17 | #include "implementation/implementation.h" | ||
3821 | 18 | #include "effect.h" | ||
3822 | 19 | #include "execution-env.h" | ||
3823 | 20 | #include "timer.h" | ||
3824 | 21 | |||
3825 | 22 | |||
3826 | 23 | |||
3827 | 24 | /* Inkscape::Extension::Effect */ | ||
3828 | 25 | |||
3829 | 26 | namespace Inkscape { | ||
3830 | 27 | namespace Extension { | ||
3831 | 28 | |||
3832 | 29 | Effect * Effect::_last_effect = NULL; | ||
3833 | 30 | Inkscape::XML::Node * Effect::_effects_list = NULL; | ||
3834 | 31 | Inkscape::XML::Node * Effect::_filters_list = NULL; | ||
3835 | 32 | |||
3836 | 33 | #define EFFECTS_LIST "effects-list" | ||
3837 | 34 | #define FILTERS_LIST "filters-list" | ||
3838 | 35 | |||
3839 | 36 | Effect::Effect (Inkscape::XML::Node * in_repr, Implementation::Implementation * in_imp) | ||
3840 | 37 | : Extension(in_repr, in_imp), | ||
3841 | 38 | _id_noprefs(Glib::ustring(get_id()) + ".noprefs"), | ||
3842 | 39 | _name_noprefs(Glib::ustring(get_name()) + _(" (No preferences)")), | ||
3843 | 40 | _verb(get_id(), get_name(), NULL, NULL, this, true), | ||
3844 | 41 | _verb_nopref(_id_noprefs.c_str(), _name_noprefs.c_str(), NULL, NULL, this, false), | ||
3845 | 42 | _menu_node(NULL), _workingDialog(true), | ||
3846 | 43 | _prefDialog(NULL) | ||
3847 | 44 | { | ||
3848 | 45 | Inkscape::XML::Node * local_effects_menu = NULL; | ||
3849 | 46 | |||
3850 | 47 | // This is a weird hack | ||
3851 | 48 | if (!strcmp(this->get_id(), "org.inkscape.filter.dropshadow")) | ||
3852 | 49 | return; | ||
3853 | 50 | |||
3854 | 51 | bool hidden = false; | ||
3855 | 52 | |||
3856 | 53 | no_doc = false; | ||
3857 | 54 | no_live_preview = false; | ||
3858 | 55 | |||
3859 | 56 | if (repr != NULL) { | ||
3860 | 57 | |||
3861 | 58 | for (Inkscape::XML::Node *child = sp_repr_children(repr); child != NULL; child = child->next()) { | ||
3862 | 59 | if (!strcmp(child->name(), INKSCAPE_EXTENSION_NS "effect")) { | ||
3863 | 60 | if (child->attribute("needs-document") && !strcmp(child->attribute("needs-document"), "false")) { | ||
3864 | 61 | no_doc = true; | ||
3865 | 62 | } | ||
3866 | 63 | if (child->attribute("needs-live-preview") && !strcmp(child->attribute("needs-live-preview"), "false")) { | ||
3867 | 64 | no_live_preview = true; | ||
3868 | 65 | } | ||
3869 | 66 | for (Inkscape::XML::Node *effect_child = sp_repr_children(child); effect_child != NULL; effect_child = effect_child->next()) { | ||
3870 | 67 | if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "effects-menu")) { | ||
3871 | 68 | // printf("Found local effects menu in %s\n", this->get_name()); | ||
3872 | 69 | local_effects_menu = sp_repr_children(effect_child); | ||
3873 | 70 | if (effect_child->attribute("hidden") && !strcmp(effect_child->attribute("hidden"), "true")) { | ||
3874 | 71 | hidden = true; | ||
3875 | 72 | } | ||
3876 | 73 | } | ||
3877 | 74 | if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "menu-name") || | ||
3878 | 75 | !strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "_menu-name")) { | ||
3879 | 76 | // printf("Found local effects menu in %s\n", this->get_name()); | ||
3880 | 77 | _verb.set_name(sp_repr_children(effect_child)->content()); | ||
3881 | 78 | } | ||
3882 | 79 | if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "menu-tip") || | ||
3883 | 80 | !strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "_menu-tip")) { | ||
3884 | 81 | // printf("Found local effects menu in %s\n", this->get_name()); | ||
3885 | 82 | _verb.set_tip(sp_repr_children(effect_child)->content()); | ||
3886 | 83 | } | ||
3887 | 84 | } // children of "effect" | ||
3888 | 85 | break; // there can only be one effect | ||
3889 | 86 | } // find "effect" | ||
3890 | 87 | } // children of "inkscape-extension" | ||
3891 | 88 | } // if we have an XML file | ||
3892 | 89 | |||
3893 | 90 | if (INKSCAPE != NULL) { | ||
3894 | 91 | if (_effects_list == NULL) | ||
3895 | 92 | _effects_list = find_menu(inkscape_get_menus(INKSCAPE), EFFECTS_LIST); | ||
3896 | 93 | if (_filters_list == NULL) | ||
3897 | 94 | _filters_list = find_menu(inkscape_get_menus(INKSCAPE), FILTERS_LIST); | ||
3898 | 95 | } | ||
3899 | 96 | |||
3900 | 97 | if ((_effects_list != NULL || _filters_list != NULL)) { | ||
3901 | 98 | Inkscape::XML::Document *xml_doc; | ||
3902 | 99 | xml_doc = _effects_list->document(); | ||
3903 | 100 | _menu_node = xml_doc->createElement("verb"); | ||
3904 | 101 | _menu_node->setAttribute("verb-id", this->get_id(), false); | ||
3905 | 102 | |||
3906 | 103 | if (!hidden) { | ||
3907 | 104 | if (_filters_list && | ||
3908 | 105 | local_effects_menu && | ||
3909 | 106 | local_effects_menu->attribute("name") && | ||
3910 | 107 | !strcmp(local_effects_menu->attribute("name"), ("Filters"))) { | ||
3911 | 108 | merge_menu(_filters_list->parent(), _filters_list, sp_repr_children(local_effects_menu), _menu_node); | ||
3912 | 109 | } else if (_effects_list) { | ||
3913 | 110 | merge_menu(_effects_list->parent(), _effects_list, local_effects_menu, _menu_node); | ||
3914 | 111 | } | ||
3915 | 112 | } | ||
3916 | 113 | } | ||
3917 | 114 | |||
3918 | 115 | return; | ||
3919 | 116 | } | ||
3920 | 117 | |||
3921 | 118 | void | ||
3922 | 119 | Effect::merge_menu (Inkscape::XML::Node * base, | ||
3923 | 120 | Inkscape::XML::Node * start, | ||
3924 | 121 | Inkscape::XML::Node * patern, | ||
3925 | 122 | Inkscape::XML::Node * mergee) { | ||
3926 | 123 | Glib::ustring mergename; | ||
3927 | 124 | Inkscape::XML::Node * tomerge = NULL; | ||
3928 | 125 | Inkscape::XML::Node * submenu = NULL; | ||
3929 | 126 | |||
3930 | 127 | /* printf("Merge menu with '%s' '%s' '%s'\n", | ||
3931 | 128 | base != NULL ? base->name() : "NULL", | ||
3932 | 129 | patern != NULL ? patern->name() : "NULL", | ||
3933 | 130 | mergee != NULL ? mergee->name() : "NULL"); */ | ||
3934 | 131 | |||
3935 | 132 | if (patern == NULL) { | ||
3936 | 133 | // Merge the verb name | ||
3937 | 134 | tomerge = mergee; | ||
3938 | 135 | mergename = _(this->get_name()); | ||
3939 | 136 | } else { | ||
3940 | 137 | gchar const * menuname = patern->attribute("name"); | ||
3941 | 138 | if (menuname == NULL) menuname = patern->attribute("_name"); | ||
3942 | 139 | if (menuname == NULL) return; | ||
3943 | 140 | |||
3944 | 141 | Inkscape::XML::Document *xml_doc; | ||
3945 | 142 | xml_doc = base->document(); | ||
3946 | 143 | tomerge = xml_doc->createElement("submenu"); | ||
3947 | 144 | tomerge->setAttribute("name", menuname, false); | ||
3948 | 145 | |||
3949 | 146 | mergename = _(menuname); | ||
3950 | 147 | } | ||
3951 | 148 | |||
3952 | 149 | int position = -1; | ||
3953 | 150 | |||
3954 | 151 | if (start != NULL) { | ||
3955 | 152 | Inkscape::XML::Node * menupass; | ||
3956 | 153 | for (menupass = start; menupass != NULL && strcmp(menupass->name(), "separator"); menupass = menupass->next()) { | ||
3957 | 154 | gchar const * compare_char = NULL; | ||
3958 | 155 | if (!strcmp(menupass->name(), "verb")) { | ||
3959 | 156 | gchar const * verbid = menupass->attribute("verb-id"); | ||
3960 | 157 | Inkscape::Verb * verb = Inkscape::Verb::getbyid(verbid); | ||
3961 | 158 | if (verb == NULL) { | ||
3962 | 159 | g_warning("Unable to find verb '%s' which is referred to in the menus.", verbid); | ||
3963 | 160 | continue; | ||
3964 | 161 | } | ||
3965 | 162 | compare_char = verb->get_name(); | ||
3966 | 163 | } else if (!strcmp(menupass->name(), "submenu")) { | ||
3967 | 164 | compare_char = menupass->attribute("name"); | ||
3968 | 165 | if (compare_char == NULL) | ||
3969 | 166 | compare_char = menupass->attribute("_name"); | ||
3970 | 167 | } | ||
3971 | 168 | |||
3972 | 169 | position = menupass->position() + 1; | ||
3973 | 170 | |||
3974 | 171 | /* This will cause us to skip tags we don't understand */ | ||
3975 | 172 | if (compare_char == NULL) { | ||
3976 | 173 | continue; | ||
3977 | 174 | } | ||
3978 | 175 | |||
3979 | 176 | Glib::ustring compare(_(compare_char)); | ||
3980 | 177 | |||
3981 | 178 | if (mergename == compare) { | ||
3982 | 179 | Inkscape::GC::release(tomerge); | ||
3983 | 180 | tomerge = NULL; | ||
3984 | 181 | submenu = menupass; | ||
3985 | 182 | break; | ||
3986 | 183 | } | ||
3987 | 184 | |||
3988 | 185 | if (mergename < compare) { | ||
3989 | 186 | position = menupass->position(); | ||
3990 | 187 | break; | ||
3991 | 188 | } | ||
3992 | 189 | } // for menu items | ||
3993 | 190 | } // start != NULL | ||
3994 | 191 | |||
3995 | 192 | if (tomerge != NULL) { | ||
3996 | 193 | base->appendChild(tomerge); | ||
3997 | 194 | Inkscape::GC::release(tomerge); | ||
3998 | 195 | if (position != -1) | ||
3999 | 196 | tomerge->setPosition(position); | ||
4000 | 197 | } | ||
4001 | 198 | |||
4002 | 199 | if (patern != NULL) { | ||
4003 | 200 | if (submenu == NULL) | ||
4004 | 201 | submenu = tomerge; | ||
4005 | 202 | merge_menu(submenu, submenu->firstChild(), patern->firstChild(), mergee); | ||
4006 | 203 | } | ||
4007 | 204 | |||
4008 | 205 | return; | ||
4009 | 206 | } | ||
4010 | 207 | |||
4011 | 208 | Effect::~Effect (void) | ||
4012 | 209 | { | ||
4013 | 210 | if (get_last_effect() == this) | ||
4014 | 211 | set_last_effect(NULL); | ||
4015 | 212 | if (_menu_node) | ||
4016 | 213 | Inkscape::GC::release(_menu_node); | ||
4017 | 214 | return; | ||
4018 | 215 | } | ||
4019 | 216 | |||
4020 | 217 | bool | ||
4021 | 218 | Effect::check (void) | ||
4022 | 219 | { | ||
4023 | 220 | if (!Extension::check()) { | ||
4024 | 221 | /** \todo Check to see if parent has this as its only child, | ||
4025 | 222 | if so, delete it too */ | ||
4026 | 223 | if (_menu_node != NULL) | ||
4027 | 224 | sp_repr_unparent(_menu_node); | ||
4028 | 225 | _menu_node = NULL; | ||
4029 | 226 | return false; | ||
4030 | 227 | } | ||
4031 | 228 | return true; | ||
4032 | 229 | } | ||
4033 | 230 | |||
4034 | 231 | bool | ||
4035 | 232 | Effect::prefs (Inkscape::UI::View::View * doc) | ||
4036 | 233 | { | ||
4037 | 234 | if (_prefDialog != NULL) { | ||
4038 | 235 | _prefDialog->raise(); | ||
4039 | 236 | return true; | ||
4040 | 237 | } | ||
4041 | 238 | |||
4042 | 239 | if (param_visible_count() == 0) { | ||
4043 | 240 | effect(doc); | ||
4044 | 241 | return true; | ||
4045 | 242 | } | ||
4046 | 243 | |||
4047 | 244 | if (!loaded()) | ||
4048 | 245 | set_state(Extension::STATE_LOADED); | ||
4049 | 246 | if (!loaded()) return false; | ||
4050 | 247 | |||
4051 | 248 | _prefDialog = new PrefDialog(this->get_name(), this->get_help(), NULL, this); | ||
4052 | 249 | _prefDialog->show(); | ||
4053 | 250 | |||
4054 | 251 | return true; | ||
4055 | 252 | } | ||
4056 | 253 | |||
4057 | 254 | /** | ||
4058 | 255 | \brief The function that 'does' the effect itself | ||
4059 | 256 | \param doc The Inkscape::UI::View::View to do the effect on | ||
4060 | 257 | |||
4061 | 258 | This function first insures that the extension is loaded, and if not, | ||
4062 | 259 | loads it. It then calls the implemention to do the actual work. It | ||
4063 | 260 | also resets the last effect pointer to be this effect. Finally, it | ||
4064 | 261 | executes a \c sp_document_done to commit the changes to the undo | ||
4065 | 262 | stack. | ||
4066 | 263 | */ | ||
4067 | 264 | void | ||
4068 | 265 | Effect::effect (Inkscape::UI::View::View * doc) | ||
4069 | 266 | { | ||
4070 | 267 | //printf("Execute effect\n"); | ||
4071 | 268 | if (!loaded()) | ||
4072 | 269 | set_state(Extension::STATE_LOADED); | ||
4073 | 270 | if (!loaded()) return; | ||
4074 | 271 | |||
4075 | 272 | |||
4076 | 273 | ExecutionEnv executionEnv(this, doc); | ||
4077 | 274 | timer->lock(); | ||
4078 | 275 | executionEnv.run(); | ||
4079 | 276 | if (executionEnv.wait()) { | ||
4080 | 277 | executionEnv.commit(); | ||
4081 | 278 | } else { | ||
4082 | 279 | executionEnv.cancel(); | ||
4083 | 280 | } | ||
4084 | 281 | timer->unlock(); | ||
4085 | 282 | |||
4086 | 283 | return; | ||
4087 | 284 | } | ||
4088 | 285 | |||
4089 | 286 | /** \brief Sets which effect was called last | ||
4090 | 287 | \param in_effect The effect that has been called | ||
4091 | 288 | |||
4092 | 289 | This function sets the static variable \c _last_effect and it | ||
4093 | 290 | ensures that the last effect verb is sensitive. | ||
4094 | 291 | |||
4095 | 292 | If the \c in_effect variable is \c NULL then the last effect | ||
4096 | 293 | verb is made insesitive. | ||
4097 | 294 | */ | ||
4098 | 295 | void | ||
4099 | 296 | Effect::set_last_effect (Effect * in_effect) | ||
4100 | 297 | { | ||
4101 | 298 | gchar const * verb_id = in_effect->get_verb()->get_id(); | ||
4102 | 299 | gchar const * help_id_prefix = "org.inkscape.help."; | ||
4103 | 300 | |||
4104 | 301 | // We don't want these "effects" to register as the last effect, | ||
4105 | 302 | // this wouldn't be helpful to the user who selects a real effect, | ||
4106 | 303 | // then goes to the help file (implemented as an effect), then goes | ||
4107 | 304 | // back to the effect, only to see it written over by the help file | ||
4108 | 305 | // selection. | ||
4109 | 306 | |||
4110 | 307 | // This snippet should fix this bug: | ||
4111 | 308 | // https://bugs.launchpad.net/inkscape/+bug/600671 | ||
4112 | 309 | if (strncmp(verb_id, help_id_prefix, strlen(help_id_prefix)) == 0) return; | ||
4113 | 310 | |||
4114 | 311 | if (in_effect == NULL) { | ||
4115 | 312 | Inkscape::Verb::get(SP_VERB_EFFECT_LAST)->sensitive(NULL, false); | ||
4116 | 313 | Inkscape::Verb::get(SP_VERB_EFFECT_LAST_PREF)->sensitive(NULL, false); | ||
4117 | 314 | } else if (_last_effect == NULL) { | ||
4118 | 315 | Inkscape::Verb::get(SP_VERB_EFFECT_LAST)->sensitive(NULL, true); | ||
4119 | 316 | Inkscape::Verb::get(SP_VERB_EFFECT_LAST_PREF)->sensitive(NULL, true); | ||
4120 | 317 | } | ||
4121 | 318 | |||
4122 | 319 | _last_effect = in_effect; | ||
4123 | 320 | return; | ||
4124 | 321 | } | ||
4125 | 322 | |||
4126 | 323 | Inkscape::XML::Node * | ||
4127 | 324 | Effect::find_menu (Inkscape::XML::Node * menustruct, const gchar *name) | ||
4128 | 325 | { | ||
4129 | 326 | if (menustruct == NULL) return false; | ||
4130 | 327 | for (Inkscape::XML::Node * child = menustruct; | ||
4131 | 328 | child != NULL; | ||
4132 | 329 | child = child->next()) { | ||
4133 | 330 | if (!strcmp(child->name(), name)) { | ||
4134 | 331 | return child; | ||
4135 | 332 | } | ||
4136 | 333 | Inkscape::XML::Node * firstchild = child->firstChild(); | ||
4137 | 334 | if (firstchild != NULL) { | ||
4138 | 335 | Inkscape::XML::Node *found = find_menu (firstchild, name); | ||
4139 | 336 | if (found) | ||
4140 | 337 | return found; | ||
4141 | 338 | } | ||
4142 | 339 | } | ||
4143 | 340 | return NULL; | ||
4144 | 341 | } | ||
4145 | 342 | |||
4146 | 343 | |||
4147 | 344 | Gtk::VBox * | ||
4148 | 345 | Effect::get_info_widget(void) | ||
4149 | 346 | { | ||
4150 | 347 | return Extension::get_info_widget(); | ||
4151 | 348 | } | ||
4152 | 349 | |||
4153 | 350 | void | ||
4154 | 351 | Effect::set_pref_dialog (PrefDialog * prefdialog) | ||
4155 | 352 | { | ||
4156 | 353 | _prefDialog = prefdialog; | ||
4157 | 354 | return; | ||
4158 | 355 | } | ||
4159 | 356 | |||
4160 | 357 | /** \brief Create an action for a \c EffectVerb | ||
4161 | 358 | \param view Which view the action should be created for | ||
4162 | 359 | \return The built action. | ||
4163 | 360 | |||
4164 | 361 | Calls \c make_action_helper with the \c vector. | ||
4165 | 362 | */ | ||
4166 | 363 | SPAction * | ||
4167 | 364 | Effect::EffectVerb::make_action (Inkscape::UI::View::View * view) | ||
4168 | 365 | { | ||
4169 | 366 | return make_action_helper(view, &vector, static_cast<void *>(this)); | ||
4170 | 367 | } | ||
4171 | 368 | |||
4172 | 369 | /** \brief Decode the verb code and take appropriate action */ | ||
4173 | 370 | void | ||
4174 | 371 | Effect::EffectVerb::perform( SPAction *action, void * data, void */*pdata*/ ) | ||
4175 | 372 | { | ||
4176 | 373 | Inkscape::UI::View::View * current_view = sp_action_get_view(action); | ||
4177 | 374 | // SPDocument * current_document = current_view->doc; | ||
4178 | 375 | Effect::EffectVerb * ev = reinterpret_cast<Effect::EffectVerb *>(data); | ||
4179 | 376 | Effect * effect = ev->_effect; | ||
4180 | 377 | |||
4181 | 378 | if (effect == NULL) return; | ||
4182 | 379 | if (current_view == NULL) return; | ||
4183 | 380 | |||
4184 | 381 | if (ev->_showPrefs) { | ||
4185 | 382 | effect->prefs(current_view); | ||
4186 | 383 | } else { | ||
4187 | 384 | effect->effect(current_view); | ||
4188 | 385 | } | ||
4189 | 386 | |||
4190 | 387 | return; | ||
4191 | 388 | } | ||
4192 | 389 | |||
4193 | 390 | /** | ||
4194 | 391 | * Action vector to define functions called if a staticly defined file verb | ||
4195 | 392 | * is called. | ||
4196 | 393 | */ | ||
4197 | 394 | SPActionEventVector Effect::EffectVerb::vector = | ||
4198 | 395 | {{NULL}, Effect::EffectVerb::perform, NULL, NULL, NULL, NULL}; | ||
4199 | 396 | |||
4200 | 397 | |||
4201 | 398 | } } /* namespace Inkscape, Extension */ | ||
4202 | 399 | |||
4203 | 400 | /* | ||
4204 | 401 | Local Variables: | ||
4205 | 402 | mode:c++ | ||
4206 | 403 | c-file-style:"stroustrup" | ||
4207 | 404 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) | ||
4208 | 405 | indent-tabs-mode:nil | ||
4209 | 406 | fill-column:99 | ||
4210 | 407 | End: | ||
4211 | 408 | */ | ||
4212 | 409 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : | ||
4213 | 410 | 0 | ||
4214 | === removed file '.pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/gradient-drag.cpp' | |||
4215 | --- .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/gradient-drag.cpp 2013-07-02 17:25:52 +0000 | |||
4216 | +++ .pc/0004-Fix_FTBFS_on_gcc-4.8.patch/src/gradient-drag.cpp 1970-01-01 00:00:00 +0000 | |||
4217 | @@ -1,2216 +0,0 @@ | |||
4218 | 1 | /* | ||
4219 | 2 | * On-canvas gradient dragging | ||
4220 | 3 | * | ||
4221 | 4 | * Authors: | ||
4222 | 5 | * bulia byak <buliabyak@users.sf.net> | ||
4223 | 6 | * Johan Engelen <j.b.c.engelen@ewi.utwente.nl> | ||
4224 | 7 | * Jon A. Cruz <jon@joncruz.org> | ||
4225 | 8 | * | ||
4226 | 9 | * Copyright (C) 2007 Johan Engelen | ||
4227 | 10 | * Copyright (C) 2005,2010 Authors | ||
4228 | 11 | * | ||
4229 | 12 | * Released under GNU GPL, read the file 'COPYING' for more information | ||
4230 | 13 | */ | ||
4231 | 14 | |||
4232 | 15 | #ifdef HAVE_CONFIG_H | ||
4233 | 16 | #include "config.h" | ||
4234 | 17 | #endif | ||
4235 | 18 | |||
4236 | 19 | #include <glibmm/i18n.h> | ||
4237 | 20 | #include <cstring> | ||
4238 | 21 | #include <string> | ||
4239 | 22 | |||
4240 | 23 | #include "desktop-handles.h" | ||
4241 | 24 | #include "selection.h" | ||
4242 | 25 | #include "desktop.h" | ||
4243 | 26 | #include "desktop-style.h" | ||
4244 | 27 | #include "document.h" | ||
4245 | 28 | #include "display/sp-ctrlline.h" | ||
4246 | 29 | #include "display/sp-canvas-util.h" | ||
4247 | 30 | #include "xml/repr.h" | ||
4248 | 31 | #include "svg/css-ostringstream.h" | ||
4249 | 32 | #include "svg/svg.h" | ||
4250 | 33 | #include "libnr/nr-point-fns.h" | ||
4251 | 34 | #include "preferences.h" | ||
4252 | 35 | #include "sp-item.h" | ||
4253 | 36 | #include "style.h" | ||
4254 | 37 | #include "knot.h" | ||
4255 | 38 | #include "sp-linear-gradient.h" | ||
4256 | 39 | #include "sp-radial-gradient.h" | ||
4257 | 40 | #include "gradient-chemistry.h" | ||
4258 | 41 | #include "gradient-drag.h" | ||
4259 | 42 | #include "sp-stop.h" | ||
4260 | 43 | #include "snap.h" | ||
4261 | 44 | #include "sp-namedview.h" | ||
4262 | 45 | #include "selection-chemistry.h" | ||
4263 | 46 | |||
4264 | 47 | #define GR_KNOT_COLOR_NORMAL 0xffffff00 | ||
4265 | 48 | #define GR_KNOT_COLOR_MOUSEOVER 0xff000000 | ||
4266 | 49 | #define GR_KNOT_COLOR_SELECTED 0x0000ff00 | ||
4267 | 50 | |||
4268 | 51 | #define GR_LINE_COLOR_FILL 0x0000ff7f | ||
4269 | 52 | #define GR_LINE_COLOR_STROKE 0x9999007f | ||
4270 | 53 | |||
4271 | 54 | // screen pixels between knots when they snap: | ||
4272 | 55 | #define SNAP_DIST 5 | ||
4273 | 56 | |||
4274 | 57 | // absolute distance between gradient points for them to become a single dragger when the drag is created: | ||
4275 | 58 | #define MERGE_DIST 0.1 | ||
4276 | 59 | |||
4277 | 60 | // knot shapes corresponding to GrPointType enum | ||
4278 | 61 | SPKnotShapeType gr_knot_shapes [] = { | ||
4279 | 62 | SP_KNOT_SHAPE_SQUARE, //POINT_LG_BEGIN | ||
4280 | 63 | SP_KNOT_SHAPE_CIRCLE, //POINT_LG_END | ||
4281 | 64 | SP_KNOT_SHAPE_DIAMOND, //POINT_LG_MID | ||
4282 | 65 | SP_KNOT_SHAPE_SQUARE, // POINT_RG_CENTER | ||
4283 | 66 | SP_KNOT_SHAPE_CIRCLE, // POINT_RG_R1 | ||
4284 | 67 | SP_KNOT_SHAPE_CIRCLE, // POINT_RG_R2 | ||
4285 | 68 | SP_KNOT_SHAPE_CROSS, // POINT_RG_FOCUS | ||
4286 | 69 | SP_KNOT_SHAPE_DIAMOND, //POINT_RG_MID1 | ||
4287 | 70 | SP_KNOT_SHAPE_DIAMOND //POINT_RG_MID2 | ||
4288 | 71 | }; | ||
4289 | 72 | |||
4290 | 73 | const gchar *gr_knot_descr [] = { | ||
4291 | 74 | N_("Linear gradient <b>start</b>"), //POINT_LG_BEGIN | ||
4292 | 75 | N_("Linear gradient <b>end</b>"), | ||
4293 | 76 | N_("Linear gradient <b>mid stop</b>"), | ||
4294 | 77 | N_("Radial gradient <b>center</b>"), | ||
4295 | 78 | N_("Radial gradient <b>radius</b>"), | ||
4296 | 79 | N_("Radial gradient <b>radius</b>"), | ||
4297 | 80 | N_("Radial gradient <b>focus</b>"), // POINT_RG_FOCUS | ||
4298 | 81 | N_("Radial gradient <b>mid stop</b>"), | ||
4299 | 82 | N_("Radial gradient <b>mid stop</b>") | ||
4300 | 83 | }; | ||
4301 | 84 | |||
4302 | 85 | static void | ||
4303 | 86 | gr_drag_sel_changed(Inkscape::Selection */*selection*/, gpointer data) | ||
4304 | 87 | { | ||
4305 | 88 | GrDrag *drag = (GrDrag *) data; | ||
4306 | 89 | drag->updateDraggers (); | ||
4307 | 90 | drag->updateLines (); | ||
4308 | 91 | drag->updateLevels (); | ||
4309 | 92 | } | ||
4310 | 93 | |||
4311 | 94 | static void | ||
4312 | 95 | gr_drag_sel_modified (Inkscape::Selection */*selection*/, guint /*flags*/, gpointer data) | ||
4313 | 96 | { | ||
4314 | 97 | GrDrag *drag = (GrDrag *) data; | ||
4315 | 98 | if (drag->local_change) { | ||
4316 | 99 | drag->local_change = false; | ||
4317 | 100 | } else { | ||
4318 | 101 | drag->updateDraggers (); | ||
4319 | 102 | } | ||
4320 | 103 | drag->updateLines (); | ||
4321 | 104 | drag->updateLevels (); | ||
4322 | 105 | } | ||
4323 | 106 | |||
4324 | 107 | /** | ||
4325 | 108 | When a _query_style_signal is received, check that \a property requests fill/stroke/opacity (otherwise | ||
4326 | 109 | skip), and fill the \a style with the averaged color of all draggables of the selected dragger, if | ||
4327 | 110 | any. | ||
4328 | 111 | */ | ||
4329 | 112 | int | ||
4330 | 113 | gr_drag_style_query (SPStyle *style, int property, gpointer data) | ||
4331 | 114 | { | ||
4332 | 115 | GrDrag *drag = (GrDrag *) data; | ||
4333 | 116 | |||
4334 | 117 | if (property != QUERY_STYLE_PROPERTY_FILL && property != QUERY_STYLE_PROPERTY_STROKE && property != QUERY_STYLE_PROPERTY_MASTEROPACITY) { | ||
4335 | 118 | return QUERY_STYLE_NOTHING; | ||
4336 | 119 | } | ||
4337 | 120 | |||
4338 | 121 | if (!drag->selected) { | ||
4339 | 122 | return QUERY_STYLE_NOTHING; | ||
4340 | 123 | } else { | ||
4341 | 124 | int ret = QUERY_STYLE_NOTHING; | ||
4342 | 125 | |||
4343 | 126 | float cf[4]; | ||
4344 | 127 | cf[0] = cf[1] = cf[2] = cf[3] = 0; | ||
4345 | 128 | |||
4346 | 129 | int count = 0; | ||
4347 | 130 | |||
4348 | 131 | for (GList *i = drag->selected; i != NULL; i = i->next) { // for all selected draggers | ||
4349 | 132 | GrDragger *d = (GrDragger *) i->data; | ||
4350 | 133 | for (GSList const* j = d->draggables; j != NULL; j = j->next) { // for all draggables of dragger | ||
4351 | 134 | GrDraggable *draggable = (GrDraggable *) j->data; | ||
4352 | 135 | |||
4353 | 136 | if (ret == QUERY_STYLE_NOTHING) { | ||
4354 | 137 | ret = QUERY_STYLE_SINGLE; | ||
4355 | 138 | } else if (ret == QUERY_STYLE_SINGLE) { | ||
4356 | 139 | ret = QUERY_STYLE_MULTIPLE_AVERAGED; | ||
4357 | 140 | } | ||
4358 | 141 | |||
4359 | 142 | guint32 c = sp_item_gradient_stop_query_style (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke); | ||
4360 | 143 | cf[0] += SP_RGBA32_R_F (c); | ||
4361 | 144 | cf[1] += SP_RGBA32_G_F (c); | ||
4362 | 145 | cf[2] += SP_RGBA32_B_F (c); | ||
4363 | 146 | cf[3] += SP_RGBA32_A_F (c); | ||
4364 | 147 | |||
4365 | 148 | count ++; | ||
4366 | 149 | } | ||
4367 | 150 | } | ||
4368 | 151 | |||
4369 | 152 | if (count) { | ||
4370 | 153 | cf[0] /= count; | ||
4371 | 154 | cf[1] /= count; | ||
4372 | 155 | cf[2] /= count; | ||
4373 | 156 | cf[3] /= count; | ||
4374 | 157 | |||
4375 | 158 | // set both fill and stroke with our stop-color and stop-opacity | ||
4376 | 159 | style->fill.clear(); | ||
4377 | 160 | style->fill.setColor( cf[0], cf[1], cf[2] ); | ||
4378 | 161 | style->fill.set = TRUE; | ||
4379 | 162 | style->stroke.clear(); | ||
4380 | 163 | style->stroke.setColor( cf[0], cf[1], cf[2] ); | ||
4381 | 164 | style->stroke.set = TRUE; | ||
4382 | 165 | |||
4383 | 166 | style->fill_opacity.value = SP_SCALE24_FROM_FLOAT (1.0); | ||
4384 | 167 | style->fill_opacity.set = TRUE; | ||
4385 | 168 | style->stroke_opacity.value = SP_SCALE24_FROM_FLOAT (1.0); | ||
4386 | 169 | style->stroke_opacity.set = TRUE; | ||
4387 | 170 | |||
4388 | 171 | style->opacity.value = SP_SCALE24_FROM_FLOAT (cf[3]); | ||
4389 | 172 | style->opacity.set = TRUE; | ||
4390 | 173 | } | ||
4391 | 174 | |||
4392 | 175 | return ret; | ||
4393 | 176 | } | ||
4394 | 177 | } | ||
4395 | 178 | |||
4396 | 179 | Glib::ustring GrDrag::makeStopSafeColor( gchar const *str, bool &isNull ) | ||
4397 | 180 | { | ||
4398 | 181 | Glib::ustring colorStr; | ||
4399 | 182 | if ( str ) { | ||
4400 | 183 | isNull = false; | ||
4401 | 184 | colorStr = str; | ||
4402 | 185 | Glib::ustring::size_type pos = colorStr.find("url(#"); | ||
4403 | 186 | if ( pos != Glib::ustring::npos ) { | ||
4404 | 187 | Glib::ustring targetName = colorStr.substr(pos + 5, colorStr.length() - 6); | ||
4405 | 188 | const GSList *gradients = sp_document_get_resource_list(desktop->doc(), "gradient"); | ||
4406 | 189 | for (const GSList *item = gradients; item; item = item->next) { | ||
4407 | 190 | SPGradient* grad = SP_GRADIENT(item->data); | ||
4408 | 191 | if ( targetName == grad->getId() ) { | ||
4409 | 192 | SPGradient *vect = grad->getVector(); | ||
4410 | 193 | SPStop *firstStop = (vect) ? vect->getFirstStop() : grad->getFirstStop(); | ||
4411 | 194 | if (firstStop) { | ||
4412 | 195 | Glib::ustring stopColorStr; | ||
4413 | 196 | if (firstStop->currentColor) { | ||
4414 | 197 | stopColorStr = sp_object_get_style_property(firstStop, "color", NULL); | ||
4415 | 198 | } else { | ||
4416 | 199 | stopColorStr = firstStop->specified_color.toString(); | ||
4417 | 200 | } | ||
4418 | 201 | if ( !stopColorStr.empty() ) { | ||
4419 | 202 | colorStr = stopColorStr; | ||
4420 | 203 | } | ||
4421 | 204 | } | ||
4422 | 205 | break; | ||
4423 | 206 | } | ||
4424 | 207 | } | ||
4425 | 208 | } | ||
4426 | 209 | } else { | ||
4427 | 210 | isNull = true; | ||
4428 | 211 | } | ||
4429 | 212 | |||
4430 | 213 | return colorStr; | ||
4431 | 214 | } | ||
4432 | 215 | |||
4433 | 216 | bool GrDrag::styleSet( const SPCSSAttr *css ) | ||
4434 | 217 | { | ||
4435 | 218 | if (!selected) { | ||
4436 | 219 | return false; | ||
4437 | 220 | } | ||
4438 | 221 | |||
4439 | 222 | SPCSSAttr *stop = sp_repr_css_attr_new(); | ||
4440 | 223 | |||
4441 | 224 | // See if the css contains interesting properties, and if so, translate them into the format | ||
4442 | 225 | // acceptable for gradient stops | ||
4443 | 226 | |||
4444 | 227 | // any of color properties, in order of increasing priority: | ||
4445 | 228 | if (css->attribute("flood-color")) { | ||
4446 | 229 | sp_repr_css_set_property (stop, "stop-color", css->attribute("flood-color")); | ||
4447 | 230 | } | ||
4448 | 231 | |||
4449 | 232 | if (css->attribute("lighting-color")) { | ||
4450 | 233 | sp_repr_css_set_property (stop, "stop-color", css->attribute("lighting-color")); | ||
4451 | 234 | } | ||
4452 | 235 | |||
4453 | 236 | if (css->attribute("color")) { | ||
4454 | 237 | sp_repr_css_set_property (stop, "stop-color", css->attribute("color")); | ||
4455 | 238 | } | ||
4456 | 239 | |||
4457 | 240 | if (css->attribute("stroke") && strcmp(css->attribute("stroke"), "none")) { | ||
4458 | 241 | sp_repr_css_set_property (stop, "stop-color", css->attribute("stroke")); | ||
4459 | 242 | } | ||
4460 | 243 | |||
4461 | 244 | if (css->attribute("fill") && strcmp(css->attribute("fill"), "none")) { | ||
4462 | 245 | sp_repr_css_set_property (stop, "stop-color", css->attribute("fill")); | ||
4463 | 246 | } | ||
4464 | 247 | |||
4465 | 248 | if (css->attribute("stop-color")) { | ||
4466 | 249 | sp_repr_css_set_property (stop, "stop-color", css->attribute("stop-color")); | ||
4467 | 250 | } | ||
4468 | 251 | |||
4469 | 252 | // Make sure the style is allowed for gradient stops. | ||
4470 | 253 | if ( !sp_repr_css_property_is_unset( stop, "stop-color") ) { | ||
4471 | 254 | bool stopIsNull = false; | ||
4472 | 255 | Glib::ustring tmp = makeStopSafeColor( sp_repr_css_property( stop, "stop-color", "" ), stopIsNull ); | ||
4473 | 256 | if ( !stopIsNull && !tmp.empty() ) { | ||
4474 | 257 | sp_repr_css_set_property( stop, "stop-color", tmp.c_str() ); | ||
4475 | 258 | } | ||
4476 | 259 | } | ||
4477 | 260 | |||
4478 | 261 | |||
4479 | 262 | if (css->attribute("stop-opacity")) { // direct setting of stop-opacity has priority | ||
4480 | 263 | sp_repr_css_set_property(stop, "stop-opacity", css->attribute("stop-opacity")); | ||
4481 | 264 | } else { // multiply all opacity properties: | ||
4482 | 265 | gdouble accumulated = 1.0; | ||
4483 | 266 | accumulated *= sp_svg_read_percentage(css->attribute("flood-opacity"), 1.0); | ||
4484 | 267 | accumulated *= sp_svg_read_percentage(css->attribute("opacity"), 1.0); | ||
4485 | 268 | accumulated *= sp_svg_read_percentage(css->attribute("stroke-opacity"), 1.0); | ||
4486 | 269 | accumulated *= sp_svg_read_percentage(css->attribute("fill-opacity"), 1.0); | ||
4487 | 270 | |||
4488 | 271 | Inkscape::CSSOStringStream os; | ||
4489 | 272 | os << accumulated; | ||
4490 | 273 | sp_repr_css_set_property(stop, "stop-opacity", os.str().c_str()); | ||
4491 | 274 | |||
4492 | 275 | if ((css->attribute("fill") && !css->attribute("stroke") && !strcmp(css->attribute("fill"), "none")) || | ||
4493 | 276 | (css->attribute("stroke") && !css->attribute("fill") && !strcmp(css->attribute("stroke"), "none"))) { | ||
4494 | 277 | sp_repr_css_set_property(stop, "stop-opacity", "0"); // if a single fill/stroke property is set to none, don't change color, set opacity to 0 | ||
4495 | 278 | } | ||
4496 | 279 | } | ||
4497 | 280 | |||
4498 | 281 | if (!stop->attributeList()) { // nothing for us here, pass it on | ||
4499 | 282 | sp_repr_css_attr_unref(stop); | ||
4500 | 283 | return false; | ||
4501 | 284 | } | ||
4502 | 285 | |||
4503 | 286 | for (GList const* sel = selected; sel != NULL; sel = sel->next) { // for all selected draggers | ||
4504 | 287 | GrDragger* dragger = reinterpret_cast<GrDragger*>(sel->data); | ||
4505 | 288 | for (GSList const* i = dragger->draggables; i != NULL; i = i->next) { // for all draggables of dragger | ||
4506 | 289 | GrDraggable *draggable = reinterpret_cast<GrDraggable *>(i->data); | ||
4507 | 290 | |||
4508 | 291 | local_change = true; | ||
4509 | 292 | sp_item_gradient_stop_set_style(draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke, stop); | ||
4510 | 293 | } | ||
4511 | 294 | } | ||
4512 | 295 | |||
4513 | 296 | //sp_repr_css_print(stop); | ||
4514 | 297 | sp_repr_css_attr_unref(stop); | ||
4515 | 298 | return true; | ||
4516 | 299 | } | ||
4517 | 300 | |||
4518 | 301 | guint32 GrDrag::getColor() | ||
4519 | 302 | { | ||
4520 | 303 | if (!selected) return 0; | ||
4521 | 304 | |||
4522 | 305 | float cf[4]; | ||
4523 | 306 | cf[0] = cf[1] = cf[2] = cf[3] = 0; | ||
4524 | 307 | |||
4525 | 308 | int count = 0; | ||
4526 | 309 | |||
4527 | 310 | for (GList *i = selected; i != NULL; i = i->next) { // for all selected draggers | ||
4528 | 311 | GrDragger *d = (GrDragger *) i->data; | ||
4529 | 312 | for (GSList const* j = d->draggables; j != NULL; j = j->next) { // for all draggables of dragger | ||
4530 | 313 | GrDraggable *draggable = (GrDraggable *) j->data; | ||
4531 | 314 | |||
4532 | 315 | guint32 c = sp_item_gradient_stop_query_style (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke); | ||
4533 | 316 | cf[0] += SP_RGBA32_R_F (c); | ||
4534 | 317 | cf[1] += SP_RGBA32_G_F (c); | ||
4535 | 318 | cf[2] += SP_RGBA32_B_F (c); | ||
4536 | 319 | cf[3] += SP_RGBA32_A_F (c); | ||
4537 | 320 | |||
4538 | 321 | count ++; | ||
4539 | 322 | } | ||
4540 | 323 | } | ||
4541 | 324 | |||
4542 | 325 | if (count) { | ||
4543 | 326 | cf[0] /= count; | ||
4544 | 327 | cf[1] /= count; | ||
4545 | 328 | cf[2] /= count; | ||
4546 | 329 | cf[3] /= count; | ||
4547 | 330 | } | ||
4548 | 331 | |||
4549 | 332 | return SP_RGBA32_F_COMPOSE(cf[0], cf[1], cf[2], cf[3]); | ||
4550 | 333 | } | ||
4551 | 334 | |||
4552 | 335 | SPStop * | ||
4553 | 336 | GrDrag::addStopNearPoint (SPItem *item, Geom::Point mouse_p, double tolerance) | ||
4554 | 337 | { | ||
4555 | 338 | gfloat offset; // type of SPStop.offset = gfloat | ||
4556 | 339 | SPGradient *gradient; | ||
4557 | 340 | bool fill_or_stroke = true; | ||
4558 | 341 | bool r1_knot = false; | ||
4559 | 342 | |||
4560 | 343 | bool addknot = false; | ||
4561 | 344 | do { | ||
4562 | 345 | gradient = sp_item_gradient (item, fill_or_stroke); | ||
4563 | 346 | if (SP_IS_LINEARGRADIENT(gradient)) { | ||
4564 | 347 | Geom::Point begin = sp_item_gradient_get_coords(item, POINT_LG_BEGIN, 0, fill_or_stroke); | ||
4565 | 348 | Geom::Point end = sp_item_gradient_get_coords(item, POINT_LG_END, 0, fill_or_stroke); | ||
4566 | 349 | |||
4567 | 350 | Geom::Point nearest = snap_vector_midpoint (mouse_p, begin, end, 0); | ||
4568 | 351 | double dist_screen = Geom::L2 (mouse_p - nearest); | ||
4569 | 352 | if ( dist_screen < tolerance ) { | ||
4570 | 353 | // add the knot | ||
4571 | 354 | offset = get_offset_between_points(nearest, begin, end); | ||
4572 | 355 | addknot = true; | ||
4573 | 356 | break; // break out of the while loop: add only one knot | ||
4574 | 357 | } | ||
4575 | 358 | } else if (SP_IS_RADIALGRADIENT(gradient)) { | ||
4576 | 359 | Geom::Point begin = sp_item_gradient_get_coords(item, POINT_RG_CENTER, 0, fill_or_stroke); | ||
4577 | 360 | Geom::Point end = sp_item_gradient_get_coords(item, POINT_RG_R1, 0, fill_or_stroke); | ||
4578 | 361 | Geom::Point nearest = snap_vector_midpoint (mouse_p, begin, end, 0); | ||
4579 | 362 | double dist_screen = Geom::L2 (mouse_p - nearest); | ||
4580 | 363 | if ( dist_screen < tolerance ) { | ||
4581 | 364 | offset = get_offset_between_points(nearest, begin, end); | ||
4582 | 365 | addknot = true; | ||
4583 | 366 | r1_knot = true; | ||
4584 | 367 | break; // break out of the while loop: add only one knot | ||
4585 | 368 | } | ||
4586 | 369 | |||
4587 | 370 | end = sp_item_gradient_get_coords(item, POINT_RG_R2, 0, fill_or_stroke); | ||
4588 | 371 | nearest = snap_vector_midpoint (mouse_p, begin, end, 0); | ||
4589 | 372 | dist_screen = Geom::L2 (mouse_p - nearest); | ||
4590 | 373 | if ( dist_screen < tolerance ) { | ||
4591 | 374 | offset = get_offset_between_points(nearest, begin, end); | ||
4592 | 375 | addknot = true; | ||
4593 | 376 | r1_knot = false; | ||
4594 | 377 | break; // break out of the while loop: add only one knot | ||
4595 | 378 | } | ||
4596 | 379 | } | ||
4597 | 380 | fill_or_stroke = !fill_or_stroke; | ||
4598 | 381 | } while (!fill_or_stroke && !addknot) ; | ||
4599 | 382 | |||
4600 | 383 | if (addknot) { | ||
4601 | 384 | SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (gradient, false); | ||
4602 | 385 | SPStop* prev_stop = vector->getFirstStop(); | ||
4603 | 386 | SPStop* next_stop = prev_stop->getNextStop(); | ||
4604 | 387 | guint i = 1; | ||
4605 | 388 | while ( (next_stop) && (next_stop->offset < offset) ) { | ||
4606 | 389 | prev_stop = next_stop; | ||
4607 | 390 | next_stop = next_stop->getNextStop(); | ||
4608 | 391 | i++; | ||
4609 | 392 | } | ||
4610 | 393 | if (!next_stop) { | ||
4611 | 394 | // logical error: the endstop should have offset 1 and should always be more than this offset here | ||
4612 | 395 | return NULL; | ||
4613 | 396 | } | ||
4614 | 397 | |||
4615 | 398 | |||
4616 | 399 | SPStop *newstop = sp_vector_add_stop (vector, prev_stop, next_stop, offset); | ||
4617 | 400 | gradient->ensureVector(); | ||
4618 | 401 | updateDraggers(); | ||
4619 | 402 | |||
4620 | 403 | return newstop; | ||
4621 | 404 | } | ||
4622 | 405 | |||
4623 | 406 | return NULL; | ||
4624 | 407 | } | ||
4625 | 408 | |||
4626 | 409 | |||
4627 | 410 | bool | ||
4628 | 411 | GrDrag::dropColor(SPItem */*item*/, gchar const *c, Geom::Point p) | ||
4629 | 412 | { | ||
4630 | 413 | // Note: not sure if a null pointer can come in for the style, but handle that just in case | ||
4631 | 414 | bool stopIsNull = false; | ||
4632 | 415 | Glib::ustring toUse = makeStopSafeColor( c, stopIsNull ); | ||
4633 | 416 | |||
4634 | 417 | // first, see if we can drop onto one of the existing draggers | ||
4635 | 418 | for (GList *i = draggers; i != NULL; i = i->next) { // for all draggables of dragger | ||
4636 | 419 | GrDragger *d = (GrDragger *) i->data; | ||
4637 | 420 | |||
4638 | 421 | if (Geom::L2(p - d->point)*desktop->current_zoom() < 5) { | ||
4639 | 422 | SPCSSAttr *stop = sp_repr_css_attr_new (); | ||
4640 | 423 | sp_repr_css_set_property( stop, "stop-color", stopIsNull ? 0 : toUse.c_str() ); | ||
4641 | 424 | sp_repr_css_set_property( stop, "stop-opacity", "1" ); | ||
4642 | 425 | for (GSList *j = d->draggables; j != NULL; j = j->next) { // for all draggables of dragger | ||
4643 | 426 | GrDraggable *draggable = (GrDraggable *) j->data; | ||
4644 | 427 | local_change = true; | ||
4645 | 428 | sp_item_gradient_stop_set_style (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke, stop); | ||
4646 | 429 | } | ||
4647 | 430 | sp_repr_css_attr_unref(stop); | ||
4648 | 431 | return true; | ||
4649 | 432 | } | ||
4650 | 433 | } | ||
4651 | 434 | |||
4652 | 435 | // now see if we're over line and create a new stop | ||
4653 | 436 | bool over_line = false; | ||
4654 | 437 | SPCtrlLine *line = NULL; | ||
4655 | 438 | if (lines) { | ||
4656 | 439 | for (GSList *l = lines; (l != NULL) && (!over_line); l = l->next) { | ||
4657 | 440 | line = (SPCtrlLine*) l->data; | ||
4658 | 441 | Geom::Point nearest = snap_vector_midpoint (p, line->s, line->e, 0); | ||
4659 | 442 | double dist_screen = Geom::L2 (p - nearest) * desktop->current_zoom(); | ||
4660 | 443 | if (line->item && dist_screen < 5) { | ||
4661 | 444 | SPStop *stop = addStopNearPoint (line->item, p, 5/desktop->current_zoom()); | ||
4662 | 445 | if (stop) { | ||
4663 | 446 | SPCSSAttr *css = sp_repr_css_attr_new (); | ||
4664 | 447 | sp_repr_css_set_property( css, "stop-color", stopIsNull ? 0 : toUse.c_str() ); | ||
4665 | 448 | sp_repr_css_set_property( css, "stop-opacity", "1" ); | ||
4666 | 449 | sp_repr_css_change (SP_OBJECT_REPR (stop), css, "style"); | ||
4667 | 450 | return true; | ||
4668 | 451 | } | ||
4669 | 452 | } | ||
4670 | 453 | } | ||
4671 | 454 | } | ||
4672 | 455 | |||
4673 | 456 | return false; | ||
4674 | 457 | } | ||
4675 | 458 | |||
4676 | 459 | |||
4677 | 460 | GrDrag::GrDrag(SPDesktop *desktop) : | ||
4678 | 461 | selected(0), | ||
4679 | 462 | keep_selection(false), | ||
4680 | 463 | local_change(false), | ||
4681 | 464 | desktop(desktop), | ||
4682 | 465 | hor_levels(), | ||
4683 | 466 | vert_levels(), | ||
4684 | 467 | draggers(0), | ||
4685 | 468 | lines(0), | ||
4686 | 469 | selection(sp_desktop_selection(desktop)), | ||
4687 | 470 | sel_changed_connection(), | ||
4688 | 471 | sel_modified_connection(), | ||
4689 | 472 | style_set_connection(), | ||
4690 | 473 | style_query_connection() | ||
4691 | 474 | { | ||
4692 | 475 | sel_changed_connection = selection->connectChanged( | ||
4693 | 476 | sigc::bind( | ||
4694 | 477 | sigc::ptr_fun(&gr_drag_sel_changed), | ||
4695 | 478 | (gpointer)this ) | ||
4696 | 479 | |||
4697 | 480 | ); | ||
4698 | 481 | sel_modified_connection = selection->connectModified( | ||
4699 | 482 | sigc::bind( | ||
4700 | 483 | sigc::ptr_fun(&gr_drag_sel_modified), | ||
4701 | 484 | (gpointer)this ) | ||
4702 | 485 | ); | ||
4703 | 486 | |||
4704 | 487 | style_set_connection = desktop->connectSetStyle( sigc::mem_fun(*this, &GrDrag::styleSet) ); | ||
4705 | 488 | |||
4706 | 489 | style_query_connection = desktop->connectQueryStyle( | ||
4707 | 490 | sigc::bind( | ||
4708 | 491 | sigc::ptr_fun(&gr_drag_style_query), | ||
4709 | 492 | (gpointer)this ) | ||
4710 | 493 | ); | ||
4711 | 494 | |||
4712 | 495 | updateDraggers(); | ||
4713 | 496 | updateLines(); | ||
4714 | 497 | updateLevels(); | ||
4715 | 498 | |||
4716 | 499 | if (desktop->gr_item) { | ||
4717 | 500 | setSelected(getDraggerFor(desktop->gr_item, desktop->gr_point_type, desktop->gr_point_i, desktop->gr_fill_or_stroke)); | ||
4718 | 501 | } | ||
4719 | 502 | } | ||
4720 | 503 | |||
4721 | 504 | GrDrag::~GrDrag() | ||
4722 | 505 | { | ||
4723 | 506 | this->sel_changed_connection.disconnect(); | ||
4724 | 507 | this->sel_modified_connection.disconnect(); | ||
4725 | 508 | this->style_set_connection.disconnect(); | ||
4726 | 509 | this->style_query_connection.disconnect(); | ||
4727 | 510 | |||
4728 | 511 | if (this->selected) { | ||
4729 | 512 | GrDraggable *draggable = (GrDraggable *) ((GrDragger*)this->selected->data)->draggables->data; | ||
4730 | 513 | desktop->gr_item = draggable->item; | ||
4731 | 514 | desktop->gr_point_type = draggable->point_type; | ||
4732 | 515 | desktop->gr_point_i = draggable->point_i; | ||
4733 | 516 | desktop->gr_fill_or_stroke = draggable->fill_or_stroke; | ||
4734 | 517 | } else { | ||
4735 | 518 | desktop->gr_item = NULL; | ||
4736 | 519 | desktop->gr_point_type = 0; | ||
4737 | 520 | desktop->gr_point_i = 0; | ||
4738 | 521 | desktop->gr_fill_or_stroke = true; | ||
4739 | 522 | } | ||
4740 | 523 | |||
4741 | 524 | deselect_all(); | ||
4742 | 525 | for (GList *l = this->draggers; l != NULL; l = l->next) { | ||
4743 | 526 | delete ((GrDragger *) l->data); | ||
4744 | 527 | } | ||
4745 | 528 | g_list_free (this->draggers); | ||
4746 | 529 | this->draggers = NULL; | ||
4747 | 530 | this->selected = NULL; | ||
4748 | 531 | |||
4749 | 532 | for (GSList *l = this->lines; l != NULL; l = l->next) { | ||
4750 | 533 | gtk_object_destroy( GTK_OBJECT (l->data)); | ||
4751 | 534 | } | ||
4752 | 535 | g_slist_free (this->lines); | ||
4753 | 536 | this->lines = NULL; | ||
4754 | 537 | } | ||
4755 | 538 | |||
4756 | 539 | GrDraggable::GrDraggable (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke) | ||
4757 | 540 | { | ||
4758 | 541 | this->item = item; | ||
4759 | 542 | this->point_type = point_type; | ||
4760 | 543 | this->point_i = point_i; | ||
4761 | 544 | this->fill_or_stroke = fill_or_stroke; | ||
4762 | 545 | |||
4763 | 546 | g_object_ref (G_OBJECT (this->item)); | ||
4764 | 547 | } | ||
4765 | 548 | |||
4766 | 549 | GrDraggable::~GrDraggable () | ||
4767 | 550 | { | ||
4768 | 551 | g_object_unref (G_OBJECT (this->item)); | ||
4769 | 552 | } | ||
4770 | 553 | |||
4771 | 554 | |||
4772 | 555 | SPObject *GrDraggable::getServer() | ||
4773 | 556 | { | ||
4774 | 557 | if (!item) { | ||
4775 | 558 | return NULL; | ||
4776 | 559 | } | ||
4777 | 560 | |||
4778 | 561 | SPObject *server = NULL; | ||
4779 | 562 | if (fill_or_stroke) { | ||
4780 | 563 | server = item->style->getFillPaintServer(); | ||
4781 | 564 | }else { | ||
4782 | 565 | server = item->style->getStrokePaintServer(); | ||
4783 | 566 | } | ||
4784 | 567 | |||
4785 | 568 | return server; | ||
4786 | 569 | } | ||
4787 | 570 | |||
4788 | 571 | static | ||
4789 | 572 | boost::optional<Geom::Point> | ||
4790 | 573 | get_snap_vector (Geom::Point p, Geom::Point o, double snap, double initial) | ||
4791 | 574 | { | ||
4792 | 575 | double r = L2 (p - o); | ||
4793 | 576 | if (r < 1e-3) { | ||
4794 | 577 | return boost::optional<Geom::Point>(); | ||
4795 | 578 | } | ||
4796 | 579 | |||
4797 | 580 | double angle = atan2 (p - o); | ||
4798 | 581 | // snap angle to snaps increments, starting from initial: | ||
4799 | 582 | double a_snapped = initial + floor((angle - initial)/snap + 0.5) * snap; | ||
4800 | 583 | // calculate the new position and subtract p to get the vector: | ||
4801 | 584 | return (o + r * Geom::Point(cos(a_snapped), sin(a_snapped)) - p); | ||
4802 | 585 | } | ||
4803 | 586 | |||
4804 | 587 | static void | ||
4805 | 588 | gr_knot_moved_handler(SPKnot *knot, Geom::Point const &ppointer, guint state, gpointer data) | ||
4806 | 589 | { | ||
4807 | 590 | GrDragger *dragger = (GrDragger *) data; | ||
4808 | 591 | GrDrag *drag = dragger->parent; | ||
4809 | 592 | |||
4810 | 593 | Geom::Point p = ppointer; | ||
4811 | 594 | |||
4812 | 595 | SPDesktop *desktop = dragger->parent->desktop; | ||
4813 | 596 | SnapManager &m = desktop->namedview->snap_manager; | ||
4814 | 597 | double snap_dist = m.snapprefs.getObjectTolerance() / dragger->parent->desktop->current_zoom(); | ||
4815 | 598 | |||
4816 | 599 | if (state & GDK_SHIFT_MASK) { | ||
4817 | 600 | // with Shift; unsnap if we carry more than one draggable | ||
4818 | 601 | if (dragger->draggables && dragger->draggables->next) { | ||
4819 | 602 | // create a new dragger | ||
4820 | 603 | GrDragger *dr_new = new GrDragger (dragger->parent, dragger->point, NULL); | ||
4821 | 604 | dragger->parent->draggers = g_list_prepend (dragger->parent->draggers, dr_new); | ||
4822 | 605 | // relink to it all but the first draggable in the list | ||
4823 | 606 | for (GSList const* i = dragger->draggables->next; i != NULL; i = i->next) { | ||
4824 | 607 | GrDraggable *draggable = (GrDraggable *) i->data; | ||
4825 | 608 | dr_new->addDraggable (draggable); | ||
4826 | 609 | } | ||
4827 | 610 | dr_new->updateKnotShape(); | ||
4828 | 611 | g_slist_free (dragger->draggables->next); | ||
4829 | 612 | dragger->draggables->next = NULL; | ||
4830 | 613 | dragger->updateKnotShape(); | ||
4831 | 614 | dragger->updateTip(); | ||
4832 | 615 | } | ||
4833 | 616 | } else if (!(state & GDK_CONTROL_MASK)) { | ||
4834 | 617 | // without Shift or Ctrl; see if we need to snap to another dragger | ||
4835 | 618 | for (GList *di = dragger->parent->draggers; di != NULL; di = di->next) { | ||
4836 | 619 | GrDragger *d_new = (GrDragger *) di->data; | ||
4837 | 620 | if (dragger->mayMerge(d_new) && Geom::L2 (d_new->point - p) < snap_dist) { | ||
4838 | 621 | |||
4839 | 622 | // Merge draggers: | ||
4840 | 623 | for (GSList const* i = dragger->draggables; i != NULL; i = i->next) { // for all draggables of dragger | ||
4841 | 624 | GrDraggable *draggable = (GrDraggable *) i->data; | ||
4842 | 625 | // copy draggable to d_new: | ||
4843 | 626 | GrDraggable *da_new = new GrDraggable (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke); | ||
4844 | 627 | d_new->addDraggable (da_new); | ||
4845 | 628 | } | ||
4846 | 629 | |||
4847 | 630 | // unlink and delete this dragger | ||
4848 | 631 | dragger->parent->draggers = g_list_remove (dragger->parent->draggers, dragger); | ||
4849 | 632 | delete dragger; | ||
4850 | 633 | |||
4851 | 634 | // update the new merged dragger | ||
4852 | 635 | d_new->fireDraggables(true, false, true); | ||
4853 | 636 | d_new->parent->updateLines(); | ||
4854 | 637 | d_new->parent->setSelected (d_new); | ||
4855 | 638 | d_new->updateKnotShape (); | ||
4856 | 639 | d_new->updateTip (); | ||
4857 | 640 | d_new->updateDependencies(true); | ||
4858 | 641 | sp_document_done (sp_desktop_document (d_new->parent->desktop), SP_VERB_CONTEXT_GRADIENT, | ||
4859 | 642 | _("Merge gradient handles")); | ||
4860 | 643 | return; | ||
4861 | 644 | } | ||
4862 | 645 | } | ||
4863 | 646 | } | ||
4864 | 647 | |||
4865 | 648 | m.setup(desktop); | ||
4866 | 649 | if (!((state & GDK_SHIFT_MASK) || (state & GDK_CONTROL_MASK))) { | ||
4867 | 650 | Inkscape::SnappedPoint s = m.freeSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE)); | ||
4868 | 651 | if (s.getSnapped()) { | ||
4869 | 652 | p = s.getPoint(); | ||
4870 | 653 | sp_knot_moveto (knot, p); | ||
4871 | 654 | } | ||
4872 | 655 | } else if (state & GDK_CONTROL_MASK) { | ||
4873 | 656 | SnappedConstraints sc; | ||
4874 | 657 | Inkscape::Preferences *prefs = Inkscape::Preferences::get(); | ||
4875 | 658 | unsigned snaps = abs(prefs->getInt("/options/rotationsnapsperpi/value", 12)); | ||
4876 | 659 | /* 0 means no snapping. */ | ||
4877 | 660 | |||
4878 | 661 | for (GSList const* i = dragger->draggables; i != NULL; i = i->next) { | ||
4879 | 662 | GrDraggable *draggable = (GrDraggable *) i->data; | ||
4880 | 663 | |||
4881 | 664 | Geom::Point dr_snap(Geom::infinity(), Geom::infinity()); | ||
4882 | 665 | |||
4883 | 666 | if (draggable->point_type == POINT_LG_BEGIN || draggable->point_type == POINT_LG_END) { | ||
4884 | 667 | for (GList *di = dragger->parent->draggers; di != NULL; di = di->next) { | ||
4885 | 668 | GrDragger *d_new = (GrDragger *) di->data; | ||
4886 | 669 | if (d_new == dragger) | ||
4887 | 670 | continue; | ||
4888 | 671 | if (d_new->isA (draggable->item, | ||
4889 | 672 | draggable->point_type == POINT_LG_BEGIN? POINT_LG_END : POINT_LG_BEGIN, | ||
4890 | 673 | draggable->fill_or_stroke)) { | ||
4891 | 674 | // found the other end of the linear gradient; | ||
4892 | 675 | if (state & GDK_SHIFT_MASK) { | ||
4893 | 676 | // moving linear around center | ||
4894 | 677 | Geom::Point center = Geom::Point (0.5*(d_new->point + dragger->point)); | ||
4895 | 678 | dr_snap = center; | ||
4896 | 679 | } else { | ||
4897 | 680 | // moving linear around the other end | ||
4898 | 681 | dr_snap = d_new->point; | ||
4899 | 682 | } | ||
4900 | 683 | } | ||
4901 | 684 | } | ||
4902 | 685 | } else if (draggable->point_type == POINT_RG_R1 || draggable->point_type == POINT_RG_R2 || draggable->point_type == POINT_RG_FOCUS) { | ||
4903 | 686 | for (GList *di = dragger->parent->draggers; di != NULL; di = di->next) { | ||
4904 | 687 | GrDragger *d_new = (GrDragger *) di->data; | ||
4905 | 688 | if (d_new == dragger) | ||
4906 | 689 | continue; | ||
4907 | 690 | if (d_new->isA (draggable->item, | ||
4908 | 691 | POINT_RG_CENTER, | ||
4909 | 692 | draggable->fill_or_stroke)) { | ||
4910 | 693 | // found the center of the radial gradient; | ||
4911 | 694 | dr_snap = d_new->point; | ||
4912 | 695 | } | ||
4913 | 696 | } | ||
4914 | 697 | } else if (draggable->point_type == POINT_RG_CENTER) { | ||
4915 | 698 | // radial center snaps to hor/vert relative to its original position | ||
4916 | 699 | dr_snap = dragger->point_original; | ||
4917 | 700 | } | ||
4918 | 701 | |||
4919 | 702 | boost::optional<Geom::Point> snap_vector; | ||
4920 | 703 | if (dr_snap.isFinite()) { | ||
4921 | 704 | if (state & GDK_MOD1_MASK) { | ||
4922 | 705 | // with Alt, snap to the original angle and its perpendiculars | ||
4923 | 706 | snap_vector = get_snap_vector (p, dr_snap, M_PI/2, Geom::atan2 (dragger->point_original - dr_snap)); | ||
4924 | 707 | } else { | ||
4925 | 708 | // with Ctrl, snap to M_PI/snaps | ||
4926 | 709 | snap_vector = get_snap_vector (p, dr_snap, M_PI/snaps, 0); | ||
4927 | 710 | } | ||
4928 | 711 | if (snap_vector) { | ||
4929 | 712 | Inkscape::Snapper::ConstraintLine cl(dr_snap, p + *snap_vector - dr_snap); | ||
4930 | 713 | Inkscape::SnappedPoint s = m.constrainedSnap(Inkscape::SnapCandidatePoint(p + *snap_vector, Inkscape::SNAPSOURCE_OTHER_HANDLE), cl); | ||
4931 | 714 | if (s.getSnapped()) { | ||
4932 | 715 | s.setTransformation(s.getPoint() - p); | ||
4933 | 716 | sc.points.push_back(s); | ||
4934 | 717 | } else { | ||
4935 | 718 | Inkscape::SnappedPoint dummy(p + *snap_vector, Inkscape::SNAPSOURCE_OTHER_HANDLE, 0, Inkscape::SNAPTARGET_CONSTRAINED_ANGLE, Geom::L2(*snap_vector), 10000, true, true, false); | ||
4936 | 719 | dummy.setTransformation(*snap_vector); | ||
4937 | 720 | sc.points.push_back(dummy); | ||
4938 | 721 | } | ||
4939 | 722 | } | ||
4940 | 723 | } | ||
4941 | 724 | } | ||
4942 | 725 | |||
4943 | 726 | Inkscape::SnappedPoint bsp = m.findBestSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE), sc, true); // snap indicator will be displayed if needed | ||
4944 | 727 | |||
4945 | 728 | if (bsp.getSnapped()) { | ||
4946 | 729 | p += bsp.getTransformation(); | ||
4947 | 730 | sp_knot_moveto (knot, p); | ||
4948 | 731 | } | ||
4949 | 732 | } | ||
4950 | 733 | |||
4951 | 734 | drag->keep_selection = (bool) g_list_find(drag->selected, dragger); | ||
4952 | 735 | bool scale_radial = (state & GDK_CONTROL_MASK) && (state & GDK_SHIFT_MASK); | ||
4953 | 736 | |||
4954 | 737 | if (drag->keep_selection) { | ||
4955 | 738 | Geom::Point diff = p - dragger->point; | ||
4956 | 739 | drag->selected_move_nowrite (diff[Geom::X], diff[Geom::Y], scale_radial); | ||
4957 | 740 | } else { | ||
4958 | 741 | dragger->point = p; | ||
4959 | 742 | dragger->fireDraggables (false, scale_radial); | ||
4960 | 743 | dragger->updateDependencies(false); | ||
4961 | 744 | } | ||
4962 | 745 | |||
4963 | 746 | } | ||
4964 | 747 | |||
4965 | 748 | |||
4966 | 749 | static void | ||
4967 | 750 | gr_midpoint_limits(GrDragger *dragger, SPObject *server, Geom::Point *begin, Geom::Point *end, Geom::Point *low_lim, Geom::Point *high_lim, GSList **moving) | ||
4968 | 751 | { | ||
4969 | 752 | |||
4970 | 753 | GrDrag *drag = dragger->parent; | ||
4971 | 754 | // a midpoint dragger can (logically) only contain one GrDraggable | ||
4972 | 755 | GrDraggable *draggable = (GrDraggable *) dragger->draggables->data; | ||
4973 | 756 | |||
4974 | 757 | // get begin and end points between which dragging is allowed: | ||
4975 | 758 | // the draglimits are between knot(lowest_i - 1) and knot(highest_i + 1) | ||
4976 | 759 | *moving = g_slist_append(*moving, dragger); | ||
4977 | 760 | |||
4978 | 761 | guint lowest_i = draggable->point_i; | ||
4979 | 762 | guint highest_i = draggable->point_i; | ||
4980 | 763 | GrDragger *lowest_dragger = dragger; | ||
4981 | 764 | GrDragger *highest_dragger = dragger; | ||
4982 | 765 | if (dragger->isSelected()) { | ||
4983 | 766 | GrDragger* d_add; | ||
4984 | 767 | while ( true ) | ||
4985 | 768 | { | ||
4986 | 769 | d_add = drag->getDraggerFor(draggable->item, draggable->point_type, lowest_i - 1, draggable->fill_or_stroke); | ||
4987 | 770 | if ( d_add && g_list_find(drag->selected, d_add) ) { | ||
4988 | 771 | lowest_i = lowest_i - 1; | ||
4989 | 772 | *moving = g_slist_prepend(*moving, d_add); | ||
4990 | 773 | lowest_dragger = d_add; | ||
4991 | 774 | } else { | ||
4992 | 775 | break; | ||
4993 | 776 | } | ||
4994 | 777 | } | ||
4995 | 778 | |||
4996 | 779 | while ( true ) | ||
4997 | 780 | { | ||
4998 | 781 | d_add = drag->getDraggerFor(draggable->item, draggable->point_type, highest_i + 1, draggable->fill_or_stroke); | ||
4999 | 782 | if ( d_add && g_list_find(drag->selected, d_add) ) { | ||
5000 | 783 | highest_i = highest_i + 1; |
The diff has been truncated for viewing.
Thanks. Uploaded.