SUAPI-CppWrapper
C++WrapperforSketchUpCAPI
C++ Wrapper for SketchUp C API

================

Introduction

SketchUp C API is made for the C programming language:

For C++ programmers, the non-object-orientated nature of the C API means simple operations for retrieving objects through is time consuming. This project provides a wrapper class for every SketchUp C API object that considerably shortens the amount of code required to perform simple tasks.

For example, to get an array of faces from an entities object, you could write this:

1 SUEntitiesRef entities = SU_INVALID;
2 SUModelGetEntities(model, &entities);
3 size_t faceCount = 0;
4 SUEntitiesGetNumFaces(entities, &faceCount);
5 std::vector<SUFaceRef> faces[faceCount];
6 SUEntitiesGetFaces(entities, faceCount, &faces[0], &faceCount);

With the C++ Wrapper, to achieve the above, you just need to write this:

1 #include <SUAPI-CppWrapper/model/Model.hpp>
2 #include <SUAPI-CppWrapper/model/Face.hpp>
3 std::vector<CW::Face> faces = CW::Model(model).entities().faces();

Added to this benefit, the wrapper classes have helper functions to help with geometric manipulations, much in the style of the SketchUp Ruby API


Reference

The project is documented in Doxygen, accessible here: https://tommykaneko.github.io/Sketchup-API-C-Wrapper/html

CMake

Visual Studio

1 CMake .. -G "Visual Studio 15 2017 Win64"

XCode

Navigate to the Sketchup-API-C-Wrapper project folder in Terminal and perform these commands:

1 mkdir xcode
2 cd xcode
3 cmake -G "Xcode" ..

If you get an error, it's probably because you haven't fetched the googletests submodules, so do this and try again:

1 git submodule update --init --recursive

Testing

The project uses GoogleTest for unit testing. It's included as a submodule so make sure to also initialize those when checking out the project.

The tests are located under /tests/. One file per testcase. One testcase per class being tested.

Keep tests small, keep their name descriptive.

Running Tests

Visual Studio

  1. Set the SketchUpAPITests project as your startup project.
  2. Build
  3. Run

Alternativly you can use the Google Test Adapter extension which provides overview of the tests from the UI. Makes it easy to run induvidual tests.

Xcode

Coming soon.

GoogleTests References

The aims of this set of wrapper classes are:


Programming Principles

Data Structure

Each C++ Wrapper class object holds its equivalent C API class object as a member variable (ie - CW::Face holds SUFaceRef). Further variables should be kept to a minimum, if at all.

Releasing Objects

With the use of the C++ Wrapper, the SketchUp API should "feel" like a native C++ API. This means the idea of "releasing" objects that are not attached to a model object, for example, should not have to be considered by the programmer. Instead, the wrapper class will deal with releasing of an object when the object goes out of scope.

The only exception to this rule is if the wrapped object (CW::Face, for example), is converted to a regular C object ( SUFaceRef, for example), in which case it can be assumed that the programmer is taking charge of the C object and will be dealing with any releasing.

Method Names

Method names take inspiration mostly from the SketchUp Ruby API. That said, these are not wholy consistent, and some liberties have been taken to make the method names make sense.