rrt_ruby 0.3.0-mswin32 → 0.3.1-mswin32

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.
Files changed (3) hide show
  1. data/lib/rrt_ruby.rb +2 -0
  2. data/lib/rrt_ruby/writer.rb +78 -54
  3. metadata +2 -2
data/lib/rrt_ruby.rb CHANGED
@@ -87,6 +87,7 @@ module RRT_RUBY
87
87
  @logger.debug("Opening model #{@modelname}")
88
88
  @app=WIN32OLE.new(OLEAPP_NAME)
89
89
  @model=@app.OpenModel(@modelname) unless modelname.empty?
90
+ @model=@app.CurrentModel if modelname.empty?
90
91
  raise FinderException.new(@modelname),"Model not loaded" unless @model
91
92
  end
92
93
  #open is used in conjuction with a block.
@@ -120,6 +121,7 @@ module RRT_RUBY
120
121
  @modelname=modelname
121
122
  @model=@app.openmodel(@modelname)
122
123
  raise FinderException.new(@modelname),"Model not loaded" unless @model
124
+ raise FinderException.new(@modelname),"Model not loaded" unless @model.GetFileName.upcase==modelname.upcase
123
125
  end if @app && @app.CurrentModel.GetFileName.upcase!=modelname.upcase
124
126
  end
125
127
  #Stops the RRTFinder releasing the OLE interface and invalidating this RRTFinder instance.
@@ -19,44 +19,28 @@ module RRT_RUBY
19
19
  #
20
20
  #Things that can go wrong:
21
21
  #
22
- #* The parent package for _package_ does not exist
22
+ #* The parent package for _package_ does not exist
23
+ #* The parent package is not defined and _package_ is not Logical View
23
24
  #* The parent package for _package_ is not writeable
25
+ #
24
26
  def add_logical_package package,save=true
25
- @logger.debug("Adding #{package.to_s}")
26
- #if no parent it goes directly to logical view
27
- if package.parent.empty?
28
- host=@model.RootLogicalPackage
29
- else
30
- #find if the parent exists
31
- host=ole_element(package.parent,TYPE_LOGICAL_PACKAGE)
32
- end
27
+ @logger.debug("Writing #{package.to_s}")
28
+ #check parentage
29
+ raise ModelException, "No parent package specified" if package.parent.empty?&&package.name!="Logical View"
30
+ host=@model.RootLogicalPackage if package.name=="Logical View"
31
+ #find if the parent exists
32
+ host=ole_element(package.parent,TYPE_LOGICAL_PACKAGE) unless host
33
33
  if host
34
- if host.IsModifiable
35
- #add the package
36
- added_package=host.AddLogicalPackage(package.name)
37
- added_package.stereotype=package.stereotype
38
- #add all the classes
39
- package.classes.each{|c|
40
- add_class(c,added_package)
34
+ #if the package is "Logical View", write it's subpackages, else write the package
35
+ if package.name=="Logical View"
36
+ package.packages.each{|pkg|
37
+ write_logical_package(pkg,host)
41
38
  }
42
- #add all the contained packages
43
- package.packages.each{|p|
44
- add_logical_package(p,false)
45
- }
46
- #save if wanted
47
- begin
48
- update_relations(package)
49
- #show so that no errors are generated when dialogs pop up
50
- self.show
51
- #save, hide and invalidated the view cache
52
- unit=host.GetContainingControlledElement
53
- raise ModelException,"Could not save#{unit.name}" unless unit.Save
54
- self.hide
55
- @logical_view=nil
56
- end if save
57
39
  else
58
- raise ModelException,"#{host.name} is not writable"
40
+ write_logical_package(package,host)
59
41
  end
42
+ update_relations(package)
43
+ save(host) if save
60
44
  else
61
45
  raise ModelException,"#{package.parent} does not exist in the model"
62
46
  end
@@ -69,34 +53,25 @@ module RRT_RUBY
69
53
  #
70
54
  #* The parent package for _package_ does not exist
71
55
  #* _package_ does not exist
56
+ #* The parent package is not defined and _package_ is not Logical View
72
57
  #* The parent package for _package_ is not writeable
73
58
  def remove_logical_package package
74
59
  @logger.debug("Removing #{package.to_s}")
75
- #if no parent it goes directly to logical view
76
- if package.parent.empty?
77
- host=@model.RootLogicalPackage
78
- @logger.debug("...from the root logical package")
79
- else
80
- #find if the parent exists
81
- host=ole_element(package.parent,TYPE_LOGICAL_PACKAGE)
82
- end
60
+ #check parentage
61
+ raise ModelException, "No parent package specified" if package.parent.empty?&&package.name!="Logical View"
62
+ host=@model.RootLogicalPackage if package.name=="Logical View"
63
+ #find if the parent exists
64
+ host=ole_element(package.parent,TYPE_LOGICAL_PACKAGE) unless host
83
65
  if host
84
- if host.IsModifiable
85
- pkg=ole_element(package.qualified_name,TYPE_LOGICAL_PACKAGE)
86
- if pkg
87
- self.show
88
- #delete the package
89
- host.DeleteLogicalPackage(pkg)
90
- unit=host.GetContainingControlledElement
91
- raise ModelException,"Could not save#{unit.name}" unless unit.Save
92
- self.hide
93
- @logical_view=nil
94
- else
95
- @logger.info("#{package.name} does not exist in the model")
96
- end
66
+ #if the package is "Logical View", write it's subpackages, else write the package
67
+ if package.name=="Logical View"
68
+ package.packages.each{|pkg|
69
+ delete_logical_package(pkg,host)
70
+ }
97
71
  else
98
- raise ModelException,"#{host.name} is not writable"
72
+ delete_logical_package(package,host)
99
73
  end
74
+ save(host)
100
75
  else
101
76
  raise ModelException,"#{package.parent} does not exist in the model"
102
77
  end
@@ -115,6 +90,50 @@ module RRT_RUBY
115
90
  end
116
91
 
117
92
  private
93
+ #
94
+ def save host
95
+ #show so that no errors are generated when dialogs pop up
96
+ self.show
97
+ #save, hide and invalidated the view cache
98
+ unit=host.GetContainingControlledElement
99
+ raise ModelException,"Could not save#{unit.name}" unless unit.Save
100
+ self.hide
101
+ @logical_view=nil
102
+ end
103
+ #
104
+ def write_logical_package package,host
105
+ if host.IsModifiable
106
+ #add the package
107
+ added_package=host.AddLogicalPackage(package.name)
108
+ added_package.stereotype=package.stereotype
109
+ #add all the classes
110
+ package.classes.each{|c|
111
+ add_class(c,added_package)
112
+ }
113
+ #add all the contained packages
114
+ package.packages.each{|p|
115
+ write_logical_package(p,added_package)
116
+ }
117
+ else
118
+ raise ModelException,"#{host.name} is not writable"
119
+ end
120
+ end
121
+ #
122
+ def delete_logical_package package,host
123
+ if host.IsModifiable
124
+ pkg=ole_element(package.qualified_name,TYPE_LOGICAL_PACKAGE)
125
+ if pkg
126
+ #delete the package
127
+ host.DeleteLogicalPackage(pkg)
128
+ @logical_view=nil
129
+ else
130
+ @logger.info("#{package.name} does not exist in the model")
131
+ end
132
+
133
+ else
134
+ raise ModelException,"#{host.name} is not writable"
135
+ end
136
+ end
118
137
  #Adds _c_ to the OLE _package_element_
119
138
  def add_class c,package_element
120
139
  added=package_element.AddClass(c.name)
@@ -123,6 +142,7 @@ module RRT_RUBY
123
142
  #Adds _c_ to the OLE _package_element_
124
143
  def add_capsule c,package_element
125
144
  added=package_element.AddCapsule(c.name)
145
+ added.stereotype=c.stereotype
126
146
  end
127
147
 
128
148
 
@@ -150,9 +170,13 @@ module RRT_RUBY
150
170
  when Relation::CLASS
151
171
  el.AddClassDependency("",r.supplier)
152
172
  when Relation::COMPONENT
173
+
153
174
  when Relation::PACKAGE
175
+
154
176
  when Relation::GENERALIZATION
177
+
155
178
  when Relation::REALIZE
179
+
156
180
  end
157
181
  rescue
158
182
  @logger.warn("Could not add dependency: #{$!}")
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.3
3
3
  specification_version: 1
4
4
  name: rrt_ruby
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.0
7
- date: 2005-10-19
6
+ version: 0.3.1
7
+ date: 2005-10-20
8
8
  summary: rrt_ruby is a Ruby library providing access to Rose RealTime models through RRTEI
9
9
  require_paths:
10
10
  - lib