Class: Autocad::SelectionFilter
- Inherits:
-
Object
- Object
- Autocad::SelectionFilter
- Defined in:
- lib/autocad/selection_filter.rb
Overview
Builds AutoCAD selection filter criteria using group codes
Provides a fluent interface for creating complex entity filters based on AutoCAD DXF group codes and logical operations.
Key Features:
-
Logical operators (AND, OR, NOT, XOR)
-
Comparison operators (>, <, =, !=)
-
Entity property filters (type, layer, color)
-
Text content matching
-
Space-specific filtering (model/paper)
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
-
#and(*conditions) ⇒ self
Logical AND combination of filters.
-
#block_reference(name = nil) ⇒ self
Filter by block references.
-
#color(num) ⇒ self
Filter by color index.
-
#contains(str) ⇒ self
Filter text content using wildcards.
-
#equal_to(value) ⇒ self
Equal to comparison.
-
#greater_than(value) ⇒ self
Greater than comparison.
-
#has_filters? ⇒ Boolean
Check if filter has any conditions.
-
#has_text(str) ⇒ self
Helper method for text content matching.
-
#initialize ⇒ void
constructor
Initialize empty filter.
-
#layer(name) ⇒ self
Filter by layer name.
-
#less_than(value) ⇒ self
Less than comparison.
-
#model_space ⇒ self
Filter for model space entities.
-
#name(value) ⇒ self
Filter by entity name/type.
-
#not(condition) ⇒ self
Logical NOT for a filter condition.
-
#not_equal_to(value) ⇒ self
Not equal to comparison.
-
#or(*conditions) ⇒ self
Logical OR combination of filters.
-
#paper_space ⇒ self
Filter for paper space entities.
-
#type(kind) ⇒ self
Filter by entity type.
-
#visible(vis = true) ⇒ self
Filter by visibility state.
-
#xor(condition1, condition2) ⇒ self
Logical XOR combination of two filters.
Constructor Details
#initialize ⇒ void
Initialize empty filter
38 39 40 41 |
# File 'lib/autocad/selection_filter.rb', line 38 def initialize @types = [] @values = [] end |
Instance Attribute Details
#types ⇒ Object (readonly)
Returns the value of attribute types.
33 34 35 |
# File 'lib/autocad/selection_filter.rb', line 33 def types @types end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
33 34 35 |
# File 'lib/autocad/selection_filter.rb', line 33 def values @values end |
Instance Method Details
#and(*conditions) ⇒ self
Logical AND combination of filters
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/autocad/selection_filter.rb', line 62 def and(*conditions) return self if conditions.empty? @types << -4 @values << "<AND" conditions.each do |condition| @types.concat(condition.types) @values.concat(condition.values) end @types << -4 @values << "AND>" self end |
#block_reference(name = nil) ⇒ self
Filter by block references
225 226 227 228 229 230 231 |
# File 'lib/autocad/selection_filter.rb', line 225 def block_reference(name = nil) # return unless name @types << 0 @values << "INSERT" self end |
#color(num) ⇒ self
Filter by color index
294 295 296 297 298 |
# File 'lib/autocad/selection_filter.rb', line 294 def color(num) @types << 62 # Color number filter @values << num self end |
#contains(str) ⇒ self
Filter text content using wildcards
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/autocad/selection_filter.rb', line 329 def contains(str) @types << -4 @values << "<OR" # Filter for TEXT @types << 1 # Text string group code for TEXT @values << "*#{str}*" # Filter for MTEXT @types << 1 # Text string group code for MTEXT @values << "*#{str}*" @types << -4 @values << "OR>" self end |
#equal_to(value) ⇒ self
Equal to comparison
193 194 195 196 197 198 199 |
# File 'lib/autocad/selection_filter.rb', line 193 def equal_to(value) @types << -4 @values << "=" @types << 40 # floating point @values << value self end |
#greater_than(value) ⇒ self
Greater than comparison
163 164 165 166 167 168 169 |
# File 'lib/autocad/selection_filter.rb', line 163 def greater_than(value) @types << -4 @values << ">=" @types << 40 # floating point @values << value self end |
#has_filters? ⇒ Boolean
Check if filter has any conditions
48 49 50 |
# File 'lib/autocad/selection_filter.rb', line 48 def has_filters? @types.any? end |
#has_text(str) ⇒ self
Helper method for text content matching
354 355 356 |
# File 'lib/autocad/selection_filter.rb', line 354 def has_text(str) contains(str) end |
#layer(name) ⇒ self
Filter by layer name
266 267 268 269 270 |
# File 'lib/autocad/selection_filter.rb', line 266 def layer(name) @types << 8 @values << name self end |
#less_than(value) ⇒ self
Less than comparison
178 179 180 181 182 183 184 |
# File 'lib/autocad/selection_filter.rb', line 178 def less_than(value) @types << -4 @values << "<=" @types << 40 # floating point @values << value self end |
#model_space ⇒ self
Filter for model space entities
316 317 318 319 320 |
# File 'lib/autocad/selection_filter.rb', line 316 def model_space @types << 67 # Model space filter @values << 0 self end |
#name(value) ⇒ self
Filter by entity name/type
240 241 242 243 244 |
# File 'lib/autocad/selection_filter.rb', line 240 def name(value) @types << [0, 2] @values << value self end |
#not(condition) ⇒ self
Logical NOT for a filter condition
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/autocad/selection_filter.rb', line 141 def not(condition) @types << -4 @values << "<NOT" @types.concat(condition.types) @values.concat(condition.values) @types << -4 @values << "NOT>" self end |
#not_equal_to(value) ⇒ self
Not equal to comparison
208 209 210 211 212 213 214 |
# File 'lib/autocad/selection_filter.rb', line 208 def not_equal_to(value) @types << -4 @values << "<>" @types << 40 # floating point @values << value self end |
#or(*conditions) ⇒ self
Logical OR combination of filters
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/autocad/selection_filter.rb', line 89 def or(*conditions) return self if conditions.empty? @types << -4 @values << "<OR" conditions.each do |condition| @types.concat(condition.types) @values.concat(condition.values) end @types << -4 @values << "OR>" self end |
#paper_space ⇒ self
Filter for paper space entities
305 306 307 308 309 |
# File 'lib/autocad/selection_filter.rb', line 305 def paper_space @types << 67 # Paper space filter @values << 1 self end |
#type(kind) ⇒ self
Filter by entity type
253 254 255 256 257 |
# File 'lib/autocad/selection_filter.rb', line 253 def type(kind) @types << 0 @values << kind self end |
#visible(vis = true) ⇒ self
Filter by visibility state
281 282 283 284 285 |
# File 'lib/autocad/selection_filter.rb', line 281 def visible(vis = true) @types << 60 @values << (vis ? 0 : 1) self end |
#xor(condition1, condition2) ⇒ self
Logical XOR combination of two filters
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/autocad/selection_filter.rb', line 118 def xor(condition1, condition2) @types << -4 @values << "<XOR" @types.concat(condition1.types) @values.concat(condition1.values) @types.concat(condition2.types) @values.concat(condition2.values) @types << -4 @values << "XOR>" self end |