Now that we’re able to place a grid of front tiles / segments, the only thing left is the placement of the right / top blind front panels – if the front tiles don’t fit properly. As always, we’re starting with a very basic test. The right blind front (if there’s one) will be placed on the bottom board, therefore start at z == SimpleCabinetModel::kBoardThickness.
TEST_N(FrontModelRightBlindFront) { SimpleCabinetModel simpleCabinet(2 * 200 + 2 * SimpleCabinetModel::kBoardThickness + 50, 3 * 150 + 2 * SimpleCabinetModel::kBoardThickness + 70, 800); FrontModel frontModel(simpleCabinet.GetFrontModelOrigin(), simpleCabinet.GetFrontWidth(), simpleCabinet.GetFrontHeight()); CHECK_EQUAL(SimpleCabinetModel::kBoardThickness, frontModel.GetRightZBlindFront()); }
Well, you could see that one coming, making the test pass is rather trivial – but it gets us on the track to more sophisticated functionality.
WorldCoord GetRightZBlindFront() const { return fOrigin.z; }
Let’s add another check to the test. The height of the right blind front should be the height of the front model.
CHECK_EQUAL(3 * 150 + 70, frontModel.GetRightBlindFrontHeight());
Quite obvious and should be easy to implement. There’s already an instance variable fHeight in the FrontModel:
WorldCoord frontModel.GetRightBlindFrontHeight() const { return fHeight; }
The third component needed to generate the geometry for the right blind front model is the base rectangular shape for the extrude. Another check for our test.
CHECK_EQUAL(WorldRect(SimpleCabinetModel::kBoardThickness + frontModel.GetNumColumns() * FrontModel::kSegmentWidth, FrontModel::kSegmentDepth, SimpleCabinetModel::kBoardThickness + simpleCabinet.GetFrontWidth(), 0), frontModel.GetRightBlindFrontBase());
Introducing two additional constants for the tile/segment’s width and depth, making the test pass requires a few lines of code:
class FrontModel { WorldRect GetRightBlindFrontBase() const { WorldCoord xStart = fOrigin.x + GetNumColumns() * kSegmentWidth; WorldCoord xEnd = fOrigin.x + fWidth; WorldRect r(0, 0, 0, 0); if (xStart != xEnd) r.Set(xStart, kSegmentDepth, xEnd, 0); return r; } };
The top blind front is tackled the same way – We need it’s z position, it’s x dimensions and it’s height. Not an awful lot to see there. Now let’s check if we’re able to generate Vectorworks geometry with this model.
void CreateFrom(const FrontModel& frontModel) { // ... WorldRect topBlindFrontBase = frontModel.GetTopBlindFrontBase(); if (topBlindFrontBase != WorldRect(0, 0, 0, 0)) { MCObjectHandle topBlindFront = gSDK->CreateExtrude(frontModel.GetTopZBlindFront(), frontModel.GetTopZBlindFront() + frontModel.GetTopBlindFrontHeight()); gSDK->AddObjectToContainer(gSDK->CreateRectangle(frontModel.GetTopBlindFrontBase()), topBlindFront); } WorldRect rightBlindFrontBase = frontModel.GetRightBlindFrontBase(); if (rightBlindFrontBase != WorldRect(0, 0, 0, 0)) { MCObjectHandle rightBlindFront = gSDK->CreateExtrude(frontModel.GetRightZBlindFront(), frontModel.GetRightZBlindFront() + frontModel.GetRightBlindFrontHeight()); gSDK->AddObjectToContainer(gSDK->CreateRectangle(frontModel.GetRightBlindFrontBase()), rightBlindFront); }
In fact, we are:
Tune in next weeks when you hear Dr. Bob say: “Let’s sum it up, post the code and I’m outta here”.
[…] Previous Episode | Next Episode […]
[…] Episode 7 – A few more additions […]