autocad 0.4.6 → 0.5
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 +4 -4
- data/.rubocop/minitest.yml +2 -2
- data/.rubocop/strict.yml +4 -4
- data/.rubocop.yml +36 -33
- data/CHANGELOG.md +5 -5
- data/LICENSE.txt +21 -21
- data/README.md +134 -39
- data/Rakefile +26 -10
- data/exe/autocad +3 -3
- data/gemfiles/rubocop.gemfile +2 -1
- data/lib/autocad/app.rb +127 -28
- data/lib/autocad/arc.rb +3 -0
- data/lib/autocad/block.rb +11 -6
- data/lib/autocad/block_reference.rb +33 -4
- data/lib/autocad/bounding_box.rb +202 -0
- data/lib/autocad/dim_style.rb +4 -0
- data/lib/autocad/drawing.rb +873 -172
- data/lib/autocad/element.rb +217 -25
- data/lib/autocad/errors.rb +9 -0
- data/lib/autocad/filter.rb +502 -168
- data/lib/autocad/layer.rb +129 -41
- data/lib/autocad/layout.rb +120 -0
- data/lib/autocad/line.rb +154 -55
- data/lib/autocad/message_box.rb +95 -95
- data/lib/autocad/model.rb +217 -89
- data/lib/autocad/mtext.rb +189 -110
- data/lib/autocad/plot.rb +45 -0
- data/lib/autocad/plot_configuration.rb +372 -0
- data/lib/autocad/point.rb +7 -0
- data/lib/autocad/point3d.rb +18 -11
- data/lib/autocad/pviewport.rb +136 -21
- data/lib/autocad/selection_filter.rb +358 -180
- data/lib/autocad/selection_set.rb +140 -61
- data/lib/autocad/selection_set_adapter.rb +187 -8
- data/lib/autocad/spline.rb +27 -0
- data/lib/autocad/text.rb +66 -11
- data/lib/autocad/text_style.rb +4 -0
- data/lib/autocad/version.rb +1 -1
- data/lib/autocad/viewport.rb +57 -0
- data/lib/autocad.rb +126 -30
- data/lib/faa/cleanup.rb +137 -0
- data/lib/win32ole_helper.rb +52 -0
- data/rbs_collection.lock.yaml +38 -18
- data/sig/generated/autocad/app.rbs +278 -251
- data/sig/generated/autocad/arc.rbs +6 -3
- data/sig/generated/autocad/block.rbs +8 -5
- data/sig/generated/autocad/block_reference.rbs +99 -59
- data/sig/generated/autocad/bounding_box.rbs +78 -0
- data/sig/generated/autocad/dim_style.rbs +6 -0
- data/sig/generated/autocad/drawing.rbs +597 -158
- data/sig/generated/autocad/element.rbs +233 -166
- data/sig/generated/autocad/errors.rbs +29 -23
- data/sig/generated/autocad/filter.rbs +388 -60
- data/sig/generated/autocad/layer.rbs +76 -19
- data/sig/generated/autocad/layout.rbs +64 -0
- data/sig/generated/autocad/line.rbs +128 -25
- data/sig/generated/autocad/message_box.rbs +81 -81
- data/sig/generated/autocad/model.rbs +115 -41
- data/sig/generated/autocad/mtext.rbs +123 -0
- data/sig/generated/autocad/plot.rbs +26 -0
- data/sig/generated/autocad/plot_configuration.rbs +176 -0
- data/sig/generated/autocad/point.rbs +7 -0
- data/sig/generated/autocad/point3d.rbs +70 -66
- data/sig/generated/autocad/pviewport.rbs +64 -0
- data/sig/generated/autocad/selection_filter.rbs +226 -50
- data/sig/generated/autocad/selection_set.rbs +112 -37
- data/sig/generated/autocad/selection_set_adapter.rbs +235 -28
- data/sig/generated/autocad/spline.rbs +22 -0
- data/sig/generated/autocad/text.rbs +66 -7
- data/sig/generated/autocad/text_style.rbs +6 -0
- data/sig/generated/autocad/viewport.rbs +19 -2
- data/sig/generated/autocad.rbs +140 -68
- data/sig/generated/faa/cleanup.rbs +53 -0
- data/sig/generated/win32ole_helper.rbs +9 -0
- data/sig/prototype/lib/autocad/app.rbs +3 -1
- data/sig/prototype/lib/autocad/bounding_box.rbs +15 -0
- data/sig/prototype/lib/autocad/drawing.rbs +6 -0
- data/sig/prototype/lib/autocad/layer.rbs +5 -0
- data/sig/prototype/lib/autocad/viewport.rbs +7 -0
- data/sig/prototype/lib/autocad.rbs +1 -1
- metadata +29 -5
- data/event_handler.log +0 -24
- data/sig/generated/autocad/text_node.rbs +0 -37
@@ -1,61 +1,140 @@
|
|
1
|
-
# require_relative "selection_filter"
|
2
|
-
require_relative
|
3
|
-
|
4
|
-
module Autocad
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
#
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
1
|
+
# require_relative "selection_filter"
|
2
|
+
require_relative "filter"
|
3
|
+
|
4
|
+
module Autocad
|
5
|
+
# Manages named selection criteria for AutoCAD entities
|
6
|
+
#
|
7
|
+
# Stores filter criteria for entity selection without executing the selection.
|
8
|
+
# Works with SelectionSetAdapter to apply filters and retrieve entities.
|
9
|
+
#
|
10
|
+
# @example Create a selection set with complex filters
|
11
|
+
# ss = SelectionSet.new("walls")
|
12
|
+
# ss.filter do |f|
|
13
|
+
# f.and(f.layer("WALLS"), f.or(f.type("LINE"), f.type("POLYLINE")))
|
14
|
+
# end
|
15
|
+
class SelectionSet
|
16
|
+
# @rbs attr_reader name: String -- Unique identifier for the selection set
|
17
|
+
# @rbs attr_reader filter_types: Array[Integer] -- AutoCAD group codes (DXF codes)
|
18
|
+
# @rbs attr_reader filter_values: Array[untyped] -- Filter values matching group codes
|
19
|
+
attr_reader :filter_types, :filter_values, :name
|
20
|
+
|
21
|
+
# Initialize a new selection set with a name
|
22
|
+
# @param name [String] Unique identifier for the selection set
|
23
|
+
# @rbs name: String
|
24
|
+
# @rbs return void
|
25
|
+
def initialize(name)
|
26
|
+
@name = name
|
27
|
+
@filter_types = []
|
28
|
+
@filter_values = []
|
29
|
+
end
|
30
|
+
|
31
|
+
# Check if set has active filters
|
32
|
+
# @return [Boolean] True if filters are defined
|
33
|
+
# @rbs return bool
|
34
|
+
def has_filter?
|
35
|
+
filter_types && filter_types.any?
|
36
|
+
end
|
37
|
+
|
38
|
+
# Filter for text entities with optional content matching
|
39
|
+
# @param str [String, nil] Optional text pattern to match
|
40
|
+
# @return [self] The selection set for chaining
|
41
|
+
# @example Filter all text entities
|
42
|
+
# ss.filter_text
|
43
|
+
# @example Filter text with specific content
|
44
|
+
# ss.filter_text("Revision")
|
45
|
+
# @rbs str: String? -- Optional text pattern to match
|
46
|
+
# @rbs return self
|
47
|
+
def filter_text(str = nil)
|
48
|
+
if str
|
49
|
+
filter_text_containing(str)
|
50
|
+
else
|
51
|
+
filter do |f|
|
52
|
+
f.or(f.type("TEXT"), f.type("MTEXT"))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Configure complex filters through block
|
58
|
+
# @yield [Filter] Block for building filter criteria
|
59
|
+
# @return [self] The selection set for chaining
|
60
|
+
# @example Create a filter for red circles
|
61
|
+
# ss.filter do |f|
|
62
|
+
# f.and(f.type("CIRCLE"), f.color(1))
|
63
|
+
# end
|
64
|
+
# @example Combine multiple conditions
|
65
|
+
# ss.filter do |f|
|
66
|
+
# st = f.type('Circle').or(f.type('Arc'))
|
67
|
+
# st2 = f.layer('0').or(f.layer('1'))
|
68
|
+
# f.and(st, st2)
|
69
|
+
# end
|
70
|
+
# @rbs &: (Filter) -> Filter
|
71
|
+
# @rbs return self
|
72
|
+
def filter
|
73
|
+
if block_given?
|
74
|
+
filter = Filter.new
|
75
|
+
result = yield filter
|
76
|
+
@filter_types, @filter_values = result.convert_clauses
|
77
|
+
end
|
78
|
+
self
|
79
|
+
end
|
80
|
+
|
81
|
+
# Clear all filter criteria
|
82
|
+
# @return [self] The selection set for chaining
|
83
|
+
# @rbs return self
|
84
|
+
def clear_filter
|
85
|
+
@filter_types = []
|
86
|
+
@filter_values = []
|
87
|
+
self
|
88
|
+
end
|
89
|
+
|
90
|
+
# Helper methods for common operations
|
91
|
+
|
92
|
+
# Filter by entity types
|
93
|
+
# @param types [Array<String>] Entity type names (e.g., "LINE", "CIRCLE")
|
94
|
+
# @return [self] The selection set for chaining
|
95
|
+
# @example Filter for lines and polylines
|
96
|
+
# ss.filter_by_type("LINE", "POLYLINE")
|
97
|
+
# @rbs *types: Array[String]
|
98
|
+
# @rbs return self
|
99
|
+
def filter_by_type(*types)
|
100
|
+
filter { |f| f.or(*types.map { |t| f.type(t) }) }
|
101
|
+
end
|
102
|
+
|
103
|
+
# Filter by layer names
|
104
|
+
# @param layers [Array<String>] Layer names to filter
|
105
|
+
# @return [self] The selection set for chaining
|
106
|
+
# @example Filter for entities on specific layers
|
107
|
+
# ss.filter_by_layer("WALLS", "DOORS")
|
108
|
+
# @rbs *layers: Array[String]
|
109
|
+
# @rbs return self
|
110
|
+
def filter_by_layer(*layers)
|
111
|
+
filter { |f| f.or(*layers.map { |l| f.layer(l) }) }
|
112
|
+
end
|
113
|
+
|
114
|
+
# Filter text entities containing specific text
|
115
|
+
# @param text [String] Text pattern to search for (supports wildcards)
|
116
|
+
# @return [self] The selection set for chaining
|
117
|
+
# @example Find text containing "NOTE"
|
118
|
+
# ss.filter_text_containing("*NOTE*")
|
119
|
+
# @rbs text: String
|
120
|
+
# @rbs return self
|
121
|
+
def filter_text_containing(text)
|
122
|
+
filter do |f|
|
123
|
+
f.and(f.has_text(text), f.or(f.type("TEXT"), f.type("MTEXT")))
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Filter for block references with optional name
|
128
|
+
# @param name [String, nil] Optional block name to filter
|
129
|
+
# @return [self] The selection set for chaining
|
130
|
+
# @example Filter for any block reference
|
131
|
+
# ss.filter_block_references
|
132
|
+
# @example Filter for specific block
|
133
|
+
# ss.filter_block_references("DOOR")
|
134
|
+
# @rbs name: String?
|
135
|
+
# @rbs return self
|
136
|
+
def filter_block_references(name = nil)
|
137
|
+
filter { |f| f.block_reference(name) }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -1,71 +1,208 @@
|
|
1
1
|
module Autocad
|
2
|
+
# Manages AutoCAD selection set operations and OLE integration
|
3
|
+
#
|
4
|
+
# Executes selections using stored criteria and provides access to selected entities.
|
5
|
+
# Bridges between Ruby selection criteria and AutoCAD's native selection mechanisms.
|
6
|
+
#
|
7
|
+
# Key Features:
|
8
|
+
# - Multiple selection methods (window, crossing, fence, point)
|
9
|
+
# - Filter-based entity selection
|
10
|
+
# - Enumeration of selected entities
|
11
|
+
# - OLE integration with AutoCAD
|
12
|
+
#
|
13
|
+
# @example Create and use a selection set
|
14
|
+
# ss = drawing.create_selection_set("walls")
|
15
|
+
# ss.filter { |f| f.layer("WALLS") }
|
16
|
+
# ss.select(mode: :all)
|
17
|
+
# ss.each { |wall| wall.color = 1 }
|
2
18
|
class SelectionSetAdapter
|
19
|
+
# Initialize from OLE object
|
20
|
+
# @param drawing [Drawing] Parent drawing document
|
21
|
+
# @param ole [WIN32OLE] AutoCAD OLE selection set object
|
22
|
+
# @return [SelectionSetAdapter] New adapter instance
|
23
|
+
# @rbs drawing: Drawing
|
24
|
+
# @rbs ole: WIN32OLE
|
25
|
+
# @rbs return SelectionSetAdapter
|
3
26
|
def self.from_ole_obj(drawing, ole)
|
4
27
|
ss = SelectionSet.new(ole.Name)
|
5
28
|
new(drawing, ss, ole)
|
6
29
|
end
|
7
30
|
|
31
|
+
# @rbs attr_reader ole_obj: WIN32OLE -- Underlying OLE selection set
|
32
|
+
# @rbs attr_reader drawing: Drawing -- Parent drawing document
|
33
|
+
# @rbs attr_reader selection_set: SelectionSet -- Configured selection criteria
|
8
34
|
attr_reader :ole_obj, :drawing, :selection_set
|
9
35
|
|
36
|
+
# Initialize new adapter
|
37
|
+
# @param drawing [Drawing] Parent drawing document
|
38
|
+
# @param selection_set [SelectionSet] Selection criteria container
|
39
|
+
# @param ole [WIN32OLE, nil] Optional existing OLE selection set
|
40
|
+
# @rbs drawing: Drawing
|
41
|
+
# @rbs selection_set: SelectionSet
|
42
|
+
# @rbs ole: WIN32OLE?
|
43
|
+
# @rbs return void
|
10
44
|
def initialize(drawing, selection_set, ole = nil)
|
11
45
|
@drawing = drawing
|
12
46
|
@selection_set = selection_set
|
13
47
|
@ole_obj = ole || create_selection_set
|
14
48
|
end
|
15
49
|
|
50
|
+
# Delete the selection set from AutoCAD
|
51
|
+
# @return [void]
|
52
|
+
# @example Remove selection set when no longer needed
|
53
|
+
# ss.delete if ss.count == 0
|
54
|
+
# @rbs return void
|
16
55
|
def delete
|
17
56
|
@ole_obj.Delete
|
18
57
|
@selection_set = nil
|
19
58
|
end
|
20
59
|
|
21
|
-
#
|
22
|
-
# @
|
60
|
+
# Checks if the selection set has any items
|
61
|
+
# @return [Boolean] True if selection contains entities
|
62
|
+
# @example Skip processing if selection is empty
|
63
|
+
# next unless ss.has_items?
|
64
|
+
# @rbs return bool
|
23
65
|
def has_items?
|
24
66
|
ole_obj.Count > 0
|
25
67
|
end
|
26
68
|
|
69
|
+
# Get item count in selection set
|
70
|
+
# @return [Integer] Number of selected entities
|
71
|
+
# @example Report selection count
|
72
|
+
# puts "Selected #{ss.count} entities"
|
73
|
+
# @rbs return Integer
|
27
74
|
def count
|
28
75
|
ole_obj.Count
|
29
76
|
end
|
30
77
|
|
78
|
+
# Clear selection set contents
|
79
|
+
# @return [void]
|
80
|
+
# @example Clear before new selection
|
81
|
+
# ss.clear
|
82
|
+
# ss.select_on_screen
|
83
|
+
# @rbs return void
|
31
84
|
def clear
|
32
85
|
ole_obj.Clear
|
33
86
|
end
|
34
87
|
|
88
|
+
# Clear filter criteria
|
89
|
+
# @return [void]
|
90
|
+
# @example Reset filters for new selection
|
91
|
+
# ss.clear_filter
|
92
|
+
# ss.filter { |f| f.type("LINE") }
|
93
|
+
# @rbs return void
|
94
|
+
def clear_filter
|
95
|
+
selection_set.clear_filter
|
96
|
+
end
|
97
|
+
|
98
|
+
# Set text content filter
|
99
|
+
# @param str [String] Text pattern to match
|
100
|
+
# @return [void]
|
101
|
+
# @example Filter for text with specific content
|
102
|
+
# ss.filter_text("Revision")
|
103
|
+
# @rbs str: String -- Text pattern to match
|
104
|
+
# @rbs return void
|
35
105
|
def filter_text(str)
|
36
106
|
@selection_set.filter_text(str)
|
37
107
|
end
|
38
108
|
|
109
|
+
# Filter text containing substring
|
110
|
+
# @param str [String] Substring to match
|
111
|
+
# @return [void]
|
112
|
+
# @example Find text containing "NOTE"
|
113
|
+
# ss.filter_text_containing("NOTE")
|
114
|
+
# @rbs str: String -- Substring to match
|
115
|
+
# @rbs return void
|
39
116
|
def filter_text_containing(str)
|
40
117
|
@selection_set.filter_text_containing(str)
|
41
118
|
end
|
42
119
|
|
120
|
+
# Get the application instance
|
121
|
+
# @return [Autocad::App] The application instance
|
122
|
+
# @private
|
43
123
|
def app
|
44
124
|
@drawing.app
|
45
125
|
end
|
46
126
|
|
127
|
+
# Iterate through selected entities
|
128
|
+
# @yield [Element] Block to process each entity
|
129
|
+
# @return [Enumerator<Element>] Enumerator of selected entities if no block given
|
130
|
+
# @example Process each selected entity
|
131
|
+
# ss.each { |entity| entity.color = 1 }
|
132
|
+
# @example Convert to array
|
133
|
+
# entities = ss.each.to_a
|
134
|
+
# @rbs &: (Element) -> void
|
135
|
+
# @rbs return Enumerator[Element]
|
47
136
|
def each
|
48
137
|
return to_enum(__callee__) unless block_given?
|
49
138
|
|
50
139
|
ole_obj.each { |o| yield app.wrap(o) }
|
51
140
|
end
|
52
141
|
|
142
|
+
# Get the name of the selection set
|
143
|
+
# @return [String] The selection set name
|
144
|
+
# @example Get selection set identifier
|
145
|
+
# puts "Working with selection set: #{ss.name}"
|
146
|
+
# @rbs return String
|
53
147
|
def name
|
54
148
|
@ole_obj.Name
|
55
149
|
end
|
56
150
|
|
151
|
+
# Get filter types from selection set
|
152
|
+
# @return [Array<Integer>] Array of DXF group codes
|
153
|
+
# @example Access raw filter data
|
154
|
+
# puts "Using filter types: #{ss.filter_types.join(', ')}"
|
155
|
+
# @rbs return Array[Integer]
|
57
156
|
def filter_types
|
58
157
|
@selection_set.filter_types
|
59
158
|
end
|
60
159
|
|
160
|
+
# Get filter values from selection set
|
161
|
+
# @return [Array<Object>] Array of filter values
|
162
|
+
# @example Access raw filter data
|
163
|
+
# puts "Using filter values: #{ss.filter_values.inspect}"
|
164
|
+
# @rbs return Array[untyped]
|
61
165
|
def filter_values
|
62
166
|
@selection_set.filter_values
|
63
167
|
end
|
64
168
|
|
169
|
+
# Select entities interactively on screen
|
170
|
+
# @param ft [WIN32OLE::Variant, nil] Optional filter types variant
|
171
|
+
# @param fv [WIN32OLE::Variant, nil] Optional filter values variant
|
172
|
+
# @return [void]
|
173
|
+
# @example Select entities with user interaction
|
174
|
+
# ss.select_on_screen
|
175
|
+
# @example Select with predefined filters
|
176
|
+
# ss.filter { |f| f.type("CIRCLE") }
|
177
|
+
# ss.select_on_screen
|
178
|
+
# @rbs ft: WIN32OLE::Variant? -- Filter types variant
|
179
|
+
# @rbs fv: WIN32OLE::Variant? -- Filter values variant
|
180
|
+
# @rbs return void
|
65
181
|
def select_on_screen(ft = ole_filter_types, fv = ole_filter_values)
|
66
|
-
|
182
|
+
if filter_types.empty? && filter_values.empty?
|
183
|
+
@ole_obj.SelectOnScreen(nil, nil)
|
184
|
+
else
|
185
|
+
@ole_obj.SelectOnScreen(ft, fv)
|
186
|
+
end
|
67
187
|
end
|
68
188
|
|
189
|
+
# Select entities using various methods
|
190
|
+
# @param mode [Symbol] Selection mode (:all, :window, :crossing, :previous, :last)
|
191
|
+
# @param pt1 [Point3d, nil] First point for window selection
|
192
|
+
# @param pt2 [Point3d, nil] Second point for window selection
|
193
|
+
# @param ft [WIN32OLE::Variant, nil] Optional filter types variant
|
194
|
+
# @param fv [WIN32OLE::Variant, nil] Optional filter values variant
|
195
|
+
# @return [void]
|
196
|
+
# @example Select all entities matching filter
|
197
|
+
# ss.select(mode: :all)
|
198
|
+
# @example Window selection
|
199
|
+
# ss.select(mode: :window, pt1: [0,0,0], pt2: [10,10,0])
|
200
|
+
# @rbs mode: Symbol -- Selection mode (:all, :window, :crossing, :previous, :last)
|
201
|
+
# @rbs pt1: Point3d? -- First point for window selection
|
202
|
+
# @rbs pt2: Point3d? -- Second point for window selection
|
203
|
+
# @rbs ft: WIN32OLE::Variant? -- Filter types variant
|
204
|
+
# @rbs fv: WIN32OLE::Variant? -- Filter values variant
|
205
|
+
# @rbs return void
|
69
206
|
def select(mode: :all, pt1: nil, pt2: nil, ft: ole_filter_types, fv: ole_filter_values)
|
70
207
|
acad_mode = case mode
|
71
208
|
when :all
|
@@ -82,9 +219,21 @@ module Autocad
|
|
82
219
|
Acad::AcSelectionSetAll
|
83
220
|
end
|
84
221
|
@ole_obj.Select(acad_mode, nil, nil, ft, fv)
|
222
|
+
rescue => ex
|
223
|
+
binding.irb
|
85
224
|
end
|
86
225
|
|
87
|
-
#
|
226
|
+
# Select entities at specific point
|
227
|
+
# @param x [Numeric, Point3d, Array<Numeric>] X coordinate or point object
|
228
|
+
# @param y [Numeric, nil] Y coordinate (if using separate coordinates)
|
229
|
+
# @return [void]
|
230
|
+
# @example Select at specific point
|
231
|
+
# ss.select_at_point(10, 20)
|
232
|
+
# @example Select at point object
|
233
|
+
# ss.select_at_point(Point3d.new(10, 20, 0))
|
234
|
+
# @rbs x: Numeric | Point3d | Array[Numeric] -- X coordinate or point object
|
235
|
+
# @rbs y: Numeric? -- Y coordinate (if using separate coordinates)
|
236
|
+
# @rbs return void
|
88
237
|
def select_at_point(x, y)
|
89
238
|
point = if x.respond_to?(:x) && x.respond_to?(:y)
|
90
239
|
# Handle Point3d object
|
@@ -100,11 +249,21 @@ module Autocad
|
|
100
249
|
@ole_obj.SelectAtPoint(point, filter_types, filter_values)
|
101
250
|
end
|
102
251
|
|
103
|
-
#
|
104
|
-
# @param
|
252
|
+
# Select entities using polygonal fence
|
253
|
+
# @param points [Array<Point3d>] Polygon vertices
|
254
|
+
# @param mode [Symbol] Selection mode (:fence, :window, :crossing)
|
255
|
+
# @return [void]
|
256
|
+
# @raise [ArgumentError] For invalid mode
|
257
|
+
# @example Select using fence
|
258
|
+
# points = [[0,0], [10,0], [10,10], [0,10]]
|
259
|
+
# ss.select_by_polygon(points: points, mode: :fence)
|
260
|
+
# @rbs points: Array[Point3d] -- Polygon vertices
|
261
|
+
# @rbs mode: Symbol -- Selection mode (:fence, :window, :crossing)
|
262
|
+
# @rbs return void
|
263
|
+
# @raise [ArgumentError] For invalid mode
|
105
264
|
def select_by_polygon(points: [], mode: :fence)
|
106
265
|
# Convert points to arrays of coordinates
|
107
|
-
point_coords = points.map { |p| [p.x, p.y] }
|
266
|
+
point_coords = points.map { |p| Point3d(p) }.map { |p| [p.x, p.y, p.z] }.flatten
|
108
267
|
|
109
268
|
mode_code = case mode
|
110
269
|
when :fence then 5
|
@@ -113,24 +272,44 @@ module Autocad
|
|
113
272
|
else
|
114
273
|
raise ArgumentError, "Invalid selection mode: #{mode}. Must be :fence, :window, or :crossing"
|
115
274
|
end
|
275
|
+
ole_point_coords = WIN32OLE::Variant.new(point_coords, WIN32OLE::VARIANT::VT_ARRAY | WIN32OLE::VARIANT::VT_R8)
|
116
276
|
|
117
|
-
|
277
|
+
binding.irb
|
278
|
+
@ole_obj.SelectByPolygon(mode_code, ole_point_coords, filter_types, filter_values)
|
118
279
|
end
|
119
280
|
|
281
|
+
# Configure filter through block
|
282
|
+
# @yield [Filter] Block for building filter criteria
|
283
|
+
# @return [void]
|
284
|
+
# @example Create complex filter
|
285
|
+
# ss.filter do |f|
|
286
|
+
# f.and(f.layer("WALLS"), f.or(f.type("LINE"), f.type("POLYLINE")))
|
287
|
+
# end
|
288
|
+
# @rbs &: (Filter) -> Filter
|
289
|
+
# @rbs return void
|
120
290
|
def filter(&)
|
121
291
|
@selection_set.filter(&)
|
122
292
|
end
|
123
293
|
|
124
294
|
private
|
125
295
|
|
296
|
+
# Create new OLE selection set
|
297
|
+
# @return [WIN32OLE] The created OLE selection set
|
298
|
+
# @rbs return WIN32OLE
|
126
299
|
def create_selection_set
|
127
300
|
@drawing.ole_obj.SelectionSets.Add(@selection_set.name)
|
128
301
|
end
|
129
302
|
|
303
|
+
# Convert filter types to OLE variant
|
304
|
+
# @return [WIN32OLE::Variant] OLE variant for filter types
|
305
|
+
# @rbs return WIN32OLE::Variant
|
130
306
|
def ole_filter_types
|
131
307
|
WIN32OLE::Variant.new(filter_types, WIN32OLE::VARIANT::VT_ARRAY | WIN32OLE::VARIANT::VT_I2)
|
132
308
|
end
|
133
309
|
|
310
|
+
# Convert filter values to OLE variant
|
311
|
+
# @return [WIN32OLE::Variant] OLE variant for filter values
|
312
|
+
# @rbs return WIN32OLE::Variant
|
134
313
|
def ole_filter_values
|
135
314
|
WIN32OLE::Variant.new(filter_values, WIN32OLE::VARIANT::VT_ARRAY | WIN32OLE::VARIANT::VT_VARIANT)
|
136
315
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Autocad
|
2
|
+
class Spline < Element
|
3
|
+
# @rbs return float -- The area of the arc
|
4
|
+
def area
|
5
|
+
@ole_obj.Area
|
6
|
+
end
|
7
|
+
|
8
|
+
# whether the spline is closed
|
9
|
+
def closed? # : bool
|
10
|
+
@ole_obj.Closed
|
11
|
+
end
|
12
|
+
|
13
|
+
# ole obj Variant (array of doubles)
|
14
|
+
# 3D WCS Control Points for the spline
|
15
|
+
# @rbs return Array(Point3d)
|
16
|
+
def control_points
|
17
|
+
end
|
18
|
+
|
19
|
+
# set the control points for the spline
|
20
|
+
# @rbs pts Array(Point3d) | Array(Array[Double,Double,Double?])
|
21
|
+
def control_points=(pts)
|
22
|
+
end
|
23
|
+
|
24
|
+
def degree
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/autocad/text.rb
CHANGED
@@ -1,38 +1,86 @@
|
|
1
|
+
# rbs_inline: enabled
|
2
|
+
|
1
3
|
require_relative "element"
|
2
4
|
|
3
5
|
module Autocad
|
6
|
+
# Single-line text annotation element in AutoCAD
|
7
|
+
#
|
8
|
+
# Represents a simple text entity with a single line of content.
|
9
|
+
# Provides methods for reading, writing, and manipulating text properties.
|
10
|
+
#
|
11
|
+
# @example Create and modify text
|
12
|
+
# text = drawing.model.add_text("Label", [10,5,0])
|
13
|
+
# text.height = 2.5
|
14
|
+
# text.update("New Label")
|
4
15
|
class Text < Element
|
16
|
+
# Read text content from OLE object
|
17
|
+
#
|
18
|
+
# @param _ole [WIN32OLE] The OLE object to read from (unused parameter)
|
19
|
+
# @return [String] The text content
|
20
|
+
# @rbs (_ole: WIN32OLE) -> String
|
5
21
|
def read_ole(_ole)
|
6
22
|
ole_obj.TextString
|
7
23
|
end
|
8
24
|
|
25
|
+
# Confirm this is a text element (always true)
|
26
|
+
#
|
27
|
+
# @return [Boolean] Always returns true for Text objects
|
28
|
+
# @rbs return bool
|
29
|
+
def text?
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
# Update text content in AutoCAD
|
34
|
+
#
|
35
|
+
# @param text [String] The new text content
|
36
|
+
# @return [void]
|
37
|
+
# @rbs text: String -> void
|
9
38
|
def write_ole(text)
|
10
39
|
ole_obj.TextString = text
|
11
40
|
end
|
12
41
|
|
42
|
+
# Convert text content to regex pattern
|
43
|
+
#
|
44
|
+
# @return [Regexp] A regular expression based on the text content
|
45
|
+
# @rbs return Regexp
|
13
46
|
def to_regexp
|
14
47
|
Regexp.new(read_ole.to_s)
|
15
48
|
end
|
16
49
|
|
50
|
+
# Toggle text highlighting in the drawing
|
51
|
+
#
|
52
|
+
# @param flag [Boolean] Whether to highlight (true) or unhighlight (false)
|
53
|
+
# @return [void]
|
54
|
+
# @example Highlight selected text
|
55
|
+
# selected_text.each { |t| t.highlight }
|
56
|
+
# @rbs flag: bool -> void
|
57
|
+
def highlight(flag = true)
|
58
|
+
ole_obj.Highlight(flag)
|
59
|
+
ole_obj.Update
|
60
|
+
end
|
61
|
+
|
62
|
+
# Regex pattern matching against text content
|
63
|
+
#
|
64
|
+
# @param reg [Regexp] The regular expression to match against
|
65
|
+
# @return [Integer, nil] Match position or nil if no match
|
66
|
+
# @rbs reg: Regexp -> Integer?
|
17
67
|
def =~(reg)
|
18
68
|
@original =~ reg
|
19
69
|
end
|
20
70
|
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# true
|
26
|
-
# end
|
27
|
-
|
28
|
-
# def text_node?
|
29
|
-
# false
|
30
|
-
# end
|
31
|
-
|
71
|
+
# Get text content as string
|
72
|
+
#
|
73
|
+
# @return [String] The text content
|
74
|
+
# @rbs return String
|
32
75
|
def to_s
|
33
76
|
original.to_s
|
34
77
|
end
|
35
78
|
|
79
|
+
# Experimental bounding box calculation
|
80
|
+
#
|
81
|
+
# @return [BoundingBox] The text's bounding box
|
82
|
+
# @note Contains debug code - use with caution
|
83
|
+
# @rbs return BoundingBox
|
36
84
|
def bounds
|
37
85
|
binding.break
|
38
86
|
rotation = ole_obj.Rotation
|
@@ -53,6 +101,13 @@ module Autocad
|
|
53
101
|
points[3].y = points[2].Y
|
54
102
|
end
|
55
103
|
|
104
|
+
# Delegate uppercase methods to OLE object, lowercase to string methods
|
105
|
+
#
|
106
|
+
# @param meth [Symbol] The method name
|
107
|
+
# @param * [Array] Method arguments
|
108
|
+
# @param & [Proc] Optional block
|
109
|
+
# @return [Object] Result of the method call
|
110
|
+
# @rbs (Symbol, *untyped) -> untyped
|
56
111
|
def method_missing(meth, *, &)
|
57
112
|
if /^[A-Z]/.match?(meth)
|
58
113
|
ole_obj.send(meth, *)
|
data/lib/autocad/version.rb
CHANGED