25
Jun 11

Twitter Updates for 2011-06-25


24
Jun 11

Twitter Updates for 2011-06-24


22
Jun 11

Twitter Updates for 2011-06-22


19
Jun 11

Twitter Updates for 2011-06-19


18
Jun 11

Twitter Updates for 2011-06-18


17
Jun 11

Developing a Vectorworks 2011 tool plug-in, TDD-style – Episode 2

With a basic mock implementation of the tool point collecting part of a Vectorworks tool under our belt, let’s try to connect this class to a “real” Vectorworks tool event sink.

Using the MockRedGreenLineTool from within a CTool_EventSink doesn’t sound quite right. After all it’s supposed to be a mock implementation. We need to use a real tool implementation in the CTool_EventSink. Let’s do some restructuring to accomplish that. First, create a new class RedGreenLineTool with the code from MockRedGreenLineTool.

class RedGreenLineTool {
	
public:
	
	virtual ~RedGreenLineTool() {
	}

 	void AddPoint(const WorldPt3& p) {
		fToolPoints.PushData(p);
	}	

	virtual void PopPoint() {
		fToolPoints.PopData();
	}

	short GetNumToolPoints() const {
		return fToolPoints.NumItems();
	}
	
	TSmallArray<WorldPt3> fToolPoints;

};

Now, make MockRedGreenLineTool a subclass of RedGreenLineTool:

class MockRedGreenLineTool : public RedGreenLineTool {
}

and create VectorworksRedGreenLineTool, which is also a subclass of RedGreenLineTool.

class VectorworksRedGreenLineTool : public RedGreenLineTool {
}

This sure looks better to our TDD newbie eye. We have a common implementation for both the MockRedGreenLineTool used for testing and a VectorworksRedGreenLineTool used to connect the code to Vectorworks. Running the tests shows we didn’t break anything. Now we are able to use VectorworksRedGreenLineTool in a VWToolDefaultLine_EventSink implementation:

long CTool_EventSink::LegacyMain(long action, long message1, long message2)
{
	long result = 0;
	
	switch (action) {

		case kToolDoSetup:
			result = VWToolDefaultLine_EventSink::LegacyMain(action, message1, message2);
			
			fRedGreenLineTool = new VectorworksRedGreenLineTool();
			break;
			
		case kToolDoSetDown:
			result = VWToolDefaultLine_EventSink::LegacyMain(action, message1, message2);

			if (fRedGreenLineTool)
				delete fRedGreenLineTool;
			fRedGreenLineTool = NULL;
			break;
			
		case kToolPointAdded: {

			WorldPt3 toolPoint;
			if (gSDK->GetToolPt3D(gSDK->GetNumToolPts() - 1, toolPoint))
				fRedGreenLineTool->AddPoint(toolPoint);
			break;
		}
			
		case kToolPointRemoved:
			fRedGreenLineTool->PopPoint();
			break;
			
		default:
			result = VWToolDefaultLine_EventSink::LegacyMain(action, message1, message2);
			break;

	}
	
	return result;
}

Using the debugger, we are able to verify that everything is working out as expected.

Not a lot of functional but structural code changes in this episode, but we ended up with a class hierarchy which hints at things to come. We expect to push code common between the mock and Vectorworks implementation of the tool up the class hierarchy and code specific to the mock or Vectorworks implementation of the tool in the subclasses.

Let’s see how this class hierarchy holds up in the next episode when we tackle creating a line – test first, of course.

Previous Episode | Next Episode


17
Jun 11

Twitter Updates for 2011-06-17


16
Jun 11

Twitter Updates for 2011-06-16


15
Jun 11

Twitter Updates for 2011-06-15

  • Kurzer Chat mit dem Entsorgungsfachmann des Vertrauens über die Vergänglichkeit von Rechnern und dann 400kg Elektroschrott abgeladen. #
  • Thoughtful piece by @timbray on the web app / native apps controversy – http://t.co/s2iEAoq #

14
Jun 11

Twitter Updates for 2011-06-14

  • Soeben Zeuge geworden, wie zwei Angestellte der Gemeinde den lokalen Spielplatz harken & rechen. Die Zeit blieb stehen. #