Author | Manuela Ruiz (mruiz@lcc.uma.es) |
This class gathers an Execution object and the necessary information in order to save it in a file
Initializing
# File lib/main-structures.rb, line 1505 1505: def initialize(execution) 1506: @execution = execution 1507: 1508: @saved = true 1509: @path = nil #the path in the OS file system 1510: 1511: @title = Constants::DEFAULT_PROJECT_TITLE 1512: 1513: @modifying = false 1514: 1515: @erasing = false 1516: 1517: end
path | path to load the project from |
Loads the project from the specified path
# File lib/main-structures.rb, line 1600 1600: def load(path) 1601: @path = path 1602: #the path is a .prj file 1603: #we need the directory 1604: directory = ShadeUtils.get_directory_from_path(path) 1605: 1606: @execution.constraints = Array.new 1607: @execution.goals = Array.new 1608: 1609: 1610: File.open(path.strip, 'r') do |f| 1611: while line = f.gets 1612: line_a = line.split(':') 1613: if (line_a[0] == "C") #Load a constraint 1614: constraint_name = line_a[1].strip 1615: i = 0 1616: found = false 1617: while (i < Shade.constraint_class_names.size) && !found 1618: if Shade.constraint_class_names[i][1] == constraint_name 1619: found = true 1620: constraint_class = Shade.constraint_class_names[i][0] 1621: @execution.add_constraint(constraint_class.new) 1622: end 1623: i += 1 1624: end 1625: elsif (line_a[0] == "G") #Load a goal 1626: goal_name = line_a[1].strip 1627: i = 0 1628: found = false 1629: while (i < Shade.goal_class_names.size) && !found 1630: if Shade.goal_class_names[i][1] == goal_name 1631: found = true 1632: goal_class = Shade.goal_class_names[i][0] 1633: @execution.add_goal(goal_class.new) 1634: end 1635: i += 1 1636: end 1637: else 1638: grammar_title = line.strip 1639: @execution.grammar.load("#{directory}#{grammar_title}") 1640: end 1641: end 1642: end 1643: 1644: 1645: end
force | true if we want to force refreshing, even when no changes have been registered |
Refreshes the view of the shapes in the project (that is, the rule shapes and the current shape)
# File lib/main-structures.rb, line 1650 1650: def refresh(force = false) 1651: if Shade.using_sketchup 1652: @modifying = true 1653: if @execution 1654: @execution.current_shape.refresh(@execution.show_labels) 1655: if @execution.grammar 1656: @execution.grammar.rules.each {|rule| 1657: rule.alpha.refresh(force) 1658: rule.beta.refresh(force) 1659: } 1660: end 1661: end 1662: @modifying = false 1663: end 1664: end
Removes all the attached observers
# File lib/main-structures.rb, line 1549 1549: def remove_observers() 1550: if Shade.using_sketchup 1551: size = execution.grammar.rules.size 1552: i = 0 1553: while i < size 1554: execution.grammar.remove_rule(size-i-1) 1555: i += 1 1556: end 1557: 1558: Sketchup.active_model.entities.remove_observer Shade.rule_groups_observer 1559: Shade.rule_groups_observer = nil 1560: GC.start 1561: end 1562: end
path | path to save the project in |
Saves the project in the specified path
# File lib/main-structures.rb, line 1522 1522: def save(path = @path, text = false) 1523: #the path is a .prj file 1524: #we need the directory 1525: directory = ShadeUtils.get_directory_from_path(path) 1526: title = ShadeUtils.get_title_from_path(path) 1527: File.open(path.strip, 'w') do |f| 1528: f.write("#{title}Grammar.gr2\n") 1529: @execution.constraints.each { |c| 1530: f.write "C:" 1531: f.write c.name + "\n" 1532: } 1533: @execution.goals.each { |g| 1534: f.write "G:" 1535: f.write g.name + "\n" 1536: } 1537: end 1538: @path = path 1539: @execution.grammar.save("#{directory}#{title}Grammar.gr2", text) 1540: @saved = true 1541: end
Returns true if both the project and its related grammar are saved
# File lib/main-structures.rb, line 1544 1544: def saved() 1545: return (@execution.grammar.saved and @saved) 1546: end
path | new path |
closing | true iff we are closing SU |
Sets the path
# File lib/main-structures.rb, line 1586 1586: def set_path(path, closing = false) 1587: #Set the path attribute 1588: @path = path 1589: 1590: if path 1591: set_title(ShadeUtils.get_title_from_path(path), closing) 1592: else 1593: set_title(Constants::DEFAULT_PROJECT_TITLE, closing) 1594: end 1595: end
new_title | String with the new title for the project |
closing | true iff SketchUp is being closed |
Changes the title of the project to new_title
# File lib/main-structures.rb, line 1568 1568: def set_title(new_title, closing = false) 1569: @title = title 1570: if Shade.using_sketchup 1571: if !closing 1572: if @title_text 1573: Sketchup.active_model.entities.erase_entities @title_text 1574: end 1575: if Shade.show_text 1576: @title_text = Sketchup.active_model.entities.add_text("Project: " + @title, Constants::PT_PROJECT_TEXT) 1577: end 1578: end 1579: end 1580: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.