Skip to content

Commit

Permalink
Generate documentation command (#172)
Browse files Browse the repository at this point in the history
* Create command for generating documentation files.

* Fix reference resolution on top level.

* Add about dialog.

* Remove logo background.
  • Loading branch information
kovacsv committed Sep 13, 2024
1 parent 21f5108 commit 8fd698f
Show file tree
Hide file tree
Showing 13 changed files with 294 additions and 46 deletions.
2 changes: 1 addition & 1 deletion archicad-addon/Examples/aclib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ def RunTapirCommand (command, parameters, debug = True):
return result

def JsonDumpDictionary (d):
return json.dumps (d, indent = 4)
return json.dumps (d, indent = 4)
13 changes: 13 additions & 0 deletions archicad-addon/Examples/generate_documentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os
import aclib

rootFolder = os.path.dirname (os.path.dirname (os.path.dirname (os.path.abspath (__file__))))
docFolder = os.path.join (rootFolder, 'docs', 'archicad-addon')

commandName = 'GenerateDocumentation'
commandParameters = {
'destinationFolder' : docFolder
}

response = aclib.RunTapirCommand (commandName, commandParameters)
print (response)
25 changes: 25 additions & 0 deletions archicad-addon/Sources/AboutDialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "AboutDialog.hpp"

#include "AddOnVersion.hpp"
#include "ResourceIds.hpp"

#include "ACAPinc.h"

AboutDialog::AboutDialog () :
DG::ModalDialog (ACAPI_GetOwnResModule (), ID_ABOUT_DIALOG, ACAPI_GetOwnResModule ()),
okButton (GetReference (), 1),
versionText (GetReference (), 4)
{
AttachToAllItems (*this);
Attach (*this);

GS::UniString versionTextContent = versionText.GetText ();
versionText.SetText (GS::UniString::SPrintf (versionTextContent, GS::UniString (ADDON_VERSION).ToPrintf ()));
}

void AboutDialog::ButtonClicked (const DG::ButtonClickEvent& ev)
{
if (ev.GetSource () == &okButton) {
PostCloseRequest (DG::ModalDialog::Accept);
}
}
19 changes: 19 additions & 0 deletions archicad-addon/Sources/AboutDialog.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include "DGModule.hpp"

class AboutDialog :
public DG::ModalDialog,
public DG::PanelObserver,
public DG::ButtonItemObserver,
public DG::CompoundItemObserver
{
public:
AboutDialog ();

private:
virtual void ButtonClicked (const DG::ButtonClickEvent& ev) override;

DG::Button okButton;
DG::CenterText versionText;
};
43 changes: 23 additions & 20 deletions archicad-addon/Sources/AddOnMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "ResourceIds.hpp"
#include "DeveloperTools.hpp"

#include "AboutDialog.hpp"

#include "ApplicationCommands.hpp"
#include "ProjectCommands.hpp"
#include "ElementCommands.hpp"
Expand All @@ -20,8 +22,6 @@
#include "ClassificationCommands.hpp"
#include "MigrationHelper.hpp"

static std::vector<CommandGroup> gCommandGroups;

#ifdef DEBUG
static const bool IsDebugBuild = true;
#else
Expand All @@ -47,22 +47,16 @@ GSErrCode RegisterCommand (CommandGroup& group, const GS::UniString& version, co
return NoError;
}


static void GenerateDocumentation ()
{
DG::FolderDialog folderPicker;
if (folderPicker.Invoke ()) {
GenerateDocumentation (folderPicker.GetFolder (), gCommandGroups);
}
}

static GSErrCode MenuCommandHandler (const API_MenuParams* menuParams)
{
switch (menuParams->menuItemRef.menuResID) {
case ID_ADDON_MENU:
switch (menuParams->menuItemRef.itemIndex) {
case ID_ADDON_MENU_GENERATE_DOC:
GenerateDocumentation ();
case ID_ADDON_MENU_ABOUT:
{
AboutDialog aboutDialog;
aboutDialog.Invoke ();
}
break;
}
break;
Expand Down Expand Up @@ -116,7 +110,7 @@ GSErrCode Initialize (void)
applicationCommands, "1.0.7",
"Returns the type of the current (active) window."
);
gCommandGroups.push_back (applicationCommands);
AddCommandGroup (applicationCommands);
}

{ // Project Commands
Expand Down Expand Up @@ -149,7 +143,7 @@ GSErrCode Initialize (void)
projectCommands, "1.0.7",
"Opens the given project."
);
gCommandGroups.push_back (projectCommands);
AddCommandGroup (projectCommands);
}

{ // Element Commands
Expand Down Expand Up @@ -218,7 +212,7 @@ GSErrCode Initialize (void)
elementCommands, "1.0.3",
"Creates Object elements based on the given parameters."
);
gCommandGroups.push_back (elementCommands);
AddCommandGroup (elementCommands);
}

{ // Attribute Commands
Expand All @@ -239,7 +233,7 @@ GSErrCode Initialize (void)
attributeCommands, "0.1.3",
"Retrieves the physical properties of the given Building Materials."
);
gCommandGroups.push_back (attributeCommands);
AddCommandGroup (attributeCommands);
}

{ // Library Commands
Expand All @@ -252,7 +246,7 @@ GSErrCode Initialize (void)
libraryCommands, "1.0.0",
"Executes the reload libraries command."
);
gCommandGroups.push_back (libraryCommands);
AddCommandGroup (libraryCommands);
}

{ // Teamwork Commands
Expand All @@ -265,7 +259,7 @@ GSErrCode Initialize (void)
teamworkCommands, "0.1.0",
"Performs a receive operation on the currently opened Teamwork project."
);
gCommandGroups.push_back (teamworkCommands);
AddCommandGroup (teamworkCommands);
}

{ // Issue Management Commands
Expand Down Expand Up @@ -310,7 +304,16 @@ GSErrCode Initialize (void)
issueCommands, "1.0.6",
"Imports issues from the specified BCF file."
);
gCommandGroups.push_back (issueCommands);
AddCommandGroup (issueCommands);
}

{ // Developer Commands
CommandGroup developerCommands ("Developer Commands");
err |= RegisterCommand<GenerateDocumentationCommand> (
developerCommands, "1.0.7",
"Generates files for the documentation. Used by Tapir developers only."
);
AddCommandGroup (developerCommands);
}

return err;
Expand Down
94 changes: 77 additions & 17 deletions archicad-addon/Sources/DeveloperTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,7 @@

#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 std::vector<CommandGroup> gCommandGroups;

static bool WriteStringToFile (const IO::Location& location, const GS::UniString& content)
{
Expand All @@ -35,13 +22,15 @@ static bool WriteStringToFile (const IO::Location& location, const GS::UniString
return true;
}

void GenerateDocumentation (const IO::Location& folder, const std::vector<CommandGroup>& commandGroups)
static bool 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);
if (!WriteStringToFile (commonSchemaLocation, commonSchemaContent)) {
return false;
}

IO::Location commandDefinitionLocation = folder;
commandDefinitionLocation.AppendToLocal (IO::Name ("command_definitions.js"));
Expand Down Expand Up @@ -80,5 +69,76 @@ void GenerateDocumentation (const IO::Location& folder, const std::vector<Comman
}
}
commandDefinitionContent += "];";
WriteStringToFile (commandDefinitionLocation, commandDefinitionContent);
if (!WriteStringToFile (commandDefinitionLocation, commandDefinitionContent)) {
return false;
}

return true;
}

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 ()
{
}

void AddCommandGroup (const CommandGroup& commandGroup)
{
gCommandGroups.push_back (commandGroup);
}

GenerateDocumentationCommand::GenerateDocumentationCommand () :
CommandBase (CommonSchema::Used)
{
}

GS::String GenerateDocumentationCommand::GetName () const
{
return "GenerateDocumentation";
}

GS::Optional<GS::UniString> GenerateDocumentationCommand::GetInputParametersSchema () const
{
return R"({
"type": "object",
"properties": {
"destinationFolder": {
"type": "string",
"description": "Destination folder for the generated documentation files.",
"minLength": 1
}
},
"additionalProperties": false,
"required": [
"destinationFolder"
]
})";
}

GS::Optional<GS::UniString> GenerateDocumentationCommand::GetResponseSchema () const
{
return R"({
"$ref": "#/ExecutionResult"
})";
}

GS::ObjectState GenerateDocumentationCommand::Execute (const GS::ObjectState& parameters, GS::ProcessControl& /*processControl*/) const
{
GS::UniString destinationFolder;
parameters.Get ("destinationFolder", destinationFolder);

IO::Location destinationFolderLoc (destinationFolder);
if (!GenerateDocumentation (destinationFolderLoc, gCommandGroups)) {
return CreateFailedExecutionResult (APIERR_GENERAL, "Failed to generate documentation.");
}
return CreateSuccessfulExecutionResult ();
}
13 changes: 12 additions & 1 deletion archicad-addon/Sources/DeveloperTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@ class CommandGroup
std::vector<CommandInfo> commands;
};

void GenerateDocumentation (const IO::Location& folder, const std::vector<CommandGroup>& commandGroups);
class GenerateDocumentationCommand : public CommandBase
{
public:
GenerateDocumentationCommand ();

virtual GS::String GetName () const override;
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;
};

void AddCommandGroup (const CommandGroup& commandGroup);
6 changes: 5 additions & 1 deletion archicad-addon/Sources/RFIX/AddOnFix.grc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "ResourceIds.hpp"

'MDID' ID_ADDON_ID "Add-On Identifier" {
'MDID' 32500 "Add-On Identifier" {
826567491
368333322
}

'GICN' ID_TAPIR_LOGO "TapirLogo" {
"TapirLogo"
}
Loading

0 comments on commit 8fd698f

Please sign in to comment.