Skip to content

Commit

Permalink
Merge branch 'main' into FilterElements
Browse files Browse the repository at this point in the history
  • Loading branch information
tlorantfy committed Aug 26, 2024
2 parents 0624858 + ec5858d commit c798588
Show file tree
Hide file tree
Showing 14 changed files with 2,646 additions and 2,402 deletions.
15 changes: 0 additions & 15 deletions archicad-addon/Examples/building_material_props.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import json
import aclib

buildMats = aclib.RunCommand ('API.GetAttributesByType', { 'attributeType' : 'BuildingMaterial' })
print (buildMats)

commandName = 'GetBuildingMaterialPhysicalProperties'
commandParameters = buildMats

print ('Command: {commandName}'.format (commandName = commandName))
print ('Parameters:')
print (json.dumps (commandParameters, indent = 4))

response = aclib.RunTapirCommand (commandName, commandParameters)
print ('Response:')
print (json.dumps (response, indent = 4))
317 changes: 263 additions & 54 deletions archicad-addon/Sources/AddOnMain.cpp

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions archicad-addon/Sources/AttributeCommands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class CreateBuildingMaterialsCommand : public CreateAttributesCommandBase
{
public:
CreateBuildingMaterialsCommand ();
protected:
virtual GS::Optional<GS::UniString> GetInputParametersSchema () const override;
virtual void SetTypeSpecificParameters (API_Attribute& attribute, const GS::ObjectState& parameters) const override;
};
Expand All @@ -40,7 +39,6 @@ class CreateLayersCommand : public CreateAttributesCommandBase
{
public:
CreateLayersCommand ();
protected:
virtual GS::Optional<GS::UniString> GetInputParametersSchema () const override;
virtual void SetTypeSpecificParameters (API_Attribute& attribute, const GS::ObjectState& parameters) const override;
};
Expand Down
13 changes: 11 additions & 2 deletions archicad-addon/Sources/ClassificationCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,17 @@ GS::Optional<GS::UniString> GetClassificationsOfElementsCommand::GetInputParamet
GS::Optional<GS::UniString> GetClassificationsOfElementsCommand::GetResponseSchema () const
{
return R"({
"$ref": "#/ElementClassificationsOrErrors",
"description": "The list of element classification item identifiers. Order of the ids are the same as in the input. Non-existing elements or non-existing classification systems are represented by error objects."
"type": "object",
"properties": {
"elementClassifications": {
"$ref": "#/ElementClassificationsOrErrors",
"description": "The list of element classification item identifiers. Order of the ids are the same as in the input. Non-existing elements or non-existing classification systems are represented by error objects."
}
},
"additionalProperties": false,
"required": [
"elementClassifications"
]
})";
}

Expand Down
84 changes: 84 additions & 0 deletions archicad-addon/Sources/DeveloperTools.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include "DeveloperTools.hpp"

#include "SchemaDefinitions.hpp"

#include "File.hpp"

CommandInfo::CommandInfo (const GS::UniString& name, const GS::UniString& description, const GS::UniString& version, const GS::Optional<GS::UniString>& inputScheme, const GS::Optional<GS::UniString>& outputScheme) :
name (name),
description (description),
version (version),
inputScheme (inputScheme),
outputScheme (outputScheme)
{
}

CommandGroup::CommandGroup (const GS::UniString& name) :
name (name),
commands ()
{
}

static bool WriteStringToFile (const IO::Location& location, const GS::UniString& content)
{
IO::File file (location, IO::File::OnNotFound::Create);
if (file.Open (IO::File::OpenMode::WriteEmptyMode) != NoError) {
return false;
}

std::string contentString (content.ToCStr (CC_UTF8).Get ());
if (file.WriteBin ((char*) contentString.c_str (), (GS::USize) contentString.size ()) != NoError) {
return false;
}

file.Close ();
return true;
}

void GenerateDocumentation (const IO::Location& folder, const std::vector<CommandGroup>& commandGroups)
{
static const GS::UniString NullString ("null");
IO::Location commonSchemaLocation = folder;
commonSchemaLocation.AppendToLocal (IO::Name ("common_schema_definitions.js"));
GS::UniString commonSchemaContent = "var gSchemaDefinitions = " + GetCommonSchemaDefinitions () + ";";
WriteStringToFile (commonSchemaLocation, commonSchemaContent);

IO::Location commandDefinitionLocation = folder;
commandDefinitionLocation.AppendToLocal (IO::Name ("command_definitions.js"));
GS::UniString commandDefinitionContent = "var gCommands = [";
for (size_t groupIndex = 0; groupIndex < commandGroups.size (); groupIndex++) {
const CommandGroup& group = commandGroups[groupIndex];
GS::UniString groupCommandsContent;
for (size_t commandIndex = 0; commandIndex < group.commands.size (); commandIndex++) {
const CommandInfo& command = group.commands[commandIndex];
groupCommandsContent += GS::UniString::Printf (R"({
"name": "%T",
"version": "%T",
"description": "%T",
"inputScheme": %T,
"outputScheme": %T
})",
command.name.ToPrintf (),
command.version.ToPrintf (),
command.description.ToPrintf (),
command.inputScheme.HasValue () ? command.inputScheme.Get ().ToPrintf () : NullString.ToPrintf (),
command.outputScheme.HasValue () ? command.outputScheme.Get ().ToPrintf () : NullString.ToPrintf ()
);
if (commandIndex < group.commands.size () - 1) {
groupCommandsContent += ",";
}
}
commandDefinitionContent += GS::UniString::Printf (R"({
"name": "%T",
"commands": [%T]
})",
group.name.ToPrintf (),
groupCommandsContent.ToPrintf ()
);
if (groupIndex < commandGroups.size () - 1) {
commandDefinitionContent += ",";
}
}
commandDefinitionContent += "];";
WriteStringToFile (commandDefinitionLocation, commandDefinitionContent);
}
33 changes: 33 additions & 0 deletions archicad-addon/Sources/DeveloperTools.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include "MigrationHelper.hpp"
#include "CommandBase.hpp"

#include "UniString.hpp"
#include "Location.hpp"

#include <vector>
#include <string>

class CommandInfo
{
public:
CommandInfo (const GS::UniString& name, const GS::UniString& description, const GS::UniString& version, const GS::Optional<GS::UniString>& inputScheme, const GS::Optional<GS::UniString>& outputScheme);

GS::UniString name;
GS::UniString description;
GS::UniString version;
GS::Optional<GS::UniString> inputScheme;
GS::Optional<GS::UniString> outputScheme;
};

class CommandGroup
{
public:
CommandGroup (const GS::UniString& name);

GS::UniString name;
std::vector<CommandInfo> commands;
};

void GenerateDocumentation (const IO::Location& folder, const std::vector<CommandGroup>& commandGroups);
13 changes: 10 additions & 3 deletions archicad-addon/Sources/ElementCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1330,8 +1330,6 @@ GS::ObjectState FilterElementsCommand::Execute (const GS::ObjectState& parameter
return response;
}

#ifdef ServerMainVers_2600

HighlightElementsCommand::HighlightElementsCommand () :
CommandBase (CommonSchema::Used)
{
Expand Down Expand Up @@ -1390,6 +1388,8 @@ GS::Optional<GS::UniString> HighlightElementsCommand::GetResponseSchema () const
return {};
}

#ifdef ServerMainVers_2600

static API_RGBAColor GetRGBAColorFromArray (const GS::Array<GS::Int32>& color)
{
return API_RGBAColor {
Expand Down Expand Up @@ -1455,4 +1455,11 @@ GS::ObjectState HighlightElementsCommand::Execute (const GS::ObjectState& parame
return {};
}

#endif
#else

GS::ObjectState HighlightElementsCommand::Execute (const GS::ObjectState& /*parameters*/, GS::ProcessControl& /*processControl*/) const
{
return CreateErrorResponse (APIERR_GENERAL, GetName() + " command is not supported for this AC version.");
}

#endif
6 changes: 1 addition & 5 deletions archicad-addon/Sources/ElementCommands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class FilterElementsCommand : public CommandBase
virtual GS::ObjectState Execute (const GS::ObjectState& parameters, GS::ProcessControl& processControl) const override;
};

#ifdef ServerMainVers_2600

class HighlightElementsCommand : public CommandBase
{
public:
Expand All @@ -79,6 +77,4 @@ class HighlightElementsCommand : public CommandBase
virtual GS::Optional<GS::UniString> GetInputParametersSchema () const override;
virtual GS::Optional<GS::UniString> GetResponseSchema () const override;
virtual GS::ObjectState Execute (const GS::ObjectState& parameters, GS::ProcessControl& processControl) const override;
};

#endif
};
5 changes: 4 additions & 1 deletion archicad-addon/Sources/MigrationHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#ifndef ServerMainVers_2700

#define ACAPI_MenuItem_RegisterMenu ACAPI_Register_Menu
#define ACAPI_MenuItem_InstallMenuHandler ACAPI_Install_MenuHandler

#define ACAPI_Markup_Create ACAPI_MarkUp_Create
#define ACAPI_Markup_Delete ACAPI_MarkUp_Delete
#define ACAPI_Markup_GetList ACAPI_MarkUp_GetList
Expand Down Expand Up @@ -111,7 +114,7 @@ inline GSErrCode ACAPI_ProjectSetting_GetStorySettings (API_StoryInfo* storyInfo
return ACAPI_Environment (APIEnv_GetStorySettingsID, storyInfo, nullptr);
}

inline GSErrCode ACAPI_LibraryPart_Search (API_LibPart *ancestor, bool createIfMissing, bool onlyPlaceable = false)
inline GSErrCode ACAPI_LibraryPart_Search (API_LibPart* ancestor, bool createIfMissing, bool onlyPlaceable = false)
{
return ACAPI_LibPart_Search (ancestor, createIfMissing, onlyPlaceable);
}
Expand Down
8 changes: 7 additions & 1 deletion archicad-addon/Sources/RINT/AddOn.grc
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@
'STR#' ID_ADDON_INFO "Add-on Name and Description" {
/* [ 1] */ "Tapir Additional JSON Commands"
/* [ 2] */ "Tapir Additional JSON Commands"
}
}

'STR#' ID_ADDON_MENU "Add-On Menu" {
/* [ ] */ "Tapir"
/* [ ] */ "Developer Tools"
/* [ 1] */ "Generate Documentation"
}
11 changes: 7 additions & 4 deletions archicad-addon/Sources/ResourceIds.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#pragma once

#define ID_ADDON_INFO 32000
#define ID_ADDON_INFO_NAME 1
#define ID_ADDON_INFO_DESC 2
#define ID_ADDON_INFO 32000
#define ID_ADDON_INFO_NAME 1
#define ID_ADDON_INFO_DESC 2

#define ID_ADDON_ID 32500
#define ID_ADDON_MENU 32001
#define ID_ADDON_MENU_GENERATE_DOC 1

#define ID_ADDON_ID 32500
Loading

0 comments on commit c798588

Please sign in to comment.