### Home Classes Methods

### In Files

- lib/main-structures.rb

### Parent

Object

### Methods

- ::new
- #alpha_minus_beta
- #beta_minus_alpha
- #erase
- #left
- #repaint
- #right

### Files

- LessThan5BlueLabels.txt
- AtLeast2LargeSegments.txt

### Class Index

Quicksearch

- AddLabelTool
- AllRulesAppliedGoal
- Area
- AreaConstraint
- Array
- BalancedBinaryTree
- BalancedBinaryTreeNode
- CloseObserver
- Constants
- Constraint
- CurrentLabelledShape
- DistinctShapeConstraint
- Execution
- Goal
- Grammar
- Label
- LabelledShape
- LineDescriptor
- LinearLinkedList
- LinearLinkedListNode
- NoLabelsGoal
- NoMoreRulesGoal
- NoScalesConstraint
- Numeric
- Object
- OrderedPoint
- PiList
- Point
- Project
- Robot
- Rule
- RuleGroupsObserver
- RuleLabelledShape
- RuleShapeObserver
- Segment
- ShaDeLayersObserver
- Shade
- ShadeUtils
- UndoObserver

No matching classes.

# Rule

Author | Manuela Ruiz (mruiz@lcc.uma.es)

This class represents a rule

### Attributes

rule_id[RW]

Internal rule ID

alpha[RW]

The left labelled shape

beta[RW]

The right labelled shape

alpha_minus_beta[RW]

The difference left - right shape

beta_minus_alpha[RW]

The difference right - left shape

line_group[RW]

Hashes of groups (one for each layer)

arrow_group[RW]
group_origin_left[RW]
group_origin_right[RW]
line_group_component[RW]
arrow_group_component[RW]
group_origin_left_component[RW]
group_origin_right_component[RW]

### Public Class Methods

new(rule_id, alpha, beta, line_group, arrow_group, group_origin_left, group_origin_right) click to toggle source

rule_id: internal id for the rule alpha: the left RuleLabelledShape beta: the right RuleLabelledShape

Initializes the rule

        # File lib/main-structures.rb, line 49
    49:         def initialize(rule_id, alpha, beta, line_group, arrow_group, group_origin_left, group_origin_right)

    50:

    51:                 @rule_id = rule_id

    52:

    53:                 @alpha = alpha

    54:                 @alpha.host_rule_id = rule_id

    55:                 @alpha.host_rule_part = Constants::LEFT

    56:

    57:                 @beta = beta

    58:                 @beta.host_rule_id = rule_id

    59:                 @beta.host_rule_part = Constants::RIGHT

    60:

    61:

    62:                 @line_group = line_group

    63:                 @arrow_group = arrow_group

    64:                 @group_origin_left = group_origin_left

    65:                 @group_origin_right = group_origin_right

    66:

    67:         end

### Public Instance Methods

alpha_minus_beta() click to toggle source

returns | the resulting shape of making the difference: alpha - beta (left and right shapes, respectively)

         # File lib/main-structures.rb, line 151
    151:         def alpha_minus_beta

    152:                 alpha_minus_beta = @alpha.clone

    153:                 alpha_minus_beta.shape_expression(@beta, Constants::DIFFERENCE, Constants::SEGMENTS)

    154:                 alpha_minus_beta.shape_expression(@beta, Constants::DIFFERENCE, Constants::POINTS)

    155:                 return alpha_minus_beta

    156:         end

beta_minus_alpha() click to toggle source

returns | the resulting shape of making the difference: beta - alpha (right and left shapes, respectively)

         # File lib/main-structures.rb, line 159
    159:         def beta_minus_alpha

    160:

    161:                 beta_minus_alpha = @beta.clone

    162:                 beta_minus_alpha.shape_expression(@alpha, Constants::DIFFERENCE, Constants::SEGMENTS)

    163:                 beta_minus_alpha.shape_expression(@alpha, Constants::DIFFERENCE, Constants::POINTS)

    164:                 return beta_minus_alpha

    165:         end

erase() click to toggle source

Erases the SU objects attached to the rule

         # File lib/main-structures.rb, line 168
    168:         def erase()

    169:                 if Shade.using_sketchup

    170:                         entities = Sketchup.active_model.entities

    171:

    172:                         Sketchup.active_model.layers.each { |layer|

    173:

    174:                                 if @arrow_group

    175:                                         if @arrow_group[layer.name]

    176:                                                 @arrow_group[layer.name].locked = false

    177:                                                 entities.erase_entities @arrow_group[layer.name]

    178:                                         end

    179:                                 end

    180:

    181:                                 if @line_group

    182:                                         if @line_group[layer.name]

    183:                                                 @line_group[layer.name].locked = false

    184:                                                 entities.erase_entities @line_group[layer.name]

    185:                                         end

    186:                                 end

    187:

    188:                                 if @group_origin_left

    189:                                         if @group_origin_left[layer.name]

    190:                                                 @group_origin_left[layer.name].locked = false

    191:                                                 entities.erase_entities @group_origin_left[layer.name]

    192:                                         end

    193:                                 end

    194:

    195:                                 if @group_origin_right

    196:                                         if @group_origin_right[layer.name]

    197:                                                 @group_origin_right[layer.name].locked = false

    198:                                                 entities.erase_entities @group_origin_right[layer.name]

    199:                                         end

    200:                                 end

    201:                         }

    202:

    203:                         @alpha.erase

    204:                         @beta.erase

    205:                 end

    206:         end

left() click to toggle source

returns | the left shape of the rule

        # File lib/main-structures.rb, line 70
    70:         def left

    71:                 return @alpha

    72:         end

repaint() click to toggle source

Repaints the rule

         # File lib/main-structures.rb, line 80
     80:         def repaint

     81:                 if Shade.using_sketchup

     82:                         @alpha.paint

     83:                         @beta.paint

     84:

     85:                         entities = Sketchup.active_model.entities

     86:

     87:                         t = Shade.project.execution.grammar.get_rule_index(self)

     88:

     89:                         # Transform the layout transformation of the origins

     90:                         t_left = Geom::Transformation.new

     91:                         t_right = Geom::Transformation.new

     92:                         t.times do

     93:                                 t_left = Constants::DESCEND_T * t_left

     94:                                 t_right = Constants::DESCEND_T * t_right

     95:                         end

     96:                         t_left = Constants::LEFT_T * t_left

     97:                         t_right = Constants::RIGHT_T * t_right

     98:

     99:                         # Draw an arrow, for the rule

    100:                         point1 = Constants::PTS_ARROW[0].clone

    101:                         point2 = Constants::PTS_ARROW[1].clone

    102:                         point3 = Constants::PTS_ARROW[2].clone

    103:                         point4 = Constants::PTS_ARROW[3].clone

    104:

    105:                         t.times do

    106:                                 point1.transform! Constants::DESCEND_T

    107:                                 point2.transform! Constants::DESCEND_T

    108:                                 point3.transform! Constants::DESCEND_T

    109:                                 point4.transform! Constants::DESCEND_T

    110:                         end

    111:

    112:                         @arrow_group = entities.add_group

    113:                         @arrow_group.entities.add_edges point1, point2

    114:                         @arrow_group.entities.add_edges point3, point2

    115:                         @arrow_group.entities.add_edges point4, point2

    116:                         @arrow_group.locked = true

    117:

    118:                         #Draw the origin references

    119:                         point1 = Constants::PTS_ORIGIN[0].clone

    120:                         point2 = Constants::PTS_ORIGIN[1].clone

    121:                         point3 = Constants::PTS_ORIGIN[2].clone

    122:                         point4 = Constants::PTS_ORIGIN[3].clone

    123:

    124:                         @group_origin_left = entities.add_group

    125:                         @group_origin_left.entities.add_edges point1, point3

    126:                         @group_origin_left.entities.add_edges point2, point4

    127:                         @group_origin_left.transformation = t_left

    128:                         @group_origin_left.locked = true

    129:

    130:                         @group_origin_right = entities.add_group

    131:                         @group_origin_right.entities.add_edges point1, point3

    132:                         @group_origin_right.entities.add_edges point2, point4

    133:                         @group_origin_right.transformation = t_right

    134:                         @group_origin_right.locked = true

    135:

    136:                         #Draw horizontal line

    137:                         point_h1 = Constants::PTS_H[0].clone

    138:                         point_h2 = Constants::PTS_H[1].clone

    139:

    140:                         t.times do

    141:                                 point_h1.transform! Constants::DESCEND_T

    142:                                 point_h2.transform! Constants::DESCEND_T

    143:                         end

    144:                         @line_group = entities.add_group

    145:                         @line_group.entities.add_line point_h1,point_h2

    146:                         @line_group.locked = true

    147:                 end

    148:         end

right() click to toggle source

returns | the right shape of the rule

        # File lib/main-structures.rb, line 75
    75:         def right

    76:                 return @beta

    77:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.