microstation 0.4.1 → 0.8.3
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/.autotest +23 -23
- data/.rspec +2 -2
- data/Gemfile +28 -10
- data/History.txt +6 -6
- data/LICENSE.adoc +22 -0
- data/Manifest.txt +81 -60
- data/README.adoc +131 -0
- data/Rakefile +71 -30
- data/bin/dgn2pdf +36 -37
- data/bin/dgn_template +107 -0
- data/bin/microstation +231 -0
- data/bin/pw_print +35 -0
- data/cad_files/drawing_faatitle_in_non_default_model.dgn +0 -0
- data/cad_files/drawing_no_block.dgn +0 -0
- data/cad_files/drawing_with_3_block.dgn +0 -0
- data/cad_files/drawing_with_block.dgn +0 -0
- data/cad_files/seed2d.dgn +0 -0
- data/cad_files/test.dgn +0 -0
- data/lib/microstation.rb +252 -88
- data/lib/microstation/app.rb +781 -286
- data/lib/microstation/cad_input_queue.rb +100 -25
- data/lib/microstation/cell.rb +191 -0
- data/lib/microstation/changer.rb +70 -0
- data/lib/microstation/configuration.rb +193 -57
- data/lib/microstation/criteria_creation_t.rb +23 -0
- data/lib/microstation/dir.rb +252 -252
- data/lib/microstation/directory.rb +46 -0
- data/lib/microstation/drawing.rb +690 -189
- data/lib/microstation/element.rb +311 -0
- data/lib/microstation/enumerator.rb +32 -29
- data/lib/microstation/errors.rb +17 -0
- data/lib/microstation/event_handler.rb +28 -0
- data/lib/microstation/ext/pathname.rb +23 -25
- data/lib/microstation/ext/win32ole.rb +7 -0
- data/lib/microstation/extensions/faa.rb +124 -0
- data/lib/microstation/file_tests.rb +68 -0
- data/lib/microstation/functions.rb +60 -0
- data/lib/microstation/graphics.rb +35 -0
- data/lib/microstation/line.rb +19 -0
- data/lib/microstation/model.rb +45 -0
- data/lib/microstation/model_trait.rb +189 -0
- data/lib/microstation/ole_cad_input_message.rb +101 -0
- data/lib/microstation/ole_helper.rb +152 -0
- data/lib/microstation/pdf_support.rb +40 -40
- data/lib/microstation/point3d.rb +71 -0
- data/lib/microstation/primitive_command_interface.rb +66 -0
- data/lib/microstation/properties.rb +61 -57
- data/lib/microstation/property_handler.rb +48 -0
- data/lib/microstation/scan/color.rb +38 -38
- data/lib/microstation/scan/criteria.rb +89 -85
- data/lib/microstation/scan/klass.rb +43 -43
- data/lib/microstation/scan/level.rb +38 -38
- data/lib/microstation/scan/line_style.rb +45 -45
- data/lib/microstation/scan/line_weight.rb +33 -33
- data/lib/microstation/scan/range.rb +19 -0
- data/lib/microstation/scan/scan_trait.rb +51 -0
- data/lib/microstation/scan/subtype.rb +40 -40
- data/lib/microstation/scan/type.rb +134 -109
- data/lib/microstation/scan_trait.rb +62 -0
- data/lib/microstation/scanner.rb +24 -24
- data/lib/microstation/tag.rb +87 -58
- data/lib/microstation/tag_set.rb +385 -280
- data/lib/microstation/tag_set_trait.rb +51 -0
- data/lib/microstation/tagged_element.rb +105 -0
- data/lib/microstation/template.rb +90 -84
- data/lib/microstation/template_info.rb +172 -0
- data/lib/microstation/template_runner.rb +65 -0
- data/lib/microstation/text.rb +79 -54
- data/lib/microstation/text_node.rb +124 -74
- data/lib/microstation/ts/attribute.rb +140 -139
- data/lib/microstation/ts/instance.rb +146 -112
- data/lib/microstation/ts/tagset_trait.rb +49 -0
- data/lib/microstation/types.rb +91 -91
- data/lib/microstation/version.rb +5 -0
- data/lib/microstation/wrap.rb +28 -214
- data/plot/pdf-bw.plt +164 -164
- data/plot/pdf.plt +163 -163
- data/plot/png.plt +383 -383
- data/plot/tiff.plt +384 -384
- data/plot/wmbw.tbl +324 -66
- data/plot/wmcolor.tbl +62 -62
- metadata +301 -86
- data/.gemtest +0 -0
- data/README.txt +0 -75
- data/lib/microstation/attributes.rb +0 -35
- data/lib/microstation/extensions/hash.rb +0 -27
- data/spec/app_spec.rb +0 -267
- data/spec/configuration_spec.rb +0 -122
- data/spec/drawing_spec.rb +0 -247
- data/spec/drawings/new_drawing.dgn +0 -0
- data/spec/drawings/test.dgn +0 -0
- data/spec/drawings/test1.dgn +0 -0
- data/spec/drawings/testfile.pdf +0 -0
- data/spec/enumerator_spec.rb +0 -60
- data/spec/microstation_spec.rb +0 -36
- data/spec/scanner_spec.rb +0 -155
- data/spec/spec_app.rb +0 -11
- data/spec/spec_helper.rb +0 -31
- data/spec/tag_set_spec.rb +0 -123
- data/spec/text_node_spec.rb +0 -92
- data/spec/text_spec.rb +0 -62
|
@@ -1,25 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
require_relative 'ole_cad_input_message'
|
|
2
|
+
require 'dry/monads'
|
|
3
|
+
module Microstation
|
|
4
|
+
|
|
5
|
+
class CadInputQueue
|
|
6
|
+
|
|
7
|
+
include Dry::Monads[:result]
|
|
8
|
+
|
|
9
|
+
attr_reader :app,:ole_obj
|
|
10
|
+
|
|
11
|
+
def initialize(ole_obj,app)
|
|
12
|
+
@ole_obj = ole_obj
|
|
13
|
+
@app = app
|
|
14
|
+
@input_procs = []
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def <<(string)
|
|
18
|
+
send_keyin(string)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def send_keyin(string)
|
|
22
|
+
@ole_obj.SendKeyin(string)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def send_reset
|
|
26
|
+
@ole_obj.SendReset
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def close
|
|
30
|
+
@ole_ojb = nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def send_command(text)
|
|
34
|
+
@ole_obj.SendCommand(text)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def send_data_point(pt)
|
|
38
|
+
@ole_obj.SendDataPoint app.to_ole_point3d(pt)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def send_tentative_pt(pt)
|
|
42
|
+
@ole_obj.SendTentativePoint(pt)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def send_drag_points(down_pt, up_point, view_specifier:nil, qualifier:nil)
|
|
46
|
+
@ole_obj.SendDragPoints(down_pt,up_point)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def get_input(*args)
|
|
50
|
+
com = @ole_obj.GetInput(*args)
|
|
51
|
+
OLE_CadInputMessage.new(com,app)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def get_point(prompt: "Enter vertex")
|
|
56
|
+
show_prompt(prompt)
|
|
57
|
+
mycim = get_input(InputType::DataPoint, InputType::Reset)
|
|
58
|
+
if mycim.reset?
|
|
59
|
+
clear_ui
|
|
60
|
+
return Failure(:reset_pressed)
|
|
61
|
+
elsif mycim.data_point?
|
|
62
|
+
clear_ui
|
|
63
|
+
Success(mycim.get_point)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def show_command(text)
|
|
69
|
+
app.show_command(text)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def show_prompt(text)
|
|
73
|
+
app.show_prompt(text)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def show_status(text)
|
|
77
|
+
app.show_status(text)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def clear_ui
|
|
82
|
+
app.show_prompt("")
|
|
83
|
+
app.show_status("")
|
|
84
|
+
app.show_command("")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def method_missing(name,*args,&block)
|
|
89
|
+
@ole_obj.send(name,*args,&block)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def start_default_command
|
|
93
|
+
@app.ole_obj.CommandState.StartDefaultCommand
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
module Microstation
|
|
2
|
+
|
|
3
|
+
class Cell < Element
|
|
4
|
+
|
|
5
|
+
def initialize(*args)
|
|
6
|
+
super(*args)
|
|
7
|
+
@should_replace = false
|
|
8
|
+
@replacement = nil
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def shared_cell?
|
|
12
|
+
ole_obj.IsSharedCellElement
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def name
|
|
16
|
+
ole_obj.Name
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def text_elements
|
|
21
|
+
return to_enum(:text_elements) unless block_given?
|
|
22
|
+
each do |el|
|
|
23
|
+
yield el if el.textual?
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# def each
|
|
33
|
+
# return enum_for(:each) unless block_given?
|
|
34
|
+
# ole_enum = @ole_obj.GetSubElements
|
|
35
|
+
# while ole_enum.MoveNext
|
|
36
|
+
# item = ole_enum.Currentq
|
|
37
|
+
# wrapped = Microstation::Wrap.wrap(item,app)
|
|
38
|
+
|
|
39
|
+
# yield
|
|
40
|
+
# end
|
|
41
|
+
# end
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# def each_ole(ole)
|
|
45
|
+
# ole_enum = ole.GetSubElements
|
|
46
|
+
# while ole_enum.MoveNext
|
|
47
|
+
# item = ole_enum.Current
|
|
48
|
+
# if item.IsComplexElement
|
|
49
|
+
# each_ole(item)
|
|
50
|
+
# else
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# wrapped = Microstation::Wrap.wrap(item,app)
|
|
54
|
+
|
|
55
|
+
# yield
|
|
56
|
+
# end
|
|
57
|
+
# end
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# def each_ole(ole)
|
|
61
|
+
# ole_enum = ole.GetSubElements
|
|
62
|
+
# end
|
|
63
|
+
|
|
64
|
+
# def gsub_text(regex,replacement)
|
|
65
|
+
# each do |current|
|
|
66
|
+
# next unless temp_el.textual?
|
|
67
|
+
# temp_el.gsub!(regex,replacement)
|
|
68
|
+
# replace_current_with(temp_el)
|
|
69
|
+
# end
|
|
70
|
+
# end
|
|
71
|
+
|
|
72
|
+
# def replace_current_with(this_var)
|
|
73
|
+
# this_var = this_var.ole_obj if this_var.respond_to? :ole_obj
|
|
74
|
+
# ole_obj.ReplaceCurrentElement this_var
|
|
75
|
+
# end
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# Dim search_text As String
|
|
80
|
+
# Dim replace_text As String
|
|
81
|
+
|
|
82
|
+
# Private Function ReplaceTextInCell(el As Element) As Boolean
|
|
83
|
+
|
|
84
|
+
# Dim cel As CellElement
|
|
85
|
+
# Dim ret As Boolean
|
|
86
|
+
# Dim tel As TextElement
|
|
87
|
+
# ret = False
|
|
88
|
+
# Set cel = el
|
|
89
|
+
# cel.ResetElementEnumeration
|
|
90
|
+
# Do While cel.MoveToNextElement(True)
|
|
91
|
+
# Dim eleTemp As Element
|
|
92
|
+
# Set eleTemp = cel.CopyCurrentElement
|
|
93
|
+
# If eleTemp.IsTextElement Then
|
|
94
|
+
# Set tel = eleTemp
|
|
95
|
+
# If tel.Text = search_text Then
|
|
96
|
+
# tel.Text = replace_text
|
|
97
|
+
# ret = True
|
|
98
|
+
# cel.ReplaceCurrentElement tel
|
|
99
|
+
# End If
|
|
100
|
+
# End If
|
|
101
|
+
# Loop
|
|
102
|
+
# ReplaceTextInCell = ret
|
|
103
|
+
# End Function
|
|
104
|
+
|
|
105
|
+
# Public Sub ReplaceAllTextsInModel()
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
# 'USE THIS TO SET THE REPLACEMENT BY CONFIGURATION VARIABLE
|
|
109
|
+
# 'search_text = ActiveWorkspace.ExpandConfigurationVariable("SEARCH_TEXT")
|
|
110
|
+
# 'replace_text = ActiveWorkspace.ExpandConfigurationVariable("REPLACE_TEXT")
|
|
111
|
+
# search_text = "Test"
|
|
112
|
+
# replace_text = "Blubber"
|
|
113
|
+
# Dim e As ElementEnumerator
|
|
114
|
+
# Dim es As ElementScanCriteria
|
|
115
|
+
# Dim el As Element
|
|
116
|
+
# Set es = New ElementScanCriteria
|
|
117
|
+
|
|
118
|
+
# Set e = ActiveModelReference.Scan(es)
|
|
119
|
+
# Do While e.MoveNext
|
|
120
|
+
# Set el = e.Current
|
|
121
|
+
# If (el.IsCellElement) Then
|
|
122
|
+
# If ReplaceTextInCell(el) Then
|
|
123
|
+
# el.Rewrite
|
|
124
|
+
# End If
|
|
125
|
+
# End If
|
|
126
|
+
# Loop
|
|
127
|
+
# End Sub
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
# Option Explicit
|
|
131
|
+
# ' Searches in text strings and nested cells
|
|
132
|
+
|
|
133
|
+
# Private sToFind As String ' Find text
|
|
134
|
+
# Private sToReplace As String ' Replace with this text
|
|
135
|
+
# Private isComplex As Boolean
|
|
136
|
+
|
|
137
|
+
# Sub TxtRep_complex()
|
|
138
|
+
# Dim CmdLine() As String
|
|
139
|
+
# Dim Ee As ElementEnumerator
|
|
140
|
+
# Dim Sc As New ElementScanCriteria
|
|
141
|
+
|
|
142
|
+
# ' As a separator between parameters, "|" is used.
|
|
143
|
+
# CmdLine = Split(KeyinArguments, "|")
|
|
144
|
+
# ' Cancel if incorrect parameters are given:
|
|
145
|
+
# If UBound(CmdLine) < 1 Then ' no parameter given
|
|
146
|
+
# MessageCenter.AddMessage "Replace Text: Missing Parameters, see details:", "Call was made with: " + KeyinArguments, msdMessageCenterPriorityError
|
|
147
|
+
# Exit Sub
|
|
148
|
+
# End If
|
|
149
|
+
|
|
150
|
+
# sToFind = Trim(CmdLine(0)) '1. Parameter for search text
|
|
151
|
+
# sToReplace = Trim(CmdLine(1)) '2. Parameter for new text
|
|
152
|
+
# ' Check if optional parameter = yes complex was given
|
|
153
|
+
# isComplex = False
|
|
154
|
+
# If UBound(CmdLine) > 1 Then
|
|
155
|
+
# If InStr(CmdLine(2), "complex") > 0 And InStr(CmdLine(2), "yes") > 0 Then isComplex = True
|
|
156
|
+
# End If
|
|
157
|
+
|
|
158
|
+
# ' If not looking at cells, only filter texts and text nodes:
|
|
159
|
+
# If isComplex = False Then
|
|
160
|
+
# Sc.ExcludeAllTypes
|
|
161
|
+
# Sc.IncludeType msdElementTypeText
|
|
162
|
+
# Sc.IncludeType msdElementTypeTextNode ' Also text node always search
|
|
163
|
+
# Else
|
|
164
|
+
# Sc.ExcludeNonGraphical
|
|
165
|
+
# End If
|
|
166
|
+
|
|
167
|
+
# Set Ee = ActiveModelReference.Scan(Sc)
|
|
168
|
+
# ' Browse current model and start the test routine:
|
|
169
|
+
# Do While Ee.MoveNext
|
|
170
|
+
# Call complexSearch(Ee.Current)
|
|
171
|
+
# Loop
|
|
172
|
+
# End Sub
|
|
173
|
+
# ' Subroutine for recursively browsing nested complex elements
|
|
174
|
+
# Sub complexSearch(oEle As Element)
|
|
175
|
+
# Dim EeSub As ElementEnumerator
|
|
176
|
+
# ' If a complex element or text node is found, check all sub-elements:
|
|
177
|
+
# If (oEle.IsComplexElement And isComplex) Or (oEle.Type = msdElementTypeTextNode) Then
|
|
178
|
+
# Set EeSub = oEle.AsComplexElement.GetSubElements
|
|
179
|
+
# Do While EeSub.MoveNext
|
|
180
|
+
# Call complexSearch(EeSub.Current)
|
|
181
|
+
# Loop
|
|
182
|
+
# ' Otherwise string compare, if a text is present:
|
|
183
|
+
# Else
|
|
184
|
+
# If oEle.Type = msdElementTypeText Then
|
|
185
|
+
# If oEle.AsTextElement.Text = sToFind Then
|
|
186
|
+
# oEle.AsTextElement.Text = sToReplace
|
|
187
|
+
# oEle.Rewrite
|
|
188
|
+
# End If
|
|
189
|
+
# End If
|
|
190
|
+
# End If
|
|
191
|
+
# # End Sub
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Microstation
|
|
4
|
+
class Changer
|
|
5
|
+
include FileTests
|
|
6
|
+
|
|
7
|
+
attr_reader :template, :template_filename, :the_app
|
|
8
|
+
|
|
9
|
+
def initialize(template, output_dir: nil, app: nil, name: nil)
|
|
10
|
+
check_is_dgn(template)
|
|
11
|
+
@template = template
|
|
12
|
+
@template_filename = File.basename(template)
|
|
13
|
+
@the_app = app
|
|
14
|
+
@output_dir = output_dir || default_outdir(name)
|
|
15
|
+
@name = name || default_name
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def ensure_output_path(odir)
|
|
19
|
+
path = Pathname(odir)
|
|
20
|
+
path.mkpath unless path.directory?
|
|
21
|
+
path
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def run(name: nil, output_dir: nil, &block)
|
|
25
|
+
lname = name || @name
|
|
26
|
+
loutput_dir = output_dir || @output_dir
|
|
27
|
+
output_path = ensure_output_path(loutput_dir)
|
|
28
|
+
newname = output_path + lname
|
|
29
|
+
tmp_dgn = the_app ? change_in_tempfile(the_app, &block) : change_once_in_tempfile(&block)
|
|
30
|
+
FileUtils.mv(tmp_dgn.to_s, newname.to_s)
|
|
31
|
+
puts "Saved drawing #{newname}"
|
|
32
|
+
rescue StandardError => e
|
|
33
|
+
puts 'error in changing file'
|
|
34
|
+
raise e
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def change_in_tempfile(app, &block)
|
|
38
|
+
path = Pathname(File.join(::Dir.tmpdir, "#{template_filename}_#{Time.now.to_i}_#{rand(1000)}"))
|
|
39
|
+
app.new_drawing(path, seedfile: @template) do |drawing|
|
|
40
|
+
if block_given?
|
|
41
|
+
block.call(drawing)
|
|
42
|
+
else
|
|
43
|
+
default_block.call(drawing)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
path
|
|
47
|
+
rescue MultipleUpdateError => e
|
|
48
|
+
puts "Error while #change_into_tempfile: #{e.message}"
|
|
49
|
+
raise e
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def change_once_in_tempfile(&block)
|
|
53
|
+
::Microstation.run do |app|
|
|
54
|
+
change_in_tempfile(app, &block)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def default_block
|
|
59
|
+
->(d) { d }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def default_outdir(_name = nil)
|
|
63
|
+
Pathname.getwd
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def default_name
|
|
67
|
+
template_filename
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -1,57 +1,193 @@
|
|
|
1
|
-
module Microstation
|
|
2
|
-
|
|
3
|
-
class
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
end
|
|
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
|
-
end
|
|
44
|
-
|
|
45
|
-
def
|
|
46
|
-
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
end
|
|
1
|
+
module Microstation
|
|
2
|
+
|
|
3
|
+
class Capabilities
|
|
4
|
+
|
|
5
|
+
attr_reader :variable, :capabilities
|
|
6
|
+
|
|
7
|
+
def initialize(config,variable)
|
|
8
|
+
@config = config
|
|
9
|
+
@variable = variable
|
|
10
|
+
@capabilities = get_capabilities
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def get_capabilities
|
|
14
|
+
@capabilities = @config[variable].split(';')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def search(name)
|
|
19
|
+
@capabilities.select{|c| c =~ Regexp.new(Regexp.escape(name), Regexp::IGNORECASE)}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def enabled
|
|
23
|
+
@capabilities.select{|c| c.start_with?('+')}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def disabled
|
|
27
|
+
@capabilities.select{|c| c.start_with?('-')}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def enabled?(name)
|
|
31
|
+
capa = remove_prefix(name)
|
|
32
|
+
@capabilities.any?{|c| c == "+#{capa}"}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def disabled?(name)
|
|
36
|
+
capa = remove_prefix(name)
|
|
37
|
+
@capabilities.any?{|c| c == "-#{capa}"}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def write_configuration
|
|
41
|
+
caps = @capabilities.uniq.join(';')
|
|
42
|
+
@config.set!(variable, caps)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def prepend(value)
|
|
46
|
+
@config.prepend(variable,value)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def enable(name)
|
|
50
|
+
return if enabled?(name) && !disabled?(name)
|
|
51
|
+
capa = remove_prefix(name)
|
|
52
|
+
@capabilities.delete("-#{capa}")
|
|
53
|
+
@capabilities.unshift("+#{capa}")
|
|
54
|
+
write_configuration
|
|
55
|
+
get_capabilities
|
|
56
|
+
self
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def disable(name)
|
|
60
|
+
return if disabled?(name) && !enabled?(name)
|
|
61
|
+
capa = remove_prefix(name)
|
|
62
|
+
capabilities.delete("+#{name}")
|
|
63
|
+
@capabilities.unshift("-#{capa}")
|
|
64
|
+
write_configuration
|
|
65
|
+
get_capabilities
|
|
66
|
+
self
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def remove_prefix(name)
|
|
70
|
+
if name =~ /[+-](.+)/
|
|
71
|
+
name = Regexp.last_match(1)
|
|
72
|
+
end
|
|
73
|
+
name
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
class VariableDefined < ::StandardError
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class App
|
|
84
|
+
|
|
85
|
+
def with_config
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
class Configuration
|
|
92
|
+
|
|
93
|
+
def initialize(app)
|
|
94
|
+
@app = app
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def prepend(variable,value)
|
|
98
|
+
if exists?(variable)
|
|
99
|
+
old_value = get(variable)
|
|
100
|
+
new_value = "#{value};#{old_value}"
|
|
101
|
+
else
|
|
102
|
+
new_value = value.to_s
|
|
103
|
+
end
|
|
104
|
+
set!(variable,new_value)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def append(variable,value)
|
|
108
|
+
if exists?(variable)
|
|
109
|
+
old_value = get(variable)
|
|
110
|
+
new_value = "#{old_value};#{value}"
|
|
111
|
+
else
|
|
112
|
+
new_value = value.to_s
|
|
113
|
+
end
|
|
114
|
+
set!(variable,new_value)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def [](variable)
|
|
118
|
+
return nil unless exists? variable
|
|
119
|
+
get(variable)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def remove_variable(variable)
|
|
124
|
+
workspace.RemoveConfigurationVariable variable
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def set(key,value,options = {})
|
|
128
|
+
raise VariableDefined unless should_update?(key,options)
|
|
129
|
+
set!(key,value)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def set!(key,value)
|
|
133
|
+
self.remove_variable(key)
|
|
134
|
+
workspace.AddConfigurationVariable(key,value)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def []=(key,value)
|
|
139
|
+
set(key,value)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def exists?(value)
|
|
143
|
+
workspace.IsConfigurationVariableDefined(value)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def capabilities_all
|
|
147
|
+
@workmode_all ||= Capabilities.new(self,'_USTN_CAPABILITY')
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def expand(string)
|
|
152
|
+
workspace.ExpandConfigurationVariable(string)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
private
|
|
156
|
+
def workspace
|
|
157
|
+
@app.active_workspace
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def get(variable)
|
|
161
|
+
workspace.ConfigurationVariableValue(variable)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def should_update?(key,options={force: false})
|
|
165
|
+
return true unless exists? key
|
|
166
|
+
force = options.fetch(:force){ false}
|
|
167
|
+
return !!force
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class App
|
|
174
|
+
|
|
175
|
+
def capabilities(mode = :all)
|
|
176
|
+
case mode
|
|
177
|
+
when :all
|
|
178
|
+
configuration.capabilities_all
|
|
179
|
+
when :dwg
|
|
180
|
+
configuration.capabilites_dwg
|
|
181
|
+
when :v7
|
|
182
|
+
configuration.capabilities_v7
|
|
183
|
+
else
|
|
184
|
+
configuration_capabilities_all
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
end
|