Class: Autocad::SelectionSetAdapter
- Inherits:
-
Object
- Object
- Autocad::SelectionSetAdapter
- Defined in:
- lib/autocad/selection_set_adapter.rb
Overview
Manages AutoCAD selection set operations and OLE integration
Executes selections using stored criteria and provides access to selected entities. Bridges between Ruby selection criteria and AutoCAD’s native selection mechanisms.
Key Features:
-
Multiple selection methods (window, crossing, fence, point)
-
Filter-based entity selection
-
Enumeration of selected entities
-
OLE integration with AutoCAD
Instance Attribute Summary collapse
-
#drawing ⇒ Object
readonly
Returns the value of attribute drawing.
-
#ole_obj ⇒ Object
readonly
Returns the value of attribute ole_obj.
-
#selection_set ⇒ Object
readonly
Returns the value of attribute selection_set.
Class Method Summary collapse
-
.from_ole_obj(drawing, ole) ⇒ SelectionSetAdapter
Initialize from OLE object.
Instance Method Summary collapse
-
#app ⇒ Autocad::App
Get the application instance.
-
#clear ⇒ void
Clear selection set contents.
-
#clear_filter ⇒ void
Clear filter criteria.
-
#count ⇒ Integer
Get item count in selection set.
-
#delete ⇒ void
Delete the selection set from AutoCAD.
-
#each {|Element| ... } ⇒ Enumerator<Element>
Iterate through selected entities.
-
#filter {|Filter| ... } ⇒ void
Configure filter through block.
-
#filter_text(str) ⇒ void
Set text content filter.
-
#filter_text_containing(str) ⇒ void
Filter text containing substring.
-
#filter_types ⇒ Array<Integer>
Get filter types from selection set.
-
#filter_values ⇒ Array<Object>
Get filter values from selection set.
-
#has_items? ⇒ Boolean
Checks if the selection set has any items.
-
#initialize(drawing, selection_set, ole = nil) ⇒ SelectionSetAdapter
constructor
Initialize new adapter.
-
#name ⇒ String
Get the name of the selection set.
-
#select(mode: :all, pt1: nil, pt2: nil, ft: ole_filter_types, fv: ole_filter_values) ⇒ void
Select entities using various methods.
-
#select_at_point(x, y) ⇒ void
Select entities at specific point.
-
#select_by_polygon(points: [], mode: :fence) ⇒ void
Select entities using polygonal fence.
-
#select_on_screen(ft = ole_filter_types, fv = ole_filter_values) ⇒ void
Select entities interactively on screen.
Constructor Details
#initialize(drawing, selection_set, ole = nil) ⇒ SelectionSetAdapter
Initialize new adapter
44 45 46 47 48 |
# File 'lib/autocad/selection_set_adapter.rb', line 44 def initialize(drawing, selection_set, ole = nil) @drawing = drawing @selection_set = selection_set @ole_obj = ole || create_selection_set end |
Instance Attribute Details
#drawing ⇒ Object (readonly)
Returns the value of attribute drawing.
34 35 36 |
# File 'lib/autocad/selection_set_adapter.rb', line 34 def drawing @drawing end |
#ole_obj ⇒ Object (readonly)
Returns the value of attribute ole_obj.
34 35 36 |
# File 'lib/autocad/selection_set_adapter.rb', line 34 def ole_obj @ole_obj end |
#selection_set ⇒ Object (readonly)
Returns the value of attribute selection_set.
34 35 36 |
# File 'lib/autocad/selection_set_adapter.rb', line 34 def selection_set @selection_set end |
Class Method Details
.from_ole_obj(drawing, ole) ⇒ SelectionSetAdapter
Initialize from OLE object
26 27 28 29 |
# File 'lib/autocad/selection_set_adapter.rb', line 26 def self.from_ole_obj(drawing, ole) ss = SelectionSet.new(ole.Name) new(drawing, ss, ole) end |
Instance Method Details
#app ⇒ Autocad::App
Get the application instance
123 124 125 |
# File 'lib/autocad/selection_set_adapter.rb', line 123 def app @drawing.app end |
#clear ⇒ void
This method returns an undefined value.
Clear selection set contents
84 85 86 |
# File 'lib/autocad/selection_set_adapter.rb', line 84 def clear ole_obj.Clear end |
#clear_filter ⇒ void
This method returns an undefined value.
Clear filter criteria
94 95 96 |
# File 'lib/autocad/selection_set_adapter.rb', line 94 def clear_filter selection_set.clear_filter end |
#count ⇒ Integer
Get item count in selection set
74 75 76 |
# File 'lib/autocad/selection_set_adapter.rb', line 74 def count ole_obj.Count end |
#delete ⇒ void
This method returns an undefined value.
Delete the selection set from AutoCAD
55 56 57 58 |
# File 'lib/autocad/selection_set_adapter.rb', line 55 def delete @ole_obj.Delete @selection_set = nil end |
#each {|Element| ... } ⇒ Enumerator<Element>
Iterate through selected entities
136 137 138 139 140 |
# File 'lib/autocad/selection_set_adapter.rb', line 136 def each return to_enum(__callee__) unless block_given? ole_obj.each { |o| yield app.wrap(o) } end |
#filter {|Filter| ... } ⇒ void
This method returns an undefined value.
Configure filter through block
290 291 292 |
# File 'lib/autocad/selection_set_adapter.rb', line 290 def filter(&) @selection_set.filter(&) end |
#filter_text(str) ⇒ void
This method returns an undefined value.
Set text content filter
105 106 107 |
# File 'lib/autocad/selection_set_adapter.rb', line 105 def filter_text(str) @selection_set.filter_text(str) end |
#filter_text_containing(str) ⇒ void
This method returns an undefined value.
Filter text containing substring
116 117 118 |
# File 'lib/autocad/selection_set_adapter.rb', line 116 def filter_text_containing(str) @selection_set.filter_text_containing(str) end |
#filter_types ⇒ Array<Integer>
Get filter types from selection set
156 157 158 |
# File 'lib/autocad/selection_set_adapter.rb', line 156 def filter_types @selection_set.filter_types end |
#filter_values ⇒ Array<Object>
Get filter values from selection set
165 166 167 |
# File 'lib/autocad/selection_set_adapter.rb', line 165 def filter_values @selection_set.filter_values end |
#has_items? ⇒ Boolean
Checks if the selection set has any items
65 66 67 |
# File 'lib/autocad/selection_set_adapter.rb', line 65 def has_items? ole_obj.Count > 0 end |
#name ⇒ String
Get the name of the selection set
147 148 149 |
# File 'lib/autocad/selection_set_adapter.rb', line 147 def name @ole_obj.Name end |
#select(mode: :all, pt1: nil, pt2: nil, ft: ole_filter_types, fv: ole_filter_values) ⇒ void
This method returns an undefined value.
Select entities using various methods
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/autocad/selection_set_adapter.rb', line 206 def select(mode: :all, pt1: nil, pt2: nil, ft: ole_filter_types, fv: ole_filter_values) acad_mode = case mode when :all ACAD::AcSelectionSetAll when :window ACAD::AcSelectionSetWindow when :crossing ACAD::AcSelectionSetCrossing when :previous ACAD::AcSelectionSetPrevious when :last ACAD::AcSelectionSetLast else Acad::AcSelectionSetAll end @ole_obj.Select(acad_mode, nil, nil, ft, fv) rescue => ex binding.irb end |
#select_at_point(x, y) ⇒ void
This method returns an undefined value.
Select entities at specific point
237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/autocad/selection_set_adapter.rb', line 237 def select_at_point(x, y) point = if x.respond_to?(:x) && x.respond_to?(:y) # Handle Point3d object [x.x, x.y] elsif x.is_a?(Array) # Handle array input x else # Handle separate x,y coordinates [x, y] end @ole_obj.SelectAtPoint(point, filter_types, filter_values) end |
#select_by_polygon(points: [], mode: :fence) ⇒ void
This method returns an undefined value.
Select entities using polygonal fence
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/autocad/selection_set_adapter.rb', line 264 def select_by_polygon(points: [], mode: :fence) # Convert points to arrays of coordinates point_coords = points.map { |p| Point3d(p) }.map { |p| [p.x, p.y, p.z] }.flatten mode_code = case mode when :fence then 5 when :window then 3 when :crossing then 4 else raise ArgumentError, "Invalid selection mode: #{mode}. Must be :fence, :window, or :crossing" end ole_point_coords = WIN32OLE::Variant.new(point_coords, WIN32OLE::VARIANT::VT_ARRAY | WIN32OLE::VARIANT::VT_R8) binding.irb @ole_obj.SelectByPolygon(mode_code, ole_point_coords, filter_types, filter_values) end |
#select_on_screen(ft = ole_filter_types, fv = ole_filter_values) ⇒ void
This method returns an undefined value.
Select entities interactively on screen
181 182 183 184 185 186 187 |
# File 'lib/autocad/selection_set_adapter.rb', line 181 def select_on_screen(ft = ole_filter_types, fv = ole_filter_values) if filter_types.empty? && filter_values.empty? @ole_obj.SelectOnScreen(nil, nil) else @ole_obj.SelectOnScreen(ft, fv) end end |