tecscde 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rubocop.yml +125 -0
- data/.rubocop_todo.yml +188 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +6 -0
- data/LICENSE +46 -0
- data/LICENSE.ja +32 -0
- data/README.ja.md +200 -0
- data/README.md +35 -0
- data/Rakefile +27 -0
- data/bin/tecscde +64 -0
- data/glade/tecscde-cell-property.glade +205 -0
- data/glade/tecscde-celltype-property.glade +172 -0
- data/glade/tecscde-celltype.glade +414 -0
- data/glade/tecscde-export.glade +161 -0
- data/glade/test-cell-plugin.rb +51 -0
- data/glade/test-cell-property.rb +35 -0
- data/glade/test-export.rb +35 -0
- data/glade/test-palette.rb +26 -0
- data/lib/tcflow.rb +148 -0
- data/lib/tecscde.rb +65 -0
- data/lib/tecscde/NewCell.png +0 -0
- data/lib/tecscde/SelectArrow.png +0 -0
- data/lib/tecscde/attr_tree_view.rb +253 -0
- data/lib/tecscde/cell_plugin_dialog.glade +294 -0
- data/lib/tecscde/cell_plugin_dialog.rb +89 -0
- data/lib/tecscde/celltype_tree_view.rb +105 -0
- data/lib/tecscde/change_set_control.rb +35 -0
- data/lib/tecscde/change_set_control/change_set.rb +32 -0
- data/lib/tecscde/change_set_control/change_set_manager.rb +62 -0
- data/lib/tecscde/command.rb +35 -0
- data/lib/tecscde/control.rb +491 -0
- data/lib/tecscde/highlighted_objects.rb +180 -0
- data/lib/tecscde/logger.rb +74 -0
- data/lib/tecscde/main_view_and_model.rb +80 -0
- data/lib/tecscde/palette.glade +553 -0
- data/lib/tecscde/palette.rb +174 -0
- data/lib/tecscde/preferences.glade +117 -0
- data/lib/tecscde/preferences.rb +44 -0
- data/lib/tecscde/tecs_model.rb +1137 -0
- data/lib/tecscde/tecs_model/hbar.rb +68 -0
- data/lib/tecscde/tecs_model/tm_c_port.rb +122 -0
- data/lib/tecscde/tecs_model/tm_c_port_array.rb +98 -0
- data/lib/tecscde/tecs_model/tm_cell.rb +496 -0
- data/lib/tecscde/tecs_model/tm_e_port.rb +126 -0
- data/lib/tecscde/tecs_model/tm_e_port_array.rb +78 -0
- data/lib/tecscde/tecs_model/tm_join.rb +293 -0
- data/lib/tecscde/tecs_model/tm_join_bar.rb +146 -0
- data/lib/tecscde/tecs_model/tm_port.rb +238 -0
- data/lib/tecscde/tecs_model/tm_port_array.rb +246 -0
- data/lib/tecscde/tecs_model/tm_region.rb +107 -0
- data/lib/tecscde/tecs_model/tm_uneditable.rb +68 -0
- data/lib/tecscde/tecs_model/vbar.rb +68 -0
- data/lib/tecscde/templates/_cell_info.cde.erb +15 -0
- data/lib/tecscde/templates/_join_info.cde.erb +28 -0
- data/lib/tecscde/templates/main.cde.erb +49 -0
- data/lib/tecscde/tm_object.rb +91 -0
- data/lib/tecscde/version.rb +4 -0
- data/lib/tecscde/view.rb +58 -0
- data/lib/tecscde/view/cairo_matrix.rb +90 -0
- data/lib/tecscde/view/canvas.rb +59 -0
- data/lib/tecscde/view/constants.rb +114 -0
- data/lib/tecscde/view/main_view.rb +1245 -0
- data/lib/tecsflow.rb +475 -0
- data/lib/tecsflow/C_parser.tab.rb +2471 -0
- data/lib/tecsflow/C_parser.y.rb +1087 -0
- data/lib/tecsflow/classes.rb +421 -0
- data/lib/tecsgen.rb +581 -0
- data/lib/tecsgen/core/C_parser.tab.rb +2477 -0
- data/lib/tecsgen/core/C_parser.y +1032 -0
- data/lib/tecsgen/core/bnf-deb.tab.rb +5193 -0
- data/lib/tecsgen/core/bnf.tab.rb +5193 -0
- data/lib/tecsgen/core/bnf.y +2211 -0
- data/lib/tecsgen/core/componentobj.rb +7901 -0
- data/lib/tecsgen/core/ctypes.rb +226 -0
- data/lib/tecsgen/core/expression.rb +1031 -0
- data/lib/tecsgen/core/gen_xml.rb +374 -0
- data/lib/tecsgen/core/generate.rb +5206 -0
- data/lib/tecsgen/core/location.rb +116 -0
- data/lib/tecsgen/core/messages.rb +101 -0
- data/lib/tecsgen/core/optimize.rb +456 -0
- data/lib/tecsgen/core/plugin.rb +332 -0
- data/lib/tecsgen/core/pluginModule.rb +165 -0
- data/lib/tecsgen/core/syntaxobj.rb +1234 -0
- data/lib/tecsgen/core/tecs_lang.rb +306 -0
- data/lib/tecsgen/core/tecsgen.rb +453 -0
- data/lib/tecsgen/core/tecsinfo.rb +860 -0
- data/lib/tecsgen/core/tool_info.rb +258 -0
- data/lib/tecsgen/core/types.rb +1632 -0
- data/lib/tecsgen/core/unjoin_plugin.rb +218 -0
- data/lib/tecsgen/core/value.rb +650 -0
- data/lib/tecsgen/messages/messages_console_en_US.rb +1171 -0
- data/lib/tecsgen/messages/messages_console_ja_JP.rb +1171 -0
- data/lib/tecsgen/messages/messages_file_en_US.rb +334 -0
- data/lib/tecsgen/messages/messages_file_ja_JP.rb +163 -0
- data/lib/tecsgen/plugin/ATK1AlarmPlugin.rb +196 -0
- data/lib/tecsgen/plugin/ATK1DelayTaskPlugin.rb +106 -0
- data/lib/tecsgen/plugin/ATK1EventPlugin.rb +147 -0
- data/lib/tecsgen/plugin/ATK1ISRPlugin.rb +174 -0
- data/lib/tecsgen/plugin/ATK1KernelPlugin.rb +287 -0
- data/lib/tecsgen/plugin/ATK1ResourcePlugin.rb +124 -0
- data/lib/tecsgen/plugin/ATK1TaskPlugin.rb +220 -0
- data/lib/tecsgen/plugin/C2TECSBridgePlugin.rb +210 -0
- data/lib/tecsgen/plugin/CellPlugin.rb +61 -0
- data/lib/tecsgen/plugin/CelltypePlugin.rb +72 -0
- data/lib/tecsgen/plugin/CompositePlugin.rb +66 -0
- data/lib/tecsgen/plugin/DomainPlugin.rb +89 -0
- data/lib/tecsgen/plugin/HRP2AlarmHandlerPlugin.rb +76 -0
- data/lib/tecsgen/plugin/HRP2Cache.rb +1 -0
- data/lib/tecsgen/plugin/HRP2CyclicHandlerPlugin.rb +75 -0
- data/lib/tecsgen/plugin/HRP2DataqueuePlugin.rb +68 -0
- data/lib/tecsgen/plugin/HRP2EventflagPlugin.rb +68 -0
- data/lib/tecsgen/plugin/HRP2FixedSizeMemoryPoolPlugin.rb +68 -0
- data/lib/tecsgen/plugin/HRP2HandlerPlugin.rb +117 -0
- data/lib/tecsgen/plugin/HRP2KernelObjectPlugin.rb +372 -0
- data/lib/tecsgen/plugin/HRP2ObjectPlugin.rb +94 -0
- data/lib/tecsgen/plugin/HRP2Plugin.rb +140 -0
- data/lib/tecsgen/plugin/HRP2PostHook.rb +111 -0
- data/lib/tecsgen/plugin/HRP2PriorityDataqueuePlugin.rb +66 -0
- data/lib/tecsgen/plugin/HRP2RPCPlugin.rb +319 -0
- data/lib/tecsgen/plugin/HRP2SVCPlugin.rb +473 -0
- data/lib/tecsgen/plugin/HRP2SemaphorePlugin.rb +67 -0
- data/lib/tecsgen/plugin/HRP2TaskPlugin.rb +200 -0
- data/lib/tecsgen/plugin/HRPHandlerPlugin.rb +125 -0
- data/lib/tecsgen/plugin/HRPKernelObjectManager.rb +72 -0
- data/lib/tecsgen/plugin/HRPKernelObjectPlugin.rb +333 -0
- data/lib/tecsgen/plugin/HRPObjectPlugin.rb +93 -0
- data/lib/tecsgen/plugin/HRPPlugin.rb +356 -0
- data/lib/tecsgen/plugin/HRPRPCPlugin.rb +407 -0
- data/lib/tecsgen/plugin/HRPSVCPlugin.rb +859 -0
- data/lib/tecsgen/plugin/HRPTaskPlugin.rb +107 -0
- data/lib/tecsgen/plugin/Mruby2CBridgePlugin.rb +86 -0
- data/lib/tecsgen/plugin/MrubyBridgeCellPlugin.rb +264 -0
- data/lib/tecsgen/plugin/MrubyBridgeCelltypePlugin.rb +293 -0
- data/lib/tecsgen/plugin/MrubyBridgeCompositePlugin.rb +49 -0
- data/lib/tecsgen/plugin/MrubyBridgePlugin.rb +67 -0
- data/lib/tecsgen/plugin/MrubyBridgeSignaturePlugin.rb +1307 -0
- data/lib/tecsgen/plugin/MrubyInfoBridgePlugin.rb +14 -0
- data/lib/tecsgen/plugin/MrubyInfoBridgeSignaturePlugin.rb +994 -0
- data/lib/tecsgen/plugin/MultiPlugin.rb +57 -0
- data/lib/tecsgen/plugin/NotifierPlugin.rb +1217 -0
- data/lib/tecsgen/plugin/OpaqueMarshalerPlugin.rb +81 -0
- data/lib/tecsgen/plugin/OpaqueRPCPlugin.rb +323 -0
- data/lib/tecsgen/plugin/RPCPlugin.rb +266 -0
- data/lib/tecsgen/plugin/RepeatCellPlugin.rb +166 -0
- data/lib/tecsgen/plugin/RepeatJoinPlugin.rb +130 -0
- data/lib/tecsgen/plugin/SharedOpaqueRPCPlugin.rb +357 -0
- data/lib/tecsgen/plugin/SharedRPCPlugin.rb +329 -0
- data/lib/tecsgen/plugin/SignaturePlugin.rb +77 -0
- data/lib/tecsgen/plugin/TECS2CBridgePlugin.rb +178 -0
- data/lib/tecsgen/plugin/TECSInfoPlugin.rb +280 -0
- data/lib/tecsgen/plugin/ThroughPlugin.rb +333 -0
- data/lib/tecsgen/plugin/TracePlugin.rb +484 -0
- data/lib/tecsgen/plugin/lib/GenHRP2Marshaler.rb +761 -0
- data/lib/tecsgen/plugin/lib/GenOpaqueMarshaler.rb +1107 -0
- data/lib/tecsgen/plugin/lib/GenParamCopy.rb +365 -0
- data/lib/tecsgen/plugin/lib/GenTransparentMarshaler.rb +683 -0
- data/lib/tecsgen/plugin/lib/MrubyBridgeCelltypePluginModule.rb +283 -0
- data/lib/tecsgen/plugin/lib/MrubyBridgeSignaturePluginModule.rb +277 -0
- data/lib/tecsgen/version.rb +6 -0
- data/samples/FigureSamples/active/active.cde +104 -0
- data/samples/FigureSamples/active/active.cdl +20 -0
- data/samples/FigureSamples/active/active.pdf +0 -0
- data/samples/FigureSamples/active/active.png +0 -0
- data/samples/FigureSamples/active/gen/tmp_C_src.c +36 -0
- data/samples/FigureSamples/active/gen/tmp_cygwin_tecs.h +1908 -0
- data/samples/FigureSamples/active/gen/tmp_plugin_post_code.cdl +0 -0
- data/samples/FigureSamples/allocator/allocator-internal.png +0 -0
- data/samples/FigureSamples/allocator/allocator.cde +171 -0
- data/samples/FigureSamples/allocator/allocator.cdl +58 -0
- data/samples/FigureSamples/allocator/allocator.png +0 -0
- data/samples/FigureSamples/basic/Makefile +87 -0
- data/samples/FigureSamples/basic/SimpleSample-trace.cdl +50 -0
- data/samples/FigureSamples/basic/SimpleSample.cde +91 -0
- data/samples/FigureSamples/basic/SimpleSample.cdl +47 -0
- data/samples/FigureSamples/basic/basic.cde +93 -0
- data/samples/FigureSamples/basic/basic.cdl +46 -0
- data/samples/FigureSamples/basic/basic.png +0 -0
- data/samples/FigureSamples/callback/callback.cde +130 -0
- data/samples/FigureSamples/callback/callback.cdl +29 -0
- data/samples/FigureSamples/callback/callback.png +0 -0
- data/samples/FigureSamples/carray/carray.cde +144 -0
- data/samples/FigureSamples/carray/carray.cdl +38 -0
- data/samples/FigureSamples/carray/carray.png +0 -0
- data/samples/FigureSamples/cearray/cearray.cde +314 -0
- data/samples/FigureSamples/cearray/cearray.cdl +60 -0
- data/samples/FigureSamples/cearray/cearray.png +0 -0
- data/samples/FigureSamples/composite/composite-internal.png +0 -0
- data/samples/FigureSamples/composite/composite.cde +216 -0
- data/samples/FigureSamples/composite/composite.cdl +95 -0
- data/samples/FigureSamples/composite/composite.png +0 -0
- data/samples/FigureSamples/earray/earray.cde +142 -0
- data/samples/FigureSamples/earray/earray.cdl +38 -0
- data/samples/FigureSamples/earray/earray.png +0 -0
- data/samples/FigureSamples/join/Makefile +87 -0
- data/samples/FigureSamples/join/join.cde +132 -0
- data/samples/FigureSamples/join/join.cdl +40 -0
- data/samples/FigureSamples/join/join.png +0 -0
- data/samples/FigureSamples/relay/Makefile +99 -0
- data/samples/FigureSamples/relay/relay-internal.png +0 -0
- data/samples/FigureSamples/relay/relay.cde +284 -0
- data/samples/FigureSamples/relay/relay.cdl +52 -0
- data/samples/FigureSamples/relay/relay.png +0 -0
- data/samples/FigureSamples/rpc/Makefile +123 -0
- data/samples/FigureSamples/rpc/rpc-expand.png +0 -0
- data/samples/FigureSamples/rpc/rpc.cde +245 -0
- data/samples/FigureSamples/rpc/rpc.png +0 -0
- data/samples/FigureSamples/rpc/rpc_sample.cdl +53 -0
- data/samples/SimpleSample/Makefile +25 -0
- data/samples/SimpleSample/SimpleSample/Makefile +86 -0
- data/samples/SimpleSample/SimpleSample/Makefile-trace +91 -0
- data/samples/SimpleSample/SimpleSample/README.txt +106 -0
- data/samples/SimpleSample/SimpleSample/SimpleSample-trace.cdl +50 -0
- data/samples/SimpleSample/SimpleSample/SimpleSample.cdl +45 -0
- data/samples/SimpleSample/SimpleSample/src/tSample.c +77 -0
- data/samples/SimpleSample/SimpleSample/src/tSimple.c +48 -0
- data/samples/SimpleSample/SimpleSample/src/tecs-types.h +27 -0
- data/samples/SimpleSample/SimpleSampleOpaqueRPC/Makefile +51 -0
- data/samples/SimpleSample/SimpleSampleOpaqueRPC/Makefile-trace +91 -0
- data/samples/SimpleSample/SimpleSampleOpaqueRPC/README.txt +106 -0
- data/samples/SimpleSample/SimpleSampleOpaqueRPC/SimpleSample-trace.cdl +80 -0
- data/samples/SimpleSample/SimpleSampleOpaqueRPC/SimpleSample.cdl +77 -0
- data/samples/SimpleSample/SimpleSampleOpaqueRPC/rSample/Makefile +112 -0
- data/samples/SimpleSample/SimpleSampleOpaqueRPC/rSimple/Makefile +109 -0
- data/samples/SimpleSample/SimpleSampleOpaqueRPC/src/tSample.c +80 -0
- data/samples/SimpleSample/SimpleSampleOpaqueRPC/src/tSimple.c +47 -0
- data/samples/SimpleSample/SimpleSampleOpaqueRPC/src/tTaskMain.c +66 -0
- data/samples/SimpleSample/SimpleSampleOpaqueRPC/src/tecs-types.h +27 -0
- data/samples/SimpleSample/SimpleSampleTransparentRPC/Makefile +125 -0
- data/samples/SimpleSample/SimpleSampleTransparentRPC/Makefile-trace +130 -0
- data/samples/SimpleSample/SimpleSampleTransparentRPC/SimpleSample-trace.cdl +54 -0
- data/samples/SimpleSample/SimpleSampleTransparentRPC/SimpleSample.cdl +53 -0
- data/samples/SimpleSample/SimpleSampleTransparentRPC/src/tSample.c +80 -0
- data/samples/SimpleSample/SimpleSampleTransparentRPC/src/tSimple.c +54 -0
- data/tecscde.gemspec +41 -0
- metadata +353 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#
|
|
2
|
+
# TECSCDE - TECS Component Diagram Editor
|
|
3
|
+
#
|
|
4
|
+
# Copyright (C) 2014-2019 by TOPPERS Project
|
|
5
|
+
#
|
|
6
|
+
# The above copyright holders grant permission gratis to use,
|
|
7
|
+
# duplicate, modify, or redistribute (hereafter called use) this
|
|
8
|
+
# software (including the one made by modifying this software),
|
|
9
|
+
# provided that the following four conditions (1) through (4) are
|
|
10
|
+
# satisfied.
|
|
11
|
+
#
|
|
12
|
+
# (1) When this software is used in the form of source code, the above
|
|
13
|
+
# copyright notice, this use conditions, and the disclaimer shown
|
|
14
|
+
# below must be retained in the source code without modification.
|
|
15
|
+
#
|
|
16
|
+
# (2) When this software is redistributed in the forms usable for the
|
|
17
|
+
# development of other software, such as in library form, the above
|
|
18
|
+
# copyright notice, this use conditions, and the disclaimer shown
|
|
19
|
+
# below must be shown without modification in the document provided
|
|
20
|
+
# with the redistributed software, such as the user manual.
|
|
21
|
+
#
|
|
22
|
+
# (3) When this software is redistributed in the forms unusable for the
|
|
23
|
+
# development of other software, such as the case when the software
|
|
24
|
+
# is embedded in a piece of equipment, either of the following two
|
|
25
|
+
# conditions must be satisfied:
|
|
26
|
+
#
|
|
27
|
+
# (a) The above copyright notice, this use conditions, and the
|
|
28
|
+
# disclaimer shown below must be shown without modification in
|
|
29
|
+
# the document provided with the redistributed software, such as
|
|
30
|
+
# the user manual.
|
|
31
|
+
#
|
|
32
|
+
# (b) How the software is to be redistributed must be reported to the
|
|
33
|
+
# TOPPERS Project according to the procedure described
|
|
34
|
+
# separately.
|
|
35
|
+
#
|
|
36
|
+
# (4) The above copyright holders and the TOPPERS Project are exempt
|
|
37
|
+
# from responsibility for any type of damage directly or indirectly
|
|
38
|
+
# caused from the use of this software and are indemnified by any
|
|
39
|
+
# users or end users of this software from any and all causes of
|
|
40
|
+
# action whatsoever.
|
|
41
|
+
#
|
|
42
|
+
# THIS SOFTWARE IS PROVIDED "AS IS." THE ABOVE COPYRIGHT HOLDERS AND
|
|
43
|
+
# THE TOPPERS PROJECT DISCLAIM ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
44
|
+
# INCLUDING, BUT NOT LIMITED TO, ITS APPLICABILITY TO A PARTICULAR
|
|
45
|
+
# PURPOSE. IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS AND THE
|
|
46
|
+
# TOPPERS PROJECT BE LIABLE FOR ANY TYPE OF DAMAGE DIRECTLY OR
|
|
47
|
+
# INDIRECTLY CAUSED FROM THE USE OF THIS SOFTWARE.
|
|
48
|
+
#
|
|
49
|
+
|
|
50
|
+
require "gtk2"
|
|
51
|
+
|
|
52
|
+
module TECSCDE
|
|
53
|
+
module View
|
|
54
|
+
#== CairoMatrix
|
|
55
|
+
# this class is necessary for draw_text_v_cairo & totally shift when writing PDF
|
|
56
|
+
class CairoMatrix < Cairo::Matrix
|
|
57
|
+
def initialize
|
|
58
|
+
@base_x = 0
|
|
59
|
+
@base_y = 0
|
|
60
|
+
super(1, 0, 0, 1, 0, 0)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def set(xx, yx, xy, yy, x0, y0)
|
|
64
|
+
x0 += @base_x
|
|
65
|
+
y0 += @base_y
|
|
66
|
+
super
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
#=== CairoMatrix#set_rotate0
|
|
70
|
+
# no rotate, then shift (x, y)
|
|
71
|
+
def set_rotate0(x = 0, y = 0)
|
|
72
|
+
set(1, 0, 0, 1, x, y)
|
|
73
|
+
self
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
#=== CairoMatrix#set_rotate90
|
|
77
|
+
# rotate 90 around (0, 0) then shift (x, y)
|
|
78
|
+
def set_rotate90(x, y)
|
|
79
|
+
set(0, -1, 1, 0, x, y)
|
|
80
|
+
self
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def set_base_shift(x, y)
|
|
84
|
+
@base_x = x
|
|
85
|
+
@base_y = y
|
|
86
|
+
set_rotate0
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#
|
|
2
|
+
# TECSCDE - TECS Component Diagram Editor
|
|
3
|
+
#
|
|
4
|
+
# Copyright (C) 2014-2019 by TOPPERS Project
|
|
5
|
+
#
|
|
6
|
+
# The above copyright holders grant permission gratis to use,
|
|
7
|
+
# duplicate, modify, or redistribute (hereafter called use) this
|
|
8
|
+
# software (including the one made by modifying this software),
|
|
9
|
+
# provided that the following four conditions (1) through (4) are
|
|
10
|
+
# satisfied.
|
|
11
|
+
#
|
|
12
|
+
# (1) When this software is used in the form of source code, the above
|
|
13
|
+
# copyright notice, this use conditions, and the disclaimer shown
|
|
14
|
+
# below must be retained in the source code without modification.
|
|
15
|
+
#
|
|
16
|
+
# (2) When this software is redistributed in the forms usable for the
|
|
17
|
+
# development of other software, such as in library form, the above
|
|
18
|
+
# copyright notice, this use conditions, and the disclaimer shown
|
|
19
|
+
# below must be shown without modification in the document provided
|
|
20
|
+
# with the redistributed software, such as the user manual.
|
|
21
|
+
#
|
|
22
|
+
# (3) When this software is redistributed in the forms unusable for the
|
|
23
|
+
# development of other software, such as the case when the software
|
|
24
|
+
# is embedded in a piece of equipment, either of the following two
|
|
25
|
+
# conditions must be satisfied:
|
|
26
|
+
#
|
|
27
|
+
# (a) The above copyright notice, this use conditions, and the
|
|
28
|
+
# disclaimer shown below must be shown without modification in
|
|
29
|
+
# the document provided with the redistributed software, such as
|
|
30
|
+
# the user manual.
|
|
31
|
+
#
|
|
32
|
+
# (b) How the software is to be redistributed must be reported to the
|
|
33
|
+
# TOPPERS Project according to the procedure described
|
|
34
|
+
# separately.
|
|
35
|
+
#
|
|
36
|
+
# (4) The above copyright holders and the TOPPERS Project are exempt
|
|
37
|
+
# from responsibility for any type of damage directly or indirectly
|
|
38
|
+
# caused from the use of this software and are indemnified by any
|
|
39
|
+
# users or end users of this software from any and all causes of
|
|
40
|
+
# action whatsoever.
|
|
41
|
+
#
|
|
42
|
+
# THIS SOFTWARE IS PROVIDED "AS IS." THE ABOVE COPYRIGHT HOLDERS AND
|
|
43
|
+
# THE TOPPERS PROJECT DISCLAIM ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
44
|
+
# INCLUDING, BUT NOT LIMITED TO, ITS APPLICABILITY TO A PARTICULAR
|
|
45
|
+
# PURPOSE. IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS AND THE
|
|
46
|
+
# TOPPERS PROJECT BE LIABLE FOR ANY TYPE OF DAMAGE DIRECTLY OR
|
|
47
|
+
# INDIRECTLY CAUSED FROM THE USE OF THIS SOFTWARE.
|
|
48
|
+
#
|
|
49
|
+
|
|
50
|
+
require "gtk2"
|
|
51
|
+
|
|
52
|
+
module TECSCDE
|
|
53
|
+
module View
|
|
54
|
+
#=== Canvas class
|
|
55
|
+
# This 'canvas' is for TECSCDE. not relate to Gtk::Canvas.
|
|
56
|
+
class Canvas < Gtk::DrawingArea
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#
|
|
2
|
+
# TECSCDE - TECS Component Diagram Editor
|
|
3
|
+
#
|
|
4
|
+
# Copyright (C) 2014-2019 by TOPPERS Project
|
|
5
|
+
#
|
|
6
|
+
# The above copyright holders grant permission gratis to use,
|
|
7
|
+
# duplicate, modify, or redistribute (hereafter called use) this
|
|
8
|
+
# software (including the one made by modifying this software),
|
|
9
|
+
# provided that the following four conditions (1) through (4) are
|
|
10
|
+
# satisfied.
|
|
11
|
+
#
|
|
12
|
+
# (1) When this software is used in the form of source code, the above
|
|
13
|
+
# copyright notice, this use conditions, and the disclaimer shown
|
|
14
|
+
# below must be retained in the source code without modification.
|
|
15
|
+
#
|
|
16
|
+
# (2) When this software is redistributed in the forms usable for the
|
|
17
|
+
# development of other software, such as in library form, the above
|
|
18
|
+
# copyright notice, this use conditions, and the disclaimer shown
|
|
19
|
+
# below must be shown without modification in the document provided
|
|
20
|
+
# with the redistributed software, such as the user manual.
|
|
21
|
+
#
|
|
22
|
+
# (3) When this software is redistributed in the forms unusable for the
|
|
23
|
+
# development of other software, such as the case when the software
|
|
24
|
+
# is embedded in a piece of equipment, either of the following two
|
|
25
|
+
# conditions must be satisfied:
|
|
26
|
+
#
|
|
27
|
+
# (a) The above copyright notice, this use conditions, and the
|
|
28
|
+
# disclaimer shown below must be shown without modification in
|
|
29
|
+
# the document provided with the redistributed software, such as
|
|
30
|
+
# the user manual.
|
|
31
|
+
#
|
|
32
|
+
# (b) How the software is to be redistributed must be reported to the
|
|
33
|
+
# TOPPERS Project according to the procedure described
|
|
34
|
+
# separately.
|
|
35
|
+
#
|
|
36
|
+
# (4) The above copyright holders and the TOPPERS Project are exempt
|
|
37
|
+
# from responsibility for any type of damage directly or indirectly
|
|
38
|
+
# caused from the use of this software and are indemnified by any
|
|
39
|
+
# users or end users of this software from any and all causes of
|
|
40
|
+
# action whatsoever.
|
|
41
|
+
#
|
|
42
|
+
# THIS SOFTWARE IS PROVIDED "AS IS." THE ABOVE COPYRIGHT HOLDERS AND
|
|
43
|
+
# THE TOPPERS PROJECT DISCLAIM ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
44
|
+
# INCLUDING, BUT NOT LIMITED TO, ITS APPLICABILITY TO A PARTICULAR
|
|
45
|
+
# PURPOSE. IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS AND THE
|
|
46
|
+
# TOPPERS PROJECT BE LIABLE FOR ANY TYPE OF DAMAGE DIRECTLY OR
|
|
47
|
+
# INDIRECTLY CAUSED FROM THE USE OF THIS SOFTWARE.
|
|
48
|
+
#
|
|
49
|
+
|
|
50
|
+
require "gtk2"
|
|
51
|
+
|
|
52
|
+
module TECSCDE
|
|
53
|
+
module View
|
|
54
|
+
module Constants
|
|
55
|
+
DPI = 96.0 # Dot per Inch
|
|
56
|
+
|
|
57
|
+
SCALE_HEIGHT = 50 # Height of HScale widget
|
|
58
|
+
|
|
59
|
+
SCALE = 1.0 # Scale initial value
|
|
60
|
+
SCALE_VAL_INI = SCALE * 100 # 100%
|
|
61
|
+
SCALE_VAL_MAX = SCALE_VAL_INI * 2.00 # 200%
|
|
62
|
+
SCALE_VAL_MIN = SCALE_VAL_INI * 0.05 # 5%
|
|
63
|
+
|
|
64
|
+
TRIANGLE_LEN = 3 # edge length(mm)
|
|
65
|
+
TRIANGLE_HEIGHT = 2.598 # height (mm)
|
|
66
|
+
|
|
67
|
+
#----- draw text argment value -----#
|
|
68
|
+
# object
|
|
69
|
+
CELL_NAME = 1
|
|
70
|
+
CELLTYPE_NAME = 2
|
|
71
|
+
CELL_NAME_L = 3
|
|
72
|
+
SIGNATURE_NAME = 4
|
|
73
|
+
PORT_NAME = 5
|
|
74
|
+
PAPER_COMMENT = 6
|
|
75
|
+
|
|
76
|
+
# text alignment
|
|
77
|
+
ALIGN_CENTER = :center
|
|
78
|
+
ALIGN_LEFT = :left
|
|
79
|
+
ALIGN_RIGHT = :right
|
|
80
|
+
|
|
81
|
+
# text direction
|
|
82
|
+
TEXT_HORIZONTAL = 1 # left to right
|
|
83
|
+
TEXT_VERTICAL = 2 # bottom to top
|
|
84
|
+
|
|
85
|
+
#----- Cursor for mouse pointer -----#
|
|
86
|
+
CURSOR_PORT = Gdk::Cursor.new(Gdk::Cursor::SB_LEFT_ARROW)
|
|
87
|
+
CURSOR_JOINING = Gdk::Cursor.new(Gdk::Cursor::DOT)
|
|
88
|
+
CURSOR_JOIN_OK = Gdk::Cursor.new(Gdk::Cursor::CIRCLE)
|
|
89
|
+
CURSOR_NORMAL = Gdk::Cursor.new(Gdk::Cursor::TOP_LEFT_ARROW)
|
|
90
|
+
|
|
91
|
+
GAP_ACTIVE = 1 # (mm) gap of active cell between inner rectangle and outer one
|
|
92
|
+
GAP_PORT = 0.8 # (mm) gap between port name & edge
|
|
93
|
+
|
|
94
|
+
#----- Paper -----#
|
|
95
|
+
PAPER_MARGIN = 10 # (mm)
|
|
96
|
+
|
|
97
|
+
#----- constnts for div_string -----#
|
|
98
|
+
CHAR_A = "A"
|
|
99
|
+
CHAR_Z = "Z"
|
|
100
|
+
CHAR__ = "_"
|
|
101
|
+
|
|
102
|
+
#----- Color -----#
|
|
103
|
+
Color_editable_cell = :gray97
|
|
104
|
+
Color_uneditable = :blue
|
|
105
|
+
Color_editable = :black
|
|
106
|
+
Color_highlight = :magenta
|
|
107
|
+
Color_incomplete = :red
|
|
108
|
+
Color_unjoin = :magenta
|
|
109
|
+
# color names are found in setup_colormap
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
include TECSCDE::View::Constants
|
|
114
|
+
end
|
|
@@ -0,0 +1,1245 @@
|
|
|
1
|
+
#
|
|
2
|
+
# TECSCDE - TECS Component Diagram Editor
|
|
3
|
+
#
|
|
4
|
+
# Copyright (C) 2014-2019 by TOPPERS Project
|
|
5
|
+
#
|
|
6
|
+
# The above copyright holders grant permission gratis to use,
|
|
7
|
+
# duplicate, modify, or redistribute (hereafter called use) this
|
|
8
|
+
# software (including the one made by modifying this software),
|
|
9
|
+
# provided that the following four conditions (1) through (4) are
|
|
10
|
+
# satisfied.
|
|
11
|
+
#
|
|
12
|
+
# (1) When this software is used in the form of source code, the above
|
|
13
|
+
# copyright notice, this use conditions, and the disclaimer shown
|
|
14
|
+
# below must be retained in the source code without modification.
|
|
15
|
+
#
|
|
16
|
+
# (2) When this software is redistributed in the forms usable for the
|
|
17
|
+
# development of other software, such as in library form, the above
|
|
18
|
+
# copyright notice, this use conditions, and the disclaimer shown
|
|
19
|
+
# below must be shown without modification in the document provided
|
|
20
|
+
# with the redistributed software, such as the user manual.
|
|
21
|
+
#
|
|
22
|
+
# (3) When this software is redistributed in the forms unusable for the
|
|
23
|
+
# development of other software, such as the case when the software
|
|
24
|
+
# is embedded in a piece of equipment, either of the following two
|
|
25
|
+
# conditions must be satisfied:
|
|
26
|
+
#
|
|
27
|
+
# (a) The above copyright notice, this use conditions, and the
|
|
28
|
+
# disclaimer shown below must be shown without modification in
|
|
29
|
+
# the document provided with the redistributed software, such as
|
|
30
|
+
# the user manual.
|
|
31
|
+
#
|
|
32
|
+
# (b) How the software is to be redistributed must be reported to the
|
|
33
|
+
# TOPPERS Project according to the procedure described
|
|
34
|
+
# separately.
|
|
35
|
+
#
|
|
36
|
+
# (4) The above copyright holders and the TOPPERS Project are exempt
|
|
37
|
+
# from responsibility for any type of damage directly or indirectly
|
|
38
|
+
# caused from the use of this software and are indemnified by any
|
|
39
|
+
# users or end users of this software from any and all causes of
|
|
40
|
+
# action whatsoever.
|
|
41
|
+
#
|
|
42
|
+
# THIS SOFTWARE IS PROVIDED "AS IS." THE ABOVE COPYRIGHT HOLDERS AND
|
|
43
|
+
# THE TOPPERS PROJECT DISCLAIM ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
44
|
+
# INCLUDING, BUT NOT LIMITED TO, ITS APPLICABILITY TO A PARTICULAR
|
|
45
|
+
# PURPOSE. IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS AND THE
|
|
46
|
+
# TOPPERS PROJECT BE LIABLE FOR ANY TYPE OF DAMAGE DIRECTLY OR
|
|
47
|
+
# INDIRECTLY CAUSED FROM THE USE OF THIS SOFTWARE.
|
|
48
|
+
#
|
|
49
|
+
|
|
50
|
+
#
|
|
51
|
+
# (1) structure of MainWindow
|
|
52
|
+
#
|
|
53
|
+
# +- @main_window::Window--------------------+
|
|
54
|
+
# |+-@vbox::VBox(1/2)-----------------------+|
|
|
55
|
+
# ||+-- @scrolled_window::ScrolledWindow--+ ||
|
|
56
|
+
# ||| +---------------------------------+ | ||
|
|
57
|
+
# ||| | @canvas::Canvas | | ||
|
|
58
|
+
# ||| | | | ||
|
|
59
|
+
# ||| | | | ||
|
|
60
|
+
# ||| | | | ||
|
|
61
|
+
# ||| | | | ||
|
|
62
|
+
# ||| | | | ||
|
|
63
|
+
# ||| | | | ||
|
|
64
|
+
# ||| | | | ||
|
|
65
|
+
# ||| +---------------------------------+ | ||
|
|
66
|
+
# ||+-------------------------------------+ ||
|
|
67
|
+
# |+-@vbox::VBox(2/2)-----------------------+|
|
|
68
|
+
# || <--HScale--> ||
|
|
69
|
+
# |+----------------------------------------+|
|
|
70
|
+
# +------------------------------------------+
|
|
71
|
+
#
|
|
72
|
+
# @canvas::Canvas (<DrawingArea)
|
|
73
|
+
# 紙の大きさを持つ、描画エリア
|
|
74
|
+
# 大きさ (dots) = PaperHeight(mm) * dpi / 25.4 * Scale
|
|
75
|
+
# A4L=270*180 (Papersize=297*197)
|
|
76
|
+
#
|
|
77
|
+
# (2) canvasPixmap
|
|
78
|
+
#
|
|
79
|
+
# +---------------------------------+
|
|
80
|
+
# | @canvas_pixmap::Pixmap |
|
|
81
|
+
# | |
|
|
82
|
+
# | |
|
|
83
|
+
# | |
|
|
84
|
+
# | |
|
|
85
|
+
# | |
|
|
86
|
+
# | |
|
|
87
|
+
# | |
|
|
88
|
+
# +---------------------------------+
|
|
89
|
+
#
|
|
90
|
+
# @canvas_pixmap is invisible.
|
|
91
|
+
# draw contents on @canvas_pixmap then copy on @canvas, to avoid flickers and to redraw fast on expose.
|
|
92
|
+
#
|
|
93
|
+
|
|
94
|
+
require "gtk2"
|
|
95
|
+
|
|
96
|
+
module TECSCDE
|
|
97
|
+
module View
|
|
98
|
+
#== MainView class
|
|
99
|
+
class MainView
|
|
100
|
+
# @main_window::Gtk::Window
|
|
101
|
+
# @main_window_height::Integer
|
|
102
|
+
# @main_window_width::Integer
|
|
103
|
+
# @vbox::VBox
|
|
104
|
+
# @canvas_height::Integer
|
|
105
|
+
# @canvas_width::Integer
|
|
106
|
+
# @canvas::Canvas
|
|
107
|
+
# @canvas_pixmap::Gtk::Pixmap
|
|
108
|
+
# @gdk_window::Gdk::Window GDK window of @canvas
|
|
109
|
+
# @draw_target::Gtk::Pixmap | Gdk::Window : @canvas_pixmap or @gdk_window
|
|
110
|
+
# @canvas_gc::Gdk::GC
|
|
111
|
+
# @model::Model
|
|
112
|
+
# @hscale::HScale
|
|
113
|
+
# @scale_val::Integer
|
|
114
|
+
# @control::Control
|
|
115
|
+
# @pango_context::Gdk::Pango.context
|
|
116
|
+
# @pango_layout::Pango::Layout
|
|
117
|
+
# @pango_matrix::Pango::Matrix
|
|
118
|
+
|
|
119
|
+
include TECSCDE::View::Constants
|
|
120
|
+
|
|
121
|
+
# colors
|
|
122
|
+
@@colors = nil
|
|
123
|
+
@@colormap = nil
|
|
124
|
+
|
|
125
|
+
def initialize(model, control)
|
|
126
|
+
@model = model
|
|
127
|
+
@control = control
|
|
128
|
+
@paper = :A3L
|
|
129
|
+
@b_emphasize_cell_name = false
|
|
130
|
+
@b_color_by_region = false
|
|
131
|
+
MainView.setup_colormap
|
|
132
|
+
|
|
133
|
+
@main_window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
|
|
134
|
+
@main_window_width = width = 900
|
|
135
|
+
@main_window_height = height = 600
|
|
136
|
+
@main_window.title = "TECSCDE - TECS Component Diagram Editor"
|
|
137
|
+
@main_window.set_default_size(width, height)
|
|
138
|
+
@main_window.sensitive = true
|
|
139
|
+
@main_window.signal_connect("delete-event") do |_window, *_args|
|
|
140
|
+
TECSCDE.quit(@model, @main_window)
|
|
141
|
+
true
|
|
142
|
+
end
|
|
143
|
+
# KEY-PRESS event action
|
|
144
|
+
@main_window.signal_connect("key-press-event") do |_win, event|
|
|
145
|
+
if @entry_win.visible?
|
|
146
|
+
# while cell name editing, send forward to Entry window
|
|
147
|
+
event.set_window(@entry_win.window)
|
|
148
|
+
event.put
|
|
149
|
+
else
|
|
150
|
+
@control.key_pressed(event.keyval & 0xff, event.state)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
@main_window.signal_connect("focus-in-event") do |win, event|
|
|
154
|
+
# p "event:#{event.class} in"
|
|
155
|
+
end
|
|
156
|
+
@main_window.signal_connect("focus-out-event") do |win, event|
|
|
157
|
+
# p "event:#{event.class} out"
|
|
158
|
+
end
|
|
159
|
+
@main_window.signal_connect("grab-broken-event") do |win, event|
|
|
160
|
+
# p "event:#{event.class}"
|
|
161
|
+
end
|
|
162
|
+
@main_window.signal_connect("grab-focus") do |win|
|
|
163
|
+
# p "event:grab-focus"
|
|
164
|
+
end
|
|
165
|
+
@main_window.signal_connect("grab-notify") do |win, arg1|
|
|
166
|
+
# p "event:grab-notify"
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
create_hscale
|
|
170
|
+
create_hbox
|
|
171
|
+
|
|
172
|
+
@vbox = Gtk::VBox.new
|
|
173
|
+
# @vbox.set_resize_mode Gtk::RESIZE_IMMEDIATE
|
|
174
|
+
# p @vbox.resize_mode
|
|
175
|
+
@main_window.add(@vbox)
|
|
176
|
+
|
|
177
|
+
@scrolled_window = Gtk::ScrolledWindow.new
|
|
178
|
+
# @scrolled_window.signal_connect("expose_event") { |win, evt|
|
|
179
|
+
# gdkWin = @scrolled_window.window
|
|
180
|
+
# gc = Gdk::GC.new gdkWin
|
|
181
|
+
# gdkWin.draw_rectangle( gc, true, 0, 0, 10000, 10000 )
|
|
182
|
+
# }
|
|
183
|
+
|
|
184
|
+
@vbox.pack_start(@scrolled_window)
|
|
185
|
+
@vbox.pack_end(@hbox, false) # expand = false
|
|
186
|
+
|
|
187
|
+
create_canvas
|
|
188
|
+
@scrolled_window.set_size_request(width, height - SCALE_HEIGHT)
|
|
189
|
+
|
|
190
|
+
@main_window.show_all
|
|
191
|
+
|
|
192
|
+
create_edit_window
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def get_window
|
|
196
|
+
@main_window
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
#------ CANVAS ------#
|
|
200
|
+
|
|
201
|
+
#=== create canvas
|
|
202
|
+
def create_canvas
|
|
203
|
+
@canvas = Canvas.new
|
|
204
|
+
resize_canvas
|
|
205
|
+
TECSCDE.logger.debug("canvas width=#{@canvas_width}, height=#{@canvas_height}")
|
|
206
|
+
|
|
207
|
+
# BUTTON PRESS event action
|
|
208
|
+
@canvas.signal_connect("button-press-event") do |_canvas, event| # canvas = @canvas
|
|
209
|
+
TECSCDE.logger.debug("pressed #{event}")
|
|
210
|
+
xd, yd = event.coords
|
|
211
|
+
xm = dot2mm(xd)
|
|
212
|
+
ym = dot2mm(yd)
|
|
213
|
+
|
|
214
|
+
case event.event_type
|
|
215
|
+
when Gdk::Event::BUTTON_PRESS # single click or before ddouble, triple click
|
|
216
|
+
click_count = 1
|
|
217
|
+
when Gdk::Event::BUTTON2_PRESS # double click
|
|
218
|
+
click_count = 2
|
|
219
|
+
when Gdk::Event::BUTTON3_PRESS # triple click
|
|
220
|
+
click_count = 3
|
|
221
|
+
else
|
|
222
|
+
click_count = 1
|
|
223
|
+
end
|
|
224
|
+
@control.pressed_on_canvas(xm, ym, event.state, event.button, event.time, click_count)
|
|
225
|
+
end
|
|
226
|
+
# BUTTON RELEASE event action
|
|
227
|
+
@canvas.signal_connect("button-release-event") do |_canvas, event|
|
|
228
|
+
TECSCDE.logger.debug("released #{event}")
|
|
229
|
+
xd, yd = event.coords
|
|
230
|
+
xm = dot2mm(xd)
|
|
231
|
+
ym = dot2mm(yd)
|
|
232
|
+
@control.released_on_canvas(xm, ym, event.state, event.button)
|
|
233
|
+
end
|
|
234
|
+
# MOTION event action
|
|
235
|
+
@canvas.signal_connect("motion-notify-event") do |_canvas, event|
|
|
236
|
+
TECSCDE.logger.debug("motion #{event}")
|
|
237
|
+
xd, yd = event.coords
|
|
238
|
+
xm = dot2mm(xd)
|
|
239
|
+
ym = dot2mm(yd)
|
|
240
|
+
@control.motion_on_canvas(xm, ym, event.state)
|
|
241
|
+
end
|
|
242
|
+
# EXPOSE event action
|
|
243
|
+
@canvas.signal_connect("expose_event") do |_win, _evt|
|
|
244
|
+
refresh_canvas
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
# add events to receive
|
|
248
|
+
@canvas.add_events(Gdk::Event::POINTER_MOTION_MASK |
|
|
249
|
+
Gdk::Event::BUTTON_PRESS_MASK |
|
|
250
|
+
Gdk::Event::BUTTON_RELEASE_MASK |
|
|
251
|
+
Gdk::Event::PROPERTY_CHANGE_MASK |
|
|
252
|
+
Gdk::Event::KEY_PRESS_MASK)
|
|
253
|
+
|
|
254
|
+
@scrolled_window.add_with_viewport(@canvas)
|
|
255
|
+
# it seems that gdkWindow is nil before window.show or realize
|
|
256
|
+
@canvas.realize
|
|
257
|
+
@gdk_window = @canvas.window
|
|
258
|
+
@canvas_gc = Gdk::GC.new(@gdk_window)
|
|
259
|
+
|
|
260
|
+
# prepare pixmap (buffer for canvas)
|
|
261
|
+
# pixmap cannot be resized, so we have the largest one at initial.
|
|
262
|
+
@canvas_pixmap = Gdk::Pixmap.new(@gdk_window,
|
|
263
|
+
@canvas_width * SCALE_VAL_MAX / SCALE_VAL_INI,
|
|
264
|
+
@canvas_height * SCALE_VAL_MAX / SCALE_VAL_INI,
|
|
265
|
+
@gdk_window.depth)
|
|
266
|
+
# @draw_target = @canvas_pixmap
|
|
267
|
+
@cairo_context_pixmap = @canvas_pixmap.create_cairo_context
|
|
268
|
+
@cairo_context_pixmap.save
|
|
269
|
+
# @cairo_context_win = @gdk_window.create_cairo_context
|
|
270
|
+
# @cairo_context_win.save
|
|
271
|
+
@cairo_context_target = @cairo_context_pixmap
|
|
272
|
+
@cairo_matrix = TECSCDE::View::CairoMatrix.new
|
|
273
|
+
|
|
274
|
+
# prepare text renderer
|
|
275
|
+
@pango_context = Gdk::Pango.context
|
|
276
|
+
@pango_layout = Pango::Layout.new(@pango_context)
|
|
277
|
+
@pango_matrix = Pango::Matrix.new.rotate!(90)
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
def paint_canvas
|
|
281
|
+
clear_canvas_pixmap
|
|
282
|
+
|
|
283
|
+
#----- draw cells -----#
|
|
284
|
+
@model.get_cell_list.each do |cell|
|
|
285
|
+
draw_cell(cell)
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
#----- draw joins -----#
|
|
289
|
+
# draw linew before draw texts (if other colors are used, it is better to lay texts upper side)
|
|
290
|
+
@model.get_join_list.each do |join|
|
|
291
|
+
draw_join(join)
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
refresh_canvas
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
def refresh_canvas
|
|
298
|
+
@gdk_window.draw_drawable(@canvas_gc, @canvas_pixmap, 0, 0, 0, 0, @canvas_width, @canvas_height)
|
|
299
|
+
draw_highlight_objects(@control.highlighted_objects)
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
def resize_canvas
|
|
303
|
+
@canvas_height = Integer(mm2dot(@model.paper.height))
|
|
304
|
+
@canvas_width = Integer(mm2dot(@model.paper.width))
|
|
305
|
+
@canvas.set_size_request(@canvas_width, @canvas_height)
|
|
306
|
+
# @scrolled_window.queue_draw
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
def clear_canvas_pixmap
|
|
310
|
+
@canvas_gc.function = Gdk::GC::SET
|
|
311
|
+
@canvas_gc.fill = Gdk::GC::SOLID
|
|
312
|
+
@canvas_gc.foreground = Gdk::Color.new(255, 255, 255)
|
|
313
|
+
@canvas_pixmap.draw_rectangle(@canvas_gc, true, 0, 0, @canvas_width, @canvas_height)
|
|
314
|
+
canvas_gc_reset
|
|
315
|
+
# p "color = #{@canvas_gc.foreground.red}, #{@canvas_gc.foreground.green}, #{@canvas_gc.foreground.blue}"
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
def set_cursor(cursor)
|
|
319
|
+
@canvas.window.cursor = cursor
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
#=== TmView#draw_target_direct
|
|
323
|
+
# change draw target to Window
|
|
324
|
+
def draw_target_direct
|
|
325
|
+
# @draw_target = @gdk_window
|
|
326
|
+
# @cairo_context_target = @cairo_context_win
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
#=== TmView#draw_target_reset
|
|
330
|
+
# reset draw target to canvasPixmap
|
|
331
|
+
def draw_target_reset
|
|
332
|
+
# @draw_target = @canvas_pixmap
|
|
333
|
+
# @cairo_context_target = @cairo_context_pixmap
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
#------ HBox ------#
|
|
337
|
+
def create_hbox
|
|
338
|
+
@hbox = Gtk::HBox.new
|
|
339
|
+
#----- emphasize_cell_name button -----#
|
|
340
|
+
@emphasize_cell_name_button = Gtk::ToggleButton.new("Emphasize Cell Name")
|
|
341
|
+
@emphasize_cell_name_button.signal_connect("toggled") do |button|
|
|
342
|
+
@b_emphasize_cell_name = button.active?
|
|
343
|
+
paint_canvas
|
|
344
|
+
end
|
|
345
|
+
@hbox.pack_start(@emphasize_cell_name_button)
|
|
346
|
+
|
|
347
|
+
#----- color by region button -----#
|
|
348
|
+
# @color_by_region_button = Gtk::ToggleButton.new( "Color by Region" )
|
|
349
|
+
@color_by_region_button = Gtk::CheckButton.new("Color by Region")
|
|
350
|
+
@color_by_region_button.signal_connect("toggled") do |button|
|
|
351
|
+
@b_color_by_region = button.active?
|
|
352
|
+
# @color_by_region_button.label = button.active? ? "Color by File" : "Color by Region"
|
|
353
|
+
paint_canvas
|
|
354
|
+
end
|
|
355
|
+
@hbox.pack_start(@color_by_region_button)
|
|
356
|
+
@hbox.pack_end(@hscale)
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
#------ HScale ------#
|
|
360
|
+
def create_hscale
|
|
361
|
+
@scale_val = SCALE_VAL_INI
|
|
362
|
+
@hscale = Gtk::HScale.new(SCALE_VAL_MIN, SCALE_VAL_MAX, 1)
|
|
363
|
+
@hscale.set_digits(0) # 小数点以下
|
|
364
|
+
@hscale.set_value(@scale_val)
|
|
365
|
+
@hscale.set_size_request(@main_window_width, SCALE_HEIGHT)
|
|
366
|
+
@hscale.signal_connect("value-changed") do |scale_self, _scroll_type|
|
|
367
|
+
# set scale_val in the range [SCALE_VAL_MIN..SCALE_VAL_MAX]
|
|
368
|
+
scale_val = scale_self.value
|
|
369
|
+
if scale_val > SCALE_VAL_MAX
|
|
370
|
+
scale_val = SCALE_VAL_MAX
|
|
371
|
+
elsif scale_val < SCALE_VAL_MIN
|
|
372
|
+
scale_val = SCALE_VAL_MIN
|
|
373
|
+
end
|
|
374
|
+
@scale_val = scale_val
|
|
375
|
+
TECSCDE.logger.debug("scale_val=#{@scale_val}")
|
|
376
|
+
|
|
377
|
+
resize_canvas
|
|
378
|
+
paint_canvas
|
|
379
|
+
end
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
#------ Draw Contents on CANVAS ------#
|
|
383
|
+
|
|
384
|
+
def draw_cell(cell)
|
|
385
|
+
#----- calc position in dot -----#
|
|
386
|
+
x, y, w, h = cell.get_geometry
|
|
387
|
+
x1 = mm2dot(x)
|
|
388
|
+
y1 = mm2dot(y)
|
|
389
|
+
x2 = mm2dot(x + w)
|
|
390
|
+
y2 = mm2dot(y + h)
|
|
391
|
+
w1 = mm2dot(w)
|
|
392
|
+
h1 = mm2dot(h)
|
|
393
|
+
|
|
394
|
+
#----- paint cell -----#
|
|
395
|
+
color = get_cell_paint_color(cell)
|
|
396
|
+
# @canvas_gc.set_foreground color
|
|
397
|
+
# @draw_target.draw_rectangle( @canvas_gc, true, x1, y1, w1, h1 )
|
|
398
|
+
|
|
399
|
+
@cairo_context_target.rectangle(x1, y1, w1, h1)
|
|
400
|
+
@cairo_context_target.set_source_color(color)
|
|
401
|
+
@cairo_context_target.fill
|
|
402
|
+
|
|
403
|
+
#----- setup color -----#
|
|
404
|
+
if !cell.editable?
|
|
405
|
+
# @canvas_gc.set_foreground @@colors[ Color_uneditable ]
|
|
406
|
+
@cairo_context_target.set_source_color(@@colors[Color_uneditable])
|
|
407
|
+
else
|
|
408
|
+
# @canvas_gc.set_foreground @@colors[ Color_editable ]
|
|
409
|
+
@cairo_context_target.set_source_color(@@colors[Color_editable])
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
#----- draw cell rect -----#
|
|
413
|
+
# @draw_target.draw_rectangle( @canvas_gc, false, x1, y1, w1, h1 )
|
|
414
|
+
# @cairo_context_target.rectangle(x1, y1, w1, h1)
|
|
415
|
+
@cairo_context_target.rectangle(x1 + 0.5, y1 + 0.5, w1, h1)
|
|
416
|
+
@cairo_context_target.set_line_width(1)
|
|
417
|
+
@cairo_context_target.stroke
|
|
418
|
+
|
|
419
|
+
gap = mm2dot(GAP_ACTIVE)
|
|
420
|
+
gap = 2 if gap < 2 # if less than 2 dots, let gap 2 dots
|
|
421
|
+
if cell.get_celltype&.is_active?
|
|
422
|
+
# @draw_target.draw_rectangle( @canvas_gc, false, x1 + gap, y1 + gap, w1 - 2 * gap, h1 - 2 * gap )
|
|
423
|
+
@cairo_context_target.rectangle(x1 + gap + 0.5, y1 + gap + 0.5, w1 - 2 * gap, h1 - 2 * gap)
|
|
424
|
+
@cairo_context_target.set_line_width(1)
|
|
425
|
+
@cairo_context_target.stroke
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
#----- draw entry ports triangle -----#
|
|
429
|
+
cell.eports.each do |_name, eport|
|
|
430
|
+
if !eport.array?
|
|
431
|
+
draw_entry_port_triangle(eport)
|
|
432
|
+
else
|
|
433
|
+
if cell.editable? && eport.unsubscripted_array?
|
|
434
|
+
# @canvas_gc.set_foreground @@colors[ :brown ]
|
|
435
|
+
@cairo_context_target.set_source_color(@@colors[:brown])
|
|
436
|
+
end
|
|
437
|
+
# EPortArray
|
|
438
|
+
eport.ports.each do |ep|
|
|
439
|
+
draw_entry_port_triangle(ep)
|
|
440
|
+
end
|
|
441
|
+
if cell.editable? && eport.unsubscripted_array?
|
|
442
|
+
# @canvas_gc.set_foreground @@colors[ Color_editable ]
|
|
443
|
+
@cairo_context_target.set_source_color(@@colors[Color_editable])
|
|
444
|
+
end
|
|
445
|
+
end
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
#----- draw cell name & celltype name -----#
|
|
449
|
+
cell_name = cell.get_name
|
|
450
|
+
ct_name = cell.get_celltype.get_name
|
|
451
|
+
label = cell_name.to_s + "\n" + ct_name.to_s
|
|
452
|
+
unless cell.complete?
|
|
453
|
+
# @canvas_gc.set_foreground @@colors[ Color_incomplete ]
|
|
454
|
+
@cairo_context_target.set_source_color(@@colors[Color_incomplete])
|
|
455
|
+
end
|
|
456
|
+
# draw_text( x1 + w1/2, y1+h1/2, label, CELL_NAME, ALIGN_CENTER, TEXT_HORIZONTAL )
|
|
457
|
+
|
|
458
|
+
if @b_emphasize_cell_name
|
|
459
|
+
wmn, hmn = get_text_extent(cell_name.to_s, CELL_NAME_L, ALIGN_CENTER, TEXT_HORIZONTAL)
|
|
460
|
+
if wmn > w
|
|
461
|
+
s1, s2 = div_string(cell_name.to_s)
|
|
462
|
+
draw_text(x1 + w1 / 2, y1 + h1 / 2 - mm2dot(hmn) / 2, s1, CELL_NAME_L, ALIGN_CENTER, TEXT_HORIZONTAL)
|
|
463
|
+
draw_text(x1 + w1 / 2, y1 + h1 / 2 + mm2dot(hmn) / 2, s2, CELL_NAME_L, ALIGN_CENTER, TEXT_HORIZONTAL)
|
|
464
|
+
else
|
|
465
|
+
draw_text(x1 + w1 / 2, y1 + h1 / 2, cell_name.to_s, CELL_NAME_L, ALIGN_CENTER, TEXT_HORIZONTAL)
|
|
466
|
+
end
|
|
467
|
+
else
|
|
468
|
+
wmn, hmn = get_text_extent(cell_name.to_s, CELL_NAME, ALIGN_CENTER, TEXT_HORIZONTAL)
|
|
469
|
+
draw_text(x1 + w1 / 2, y1 + h1 / 2 + mm2dot(hmn) / 2, cell_name.to_s, CELL_NAME, ALIGN_CENTER, TEXT_HORIZONTAL)
|
|
470
|
+
draw_text(x1 + w1 / 2, y1 + h1 / 2 - mm2dot(hmn) / 2, ct_name.to_s, CELLTYPE_NAME, ALIGN_CENTER, TEXT_HORIZONTAL)
|
|
471
|
+
end
|
|
472
|
+
|
|
473
|
+
#----- draw port name -----#
|
|
474
|
+
cell.cports.merge(cell.eports).each do |_name, port|
|
|
475
|
+
if !port.array?
|
|
476
|
+
set_port_color(port, cell)
|
|
477
|
+
draw_port_name(port)
|
|
478
|
+
else
|
|
479
|
+
#--- prot array ---#
|
|
480
|
+
port.ports.each do |pt|
|
|
481
|
+
set_port_color pt, cell
|
|
482
|
+
draw_port_name(pt)
|
|
483
|
+
end
|
|
484
|
+
end
|
|
485
|
+
end
|
|
486
|
+
|
|
487
|
+
canvas_gc_reset
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
#=== set_port_color
|
|
491
|
+
def set_port_color(port, cell)
|
|
492
|
+
if port.complete?
|
|
493
|
+
if cell.editable?
|
|
494
|
+
color_name = Color_editable
|
|
495
|
+
else
|
|
496
|
+
color_name = Color_uneditable
|
|
497
|
+
end
|
|
498
|
+
else
|
|
499
|
+
if port.is_a?(TECSModel::TmCPort) && !port.optional?
|
|
500
|
+
color_name = Color_incomplete
|
|
501
|
+
else
|
|
502
|
+
color_name = Color_unjoin
|
|
503
|
+
end
|
|
504
|
+
end
|
|
505
|
+
# @canvas_gc.set_foreground @@colors[ color_name ]
|
|
506
|
+
@cairo_context_target.set_source_color(@@colors[color_name])
|
|
507
|
+
end
|
|
508
|
+
|
|
509
|
+
def draw_entry_port_triangle(eport)
|
|
510
|
+
triangle_1_2 = mm2dot(TRIANGLE_LEN / 2)
|
|
511
|
+
triangle_hi = mm2dot(TRIANGLE_HEIGHT)
|
|
512
|
+
x1, y1 = eport.get_position
|
|
513
|
+
xe = mm2dot(x1)
|
|
514
|
+
ye = mm2dot(y1)
|
|
515
|
+
case eport.get_edge_side
|
|
516
|
+
when TECSModel::EDGE_TOP
|
|
517
|
+
points = [[xe - triangle_1_2, ye], [xe + triangle_1_2, ye], [xe, ye + triangle_hi]]
|
|
518
|
+
when TECSModel::EDGE_BOTTOM
|
|
519
|
+
points = [[xe - triangle_1_2, ye], [xe + triangle_1_2, ye], [xe, ye - triangle_hi]]
|
|
520
|
+
when TECSModel::EDGE_LEFT
|
|
521
|
+
points = [[xe, ye - triangle_1_2], [xe, ye + triangle_1_2], [xe + triangle_hi, ye]]
|
|
522
|
+
when TECSModel::EDGE_RIGHT
|
|
523
|
+
points = [[xe, ye - triangle_1_2], [xe, ye + triangle_1_2], [xe - triangle_hi, ye]]
|
|
524
|
+
end
|
|
525
|
+
# fill = true
|
|
526
|
+
# @draw_target.draw_polygon( @canvas_gc, fill, points )
|
|
527
|
+
@cairo_context_target.triangle(*points[0], *points[1], *points[2])
|
|
528
|
+
@cairo_context_target.fill
|
|
529
|
+
end
|
|
530
|
+
|
|
531
|
+
def draw_port_name(port)
|
|
532
|
+
x1, y1 = port.get_position
|
|
533
|
+
xp = mm2dot(x1)
|
|
534
|
+
yp = mm2dot(y1)
|
|
535
|
+
case port.get_edge_side
|
|
536
|
+
when TECSModel::EDGE_TOP
|
|
537
|
+
alignment = ALIGN_LEFT
|
|
538
|
+
direction = TEXT_VERTICAL
|
|
539
|
+
when TECSModel::EDGE_BOTTOM
|
|
540
|
+
alignment = ALIGN_RIGHT
|
|
541
|
+
direction = TEXT_VERTICAL
|
|
542
|
+
when TECSModel::EDGE_LEFT
|
|
543
|
+
alignment = ALIGN_RIGHT
|
|
544
|
+
direction = TEXT_HORIZONTAL
|
|
545
|
+
when TECSModel::EDGE_RIGHT
|
|
546
|
+
xp += 2
|
|
547
|
+
alignment = ALIGN_LEFT
|
|
548
|
+
direction = TEXT_HORIZONTAL
|
|
549
|
+
end
|
|
550
|
+
name = port.get_name.to_s
|
|
551
|
+
subscript = port.get_subscript
|
|
552
|
+
if subscript
|
|
553
|
+
if subscript >= 0
|
|
554
|
+
name += "[#{subscript}]"
|
|
555
|
+
end
|
|
556
|
+
end
|
|
557
|
+
draw_text(xp, yp, name, PORT_NAME, alignment, direction)
|
|
558
|
+
end
|
|
559
|
+
|
|
560
|
+
#=== TView#draw_highlight_objects
|
|
561
|
+
def draw_highlight_objects(obj_list)
|
|
562
|
+
obj_list.each do |obj|
|
|
563
|
+
if obj.is_a?(TECSModel::TmCell)
|
|
564
|
+
draw_cell_rect_direct(obj)
|
|
565
|
+
# draw_target_direct
|
|
566
|
+
# draw_cell(obj)
|
|
567
|
+
# draw_target_reset
|
|
568
|
+
elsif obj.is_a?(TECSModel::TmPort)
|
|
569
|
+
draw_port_direct(obj)
|
|
570
|
+
elsif obj.is_a?(TECSModel::TmJoinBar)
|
|
571
|
+
draw_bar_direct(obj)
|
|
572
|
+
end
|
|
573
|
+
end
|
|
574
|
+
end
|
|
575
|
+
|
|
576
|
+
#=== TView#draw_cell_rect_direct
|
|
577
|
+
# directly draw on Window highlighted cell rect
|
|
578
|
+
def draw_cell_rect_direct(cell)
|
|
579
|
+
draw_target_direct
|
|
580
|
+
|
|
581
|
+
#----- set line width -----#
|
|
582
|
+
canvas_gc_set_line_width(2)
|
|
583
|
+
# @cairo_context_target.set_line_width(2)
|
|
584
|
+
|
|
585
|
+
#----- if uneditable change color ------#
|
|
586
|
+
unless cell.editable?
|
|
587
|
+
@canvas_gc.set_foreground(@@colors[Color_uneditable])
|
|
588
|
+
# @cairo_context_target.set_source_color( @@colors[ Color_uneditable ] )
|
|
589
|
+
end
|
|
590
|
+
|
|
591
|
+
#----- calc position in dot -----#
|
|
592
|
+
x, y, w, h = cell.get_geometry
|
|
593
|
+
x1 = mm2dot(x)
|
|
594
|
+
y1 = mm2dot(y)
|
|
595
|
+
w1 = mm2dot(w)
|
|
596
|
+
h1 = mm2dot(h)
|
|
597
|
+
|
|
598
|
+
#----- draw cell rect -----#
|
|
599
|
+
@gdk_window.draw_rectangle(@canvas_gc, false, x1, y1, w1, h1)
|
|
600
|
+
# @cairo_context_target.rectangle(x1, y1, w1, h1)
|
|
601
|
+
# @cairo_context_target.stroke
|
|
602
|
+
|
|
603
|
+
#----- reset GC, line width -----#
|
|
604
|
+
canvas_gc_reset
|
|
605
|
+
canvas_gc_set_line_width(1)
|
|
606
|
+
draw_target_reset
|
|
607
|
+
end
|
|
608
|
+
|
|
609
|
+
def draw_port_direct(port)
|
|
610
|
+
draw_target_direct
|
|
611
|
+
|
|
612
|
+
#----- set line width -----#
|
|
613
|
+
@canvas_gc.set_foreground(@@colors[Color_highlight])
|
|
614
|
+
# @cairo_context_target.set_source_color( @@colors[ Color_highlight ] )
|
|
615
|
+
draw_port_name(port)
|
|
616
|
+
|
|
617
|
+
if port.is_a?(TECSModel::TmEPort)
|
|
618
|
+
draw_entry_port_triangle(port)
|
|
619
|
+
end
|
|
620
|
+
|
|
621
|
+
canvas_gc_set_line_width(2)
|
|
622
|
+
x, y = port.get_position
|
|
623
|
+
x1 = x2 = mm2dot(x)
|
|
624
|
+
y1 = y2 = mm2dot(y)
|
|
625
|
+
case port.get_edge_side
|
|
626
|
+
when TECSModel::EDGE_TOP
|
|
627
|
+
y1 -= 20
|
|
628
|
+
when TECSModel::EDGE_BOTTOM
|
|
629
|
+
y2 += 20
|
|
630
|
+
when TECSModel::EDGE_LEFT
|
|
631
|
+
x1 -= 20
|
|
632
|
+
when TECSModel::EDGE_RIGHT
|
|
633
|
+
x2 += 20
|
|
634
|
+
end
|
|
635
|
+
@gdk_window.draw_line(@canvas_gc, x1, y1, x2, y2)
|
|
636
|
+
# @cairo_context_target.move_to( x1, y1 )
|
|
637
|
+
# @cairo_context_target.line_to( x2, y2 )
|
|
638
|
+
|
|
639
|
+
#----- reset GC, line width -----#
|
|
640
|
+
canvas_gc_reset
|
|
641
|
+
canvas_gc_set_line_width(1)
|
|
642
|
+
|
|
643
|
+
draw_target_reset
|
|
644
|
+
end
|
|
645
|
+
|
|
646
|
+
def draw_join(join)
|
|
647
|
+
cport = join.cport
|
|
648
|
+
eport = join.eport
|
|
649
|
+
bars = join.bars
|
|
650
|
+
x, y = cport.get_position
|
|
651
|
+
xm = mm2dot(x) + 0.5
|
|
652
|
+
ym = mm2dot(y) + 0.5
|
|
653
|
+
|
|
654
|
+
#----- setup color -----#
|
|
655
|
+
unless join.editable?
|
|
656
|
+
# @canvas_gc.set_foreground @@colors[ Color_uneditable ]
|
|
657
|
+
@cairo_context_target.set_source_color(@@colors[Color_uneditable])
|
|
658
|
+
end
|
|
659
|
+
|
|
660
|
+
@cairo_context_target.move_to(xm, ym)
|
|
661
|
+
#----- draw bars -----#
|
|
662
|
+
bars.each do |bar|
|
|
663
|
+
if bar.horizontal?
|
|
664
|
+
xm2 = mm2dot(bar.get_position) + 0.5
|
|
665
|
+
# @draw_target.draw_line( @canvas_gc, xm, ym, xm2, ym )
|
|
666
|
+
@cairo_context_target.line_to(xm2, ym)
|
|
667
|
+
xm = xm2
|
|
668
|
+
else # VBar
|
|
669
|
+
ym2 = mm2dot(bar.get_position) + 0.5
|
|
670
|
+
# @draw_target.draw_line( @canvas_gc, xm, ym, xm, ym2 )
|
|
671
|
+
@cairo_context_target.line_to(xm, ym2)
|
|
672
|
+
ym = ym2
|
|
673
|
+
end
|
|
674
|
+
end
|
|
675
|
+
@cairo_context_target.set_line_width(1)
|
|
676
|
+
@cairo_context_target.stroke
|
|
677
|
+
|
|
678
|
+
#----- draw signature name -----#
|
|
679
|
+
if eport.get_joins[0] == join
|
|
680
|
+
# draw only 1st entry port join
|
|
681
|
+
|
|
682
|
+
if (eport.get_subscript.nil? || eport.get_subscript == 0) &&
|
|
683
|
+
(join.cport.get_subscript.nil? || join.cport.get_subscript == 0)
|
|
684
|
+
|
|
685
|
+
if bars[2].vertical?
|
|
686
|
+
xm = mm2dot((bars[1].get_position + bars[3].get_position) / 2)
|
|
687
|
+
ym = mm2dot(bars[2].get_position + 2)
|
|
688
|
+
else
|
|
689
|
+
xm = mm2dot((bars[0].get_position + bars[2].get_position) / 2)
|
|
690
|
+
ym = mm2dot(bars[1].get_position + 2)
|
|
691
|
+
end
|
|
692
|
+
draw_text(xm, ym, join.get_signature.get_name.to_s, SIGNATURE_NAME, ALIGN_CENTER, TEXT_HORIZONTAL)
|
|
693
|
+
end
|
|
694
|
+
end
|
|
695
|
+
|
|
696
|
+
canvas_gc_reset
|
|
697
|
+
end
|
|
698
|
+
|
|
699
|
+
#=== TView#draw_bar_direct
|
|
700
|
+
# directly draw on Window
|
|
701
|
+
def draw_bar_direct(bar)
|
|
702
|
+
draw_target_direct
|
|
703
|
+
|
|
704
|
+
join = bar.get_join
|
|
705
|
+
cport = join.cport
|
|
706
|
+
bars = join.bars
|
|
707
|
+
x, y = cport.get_position
|
|
708
|
+
xm = mm2dot(x)
|
|
709
|
+
ym = mm2dot(y)
|
|
710
|
+
|
|
711
|
+
canvas_gc_set_line_width(2)
|
|
712
|
+
|
|
713
|
+
bars.each do |bar2|
|
|
714
|
+
if @control.highlighted_objects.include?(bar2)
|
|
715
|
+
color = @@colors[Color_highlight]
|
|
716
|
+
elsif join.editable?
|
|
717
|
+
color = @@colors[Color_editable]
|
|
718
|
+
else
|
|
719
|
+
color = @@colors[Color_uneditable]
|
|
720
|
+
end
|
|
721
|
+
@canvas_gc.foreground = color
|
|
722
|
+
@cairo_context_target.set_source_color(color)
|
|
723
|
+
|
|
724
|
+
if bar2.horizontal?
|
|
725
|
+
xm2 = mm2dot(bar2.get_position)
|
|
726
|
+
@gdk_window.draw_line(@canvas_gc, xm, ym, xm2, ym)
|
|
727
|
+
xm = xm2
|
|
728
|
+
else # VBar
|
|
729
|
+
ym2 = mm2dot(bar2.get_position)
|
|
730
|
+
@gdk_window.draw_line(@canvas_gc, xm, ym, xm, ym2)
|
|
731
|
+
ym = ym2
|
|
732
|
+
end
|
|
733
|
+
end
|
|
734
|
+
|
|
735
|
+
canvas_gc_set_line_width(1)
|
|
736
|
+
canvas_gc_reset
|
|
737
|
+
|
|
738
|
+
draw_target_reset
|
|
739
|
+
end
|
|
740
|
+
|
|
741
|
+
#----- draw and utility for text -----#
|
|
742
|
+
|
|
743
|
+
def get_text_extent(text, obj_type, alignment, direction)
|
|
744
|
+
pc = @pango_context
|
|
745
|
+
plo = @pango_layout
|
|
746
|
+
if direction != TEXT_VERTICAL
|
|
747
|
+
pc.matrix = nil
|
|
748
|
+
plo.text = text.to_s
|
|
749
|
+
pfd = pc.font_description
|
|
750
|
+
pfd.absolute_size = font_size(obj_type)
|
|
751
|
+
plo.font_description = pfd
|
|
752
|
+
plo.alignment = alignment
|
|
753
|
+
# plo.context_changed # ??
|
|
754
|
+
# rect2 = plo.get_pixel_extents[1]
|
|
755
|
+
# return [ dot2mm(rect2.rbearing), dot2mm(rect2.descent) ]
|
|
756
|
+
rect2 = plo.pixel_extents[1]
|
|
757
|
+
[dot2mm(rect2.x + rect2.width), dot2mm(rect2.y + rect2.height)]
|
|
758
|
+
else
|
|
759
|
+
pm = @pango_matrix
|
|
760
|
+
pc.matrix = pm
|
|
761
|
+
plo.text = text.to_s
|
|
762
|
+
pfd = pc.font_description
|
|
763
|
+
pfd.absolute_size = font_size(obj_type)
|
|
764
|
+
plo.font_description = pfd
|
|
765
|
+
plo.alignment = alignment
|
|
766
|
+
# plo.context_changed
|
|
767
|
+
rect2 = plo.get_pixel_extents[1]
|
|
768
|
+
[dot2mm(rect2.descent), dot2mm(rect2.rbearing)]
|
|
769
|
+
end
|
|
770
|
+
end
|
|
771
|
+
|
|
772
|
+
# x::Integer(dot)
|
|
773
|
+
# y::Integer(dot)
|
|
774
|
+
# obj_type::CELL_NAME, SIGNATURE_NAME, PORT_NAME
|
|
775
|
+
# alignment::ALIGN_CENTER, ALIGN_LEFT
|
|
776
|
+
def draw_text(x, y, text, obj_type, alignment, direction)
|
|
777
|
+
if direction == TEXT_VERTICAL
|
|
778
|
+
draw_text_v(x, y, text, obj_type, alignment)
|
|
779
|
+
else
|
|
780
|
+
draw_text_h(x, y, text, obj_type, alignment)
|
|
781
|
+
end
|
|
782
|
+
end
|
|
783
|
+
|
|
784
|
+
def draw_text_h(x, y, text, obj_type, alignment)
|
|
785
|
+
# draw_text_h_gdk( x, y, text, obj_type, alignment )
|
|
786
|
+
draw_text_h_cairo(x, y, text, obj_type, alignment)
|
|
787
|
+
# draw_text_h_cairo_pango( x, y, text, obj_type, alignment )
|
|
788
|
+
end
|
|
789
|
+
|
|
790
|
+
def draw_text_h_gdk(x, y, text, obj_type, alignment)
|
|
791
|
+
#----- Gdk Pango version -----#
|
|
792
|
+
pc = @pango_context
|
|
793
|
+
plo = @pango_layout
|
|
794
|
+
pc.matrix = nil
|
|
795
|
+
plo.text = text
|
|
796
|
+
pfd = pc.font_description
|
|
797
|
+
pfd.absolute_size = font_size(obj_type)
|
|
798
|
+
plo.font_description = pfd
|
|
799
|
+
plo.alignment = alignment
|
|
800
|
+
# plo.context_changed # ??
|
|
801
|
+
rect2 = plo.get_pixel_extents[1]
|
|
802
|
+
|
|
803
|
+
case alignment
|
|
804
|
+
when ALIGN_CENTER
|
|
805
|
+
# calc text draww postion
|
|
806
|
+
x2 = x - rect2.rbearing / 2
|
|
807
|
+
y2 = y - rect2.descent / 2
|
|
808
|
+
when ALIGN_RIGHT
|
|
809
|
+
x2 = x - rect2.rbearing - mm2dot(GAP_PORT)
|
|
810
|
+
y2 = y - rect2.descent
|
|
811
|
+
when ALIGN_LEFT
|
|
812
|
+
x2 = x + mm2dot(GAP_PORT)
|
|
813
|
+
y2 = y - rect2.descent
|
|
814
|
+
end
|
|
815
|
+
|
|
816
|
+
# pfd = Pango::FontDescription.new
|
|
817
|
+
# p pfd.size, pfd.variant, pfd.family
|
|
818
|
+
# rect = plo.get_pixel_extents[0]
|
|
819
|
+
# p rect.ascent, rect.descent, rect.lbearing, rect.rbearing
|
|
820
|
+
# p rect2.ascent, rect2.descent, rect2.lbearing, rect2.rbearing
|
|
821
|
+
|
|
822
|
+
@draw_target.draw_layout(@canvas_gc, x2, y2, plo)
|
|
823
|
+
end
|
|
824
|
+
|
|
825
|
+
#----- Cairo version -----#
|
|
826
|
+
def draw_text_h_cairo(x, y, text, obj_type, alignment)
|
|
827
|
+
cr = @cairo_context_target
|
|
828
|
+
cr.select_font_face(nil, # "courier", # font_family = "Times New Roman",
|
|
829
|
+
Cairo::FONT_SLANT_NORMAL,
|
|
830
|
+
Cairo::FONT_WEIGHT_NORMAL)
|
|
831
|
+
cr.set_font_size(font_size(obj_type) / 1000)
|
|
832
|
+
cr_te = cr.text_extents(text)
|
|
833
|
+
# p "width=#{cr_te.width} x_bearing=#{cr_te.x_bearing} height=#{cr_te.height} y_bearing=#{cr_te.y_bearing}"
|
|
834
|
+
case alignment
|
|
835
|
+
when ALIGN_CENTER
|
|
836
|
+
# calc text draww postion
|
|
837
|
+
x2 = x - (cr_te.width + cr_te.x_bearing) / 2
|
|
838
|
+
y2 = y - cr_te.y_bearing / 2
|
|
839
|
+
when ALIGN_RIGHT
|
|
840
|
+
x2 = x - cr_te.width - cr_te.x_bearing - mm2dot(GAP_PORT)
|
|
841
|
+
y2 = y - cr_te.height - cr_te.y_bearing - 2
|
|
842
|
+
when ALIGN_LEFT
|
|
843
|
+
x2 = x + mm2dot(GAP_PORT)
|
|
844
|
+
y2 = y - cr_te.height - cr_te.y_bearing - 2
|
|
845
|
+
end
|
|
846
|
+
cr.move_to(x2, y2)
|
|
847
|
+
cr.show_text(text)
|
|
848
|
+
end
|
|
849
|
+
|
|
850
|
+
#----- Cairo Pango version -----#
|
|
851
|
+
def draw_text_h_cairo_pango(x, y, text, obj_type, alignment)
|
|
852
|
+
cr = @cairo_context_target
|
|
853
|
+
# pfd = Pango::FontDescription.new( "Times" )
|
|
854
|
+
pfd = Pango::FontDescription.new
|
|
855
|
+
pfd.absolute_size = font_size(obj_type)
|
|
856
|
+
plo = cr.create_pango_layout
|
|
857
|
+
plo.font_description = pfd
|
|
858
|
+
plo.alignment = alignment
|
|
859
|
+
plo.set_text(text)
|
|
860
|
+
rect2 = plo.get_pixel_extents[1]
|
|
861
|
+
|
|
862
|
+
case alignment
|
|
863
|
+
when ALIGN_CENTER
|
|
864
|
+
# calc text draww postion
|
|
865
|
+
x2 = x - rect2.rbearing / 2
|
|
866
|
+
y2 = y - rect2.descent / 2
|
|
867
|
+
when ALIGN_RIGHT
|
|
868
|
+
x2 = x - rect2.rbearing - mm2dot(GAP_PORT)
|
|
869
|
+
y2 = y - rect2.descent
|
|
870
|
+
when ALIGN_LEFT
|
|
871
|
+
x2 = x + mm2dot(GAP_PORT)
|
|
872
|
+
y2 = y - rect2.descent
|
|
873
|
+
end
|
|
874
|
+
cr.move_to(x2, y2)
|
|
875
|
+
cr.show_pango_layout(plo)
|
|
876
|
+
end
|
|
877
|
+
|
|
878
|
+
# x::Integer(dot)
|
|
879
|
+
# y::Integer(dot)
|
|
880
|
+
# obj_type::CELL_NAME, SIGNATURE_NAME, PORT_NAME
|
|
881
|
+
# alignment::ALIGN_CENTER, ALIGN_LEFT
|
|
882
|
+
def draw_text_v(x, y, text, obj_type, alignment)
|
|
883
|
+
# draw_text_v_gdk( x, y, text, obj_type, alignment )
|
|
884
|
+
draw_text_v_cairo(x, y, text, obj_type, alignment)
|
|
885
|
+
# draw_text_v_cairo_pango( x, y, text, obj_type, alignment )
|
|
886
|
+
end
|
|
887
|
+
|
|
888
|
+
#----- Gdk Pango version -----#
|
|
889
|
+
def draw_text_v_gdk(x, y, text, obj_type, alignment)
|
|
890
|
+
pc = @pango_context
|
|
891
|
+
plo = @pango_layout
|
|
892
|
+
pm = @pango_matrix
|
|
893
|
+
pc.matrix = pm
|
|
894
|
+
plo.text = text
|
|
895
|
+
pfd = pc.font_description
|
|
896
|
+
pfd.absolute_size = font_size(obj_type)
|
|
897
|
+
plo.font_description = pfd
|
|
898
|
+
plo.alignment = alignment
|
|
899
|
+
# plo.context_changed
|
|
900
|
+
rect2 = plo.get_pixel_extents[1]
|
|
901
|
+
|
|
902
|
+
case alignment
|
|
903
|
+
when ALIGN_CENTER
|
|
904
|
+
# calc text draww postion
|
|
905
|
+
x2 = x - rect2.descent / 2
|
|
906
|
+
y2 = y - rect2.rbearing / 2
|
|
907
|
+
when ALIGN_RIGHT
|
|
908
|
+
x2 = x - rect2.descent
|
|
909
|
+
y2 = y + mm2dot(GAP_PORT)
|
|
910
|
+
when ALIGN_LEFT
|
|
911
|
+
x2 = x - rect2.descent
|
|
912
|
+
y2 = y - rect2.rbearing - mm2dot(GAP_PORT)
|
|
913
|
+
end
|
|
914
|
+
|
|
915
|
+
@draw_target.draw_layout(@canvas_gc, x2, y2, plo)
|
|
916
|
+
end
|
|
917
|
+
|
|
918
|
+
#----- Cairo version -----#
|
|
919
|
+
def draw_text_v_cairo(x, y, text, obj_type, alignment)
|
|
920
|
+
cr = @cairo_context_target
|
|
921
|
+
cr.select_font_face(nil, # "courier", # font_family = "Times New Roman",
|
|
922
|
+
Cairo::FONT_SLANT_NORMAL,
|
|
923
|
+
Cairo::FONT_WEIGHT_NORMAL)
|
|
924
|
+
cr.set_font_size(font_size(obj_type) / 1000)
|
|
925
|
+
cr_te = cr.text_extents(text)
|
|
926
|
+
# p "width=#{cr_te.width} x_bearing=#{cr_te.x_bearing} height=#{cr_te.height} y_bearing=#{cr_te.y_bearing}"
|
|
927
|
+
case alignment
|
|
928
|
+
when ALIGN_CENTER # this case is not used & not checked
|
|
929
|
+
# calc text draww postion
|
|
930
|
+
x2 = x - 2
|
|
931
|
+
y2 = y - (cr_te.width + cr_te.x_bearing) / 2
|
|
932
|
+
when ALIGN_RIGHT
|
|
933
|
+
x2 = x - 2
|
|
934
|
+
y2 = y + cr_te.width + cr_te.x_bearing + mm2dot(GAP_PORT)
|
|
935
|
+
when ALIGN_LEFT
|
|
936
|
+
x2 = x - 2
|
|
937
|
+
y2 = y - mm2dot(GAP_PORT)
|
|
938
|
+
end
|
|
939
|
+
@cairo_matrix.set_rotate90(x2, y2) # rotate around (0, 0) then shift (x2, y2)
|
|
940
|
+
cr.matrix = @cairo_matrix
|
|
941
|
+
cr.move_to(0, 0) # this assumes that (0, 0) is left bottom of strings
|
|
942
|
+
cr.show_text(text)
|
|
943
|
+
@cairo_matrix.set_rotate0
|
|
944
|
+
cr.matrix = @cairo_matrix
|
|
945
|
+
end
|
|
946
|
+
|
|
947
|
+
#----- Cairo Pango version -----#
|
|
948
|
+
def draw_text_v_cairo_pango(x, y, text, obj_type, alignment)
|
|
949
|
+
cr = @cairo_context_target
|
|
950
|
+
# pfd = Pango::FontDescription.new( "Times" )
|
|
951
|
+
pfd = Pango::FontDescription.new
|
|
952
|
+
pfd.absolute_size = font_size(obj_type)
|
|
953
|
+
# p "font_size=#{font_size( obj_type )}"
|
|
954
|
+
plo = cr.create_pango_layout
|
|
955
|
+
plo.font_description = pfd
|
|
956
|
+
plo.alignment = alignment
|
|
957
|
+
plo.set_text(text)
|
|
958
|
+
rect2 = plo.get_pixel_extents[1]
|
|
959
|
+
# p "descent=#{rect2.descent}, rbearing=#{rect2.rbearing}"
|
|
960
|
+
|
|
961
|
+
case alignment
|
|
962
|
+
when ALIGN_CENTER
|
|
963
|
+
# calc text draww postion
|
|
964
|
+
x2 = x - rect2.descent / 2
|
|
965
|
+
y2 = y - rect2.rbearing / 2
|
|
966
|
+
when ALIGN_RIGHT
|
|
967
|
+
x2 = x
|
|
968
|
+
y2 = y + rect2.rbearing + mm2dot(GAP_PORT)
|
|
969
|
+
when ALIGN_LEFT
|
|
970
|
+
x2 = x
|
|
971
|
+
y2 = y - mm2dot(GAP_PORT)
|
|
972
|
+
end
|
|
973
|
+
|
|
974
|
+
matrix = Cairo::Matrix.new(0, -1, 1, 0, x2, y2)
|
|
975
|
+
cr.matrix = matrix
|
|
976
|
+
cr.move_to(0, 0) # this assumes that (0, 0) is left bottom of strings
|
|
977
|
+
cr.show_text(text)
|
|
978
|
+
cr.matrix = Cairo::Matrix.new(1, 0, 0, 1, 0, 0)
|
|
979
|
+
end
|
|
980
|
+
|
|
981
|
+
#---------- Cell name editor ---------#
|
|
982
|
+
def create_edit_window
|
|
983
|
+
@entry = Gtk::Entry.new
|
|
984
|
+
@entry.set_has_frame(true)
|
|
985
|
+
|
|
986
|
+
@entry_win = Gtk::Window.new(Gtk::Window::TOPLEVEL)
|
|
987
|
+
@entry_win.add(@entry)
|
|
988
|
+
@entry_win.realize
|
|
989
|
+
@entry_win.window.reparent(@canvas.window, 0, 0) # Gdk level operation
|
|
990
|
+
|
|
991
|
+
# these steps are to avoid to move ( 0, 0 ) at 1st appear
|
|
992
|
+
@entry_win.show_all
|
|
993
|
+
@entry_win.hide
|
|
994
|
+
end
|
|
995
|
+
|
|
996
|
+
def begin_edit_name(cell, time)
|
|
997
|
+
@entry.set_text(cell.get_name)
|
|
998
|
+
|
|
999
|
+
x, y, w, h = get_cell_name_edit_area(cell)
|
|
1000
|
+
# p "x=#{x} y=#{y} w=#{w} h=#{h}"
|
|
1001
|
+
@entry_win.window.move(x - 3, y - 6) # Gdk level operation
|
|
1002
|
+
@entry_win.window.resize(w + 6, h + 8) # Gdk level operation
|
|
1003
|
+
@entry_win.show_all
|
|
1004
|
+
end
|
|
1005
|
+
|
|
1006
|
+
def end_edit_name
|
|
1007
|
+
name = @entry.text
|
|
1008
|
+
@entry_win.hide
|
|
1009
|
+
name
|
|
1010
|
+
end
|
|
1011
|
+
|
|
1012
|
+
def get_cell_name_edit_area(cell)
|
|
1013
|
+
name = cell.get_name
|
|
1014
|
+
obj_type = CELL_NAME
|
|
1015
|
+
alignment = ALIGN_CENTER
|
|
1016
|
+
direction = TEXT_HORIZONTAL
|
|
1017
|
+
wmn, hmn = get_text_extent(name, obj_type, alignment, direction)
|
|
1018
|
+
xm, ym, wm, hm = cell.get_geometry
|
|
1019
|
+
x = mm2dot(xm + (wm - wmn) / 2)
|
|
1020
|
+
y = mm2dot(ym + hm / 2 + 1)
|
|
1021
|
+
# y = mm2dot( ym + hm / 2 - hmn )
|
|
1022
|
+
w = mm2dot(wmn)
|
|
1023
|
+
h = mm2dot(hmn)
|
|
1024
|
+
|
|
1025
|
+
[x, y, w, h]
|
|
1026
|
+
end
|
|
1027
|
+
|
|
1028
|
+
#------ Convert Unit ------#
|
|
1029
|
+
|
|
1030
|
+
#=== convert mm to dot
|
|
1031
|
+
def mm2dot(mm)
|
|
1032
|
+
(@scale_val * mm * DPI / 25.4 / 100).to_i
|
|
1033
|
+
end
|
|
1034
|
+
|
|
1035
|
+
#=== convert dot to mm
|
|
1036
|
+
def dot2mm(dot)
|
|
1037
|
+
dot * 100 * 25.4 / DPI / @scale_val
|
|
1038
|
+
end
|
|
1039
|
+
|
|
1040
|
+
#=== font_size
|
|
1041
|
+
# obj_type::Integer CELL_NAME, SIGNATURE_NAME, PORT_NAME
|
|
1042
|
+
def font_size(obj_type)
|
|
1043
|
+
case obj_type
|
|
1044
|
+
when CELL_NAME
|
|
1045
|
+
base_size = 10500
|
|
1046
|
+
when CELLTYPE_NAME
|
|
1047
|
+
base_size = 10500
|
|
1048
|
+
when CELL_NAME_L
|
|
1049
|
+
base_size = 16000
|
|
1050
|
+
when SIGNATURE_NAME
|
|
1051
|
+
base_size = 9000
|
|
1052
|
+
when PORT_NAME
|
|
1053
|
+
base_size = 9000
|
|
1054
|
+
when PAPER_COMMENT
|
|
1055
|
+
base_size = 10500
|
|
1056
|
+
end
|
|
1057
|
+
base_size * @scale_val / 100.0 * DPI / 96.0
|
|
1058
|
+
end
|
|
1059
|
+
|
|
1060
|
+
#------ handle CanvasGC ------#
|
|
1061
|
+
def canvas_gc_reset
|
|
1062
|
+
@canvas_gc.function = Gdk::GC::COPY
|
|
1063
|
+
@canvas_gc.fill = Gdk::GC::SOLID
|
|
1064
|
+
@canvas_gc.foreground = @@colors[Color_editable]
|
|
1065
|
+
|
|
1066
|
+
@cairo_context_target.restore
|
|
1067
|
+
@cairo_context_target.save # prepare for next time
|
|
1068
|
+
@cairo_context_target.matrix = @cairo_matrix
|
|
1069
|
+
end
|
|
1070
|
+
|
|
1071
|
+
def canvas_gc_set_line_width(width)
|
|
1072
|
+
line_attr = @canvas_gc.line_attributes
|
|
1073
|
+
line_attr[0] = width
|
|
1074
|
+
@canvas_gc.set_line_attributes(*line_attr)
|
|
1075
|
+
end
|
|
1076
|
+
|
|
1077
|
+
def self.setup_colormap
|
|
1078
|
+
if !@@colors.nil?
|
|
1079
|
+
return
|
|
1080
|
+
end
|
|
1081
|
+
|
|
1082
|
+
@@colors = {}
|
|
1083
|
+
@@colormap = Gdk::Colormap.system
|
|
1084
|
+
|
|
1085
|
+
[
|
|
1086
|
+
:black, :white, :gray, :yellow, :orange, :skyblue, :magenta, :red, :blue, :green,
|
|
1087
|
+
:cyan, :brown, :violet, :lavender, :MistyRose, :lightyellow, :LightCyan, :Beige,
|
|
1088
|
+
:PapayaWhip, :Violet, :pink
|
|
1089
|
+
].each do |color_name|
|
|
1090
|
+
setup_colormap_1 color_name
|
|
1091
|
+
end
|
|
1092
|
+
setup_colormap_2(:ultraLightGreen, Gdk::Color.new(0xE000, 0xFF00, 0xE000))
|
|
1093
|
+
setup_colormap_1(Color_editable_cell)
|
|
1094
|
+
|
|
1095
|
+
@@cell_paint_colors = [
|
|
1096
|
+
:MistyRose, :lightyellow, :LightCyan, :ultraLightGreen, :lavender, :Beige,
|
|
1097
|
+
:PapayaWhip, :Violet, :pink
|
|
1098
|
+
]
|
|
1099
|
+
# plum: light purble (pastel)
|
|
1100
|
+
# pink: light magenta (pastel)
|
|
1101
|
+
# lavender: light blue (pastel)
|
|
1102
|
+
# lightyellow: light yellow (pastel)
|
|
1103
|
+
@@cell_paint_color_index = 0
|
|
1104
|
+
@@cell_file_to_color = {}
|
|
1105
|
+
end
|
|
1106
|
+
|
|
1107
|
+
def self.setup_colormap_1(name)
|
|
1108
|
+
color = Gdk::Color.parse(name.to_s)
|
|
1109
|
+
setup_colormap_2(name, color)
|
|
1110
|
+
end
|
|
1111
|
+
|
|
1112
|
+
def self.setup_colormap_2(name, color)
|
|
1113
|
+
@@colors[name] = color
|
|
1114
|
+
@@colormap.alloc_color(color, false, true)
|
|
1115
|
+
end
|
|
1116
|
+
|
|
1117
|
+
#----- cell paint colors -----#
|
|
1118
|
+
|
|
1119
|
+
def get_cell_paint_color(cell)
|
|
1120
|
+
if @b_color_by_region
|
|
1121
|
+
region = cell.get_region
|
|
1122
|
+
color = @@cell_file_to_color[region]
|
|
1123
|
+
if color
|
|
1124
|
+
return color
|
|
1125
|
+
end
|
|
1126
|
+
obj = region
|
|
1127
|
+
else
|
|
1128
|
+
tecsgen_cell = cell.get_tecsgen_cell
|
|
1129
|
+
if tecsgen_cell.nil? || cell.editable?
|
|
1130
|
+
return @@colors[Color_editable_cell]
|
|
1131
|
+
end
|
|
1132
|
+
file = tecsgen_cell.get_locale[0]
|
|
1133
|
+
color = @@cell_file_to_color[file]
|
|
1134
|
+
if color
|
|
1135
|
+
return color
|
|
1136
|
+
end
|
|
1137
|
+
obj = file
|
|
1138
|
+
end
|
|
1139
|
+
if @@cell_paint_color_index >= @@cell_paint_colors.length
|
|
1140
|
+
@@cell_paint_color_index = 0
|
|
1141
|
+
end
|
|
1142
|
+
col_name = @@cell_paint_colors[@@cell_paint_color_index]
|
|
1143
|
+
@@cell_file_to_color[obj] = @@colors[col_name]
|
|
1144
|
+
@@cell_paint_color_index += 1
|
|
1145
|
+
# p "col_name:#{col_name} index:#{@@cell_paint_color_index}"
|
|
1146
|
+
@@colors[col_name]
|
|
1147
|
+
end
|
|
1148
|
+
|
|
1149
|
+
#------ export ------#
|
|
1150
|
+
def export(fname)
|
|
1151
|
+
begin
|
|
1152
|
+
if File.exist?(fname)
|
|
1153
|
+
File.unlink(fname)
|
|
1154
|
+
end
|
|
1155
|
+
rescue => evar
|
|
1156
|
+
TECSCDE.message_box("fail to remove #{fname}\n#{evar}", :OK)
|
|
1157
|
+
return
|
|
1158
|
+
end
|
|
1159
|
+
|
|
1160
|
+
scale_val_bak = @scale_val
|
|
1161
|
+
@scale_val = 72.0 / TECSCDE::DPI * 100 # PDF surface = 72 DPI, mm2dot assume 100 DPI by default
|
|
1162
|
+
target_bak = @cairo_context_target
|
|
1163
|
+
|
|
1164
|
+
paper = @model.paper.cairo_paper_class
|
|
1165
|
+
paper_width = paper.width("pt") - mm2dot(PAPER_MARGIN * 2)
|
|
1166
|
+
paper_height = paper.height("pt") - mm2dot(PAPER_MARGIN * 2)
|
|
1167
|
+
begin
|
|
1168
|
+
surface = Cairo::PDFSurface.new(fname, paper.width("pt"), paper.height("pt"))
|
|
1169
|
+
@cairo_context_target = Cairo::Context.new(surface)
|
|
1170
|
+
|
|
1171
|
+
#----- set paper margin -----#
|
|
1172
|
+
@cairo_matrix.set_base_shift(mm2dot(PAPER_MARGIN), mm2dot(PAPER_MARGIN))
|
|
1173
|
+
@cairo_context_target.matrix = @cairo_matrix
|
|
1174
|
+
|
|
1175
|
+
#----- clip in rectangle frame -----#
|
|
1176
|
+
@cairo_context_target.rectangle(0, 0, paper_width, paper_height)
|
|
1177
|
+
@cairo_context_target.clip(false) # preserve = false
|
|
1178
|
+
@cairo_context_target.save # (* pair *) # must be saved initially
|
|
1179
|
+
|
|
1180
|
+
#----- draw contents of PDF -----#
|
|
1181
|
+
paint_canvas
|
|
1182
|
+
|
|
1183
|
+
#----- draw model name -----#
|
|
1184
|
+
draw_text(paper_width, paper_height, @model.file_editing, PAPER_COMMENT, ALIGN_RIGHT, TEXT_HORIZONTAL)
|
|
1185
|
+
|
|
1186
|
+
#----- draw rectangle frame around paper -----#
|
|
1187
|
+
@cairo_context_target.rectangle(0, 0, paper_width, paper_height)
|
|
1188
|
+
@cairo_context_target.stroke
|
|
1189
|
+
|
|
1190
|
+
#----- complete PDF file -----#
|
|
1191
|
+
surface.finish
|
|
1192
|
+
|
|
1193
|
+
#----- reset context -----#
|
|
1194
|
+
# cairo_context_target: unnecessary because the context is abandoned after this
|
|
1195
|
+
# @cairo_matrix.set_base_shift( 0, 0 )
|
|
1196
|
+
# @cairo_context_target.matrix = @cairo_matrix
|
|
1197
|
+
# @cairo_context_target.restore # (* pair *)
|
|
1198
|
+
rescue => evar
|
|
1199
|
+
TECSCDE.logger.error(evar)
|
|
1200
|
+
TECSCDE.message_box("fail to writ to #{fname}\n#{evar}", :OK)
|
|
1201
|
+
ensure
|
|
1202
|
+
@cairo_context_target = target_bak
|
|
1203
|
+
@cairo_matrix.set_base_shift(0, 0)
|
|
1204
|
+
@scale_val = scale_val_bak
|
|
1205
|
+
surface&.finish
|
|
1206
|
+
end
|
|
1207
|
+
|
|
1208
|
+
paint_canvas
|
|
1209
|
+
end
|
|
1210
|
+
|
|
1211
|
+
#=== MainView#div_string
|
|
1212
|
+
# divide string near center at A-Z or '_'
|
|
1213
|
+
def div_string(str)
|
|
1214
|
+
len = str.length
|
|
1215
|
+
if len <= 4
|
|
1216
|
+
return [str, ""]
|
|
1217
|
+
end
|
|
1218
|
+
|
|
1219
|
+
center = len / 2
|
|
1220
|
+
i = 0
|
|
1221
|
+
n = 0
|
|
1222
|
+
while (center / 2 > i) && (i < center) && !str[center + i].nil?
|
|
1223
|
+
char_i = str[center - i]
|
|
1224
|
+
char_j = str[center + i]
|
|
1225
|
+
if char_j == CHAR__ || (CHAR_A <= char_j && char_j <= CHAR_Z)
|
|
1226
|
+
n = center + i
|
|
1227
|
+
break
|
|
1228
|
+
elsif CHAR_A <= char_i && char_i <= CHAR_Z
|
|
1229
|
+
n = center - i
|
|
1230
|
+
break
|
|
1231
|
+
elsif char_i == CHAR__
|
|
1232
|
+
n = center - i + 1
|
|
1233
|
+
break
|
|
1234
|
+
end
|
|
1235
|
+
i += 1
|
|
1236
|
+
end
|
|
1237
|
+
if n > 0
|
|
1238
|
+
return [str[0, n], str[n, len]]
|
|
1239
|
+
else
|
|
1240
|
+
return [str[0, len / 2], str[len / 2, len]]
|
|
1241
|
+
end
|
|
1242
|
+
end
|
|
1243
|
+
end
|
|
1244
|
+
end
|
|
1245
|
+
end
|