Eneroth3 / open-newer-version

Convert and open models made in newer versions of SketchUp.
MIT License
44 stars 12 forks source link

Setting up C++ project and include in repo #1

Closed Eneroth3 closed 6 years ago

Eneroth3 commented 6 years ago

As of now the C++ part of this extension has been developed inside the SketchUp SDK's directory, by modifying an example. Some help for setting up a project the proper way, and include it somewhere in this repo would be much appreciated.

I'm suspecting it is also conventional to ignore the compiled .exe file in the repo, although including it would greatly benefit any potential developer who wants to improve the Ruby part of the project, but have no experience in C++ coding.

@thomthom, maybe you could help me setting up the project when you have the time :) .

(For the sake of documentation, here is the current C++ code for convert_version.exe)

#include <SketchUpAPI/common.h>
#include <SketchUpAPI/initialize.h>
#include <SketchUpAPI/model/model.h>
#include <unordered_map>
#include <string>// std::string, std::stoi

// - Source path
// - Target path
// - SketchUp version (without leading 20)
int main(int argc, char* argv[]) {
  if (argc != 4) return 1;

  const char* source = argv[1];
  const char* target = argv[2];
  int version_name = std::stoi(argv[3]);

  // REVIEW: Must be a way to simply append number to "SUModelVersion_SU" string
  // and get enum from its string name.
  const std::unordered_map<int, SUModelVersion> versions = {
    {3,SUModelVersion_SU3},
    {4,SUModelVersion_SU4},
    {5,SUModelVersion_SU5},
    {6,SUModelVersion_SU6},
    {7,SUModelVersion_SU7},
    {8,SUModelVersion_SU8},
    {13,SUModelVersion_SU2013},
    {14,SUModelVersion_SU2014},
    {15,SUModelVersion_SU2015},
    {16,SUModelVersion_SU2016},
    {17,SUModelVersion_SU2017},
    {18,SUModelVersion_SU2018}
  };
  enum SUModelVersion version = versions.at(version_name);

  SUInitialize();

  SUModelRef model = SU_INVALID;
  SUResult res = SUModelCreateFromFile(&model, source);
  if (res != SU_ERROR_NONE) return 1;
  SUModelSaveToFileWithVersion(model, target, version);

  SUModelRelease(&model);
  SUTerminate();
  // TODO: Should version, versions, source and target be released too?
  return 0;
}
Eneroth3 commented 6 years ago

After some attempts I've managed to move the C++ project into this repository (9c0f3ccd95fe94c3c9f091d5153e1980adcbd4f9).

I don't know how conventional it is to put the VS solution and project in a sub directory but I want people to be able to work on the Ruby part of this project without having to worry about VS, the SDK, setting up the VS project, compiling etc. For now the binary files used in the Ruby extension are not ignored in Git, to make the src folder represent a fully functional SketchUp plugin.

thomthom commented 6 years ago

I'm suspecting it is also conventional to ignore the compiled .exe file in the repo, although including it would greatly benefit any potential developer who wants to improve the Ruby part of the project, but have no experience in C++ coding.

Avoid checking in binaries. Instead you can make a build, then upload it to the Releases tab of your project. (Add version tags when you make a new release.)

thomthom commented 6 years ago

I don't know how conventional it is to put the VS solution and project in a sub directory but I want people to be able to work on the Ruby part of this project without having to worry about VS, the SDK, setting up the VS project, compiling etc. For now the binary files used in the Ruby extension are not ignored in Git, to make the src folder represent a fully functional SketchUp plugin.

I have done that in some projects. Don't think there is a strong convention.