### Home Classes Methods

### In Files

- lib/geometry.rb

### Parent

LabelledShape

### Methods

- ::new
- #==
- #add_label
- #clone
- #erase
- #load
- #paint
- #refresh
- #refresh_from_entities
- #save
- #transform
- #transformation

### 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.

# RuleLabelledShape

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

This class represents a RuleLabelledShape, that is, a shape which is part of a rule

### Attributes

group[RW]

Hash that stores, according to the layers, the SU objects that groups the units

shape_transformation[RW]

Hash that stores, according to the layers, the transformations applied to the shape

layout_transformation[RW]

The layout transformations (that is, to comply with the canvas arrangement) applied to the shape (to all its layers)

observer[RW]

Hash that stores, according to the layers, the observers which will listen to changes in the SU objects

host_rule_id[RW]

ID of the host rule

host_rule_part[RW]

Part of the host rule (Right, Left or Additive)

changed[RW]

True iff the shape representation has been changed

badly_erased[RW]

True iff the user has erased the shape

partner_changed[RW]

True iff the partner shape (the Right if it is a Left shape, and viceversa), has been changed

avoid_bug[RW]

Used as a trick for avoid SU bugs

shape_id[R]

ID of the shape

### Public Class Methods

new(edges, points_and_materials, host_rule_id, host_rule_part) click to toggle source

shape_id | identification of the shape
edges | list of edges
points_and_materials | list of pairs (point, material)
host_rule_id | id of the host rule, in case the shape is a rule shape
host_rule_part | part of the host rule, in case the shape is a rule shape
is_visual | true iff the shape is to be seen

Initializes the rule shape, putting the edges and points into layer 0

          # File lib/geometry.rb, line 1623
    1623:         def initialize(edges, points_and_materials, host_rule_id, host_rule_part)

    1624:                 @shape_id = 1

    1625:                 @group = Hash.new(nil)

    1626:

    1627:                 if Shade.using_sketchup

    1628:                         @shape_transformation = Hash.new(Geom::Transformation.new)

    1629:                         @layout_transformation = Geom::Transformation.new

    1630:

    1631:                         @observer = Hash.new(nil)

    1632:

    1633:                         @changed = true

    1634:                         @badly_erased = false

    1635:                         @partner_changed = false

    1636:                         @avoid_bug = false

    1637:

    1638:                         @host_rule_id = host_rule_id

    1639:                         @host_rule_part = host_rule_part

    1640:

    1641:                         @shape_id = shape_id

    1642:

    1643:                         @s = Hash.new(nil)

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

    1645:                                 @s[layer.name] = LinearLinkedList.new

    1646:                         }

    1647:                         @p = Hash.new(nil)

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

    1649:                                 @p[layer.name] = LinearLinkedList.new

    1650:                         }

    1651:                 else

    1652:                         @shape_id = shape_id

    1653:

    1654:                         @s = Hash.new(nil)

    1655:                         @s["Layer0"] = LinearLinkedList.new

    1656:                         @p = Hash.new(nil)

    1657:                         @p["Layer0"] = LinearLinkedList.new

    1658:                 end

    1659:

    1660:                 super(edges, points_and_materials)

    1661:

    1662:         end

### Public Instance Methods

==(other_shape) click to toggle source

other_shape | another LabelledShape
returns | true iff this shape and the specified one are identical

          # File lib/geometry.rb, line 2321
    2321:         def ==(other_shape)

    2322:                 result = true

    2323:                 if (other_shape.kind_of? RuleLabelledShape)

    2324:                         i = 0

    2325:                         @s.keys.each{ |layer_name|

    2326:                                 result = (result && ((@s[layer_name] == other_shape.s[layer_name])&&(@p[layer_name] == other_shape.p[layer_name])))

    2327:

    2328:                                 i+=1

    2329:                         }

    2330:                 else

    2331:                         result = false

    2332:                 end

    2333:                 return result

    2334:         end

add_label(point, value, layer_name) click to toggle source

point | a Point object
value | the name of the label value
layer_name | the layer name on which the label is going to be added

Adds a label to the shape in the position determined by point, with the specified value and in the specified layer

          # File lib/geometry.rb, line 2063
    2063:         def add_label(point, value, layer_name)

    2064:                 label = Label.new(value)

    2065:                 point_list = LinearLinkedList.new

    2066:

    2067:                 node = LinearLinkedListNode.new(label, point_list, nil)

    2068:

    2069:                 inserted_node = @p[layer_name].insert_node(node) #Insert the node corresponding to the label of the point

    2070:

    2071:                 point_node = LinearLinkedListNode.new(OrderedPoint.new(point), nil, nil)

    2072:                 inserted_node.list.insert_node(point_node) #Insert the point node

    2073:         end

clone() click to toggle source

Produces another RuleLabelledShape, identical to this one

          # File lib/geometry.rb, line 2337
    2337:         def clone()

    2338:                 new_shape = RuleLabelledShape.new(Array.new,Array.new,nil,nil)

    2339:                 @s.each_key { |layer_name|

    2340:                         new_shape.s[layer_name] = @s[layer_name].clone

    2341:                 }

    2342:                 @p.each_key { |layer_name|

    2343:                         new_shape.p[layer_name] = @p[layer_name].clone

    2344:                 }

    2345:                 return new_shape

    2346:         end

erase(print = false) click to toggle source

Erases the shape

          # File lib/geometry.rb, line 2168
    2168:         def erase(print = false)

    2169:                 if Shade.using_sketchup

    2170:                         Shade.rule_groups_observer.observed_id_list.delete @shape_id

    2171:                         Shade.project.modifying = true

    2172:                         Shade.project.erasing = true

    2173:                         @group.each_key {|layer_name|

    2174:

    2175:                                 if @group[layer_name] and !@group[layer_name].deleted?

    2176:                                         @group[layer_name].entities.remove_observer @observer[layer_name]

    2177:                                         @observer[layer_name] = nil

    2178:                                         if @group[layer_name].valid? and !@avoid_bug #For avoiding bugs

    2179:                                                 Sketchup.active_model.entities.erase_entities @group[layer_name]

    2180:

    2181:                                         end

    2182:                                 end

    2183:                                 Shade.project.modifying = true

    2184:                         }

    2185:                         Shade.project.modifying = false

    2186:                         Shade.project.erasing = false

    2187:                         @group = Hash.new(nil)

    2188:                 end

    2189:         end

load(path) click to toggle source

path | path to load the shape from

Loads the shape in the specified path

          # File lib/geometry.rb, line 1761
    1761:         def load(path)

    1762:

    1763:                 if Shade.using_sketchup

    1764:                         extension = ShadeUtils.get_extension(path)

    1765:

    1766:                         if extension == "skp"

    1767:

    1768:                                 #We remove everything

    1769:                                 rules = Shade.project.execution.grammar.rules

    1770:                                 rules.each {|rule|

    1771:                                         rule.erase

    1772:                                 }

    1773:                                 Shade.project.execution.current_shape.erase

    1774:                                 Sketchup.active_model.active_entities.erase_entities(Sketchup.active_model.active_entities.to_a)

    1775:

    1776:                                 path = path.tr("\\","/")

    1777:                                 Sketchup.active_model.save("trash.skp")

    1778:                                 Sketchup.open_file(path) #A group is loaded

    1779:                                 File.delete("trash.skp")

    1780:                                 entities = Sketchup.active_model.entities[0].entities

    1781:

    1782:                                 edges = Array.new

    1783:                                 points_and_materials = Array.new

    1784:

    1785:                                 entities.each { |e|

    1786:                                         if e.kind_of? Sketchup::Edge

    1787:                                                 edges.push e

    1788:                                         elsif e.kind_of? Sketchup::Group

    1789:                                                 e.entities.each { |ge|

    1790:                                                         if ge.kind_of? Sketchup::ConstructionPoint

    1791:                                                                 points_and_materials.push [ge.position, e.material]

    1792:                                                         end

    1793:                                                 }

    1794:

    1795:                                         end

    1796:                                 }

    1797:

    1798:                                 @shape_transformation = @layout_transformation.inverse * Sketchup.active_model.entities[0].transformation

    1799:

    1800:                                 self.refresh_from_info(edges, points_and_materials)

    1801:

    1802:                                 Sketchup.active_model.active_entities.erase_entities(Sketchup.active_model.active_entities.to_a)

    1803:

    1804:                                 #We repaint everything

    1805:                                 ShadeUtils.prepare_canvas(false)

    1806:                                 rules.each {|rule|

    1807:                                         rule.repaint

    1808:                                 }

    1809:                                 Shade.project.execution.current_shape.paint

    1810:                         elsif extension == "txt"

    1811:                                 layer_found = false

    1812:                                 File.open(path, 'r') do |f|

    1813:                                         while line = f.gets

    1814:                                                 line_a1 = line.split(":")

    1815:                                                 if line_a1[0].strip == "S" #Segment

    1816:                                                         if !layer_found

    1817:                                                                 if self.kind_of? CurrentLabelledShape

    1818:                                                                         @s["Layer0"] = BalancedBinaryTree.new

    1819:                                                                 else

    1820:                                                                         @s["Layer0"] = LinearLinkedList.new

    1821:                                                                 end

    1822:                                                                 @p["Layer0"] = LinearLinkedList.new

    1823:                                                                 layer_name = "Layer0"

    1824:                                                                 layer_found = true

    1825:                                                         end

    1826:                                                         line_a = line_a1[1].split

    1827:                                                         segment = Segment.new(OrderedPoint.new(Geom::Point3d.new(line_a[0].to_f.m, line_a[1].to_f.m, 0)), OrderedPoint.new(Geom::Point3d.new(line_a[2].to_f.m, line_a[3].to_f.m, 0)))

    1828:                                                         segment_list = LinearLinkedList.new

    1829:

    1830:                                                         if @s[layer_name].kind_of? LinearLinkedList

    1831:                                                                 node = LinearLinkedListNode.new(segment.line_descriptor, segment_list, nil)

    1832:                                                         else

    1833:                                                                 node = BalancedBinaryTreeNode.new(Constants::BALANCED, nil, nil, segment.line_descriptor, segment_list)

    1834:                                                         end

    1835:

    1836:                                                         inserted_node = @s[layer_name].insert_node(node) #Insert the node corresponding to the line descriptor of the segment

    1837:

    1838:                                                         #We create an auxiliar list filled with the new segment to add, in order to make the union and obtain the maximal lines

    1839:                                                         new_segment_list = LinearLinkedList.new

    1840:                                                         segment_node = LinearLinkedListNode.new(segment.clone, nil, nil)

    1841:                                                         new_segment_list.insert_node(segment_node)

    1842:

    1843:                                                         op_rel(inserted_node.list,  new_segment_list, Constants::UNION, Constants::SEGMENTS)

    1844:

    1845:                                                 elsif line_a1[0].strip == "L" #Label

    1846:                                                         if !layer_found

    1847:                                                                 if self.kind_of? CurrentLabelledShape

    1848:                                                                         @s["Layer0"] = BalancedBinaryTree.new

    1849:                                                                 else

    1850:                                                                         @s["Layer0"] = LinearLinkedList.new

    1851:                                                                 end

    1852:                                                                 @p["Layer0"] = LinearLinkedList.new

    1853:                                                                 layer_name = "Layer0"

    1854:                                                                 layer_found = true

    1855:                                                         end

    1856:                                                         line_a = line_a1[1].split

    1857:                                                         color = line_a[2]

    1858:                                                         raise LoadError, "The color name: #{color} of shape in file #{path} is not recognized" unless Constants::RECOGNIZED_COLORS.include? color

    1859:                                                         label = Label.new(line_a[2])

    1860:                                                         point = OrderedPoint.new(Geom::Point3d.new(line_a[0].to_f.m, line_a[1].to_f.m, 0))

    1861:                                                         point_list = LinearLinkedList.new

    1862:

    1863:                                                         if @p[layer_name].kind_of? LinearLinkedList

    1864:                                                                 node = LinearLinkedListNode.new(label, point_list, nil)

    1865:                                                         else

    1866:                                                                 node = BalancedBinaryTreeNode.new(Constants::BALANCED, nil, nil, label, point_list)

    1867:                                                         end

    1868:

    1869:                                                         inserted_node = @p[layer_name].insert_node(node) #Insert the node corresponding to the label of the point

    1870:

    1871:                                                         point_node = LinearLinkedListNode.new(point, nil, nil)

    1872:                                                         inserted_node.list.insert_node(point_node) #Insert the point node

    1873:                                                 elsif line_a1[0].strip == "LAYER"

    1874:                                                         layer_found = true

    1875:                                                         layer_name = line_a1[1].strip

    1876:                                                         if self.kind_of? CurrentLabelledShape

    1877:                                                                 @s[layer_name] = BalancedBinaryTree.new

    1878:                                                         else

    1879:                                                                 @s[layer_name] = LinearLinkedList.new

    1880:                                                         end

    1881:                                                         @p[layer_name] = LinearLinkedList.new

    1882:                                                 end

    1883:                                         end

    1884:                                 end

    1885:                                 recompute_intersection_points

    1886:                                 paint

    1887:                         end

    1888:                 else

    1889:                         extension = ShadeUtils.get_extension(path)

    1890:

    1891:                         if extension == "txt"

    1892:                                 File.open(path, 'r') do |f|

    1893:                                         layer_found = false

    1894:                                         while line = f.gets

    1895:                                                 line_a1 = line.split(":")

    1896:                                                 if line_a1[0].strip == "S" #Segment

    1897:                                                         if !layer_found

    1898:                                                                 if self.kind_of? CurrentLabelledShape

    1899:                                                                         @s["Layer0"] = BalancedBinaryTree.new

    1900:                                                                 else

    1901:                                                                         @s["Layer0"] = LinearLinkedList.new

    1902:                                                                 end

    1903:                                                                 @p["Layer0"] = LinearLinkedList.new

    1904:                                                                 layer_name = "Layer0"

    1905:                                                                 layer_found = true

    1906:                                                         end

    1907:                                                         line_a = line_a1[1].split

    1908:                                                         segment = Segment.new(OrderedPoint.new(Point.new(line_a[0].to_f, line_a[1].to_f, 0)), OrderedPoint.new(Point.new(line_a[2].to_f, line_a[3].to_f, 0)))

    1909:                                                         segment_list = LinearLinkedList.new

    1910:

    1911:                                                         if @s[layer_name].kind_of? LinearLinkedList

    1912:                                                                 node = LinearLinkedListNode.new(segment.line_descriptor, segment_list, nil)

    1913:                                                         else

    1914:                                                                 node = BalancedBinaryTreeNode.new(Constants::BALANCED, nil, nil, segment.line_descriptor, segment_list)

    1915:                                                         end

    1916:

    1917:                                                         inserted_node = @s[layer_name].insert_node(node) #Insert the node corresponding to the line descriptor of the segment

    1918:

    1919:                                                         #We create an auxiliar list filled with the new segment to add, in order to make the union and obtain the maximal lines

    1920:                                                         new_segment_list = LinearLinkedList.new

    1921:                                                         segment_node = LinearLinkedListNode.new(segment.clone, nil, nil)

    1922:                                                         new_segment_list.insert_node(segment_node)

    1923:

    1924:                                                         op_rel(inserted_node.list,  new_segment_list, Constants::UNION, Constants::SEGMENTS)

    1925:

    1926:                                                 elsif line_a1[0].strip == "L" #Label

    1927:                                                         if !layer_found

    1928:                                                                 if self.kind_of? CurrentLabelledShape

    1929:                                                                         @s["Layer0"] = BalancedBinaryTree.new

    1930:                                                                 else

    1931:                                                                         @s["Layer0"] = LinearLinkedList.new

    1932:                                                                 end

    1933:                                                                 @p["Layer0"] = LinearLinkedList.new

    1934:                                                                 layer_name = "Layer0"

    1935:                                                                 layer_found = true

    1936:                                                         end

    1937:                                                         line_a = line_a1[1].split

    1938:                                                         color = line_a[2]

    1939:                                                         raise LoadError, "The color name: #{color} of shape in file #{path} is not recognized" unless Constants::RECOGNIZED_COLORS.include? color

    1940:                                                         label = Label.new(line_a[2])

    1941:                                                         point = OrderedPoint.new(Point.new(line_a[0].to_f, line_a[1].to_f, 0))

    1942:                                                         point_list = LinearLinkedList.new

    1943:

    1944:                                                         if @p[layer_name].kind_of? LinearLinkedList

    1945:                                                                 node = LinearLinkedListNode.new(label, point_list, nil)

    1946:                                                         else

    1947:                                                                 node = BalancedBinaryTreeNode.new(Constants::BALANCED, nil, nil, label, point_list)

    1948:                                                         end

    1949:

    1950:                                                         inserted_node = @p[layer_name].insert_node(node) #Insert the node corresponding to the label of the point

    1951:

    1952:                                                         point_node = LinearLinkedListNode.new(point, nil, nil)

    1953:                                                         inserted_node.list.insert_node(point_node) #Insert the point node

    1954:                                                 elsif line_a1[0].strip == "LAYER"

    1955:                                                         layer_found = true

    1956:                                                         layer_name = line_a1[1].strip

    1957:                                                         if self.kind_of? CurrentLabelledShape

    1958:                                                                 @s[layer_name] = BalancedBinaryTree.new

    1959:                                                         else

    1960:                                                                 @s[layer_name] = LinearLinkedList.new

    1961:                                                         end

    1962:                                                         @p[layer_name] = LinearLinkedList.new

    1963:                                                 end

    1964:                                         end

    1965:                                 end

    1966:                                 recompute_intersection_points

    1967:                                 paint

    1968:                         end

    1969:                 end

    1970:

    1971:

    1972:         end

paint(layer = nil) click to toggle source

layer | name of the layer that is to be painted

Paints the view of the shape

          # File lib/geometry.rb, line 2195
    2195:         def paint(layer = nil)

    2196:                 if Shade.using_sketchup

    2197:                         Shade.project.modifying = true

    2198:                         entities = Sketchup.active_model.entities

    2199:

    2200:                         if !layer

    2201:                                 erase

    2202:                                 Shade.project.modifying = true

    2203:                                 @s.each_key { |layer_name|

    2204:

    2205:                                         if ((@s[layer_name].size > 0) or (@p[layer_name].size > 0))

    2206:

    2207:                                                 @group[layer_name] = entities.add_group

    2208:

    2209:

    2210:                                                 @s[layer_name].reset_iterator

    2211:                                                 while (node = @s[layer_name].get_next)

    2212:                                                         node.list.reset_iterator

    2213:                                                         while (segment_node = node.list.get_next)

    2214:                                                                 @group[layer_name].entities.add_edges segment_node.key.tail.point, segment_node.key.head.point

    2215:                                                         end

    2216:                                                 end

    2217:

    2218:                                                 @p[layer_name].reset_iterator

    2219:                                                 while (node = @p[layer_name].get_next)

    2220:                                                         label = node.key

    2221:                                                         node.list.reset_iterator

    2222:                                                         while (labelled_point_node = node.list.get_next)

    2223:                                                                 if !(label.value==Constants::INTERSECTION_LABEL) #The label is a coloured circle

    2224:                                                                         label_group = @group[layer_name].entities.add_group

    2225:

    2226:                                                                         # Add circle

    2227:                                                                         edges = label_group.entities.add_circle labelled_point_node.key.point, Constants::LABEL_VECTOR, Shade.label_radius

    2228:                                                                         #Add construction point in order to locate the center later

    2229:                                                                         label_group.entities.add_cpoint labelled_point_node.key.point

    2230:                                                                         #Add face

    2231:                                                                         face = label_group.entities.add_face edges

    2232:

    2233:                                                                         #Give color to the face

    2234:                                                                         label_group.material = label.value

    2235:                                                                 end

    2236:                                                         end

    2237:                                                 end

    2238:

    2239:                                                 #Find or create the layer

    2240:                                                 found = false

    2241:                                                 layer = nil

    2242:                                                 i = 0

    2243:                                                 while (!found and (i < Sketchup.active_model.layers.length))

    2244:                                                         if (Sketchup.active_model.layers[i].name == layer_name)

    2245:                                                                 found = true

    2246:                                                                 layer = Sketchup.active_model.layers[i]

    2247:                                                         end

    2248:                                                         i+=1

    2249:                                                 end

    2250:                                                 if !found

    2251:                                                         layer = Sketchup.active_model.layers.add(layer_name)

    2252:                                                         # Draw vertical line

    2253:                                                         point1 = Constants::PTS_V[0].clone

    2254:                                                         point2 = Constants::PTS_V[1].clone

    2255:                                                         v_group = Sketchup.active_model.entities.add_group

    2256:                                                         v_group.entities.add_line point1,point2

    2257:                                                         v_group.layer = layer

    2258:                                                 end

    2259:

    2260:                                                 @group[layer_name].layer = layer

    2261:

    2262:                                                 @group[layer_name].transformation = @layout_transformation

    2263:

    2264:                                                 @observer[layer_name] = RuleShapeObserver.new(self)

    2265:                                                 @group[layer_name].entities.add_observer @observer[layer_name]

    2266:                                                 @shape_id = @group[layer_name].entityID

    2267:                                                 Shade.rule_groups_observer.observed_id_list.push @group[layer_name].entityID

    2268:                                         end

    2269:                                 }

    2270:                         else

    2271:                                 if ((@s[layer.name].size > 0) or (@p[layer.name].size > 0))

    2272:                                         @group[layer.name] = entities.add_group

    2273:

    2274:

    2275:                                         @s[layer.name].reset_iterator

    2276:                                         while (node = @s[layer.name].get_next)

    2277:                                                 node.list.reset_iterator

    2278:                                                 while (segment_node = node.list.get_next)

    2279:                                                         @group[layer.name].entities.add_edges segment_node.key.tail.point, segment_node.key.head.point

    2280:                                                 end

    2281:                                         end

    2282:

    2283:                                         @p[layer.name].reset_iterator

    2284:                                         while (node = @p[layer.name].get_next)

    2285:                                                 label = node.key

    2286:                                                 node.list.reset_iterator

    2287:                                                 while (labelled_point_node = node.list.get_next)

    2288:                                                         if !(label.value==Constants::INTERSECTION_LABEL) #The label is a coloured circle

    2289:                                                                 label_group = @group[layer.name].entities.add_group

    2290:

    2291:                                                                 # Add circle

    2292:                                                                 edges = label_group.entities.add_circle labelled_point_node.key.point, Constants::LABEL_VECTOR, Shade.label_radius

    2293:                                                                 #Add construction point in order to locate the center later

    2294:                                                                 label_group.entities.add_cpoint labelled_point_node.key.point

    2295:                                                                 #Add face

    2296:                                                                 face = label_group.entities.add_face edges

    2297:

    2298:                                                                 #Give color to the face

    2299:                                                                 label_group.material = label.value

    2300:                                                         end

    2301:                                                 end

    2302:                                         end

    2303:

    2304:                                         @group[layer.name].layer = layer

    2305:

    2306:                                         @group[layer.name].transformation = @layout_transformation

    2307:

    2308:                                         @observer[layer.name] = RuleShapeObserver.new(self)

    2309:                                         @group[layer.name].entities.add_observer @observer[layer.name]

    2310:                                         @shape_id = @group[layer.name].entityID

    2311:                                         Shade.rule_groups_observer.observed_id_list.push @group[layer.name].entityID

    2312:                                 end

    2313:                         end

    2314:                         Shade.project.modifying = false

    2315:                 end

    2316:         end

refresh(force = false) click to toggle source

force | true if you want to force the refreshing (that is, to refresh it even when the flag for @changed is false); false otherwise

Refreshes the view of the shape, in case it has been changed

          # File lib/geometry.rb, line 2078
    2078:         def refresh(force = false)

    2079:                 if Shade.using_sketchup

    2080:                         Shade.project.modifying = true

    2081:                         if @changed or @badly_erased or force

    2082:                                 @avoid_bug = (@avoid_bug or @badly_erased)

    2083:                                 @changed = false

    2084:                                 @badly_erased = false

    2085:                                 paint()

    2086:                                 @avoid_bug = false

    2087:                         end

    2088:                         Shade.project.modifying = false

    2089:                 end

    2090:         end

refresh_from_entities(entities, transformation, layer_name) click to toggle source

edges | an array of SketchUp Edges
points_and_materials | an array of pairs [Point3d, Material], both of them are classes of SketchUp
layer | SketchUp Layer object that is affected

Refresh the internal representation of the shape according to the current SketchUp canvas content inside the group of the shape

          # File lib/geometry.rb, line 2097
    2097:         def refresh_from_entities(entities, transformation, layer_name)

    2098:                 if Shade.using_sketchup

    2099:

    2100:                         edges = Array.new

    2101:                         points_and_materials = Array.new

    2102:

    2103:                         final_transformation = transformation.inverse * @shape_transformation[layer_name]

    2104:

    2105:                         entities.each { |e|

    2106:                                 if e.kind_of? Sketchup::Edge

    2107:                                         edges.push e

    2108:                                 elsif e.kind_of? Sketchup::Group

    2109:                                         e.entities.each { |ge|

    2110:                                                 if ge.kind_of? Sketchup::ConstructionPoint

    2111:                                                         #points_and_materials.push [final_transformation * ge.position, e.material]

    2112:                                                         #I don't understand why it is not necessary to apply the transformation to the construction points

    2113:                                                         #Maybe their position is not given w.r.t. their parent groups...

    2114:                                                         t =  @layout_transformation.inverse * e.transformation

    2115:                                                         points_and_materials.push [t * ge.position, e.material]

    2116:                                                 end

    2117:                                         }

    2118:

    2119:                                 end

    2120:                         }

    2121:

    2122:                         @s[layer_name] = LinearLinkedList.new

    2123:                         @p[layer_name] = LinearLinkedList.new

    2124:                         edges.each { |e|

    2125:                                 segment = Segment.new(OrderedPoint.new(final_transformation*e.start.position), OrderedPoint.new(final_transformation*e.end.position))

    2126:                                 segment_list = LinearLinkedList.new

    2127:

    2128:                                 if @s[layer_name].kind_of? LinearLinkedList

    2129:                                         node = LinearLinkedListNode.new(segment.line_descriptor, segment_list, nil)

    2130:                                 else

    2131:                                         node = BalancedBinaryTreeNode.new(Constants::BALANCED, nil, nil, segment.line_descriptor, segment_list)

    2132:                                 end

    2133:

    2134:                                 inserted_node = @s[layer_name].insert_node(node) #Insert the node corresponding to the line descriptor of the segment

    2135:

    2136:                                 #We create an auxiliar list filled with the new segment to add, in order to make the union and obtain the maximal lines

    2137:                                 new_segment_list = LinearLinkedList.new

    2138:                                 segment_node = LinearLinkedListNode.new(segment.clone, nil, nil)

    2139:                                 new_segment_list.insert_node(segment_node)

    2140:

    2141:                                 op_rel(inserted_node.list,  new_segment_list, Constants::UNION, Constants::SEGMENTS)

    2142:                         }

    2143:

    2144:                         #Compound the label lists

    2145:                         points_and_materials.each { |pair|

    2146:                                 point = pair[0]

    2147:

    2148:                                 label = Label.new(pair[1])

    2149:

    2150:                                 point_list = LinearLinkedList.new

    2151:

    2152:                                 if @p[layer_name].kind_of? LinearLinkedList

    2153:                                         node = LinearLinkedListNode.new(label, point_list, nil)

    2154:                                 else

    2155:                                         node = BalancedBinaryTreeNode.new(Constants::BALANCED, nil, nil, label, point_list)

    2156:                                 end

    2157:                                 inserted_node = @p[layer_name].insert_node(node) #Insert the node corresponding to the label of the point

    2158:

    2159:                                 point_node = LinearLinkedListNode.new(OrderedPoint.new(point), nil, nil)

    2160:                                 inserted_node.list.insert_node(point_node) #Insert the point node

    2161:                         }

    2162:

    2163:                         recompute_intersection_points

    2164:                 end

    2165:         end

save(path) click to toggle source

path | path to save the shape in

Saves the shape in the specified path

          # File lib/geometry.rb, line 1667
    1667:         def save(path)

    1668:                 if Shade.using_sketchup

    1669:                         extension = ShadeUtils.get_extension(path)

    1670:

    1671:                         if extension == "skp"

    1672:                                 rules = Shade.project.execution.grammar.rules

    1673:                                 rules.each {|rule|

    1674:                                         rule.erase

    1675:                                 }

    1676:                                 Sketchup.active_model.entities

    1677:                                 Shade.project.execution.current_shape.erase

    1678:

    1679:                                 Sketchup.active_model.active_entities.erase_entities(Sketchup.active_model.active_entities.to_a)

    1680:

    1681:                                 layout_t = @layout_transformation

    1682:                                 @layout_transformation = Geom::Transformation.new

    1683:                                 self.paint

    1684:                                 @layout_transformation = layout_t

    1685:

    1686:                                 path = path.tr("\\","/")

    1687:                                 Sketchup.active_model.save(path)

    1688:

    1689:                                 ShadeUtils.prepare_canvas(false)

    1690:                                 rules.each {|rule|

    1691:                                         rule.repaint

    1692:                                 }

    1693:                                 Shade.project.execution.current_shape.paint

    1694:                         elsif extension == "txt"

    1695:                                 File.open(path, 'w') do |f|

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

    1697:                                                 f.write("LAYER: #{layer.name}\n")

    1698:                                                 if @s[layer.name]

    1699:                                                         @s[layer.name].reset_iterator

    1700:                                                         while s_node = @s[layer.name].get_next

    1701:                                                                 s_node.list.reset_iterator

    1702:                                                                 while s = s_node.list.get_next

    1703:                                                                 tail_x = ((s.key.tail.x.to_f.to_m * 100).round.to_f / 100)

    1704:                                                                 tail_y = ((s.key.tail.y.to_f.to_m * 100).round.to_f / 100)

    1705:                                                                 head_x = ((s.key.head.x.to_f.to_m* 100).round.to_f / 100)

    1706:                                                                 head_y = ((s.key.head.y.to_f.to_m * 100).round.to_f / 100)

    1707:                                                                         f.write("S: #{tail_x} #{tail_y} #{head_x} #{head_y}\n")

    1708:                                                                 end

    1709:                                                         end

    1710:                                                 end

    1711:                                                 if @p[layer.name]

    1712:                                                         @p[layer.name].reset_iterator

    1713:                                                         while l_node = @p[layer.name].get_next

    1714:                                                                 if !(l_node.key.value == Constants::INTERSECTION_LABEL)

    1715:                                                                         l_node.list.reset_iterator

    1716:                                                                         while l = l_node.list.get_next

    1717:                                                                                 key_x = ((l.key.x.to_f.to_m * 100).round.to_f / 100)

    1718:                                                                                 key_y = ((l.key.y.to_f.to_m * 100).round.to_f / 100)

    1719:                                                                                 f.write("L: #{key_x} #{key_y} #{l_node.key.value}\n")

    1720:                                                                         end

    1721:                                                                 end

    1722:                                                         end

    1723:                                                 end

    1724:                                         }

    1725:                                 end

    1726:                         end

    1727:                 else

    1728:                         extension = ShadeUtils.get_extension(path)

    1729:

    1730:                         if extension == "txt"

    1731:                                 File.open(path, 'w') do |f|

    1732:                                         @s.each_key { |layer_name|

    1733:                                                 f.write("LAYER: #{layer_name}\n")

    1734:                                                 @s[layer_name].reset_iterator

    1735:                                                 while s_node = @s[layer_name].get_next

    1736:                                                         s_node.list.reset_iterator

    1737:                                                         while s = s_node.list.get_next

    1738:                                                                 f.write("S: #{s.key.tail.x.to_f} #{s.key.tail.y.to_f} #{s.key.head.x.to_f} #{s.key.head.y.to_f}\n")

    1739:                                                         end

    1740:                                                 end

    1741:                                                 @p[layer_name].reset_iterator

    1742:                                                 while l_node = @p[layer_name].get_next

    1743:                                                         if !(l_node.key.value == Constants::INTERSECTION_LABEL)

    1744:                                                                 l_node.list.reset_iterator

    1745:                                                                 while l = l_node.list.get_next

    1746:                                                                         f.write("L: #{l.key.x.to_f} #{l.key.y.to_f} #{l_node.key.value}\n")

    1747:                                                                 end

    1748:                                                         end

    1749:                                                 end

    1750:                                         }

    1751:                                 end

    1752:                         end

    1753:                 end

    1754:

    1755:

    1756:         end

transform(t) click to toggle source

t | a transformation, represented by an array of 6 positions (representing a 2x3 transformation matrix)

Returns a new shape that is the result of transforming this shape by means of the specified transformation

          # File lib/geometry.rb, line 1977
    1977:         def transform(t)

    1978:                 #Extract the coefficients of the transformation matrix

    1979:                 ax = t[0]

    1980:                 bx = t[1]

    1981:                 cx = t[2]

    1982:                 ay = t[3]

    1983:                 by = t[4]

    1984:                 cy = t[5]

    1985:                 new_shape = self.clone

    1986:                 @s.each_key {|layer_name|

    1987:                         #First, we transform the segments

    1988:                         new_s = LinearLinkedList.new

    1989:                         new_shape.s[layer_name].reset_iterator

    1990:                         #Second, we remove the intersection points, if any

    1991:                         new_shape.p[layer_name].delete_node(Label.new(Constants::INTERSECTION_LABEL))

    1992:                         while (node = new_shape.s[layer_name].get_next)

    1993:                                 new_line_descriptor = nil

    1994:

    1995:                                 segment_list = node.list

    1996:                                 segment_list.reset_iterator

    1997:

    1998:                                 new_segment_list = LinearLinkedList.new

    1999:                                 while (segment_node = segment_list.get_next)

    2000:                                         tail = segment_node.key.tail

    2001:                                         head = segment_node.key.head

    2002:                                         #Transform the tail

    2003:                                         new_tail_x = tail.x * ax + tail.y * bx + cx

    2004:                                         new_tail_y = tail.x * ay + tail.y * by + cy

    2005:                                         new_tail = Point.new(new_tail_x, new_tail_y, 0)

    2006:                                         #Transform the head

    2007:                                         new_head_x = head.x * ax + head.y * bx + cx

    2008:                                         new_head_y = head.x * ay + head.y * by + cy

    2009:                                         new_head = Point.new(new_head_x, new_head_y, 0)

    2010:

    2011:                                         new_segment = Segment.new(OrderedPoint.new(new_tail), OrderedPoint.new(new_head))

    2012:                                         new_segment_list.insert_node(LinearLinkedListNode.new(new_segment, nil, nil))

    2013:                                         if !new_line_descriptor

    2014:                                                 new_line_descriptor = new_segment.line_descriptor

    2015:                                         end

    2016:                                 end

    2017:                                 new_node = LinearLinkedListNode.new(new_line_descriptor, new_segment_list, nil)

    2018:                                 new_s.insert_node(new_node)

    2019:                         end

    2020:                         new_shape.s[layer_name] = new_s

    2021:

    2022:                         #Second, we transform the points

    2023:                         new_p = LinearLinkedList.new

    2024:                         new_shape.p[layer_name].reset_iterator

    2025:                         while (node = new_shape.p[layer_name].get_next)

    2026:                                 new_label = node.key

    2027:

    2028:                                 point_list = node.list

    2029:                                 point_list.reset_iterator

    2030:

    2031:                                 new_point_list = LinearLinkedList.new

    2032:                                 while (point_node = point_list.get_next)

    2033:                                         point = point_node.key.point

    2034:                                         #Transform the point

    2035:                                         new_point_x = point.x * ax + point.y * bx + cx

    2036:                                         new_point_y = point.x * ay + point.y * by + cy

    2037:                                         new_point = Point.new(new_point_x, new_point_y, 0)

    2038:

    2039:                                         new_point_list.insert_node(LinearLinkedListNode.new(OrderedPoint.new(new_point), nil, nil))

    2040:                                 end

    2041:                                 new_node = LinearLinkedListNode.new(new_label, new_point_list, nil)

    2042:                                 new_p.insert_node(new_node)

    2043:                         end

    2044:                         new_shape.p[layer_name] = new_p

    2045:                 }

    2046:

    2047:                 new_shape.recompute_intersection_points

    2048:

    2049:                 return new_shape

    2050:         end

transformation(layer_name) click to toggle source

layer_name | name of the layer whose transformation is to be known

Returns transformation w.r.t. the origin

          # File lib/geometry.rb, line 2055
    2055:         def transformation(layer_name)

    2056:                 return @layout_transformation * @shape_transformation[layer_name]

    2057:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.