11#include " AdditionalJSONCommands.hpp"
22#include " ObjectState.hpp"
3+ #include " FileSystem.hpp"
34
45
56constexpr 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
2943GS::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+
4766GS::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-
8298GS::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
162178void 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}
0 commit comments