### Home Classes Methods

### In Files

- lib/geometry.rb

### Parent

LabelledShape

### Methods

- ::new
- #==
- #clone
- #create_pi
- #erase
- #paint
- #refresh

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

# CurrentLabelledShape

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

This class represents the current LabelledShape, that is, the design

### Attributes

group[RW]

Hash for the SU objects that group the units

pi[RW]

Hash for the permutation of @p, so its subsets are ordered in ascendent order of cardinality

### Public Class Methods

new(edges, points_and_materials) click to toggle source

edges | list of edges
points_and_materials | list of pairs (point, material)

Initializes the current labelled shape (the design), adding the edges and the points to the layer 0

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

    2364:

    2365:                 if Shade.using_sketchup

    2366:                         @s = Hash.new(nil)

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

    2368:                                 @s[layer.name] = BalancedBinaryTree.new

    2369:                         }

    2370:                         @p = Hash.new(nil)

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

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

    2373:                         }

    2374:                 else

    2375:                         @s = Hash.new(nil)

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

    2377:                         @p = Hash.new(nil)

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

    2379:                 end

    2380:

    2381:                 super(edges, points_and_materials)

    2382:

    2383:                 @pi = Hash.new(nil)

    2384:                 if Shade.using_sketchup

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

    2386:                                 @pi[layer.name] = PiList.new

    2387:                         }

    2388:                 else

    2389:                         @pi["Layer0"] = PiList.new

    2390:                 end

    2391:

    2392:                 @p["Layer0"].reset_iterator

    2393:                 i =0

    2394:                 while (n=@p["Layer0"].get_next)

    2395:                         cardinality = n.list.size

    2396:                         node = LinearLinkedListNode.new(cardinality, i, nil)

    2397:                         #So the indexes (i) are sorted by ascending order of the cardinalities

    2398:                         @pi["Layer0"].insert_node(node)

    2399:                         i+=1

    2400:                 end

    2401:

    2402:                 @group = Hash.new(nil)

    2403:         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 2555
    2555:         def ==(other_shape)

    2556:                 result = true

    2557:                 if (other_shape.kind_of? CurrentLabelledShape)

    2558:                         @p.keys.each { |layer_name|

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

    2560:                         }

    2561:                 else

    2562:                         result = false

    2563:                 end

    2564:                 return result

    2565:         end

clone() click to toggle source

returns | a new CurrentLabelledShape object identical to this one

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

    2569:                 new_shape = CurrentLabelledShape.new(Array.new, Array.new)

    2570:

    2571:                 @s.each_key { |layer_name|

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

    2573:                 }

    2574:                 @p.each_key { |layer_name|

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

    2576:                 }

    2577:

    2578:                 new_shape.create_pi

    2579:

    2580:                 return new_shape

    2581:         end

create_pi() click to toggle source

Creates the permutation for ordering the labelled point list

          # File lib/geometry.rb, line 2406
    2406:         def create_pi()

    2407:                 @p.keys.each {|layer_name|

    2408:                         @pi[layer_name] = PiList.new

    2409:                         @p[layer_name].reset_iterator

    2410:                         i =0

    2411:                         while (n=@p[layer_name].get_next)

    2412:                                 cardinality = n.list.size

    2413:                                 node = LinearLinkedListNode.new(cardinality, i, nil)

    2414:                                 #So the indexes (i) are sorted by ascending order of the cardinalities

    2415:                                 @pi[layer_name].insert_node(node)

    2416:                                 i+=1

    2417:                         end

    2418:                         #puts "pi size: #{@pi[layer_name].size}"

    2419:                 }

    2420:         end

erase() click to toggle source

Erases the shape

          # File lib/geometry.rb, line 2431
    2431:         def erase()

    2432:                 if Shade.using_sketchup

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

    2434:                                 if (@group[layer.name] and !@group[layer.name].deleted?)

    2435:                                         Sketchup.active_model.entities.erase_entities @group[layer.name]

    2436:                                 end

    2437:                         }

    2438:                         @group = Hash.new(nil)

    2439:                 end

    2440:         end

paint(show_labels = true, layer = nil) click to toggle source

show_labels | true if the labels are to be shown in the canvas; false otherwise
layer | SketchUp Layer object that is to be painted

Paints the view of the shape

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

    2448:                 if Shade.using_sketchup

    2449:                         entities = Sketchup.active_model.entities

    2450:

    2451:                         if !layer

    2452:                                 erase

    2453:                                 @s.each_key {|layer_name|

    2454:                                         @group[layer_name] = entities.add_group

    2455:

    2456:                                         @s[layer_name].reset_iterator

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

    2458:                                                 node.list.reset_iterator

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

    2460:                                                         @group[layer_name].entities.add_line segment_node.key.tail.point, segment_node.key.head.point

    2461:                                                 end

    2462:                                         end

    2463:

    2464:                                         if show_labels

    2465:                                                 @p[layer_name].reset_iterator

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

    2467:                                                         label = node.key

    2468:                                                         node.list.reset_iterator

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

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

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

    2472:

    2473:                                                                         # Add circle

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

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

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

    2477:                                                                         #Add face

    2478:                                                                         face = label_group.entities.add_face edges

    2479:

    2480:                                                                         #Give color to the face

    2481:                                                                         label_group.material = label.value

    2482:                                                                 end

    2483:                                                         end

    2484:                                                 end

    2485:                                         end

    2486:

    2487:                                         #Find or create the layer

    2488:                                         found = false

    2489:                                         layer = nil

    2490:                                         i = 0

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

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

    2493:                                                         found = true

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

    2495:                                                 end

    2496:                                                 i+=1

    2497:                                         end

    2498:                                         if !found

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

    2500:                                                 # Draw vertical line

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

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

    2503:                                                 v_group = Sketchup.active_model.entities.add_group

    2504:                                                 v_group.entities.add_line point1,point2

    2505:                                                 v_group.layer = layer

    2506:                                         end

    2507:                                         @group[layer_name].layer = layer

    2508:

    2509:                                         @group[layer_name].transformation = Constants::AXIOM_T

    2510:                                 }

    2511:                         else

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

    2513:

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

    2515:

    2516:                                 @s[layer.name].reset_iterator

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

    2518:                                         node.list.reset_iterator

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

    2520:                                                 @group[layer.name].entities.add_line segment_node.key.tail.point, segment_node.key.head.point

    2521:                                         end

    2522:                                 end

    2523:

    2524:                                 if show_labels

    2525:                                         @p[layer.name].reset_iterator

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

    2527:                                                 label = node.key

    2528:                                                 node.list.reset_iterator

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

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

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

    2532:

    2533:                                                                 # Add circle

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

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

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

    2537:                                                                 #Add face

    2538:                                                                 face = label_group.entities.add_face edges

    2539:

    2540:                                                                 #Give color to the face

    2541:                                                                 label_group.material = label.value

    2542:                                                         end

    2543:                                                 end

    2544:                                         end

    2545:                                 end

    2546:

    2547:                                 @group[layer.name].transformation = Constants::AXIOM_T

    2548:                         end

    2549:                 end

    2550:         end

refresh(show_labels = true) click to toggle source

show_labels | true if the labels are to be shown in the canvas; false otherwise

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

          # File lib/geometry.rb, line 2424
    2424:         def refresh(show_labels = true)

    2425:                 if Shade.using_sketchup

    2426:                         paint(show_labels)

    2427:                 end

    2428:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.