Skip to content

Commit 7ff5ba4

Browse files
committed
GetProjectInfo, GetArchicadLocation, Quit commands
1 parent a5f1ee1 commit 7ff5ba4

File tree

3 files changed

+306
-14
lines changed

3 files changed

+306
-14
lines changed

Src/AdditionalJSONCommands.cpp

Lines changed: 249 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "AdditionalJSONCommands.hpp"
22
#include "ObjectState.hpp"
3+
#include "FileSystem.hpp"
34

45

56
constexpr const char* AdditionalJSONCommandsNamespace = "AdditionalJSONCommands";
@@ -24,6 +25,19 @@ static GS::HashTable<GS::UniString, API_Guid> GetPublisherSetNameGuidTable ()
2425
}
2526

2627

28+
static GS::Optional<IO::Location> GetApplicationLocation ()
29+
{
30+
IO::Location applicationFileLocation;
31+
32+
GSErrCode error = IO::fileSystem.GetSpecialLocation (IO::FileSystem::ApplicationFile, &applicationFileLocation);
33+
if (error != NoError) {
34+
return GS::NoValue;
35+
}
36+
37+
return applicationFileLocation;
38+
}
39+
40+
2741
// --- PublishCommand ----------------------------------------------------------------------------------
2842

2943
GS::String PublishCommand::GetName () const
@@ -44,27 +58,34 @@ GS::Optional<GS::UniString> PublishCommand::GetSchemaDefinitions () const
4458
}
4559

4660

61+
constexpr const char* PublisherSetNameParameterField = "publisherSetName";
62+
constexpr const char* OutputPathParameterField = "outputPath";
63+
constexpr const char* ErrorMessageResponseField = "errorMessage";
64+
65+
4766
GS::Optional<GS::UniString> PublishCommand::GetInputParametersSchema () const
4867
{
49-
return R"({
68+
return GS::UniString::Printf (R"({
5069
"type": "object",
5170
"properties": {
52-
"publisherSetName": {
71+
"%s": {
5372
"type": "string",
5473
"description": "The name of the publisher set.",
5574
"minLength": 1
5675
},
57-
"outputPath": {
76+
"%s": {
5877
"type": "string",
5978
"description": "Full local or LAN path for publishing. Optional, by default the path set in the settings of the publiser set will be used.",
6079
"minLength": 1
6180
}
6281
},
6382
"additionalProperties": false,
6483
"required": [
65-
"publisherSetName"
84+
"%s"
6685
]
67-
})";
86+
})",
87+
PublisherSetNameParameterField, OutputPathParameterField,
88+
PublisherSetNameParameterField);
6889
}
6990

7091

@@ -74,11 +95,6 @@ GS::Optional<GS::UniString> PublishCommand::GetResponseSchema () const
7495
}
7596

7697

77-
constexpr const char* PublisherSetNameParameterField = "publisherSetName";
78-
constexpr const char* OutputPathParameterField = "outputPath";
79-
constexpr const char* ErrorMessageResponseField = "errorMessage";
80-
81-
8298
GS::ObjectState PublishCommand::Execute (const GS::ObjectState& parameters, GS::ProcessControl& /*processControl*/) const
8399
{
84100
GS::UniString publisherSetName;
@@ -161,4 +177,227 @@ GS::ObjectState TeamworkReceiveCommand::Execute (const GS::ObjectState& /*parame
161177

162178
void TeamworkReceiveCommand::OnResponseValidationFailed (const GS::ObjectState& /*response*/) const
163179
{
180+
}
181+
182+
183+
// --- GetProjectInfoCommand ----------------------------------------------------------------------------------
184+
185+
GS::String GetProjectInfoCommand::GetName () const
186+
{
187+
return "GetProjectInfo";
188+
}
189+
190+
191+
GS::String GetProjectInfoCommand::GetNamespace () const
192+
{
193+
return AdditionalJSONCommandsNamespace;
194+
}
195+
196+
197+
GS::Optional<GS::UniString> GetProjectInfoCommand::GetSchemaDefinitions () const
198+
{
199+
return {};
200+
}
201+
202+
203+
constexpr const char* IsUntitledResponseField = "isUntitled";
204+
constexpr const char* IsTeamworkResponseField = "isTeamwork";
205+
constexpr const char* ProjectLocationResponseField = "projectLocation";
206+
constexpr const char* ProjectPathResponseField = "projectPath";
207+
constexpr const char* ProjectNameResponseField = "projectName";
208+
209+
210+
GS::Optional<GS::UniString> GetProjectInfoCommand::GetInputParametersSchema () const
211+
{
212+
return {};
213+
}
214+
215+
216+
GS::Optional<GS::UniString> GetProjectInfoCommand::GetResponseSchema () const
217+
{
218+
return GS::UniString::Printf (R"({
219+
"type": "object",
220+
"properties": {
221+
"%s": {
222+
"type": "boolean",
223+
"description": "True, if the project is not saved yet."
224+
},
225+
"%s": {
226+
"type": "boolean",
227+
"description": "True, if the project is a Teamwork (BIMcloud) project."
228+
},
229+
"%s": {
230+
"type": "string",
231+
"description": "The location of the project in the filesystem or a BIMcloud project reference.",
232+
"minLength": 1
233+
},
234+
"%s": {
235+
"type": "string",
236+
"description": "The path of the project. A filesystem path or a BIMcloud server relative path.",
237+
"minLength": 1
238+
},
239+
"%s": {
240+
"type": "string",
241+
"description": "The name of the project.",
242+
"minLength": 1
243+
}
244+
},
245+
"additionalProperties": false,
246+
"required": [
247+
"%s",
248+
"%s"
249+
]
250+
})",
251+
IsUntitledResponseField, IsTeamworkResponseField, ProjectLocationResponseField, ProjectPathResponseField, ProjectNameResponseField,
252+
IsUntitledResponseField, IsTeamworkResponseField);
253+
}
254+
255+
256+
GS::ObjectState GetProjectInfoCommand::Execute (const GS::ObjectState& /*parameters*/, GS::ProcessControl& /*processControl*/) const
257+
{
258+
API_ProjectInfo projectInfo = {};
259+
GSErrCode err = ACAPI_Environment (APIEnv_ProjectID, &projectInfo);
260+
261+
if (err != NoError) {
262+
return GS::ObjectState (ErrorMessageResponseField, "Failed to retrieve project information. Check the opened project!");
263+
}
264+
265+
GS::ObjectState response;
266+
response.Add (IsUntitledResponseField, projectInfo.untitled);
267+
if (!projectInfo.untitled) {
268+
response.Add (IsTeamworkResponseField, projectInfo.teamwork);
269+
if (projectInfo.location) {
270+
response.Add (ProjectLocationResponseField, projectInfo.location->ToDisplayText ());
271+
}
272+
if (projectInfo.projectPath) {
273+
response.Add (ProjectPathResponseField, *projectInfo.projectPath);
274+
}
275+
if (projectInfo.projectName) {
276+
response.Add (ProjectNameResponseField, *projectInfo.projectName);
277+
}
278+
}
279+
280+
return response;
281+
}
282+
283+
284+
void GetProjectInfoCommand::OnResponseValidationFailed (const GS::ObjectState& /*response*/) const
285+
{
286+
}
287+
288+
289+
// --- GetArchicadLocationCommand ----------------------------------------------------------------------------------
290+
291+
GS::String GetArchicadLocationCommand::GetName () const
292+
{
293+
return "GetArchicadLocation";
294+
}
295+
296+
297+
GS::String GetArchicadLocationCommand::GetNamespace () const
298+
{
299+
return AdditionalJSONCommandsNamespace;
300+
}
301+
302+
303+
GS::Optional<GS::UniString> GetArchicadLocationCommand::GetSchemaDefinitions () const
304+
{
305+
return {};
306+
}
307+
308+
309+
constexpr const char* ArchicadLocationResponseField = "archicadLocation";
310+
311+
312+
GS::Optional<GS::UniString> GetArchicadLocationCommand::GetInputParametersSchema () const
313+
{
314+
return {};
315+
}
316+
317+
318+
GS::Optional<GS::UniString> GetArchicadLocationCommand::GetResponseSchema () const
319+
{
320+
return GS::UniString::Printf (R"({
321+
"type": "object",
322+
"properties": {
323+
"%s": {
324+
"type": "string",
325+
"description": "The location of the Archicad executable in the filesystem.",
326+
"minLength": 1
327+
}
328+
},
329+
"additionalProperties": false,
330+
"required": [
331+
"%s"
332+
]
333+
})",
334+
ArchicadLocationResponseField,
335+
ArchicadLocationResponseField);
336+
}
337+
338+
339+
GS::ObjectState GetArchicadLocationCommand::Execute (const GS::ObjectState& /*parameters*/, GS::ProcessControl& /*processControl*/) const
340+
{
341+
const GS::Optional<IO::Location> applicationFileLocation = GetApplicationLocation ();
342+
343+
if (!applicationFileLocation.HasValue ()) {
344+
return GS::ObjectState (ErrorMessageResponseField, "Failed to get the location of the Archicad application!");
345+
}
346+
347+
return GS::ObjectState (ArchicadLocationResponseField, applicationFileLocation.Get ().ToDisplayText ());
348+
}
349+
350+
351+
void GetArchicadLocationCommand::OnResponseValidationFailed (const GS::ObjectState& /*response*/) const
352+
{
353+
}
354+
355+
356+
// --- QuitCommand ----------------------------------------------------------------------------------
357+
358+
GS::String QuitCommand::GetName () const
359+
{
360+
return "Quit";
361+
}
362+
363+
364+
GS::String QuitCommand::GetNamespace () const
365+
{
366+
return AdditionalJSONCommandsNamespace;
367+
}
368+
369+
370+
GS::Optional<GS::UniString> QuitCommand::GetSchemaDefinitions () const
371+
{
372+
return {};
373+
}
374+
375+
376+
GS::Optional<GS::UniString> QuitCommand::GetInputParametersSchema () const
377+
{
378+
return {};
379+
}
380+
381+
382+
GS::Optional<GS::UniString> QuitCommand::GetResponseSchema () const
383+
{
384+
return {};
385+
}
386+
387+
388+
GS::ObjectState QuitCommand::Execute (const GS::ObjectState& /*parameters*/, GS::ProcessControl& /*processControl*/) const
389+
{
390+
Int64 magicCode = 1234;
391+
GSErrCode err = ACAPI_Automate (APIDo_QuitID, reinterpret_cast<void*> (magicCode));
392+
393+
if (err != NoError) {
394+
return GS::ObjectState (ErrorMessageResponseField, "Failed to quit Archicad!");
395+
}
396+
397+
return {};
398+
}
399+
400+
401+
void QuitCommand::OnResponseValidationFailed (const GS::ObjectState& /*response*/) const
402+
{
164403
}

Src/AdditionalJSONCommands.hpp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#if !defined (TESTCOMMANDS_HPP)
2-
#define TESTCOMMANDS_HPP
1+
#if !defined (ADDITIONALJSONCOMMANDS_HPP)
2+
#define ADDITIONALJSONCOMMANDS_HPP
33

44
#pragma once
55

@@ -41,4 +41,55 @@ class TeamworkReceiveCommand : public API_AddOnCommand {
4141
};
4242

4343

44+
class GetProjectInfoCommand : public API_AddOnCommand {
45+
public:
46+
47+
virtual GS::String GetName () const override;
48+
virtual GS::String GetNamespace () const override;
49+
virtual GS::Optional<GS::UniString> GetSchemaDefinitions () const override;
50+
virtual GS::Optional<GS::UniString> GetInputParametersSchema () const override;
51+
virtual GS::Optional<GS::UniString> GetResponseSchema () const override;
52+
53+
virtual API_AddOnCommandExecutionPolicy GetExecutionPolicy () const override { return API_AddOnCommandExecutionPolicy::ScheduleForExecutionOnMainThread; }
54+
55+
virtual GS::ObjectState Execute (const GS::ObjectState& parameters, GS::ProcessControl& processControl) const override;
56+
57+
virtual void OnResponseValidationFailed (const GS::ObjectState& response) const override;
58+
};
59+
60+
61+
class GetArchicadLocationCommand : public API_AddOnCommand {
62+
public:
63+
64+
virtual GS::String GetName () const override;
65+
virtual GS::String GetNamespace () const override;
66+
virtual GS::Optional<GS::UniString> GetSchemaDefinitions () const override;
67+
virtual GS::Optional<GS::UniString> GetInputParametersSchema () const override;
68+
virtual GS::Optional<GS::UniString> GetResponseSchema () const override;
69+
70+
virtual API_AddOnCommandExecutionPolicy GetExecutionPolicy () const override { return API_AddOnCommandExecutionPolicy::ScheduleForExecutionOnMainThread; }
71+
72+
virtual GS::ObjectState Execute (const GS::ObjectState& parameters, GS::ProcessControl& processControl) const override;
73+
74+
virtual void OnResponseValidationFailed (const GS::ObjectState& response) const override;
75+
};
76+
77+
78+
class QuitCommand : public API_AddOnCommand {
79+
public:
80+
81+
virtual GS::String GetName () const override;
82+
virtual GS::String GetNamespace () const override;
83+
virtual GS::Optional<GS::UniString> GetSchemaDefinitions () const override;
84+
virtual GS::Optional<GS::UniString> GetInputParametersSchema () const override;
85+
virtual GS::Optional<GS::UniString> GetResponseSchema () const override;
86+
87+
virtual API_AddOnCommandExecutionPolicy GetExecutionPolicy () const override { return API_AddOnCommandExecutionPolicy::ScheduleForExecutionOnMainThread; }
88+
89+
virtual GS::ObjectState Execute (const GS::ObjectState& parameters, GS::ProcessControl& processControl) const override;
90+
91+
virtual void OnResponseValidationFailed (const GS::ObjectState& response) const override;
92+
};
93+
94+
4495
#endif

Src/Main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ GSErrCode __ACDLL_CALL RegisterInterface (void)
4545
GSErrCode __ACENV_CALL Initialize (void)
4646
{
4747
GSErrCode err = ACAPI_Install_AddOnCommandHandler (GS::NewOwned<PublishCommand> ());
48-
49-
err = ACAPI_Install_AddOnCommandHandler (GS::NewOwned<TeamworkReceiveCommand> ());
48+
err |= ACAPI_Install_AddOnCommandHandler (GS::NewOwned<TeamworkReceiveCommand> ());
49+
err |= ACAPI_Install_AddOnCommandHandler (GS::NewOwned<GetProjectInfoCommand> ());
50+
err |= ACAPI_Install_AddOnCommandHandler (GS::NewOwned<GetArchicadLocationCommand> ());
51+
err |= ACAPI_Install_AddOnCommandHandler (GS::NewOwned<QuitCommand> ());
5052

5153
return err;
5254
} // Initialize

0 commit comments

Comments
 (0)