Assignment 4 - Extend Recursive Mechanism Editor

Guidelines

Due at 11.59pm, Monday, April 1

There is no late policy for this course!

If you do not complete the assignment by the deadline, you will receive a lousy grade

Overview:

You will extend your mechanism editor.

Old Mechanism Editor Brief:

Create a sketch that allows you to draw a mechanism with the keyboard and/or mouse controlling the parameters. Like the previous recursive tree, you will create a tree-like structure for the parts of your mechanism.

The Root node represents the power wheel, and there will be a number of descendant wheels that are connected by belts to the power wheel. The power wheel drives each of the other wheels via its connecting belts.

Each wheel object in the tree is an instance of a class that has the visual and geometric properties of that wheel. It also has a pointer to each connecting belt.

Each belt in the tree connects a driving wheel to a receiving wheel. Each belt in the tree is an instance of a class that has the visual and geometric properties of that belt.

The mouse and/or keyboard interaction allows you to control some of the appearance of each part.

In this example, my red power wheel in the upper left drives two smaller blue wheels with two belts: one to the right and one below. The left blue wheel in turn drives the two small green wheels with two belts.
There are 5 wheel objects that are connected by 4 belt objects in my mechanism.

You need to create a structure that stores info about the current mechanical part, and has pointers/references to child instances. You need to store information about the bounding box of each drawable part of the mechanism so that you can select it and edit it. You will need to use PVectors for this, because PVector allows you to do things like
PVector v1 = new PVector( 10.0, 5.0 );
v1.rotate( HALF_PI );

With a wheel selected, you should have a little control panel in your editor to adjust the appearance of it. Appearance could mean color or radius, or anything suitable.

The New Stuff

Implementing Interfaces

You are provided with two jar files: interfacelib.jar and reflections.jar (available via Canvas). These are similar to core.jar and controlP5.jar. You are required to add these libraries to your Eclipse/Netbeans project.

interfacelib.jar provides two interfaces: Scrubbable and MechanismFactory.

Scrubbable

Your mechanism component(s) must impelemnt the Scrubbable interface. The Scrubbale interface provides following functions:

  1. String getName()
    This method should return the unique name of the component. Every mechanism component should have a name. For example, if you create a class called Wheel for an mechanism with seven wheels, the names for the wheels can be "Wheel1", "Wheel2", "Wheel3" and so on
  2. void setName(String name)
    This method should set the name of the component to value in name
  3. String[] getProperties()
    This method returns an array of the names of the parameters that are settable/gettable above
  4. void setParameter( String name, float value )
    This method takes a String that names a parameter in your base class, and sets that parameter to the value in value.
  5. float getParameter( String name )
    This method takes a String that names a parameter in your base class, returns the value of that variable.
  6. void draw()
    This method recursively draws the component. You probably already have this method in your components
  7. Scrubbable pick(int mouseX, int mouseY)
    This method takes the x and y coordinates for the mouse and checks if a component or a child component of a component was selected. If yes, returns the mechanism component that was clicked. If nothing was clicked/selected, this method returns null
  8. Iterator createIterator()
    This method returns an iterator for the Scrubbable class.

MechanismFactory

You will also create a single class which implements the MechanismFactory Interface. This interface has one method

  1. public Scrubbable getMechanism(PApplet p)
    This method returns your mechanism, i.e. the root of the mechanism. This is the method where you will create/construct the mechanism object. A class implementing this interface should not have any contructor.

Build an iterator.

For the createIterator() function from the Scrubbable interface, you need to create an Iterator that iterates through the structure of your mechanism.

  • Create the iterator for your class. It must do an InOrder traversal of the structure your mechanism. This iterator has all the information it needs to do a traversal of your mechanism's structure.
  • Since it implements Java's Iterator interface, you must implement
    1. boolean hasNext()
      this returns true if there is more mechanism parts left, else false
    2. Object next()
      this returns the next item in the traversal. To fit with Java's specification, you should cast the next item to Object. The client of the iterator can cast it to your parent class.
    3. void remove()
      just create a stub for this method.

Code Requirements:

You can use our code:

You can use our solution to Assignment 2 to build your mechanism.

Tips and Tricks