microstation 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +23 -0
- data/.gemtest +0 -0
- data/.rspec +2 -0
- data/Gemfile +17 -0
- data/History.txt +6 -0
- data/Manifest.txt +60 -0
- data/README.txt +75 -0
- data/Rakefile +30 -0
- data/bin/dgn2pdf +37 -0
- data/lib/microstation.rb +88 -0
- data/lib/microstation/app.rb +286 -0
- data/lib/microstation/attributes.rb +35 -0
- data/lib/microstation/cad_input_queue.rb +25 -0
- data/lib/microstation/configuration.rb +57 -0
- data/lib/microstation/dir.rb +252 -0
- data/lib/microstation/drawing.rb +189 -0
- data/lib/microstation/enumerator.rb +29 -0
- data/lib/microstation/ext/pathname.rb +25 -0
- data/lib/microstation/extensions/hash.rb +27 -0
- data/lib/microstation/pdf_support.rb +40 -0
- data/lib/microstation/properties.rb +57 -0
- data/lib/microstation/scan/color.rb +38 -0
- data/lib/microstation/scan/criteria.rb +85 -0
- data/lib/microstation/scan/klass.rb +43 -0
- data/lib/microstation/scan/level.rb +38 -0
- data/lib/microstation/scan/line_style.rb +45 -0
- data/lib/microstation/scan/line_weight.rb +33 -0
- data/lib/microstation/scan/subtype.rb +40 -0
- data/lib/microstation/scan/type.rb +109 -0
- data/lib/microstation/scanner.rb +24 -0
- data/lib/microstation/tag.rb +58 -0
- data/lib/microstation/tag_set.rb +280 -0
- data/lib/microstation/template.rb +84 -0
- data/lib/microstation/text.rb +54 -0
- data/lib/microstation/text_node.rb +74 -0
- data/lib/microstation/ts/attribute.rb +139 -0
- data/lib/microstation/ts/instance.rb +112 -0
- data/lib/microstation/types.rb +91 -0
- data/lib/microstation/wrap.rb +214 -0
- data/plot/pdf-bw.plt +164 -0
- data/plot/pdf.plt +163 -0
- data/plot/png.plt +383 -0
- data/plot/tiff.plt +384 -0
- data/plot/wmbw.tbl +66 -0
- data/plot/wmcolor.tbl +62 -0
- data/spec/app_spec.rb +267 -0
- data/spec/configuration_spec.rb +122 -0
- data/spec/drawing_spec.rb +247 -0
- 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 +60 -0
- data/spec/microstation_spec.rb +36 -0
- data/spec/scanner_spec.rb +155 -0
- data/spec/spec_app.rb +11 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/tag_set_spec.rb +123 -0
- data/spec/text_node_spec.rb +92 -0
- data/spec/text_spec.rb +62 -0
- metadata +241 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'wrap'
|
2
|
+
|
3
|
+
module Microstation
|
4
|
+
|
5
|
+
class Enumerator
|
6
|
+
|
7
|
+
include Enumerable
|
8
|
+
include Wrap
|
9
|
+
|
10
|
+
def initialize(ole)
|
11
|
+
@ole_obj = ole
|
12
|
+
end
|
13
|
+
|
14
|
+
def each
|
15
|
+
while @ole_obj.MoveNext
|
16
|
+
item = @ole_obj.Current
|
17
|
+
yield wrap(item)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def reset
|
22
|
+
@ole_obj.reset
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
|
4
|
+
class Pathname
|
5
|
+
|
6
|
+
def ext(newext = '')
|
7
|
+
str = self.to_s
|
8
|
+
return self.dup if ['.', '..'].include? str
|
9
|
+
if newext != ''
|
10
|
+
newext = (newext =~ /^\./) ? newext : ("." + newext)
|
11
|
+
end
|
12
|
+
Pathname.new(str.dup.sub!(%r(([^/\\])\.[^./\\]*$)) { $1 + newext } || str + newext)
|
13
|
+
end
|
14
|
+
|
15
|
+
def extstr(newext='')
|
16
|
+
Pathname.new( self.to_s.ext(newext))
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def glob(pattern)
|
21
|
+
self.class.glob("#{self.to_s}/#{pattern}")
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Hash
|
2
|
+
|
3
|
+
|
4
|
+
def map_v
|
5
|
+
reduce({}) do |result, array|
|
6
|
+
k,v = array
|
7
|
+
new_val = yield v
|
8
|
+
result.merge( k => new_val)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def map_k
|
13
|
+
reduce({}) do |result, array|
|
14
|
+
k,v = array
|
15
|
+
new_k = yield k
|
16
|
+
result.merge(new_k => v)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def map_kv
|
21
|
+
reduce({}) do |result, array|
|
22
|
+
new_k,new_v = yield array
|
23
|
+
result.merge(new_k => new_v)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Microstation
|
2
|
+
|
3
|
+
|
4
|
+
module PdfSupport
|
5
|
+
|
6
|
+
def pdf_name(output_dir=nil)
|
7
|
+
name = self.basename
|
8
|
+
dir = output_dir || self.dirname
|
9
|
+
pdfname = Pathname(name).ext('pdf')
|
10
|
+
(dir + pdfname).expand_path
|
11
|
+
end
|
12
|
+
|
13
|
+
def pdf_exists?(output_dir = nil)
|
14
|
+
pdf_name(output_dir).file?
|
15
|
+
end
|
16
|
+
|
17
|
+
def file_exists?(file)
|
18
|
+
file.file?
|
19
|
+
end
|
20
|
+
|
21
|
+
def needs_pdf?(output_dir=nil)
|
22
|
+
pdf_path = pdf_name(output_dir)
|
23
|
+
!file_exists?(pdf_path) || pdf_older?(pdf_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def pdf_older?(pdf)
|
27
|
+
self.mtime > pdf.mtime
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def mtime
|
32
|
+
self.path.mtime
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Microstation
|
2
|
+
|
3
|
+
module Properties
|
4
|
+
|
5
|
+
def author=(var = nil)
|
6
|
+
if var
|
7
|
+
@ole_obj.Author = var
|
8
|
+
else
|
9
|
+
@ole_obj.Author rescue nil
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
alias_method :author, :author=
|
15
|
+
|
16
|
+
def subject=(var = nil)
|
17
|
+
if var
|
18
|
+
@ole_obj.Subject = var
|
19
|
+
else
|
20
|
+
@ole_obj.Subject rescue nil
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
alias_method :subject, :subject=
|
26
|
+
|
27
|
+
def comments=(var = nil)
|
28
|
+
var ? @ole_obj.Comments = var : @ole_obj.Comments
|
29
|
+
end
|
30
|
+
|
31
|
+
alias_method :comments, :comments=
|
32
|
+
|
33
|
+
def title=(var = nil)
|
34
|
+
if var
|
35
|
+
@ole_obj.Title = var
|
36
|
+
else
|
37
|
+
@ole_obj.Title rescue nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
alias_method :title,:title=
|
42
|
+
|
43
|
+
def keywords=(var = nil)
|
44
|
+
if var
|
45
|
+
@ole_obj.Keywords = var
|
46
|
+
else
|
47
|
+
@ole_obj.Keywords rescue nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
alias_method :keywords, :keywords=
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Microstation
|
2
|
+
|
3
|
+
module Scan
|
4
|
+
|
5
|
+
module Color
|
6
|
+
|
7
|
+
def color_inclusions
|
8
|
+
@color_inclusions ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
def include_color(color)
|
12
|
+
color_inclusions << color
|
13
|
+
end
|
14
|
+
|
15
|
+
def reset_colors
|
16
|
+
reset_ole_colors
|
17
|
+
@color_inclusions = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset_ole_colors
|
21
|
+
ole_obj.ExcludeAllColors
|
22
|
+
end
|
23
|
+
|
24
|
+
def resolve_color_scans
|
25
|
+
return unless color_inclusions.size > 0
|
26
|
+
reset_ole_colors
|
27
|
+
color_inclusions.each do |color|
|
28
|
+
ole_obj.IncludeColor(color)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require_relative 'klass'
|
2
|
+
require_relative 'type'
|
3
|
+
require_relative 'level'
|
4
|
+
require_relative 'color'
|
5
|
+
require_relative 'line_style'
|
6
|
+
require_relative 'line_weight'
|
7
|
+
require_relative 'subtype'
|
8
|
+
|
9
|
+
module Microstation
|
10
|
+
|
11
|
+
class App
|
12
|
+
|
13
|
+
def create_ole_scan_criteria
|
14
|
+
ole_obj.CreateObjectInMicroStation("MicroStationDGN.ElementScanCriteria")
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
module Microstation
|
22
|
+
|
23
|
+
module Scan
|
24
|
+
|
25
|
+
class Criteria
|
26
|
+
|
27
|
+
include Scan::Klass
|
28
|
+
include Scan::Type
|
29
|
+
include Scan::Level
|
30
|
+
include Scan::Color
|
31
|
+
include Scan::LineStyle
|
32
|
+
include Scan::LineWeight
|
33
|
+
include Scan::Subtype
|
34
|
+
|
35
|
+
attr_reader :app
|
36
|
+
|
37
|
+
def self.create_scanner(app,&block)
|
38
|
+
sc = create(app)
|
39
|
+
return sc unless block
|
40
|
+
block.arity < 1 ? sc.instance_eval(&block) : block.call(sc)
|
41
|
+
sc
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.create(app)
|
45
|
+
sc = new(app)
|
46
|
+
app.scanners << sc
|
47
|
+
sc
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def initialize(app)
|
52
|
+
@app = app
|
53
|
+
@ole_obj = @app.create_ole_scan_criteria
|
54
|
+
@app.load_constants #unless defined? Microstation::MSD
|
55
|
+
end
|
56
|
+
|
57
|
+
def resolve
|
58
|
+
resolve_type_scans
|
59
|
+
resolve_class_scans
|
60
|
+
resolve_color_scans
|
61
|
+
resolve_level_scans
|
62
|
+
resolve_linestyle_scans
|
63
|
+
resolve_lineweight_scans
|
64
|
+
resolve_subtype_scans
|
65
|
+
end
|
66
|
+
|
67
|
+
def close
|
68
|
+
@ole_obj = nil
|
69
|
+
@app.scanners.delete(self) if @app
|
70
|
+
@app = nil
|
71
|
+
end
|
72
|
+
|
73
|
+
def ole_obj
|
74
|
+
@ole_obj
|
75
|
+
end
|
76
|
+
|
77
|
+
def method_missing(method,*args)
|
78
|
+
@ole_obj.send(method,*args)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Microstation
|
2
|
+
|
3
|
+
module Scan
|
4
|
+
|
5
|
+
module Klass
|
6
|
+
|
7
|
+
# msdElementClassPrimary # 0 (&H0)
|
8
|
+
# msdElementClassPatternComponent #1 (&H1)
|
9
|
+
# msdElementClassConstruction #2 (&H2)
|
10
|
+
# msdElementClassDimension #3 (&H3)
|
11
|
+
# msdElementClassPrimaryRule #4 (&H4)
|
12
|
+
# msdElementClassLinearPatterned #5 (&H5)
|
13
|
+
# msdElementClassContructionRule #6 (&H6)
|
14
|
+
|
15
|
+
def class_inclusions
|
16
|
+
@class_inclusions ||= []
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset_classes
|
20
|
+
reset_ole_classes
|
21
|
+
@class_inclusions = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def reset_ole_classes
|
25
|
+
ole_obj.ExcludeAllClasses
|
26
|
+
end
|
27
|
+
|
28
|
+
def include_class(klass)
|
29
|
+
class_inclusions << klass
|
30
|
+
end
|
31
|
+
|
32
|
+
def resolve_class_scans
|
33
|
+
return unless class_inclusions.size > 0
|
34
|
+
reset_ole_classes
|
35
|
+
class_inclusions.each do |klass|
|
36
|
+
ole_obj.IncludeClass(klass)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Microstation
|
2
|
+
|
3
|
+
module Scan
|
4
|
+
|
5
|
+
module Level
|
6
|
+
|
7
|
+
def level_inclusions
|
8
|
+
@level_inclusions ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
def include_level(level)
|
12
|
+
level_inclusions << level
|
13
|
+
end
|
14
|
+
|
15
|
+
def reset_levels
|
16
|
+
reset_ole_levels
|
17
|
+
@level_inclusions = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset_ole_levels
|
21
|
+
ole_obj.ExcludeAllLevels
|
22
|
+
end
|
23
|
+
|
24
|
+
def resolve_level_scans
|
25
|
+
return unless level_inclusions.size > 0
|
26
|
+
reset_ole_levels
|
27
|
+
level_inclusions.each do |level|
|
28
|
+
ole_obj.IncludeLevel(level)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Microstation
|
2
|
+
|
3
|
+
module Scan
|
4
|
+
|
5
|
+
module LineStyle
|
6
|
+
|
7
|
+
def linestyles
|
8
|
+
@app.active_design_file.LineStyles rescue []
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def linestyle_inclusions
|
13
|
+
@linestyle_inclusions ||= []
|
14
|
+
end
|
15
|
+
|
16
|
+
def include_linestyle(style)
|
17
|
+
linestyle_inclusions << style
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset_linestyles
|
21
|
+
reset_ole_linestyles
|
22
|
+
@linestyle_inclusions = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def reset_ole_linestyles
|
26
|
+
ole_obj.ExcludeAllLineStyles
|
27
|
+
end
|
28
|
+
|
29
|
+
def resolve_linestyle_scans
|
30
|
+
return unless linestyle_inclusions.size > 0
|
31
|
+
reset_ole_linestyles
|
32
|
+
linestyle_inclusions.each do |linestyle|
|
33
|
+
ole_obj.IncludeLineStyle(linestyle)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Microstation
|
2
|
+
|
3
|
+
module Scan
|
4
|
+
|
5
|
+
module LineWeight
|
6
|
+
|
7
|
+
def lineweight_inclusions
|
8
|
+
@lineweight_inclusions ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
def include_lineweight(weight)
|
12
|
+
lineweight_inclusions << weight
|
13
|
+
end
|
14
|
+
|
15
|
+
def reset_lineweights
|
16
|
+
reset_ole_linestyles
|
17
|
+
@lineweight_inclusions = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset_ole_lineweights
|
21
|
+
ole_obj.ExcludeAllLineWeights
|
22
|
+
end
|
23
|
+
|
24
|
+
def resolve_lineweight_scans
|
25
|
+
return unless lineweight_inclusions.size > 0
|
26
|
+
reset_ole_lineweights
|
27
|
+
lineweight_inclusions.each do |lineweight|
|
28
|
+
ole_obj.IncludeLineWeight(lineweight)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|