Skip to content

Commit c64d0a4

Browse files
jinwuwu001billyjin
andauthored
Add error message management module to the export plugin (#2878)
Co-authored-by: billyjin <[email protected]>
1 parent f1d93f4 commit c64d0a4

File tree

9 files changed

+1079
-4
lines changed

9 files changed

+1079
-4
lines changed

exporter/src/aecommand/AECommand.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "AECommand.h"
2020
#include "utils/AEHelper.h"
2121
#include "utils/AEResource.h"
22-
2322
namespace exporter {
2423

2524
AEGP_Command AECommand::PAGExporterCMD = 0L;

exporter/src/ui/WindowManager.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
namespace exporter {
2727

28-
WindowManager& WindowManager::getInstance() {
28+
WindowManager& WindowManager::GetInstance() {
2929
static WindowManager instance;
3030
return instance;
3131
}
@@ -65,4 +65,14 @@ void WindowManager::initializeQtEnvironment() {
6565
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
6666
}
6767

68+
bool WindowManager::showWarnings(std::vector<std::string>& /*infos*/) {
69+
70+
return true;
71+
}
72+
73+
bool WindowManager::showErrors(std::vector<std::string>& /*infos*/) {
74+
75+
return true;
76+
}
77+
6878
} // namespace exporter

exporter/src/ui/WindowManager.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818

1919
#pragma once
2020

21+
#include <string>
22+
#include <vector>
23+
2124
namespace exporter {
2225
class WindowManager {
2326
public:
24-
static WindowManager& getInstance();
27+
static WindowManager& GetInstance();
2528

2629
void initializeQtEnvironment();
2730

@@ -31,6 +34,10 @@ class WindowManager {
3134

3235
void showExportPreviewWindow();
3336

37+
bool showWarnings(std::vector<std::string>& infos);
38+
39+
bool showErrors(std::vector<std::string>& infos);
40+
3441
WindowManager(const WindowManager&) = delete;
3542
WindowManager& operator=(const WindowManager&) = delete;
3643

exporter/src/utils/AEHelper.cpp

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
/////////////////////////////////////////////////////////////////////////////////////////////////
1818

1919
#include "AEHelper.h"
20+
#include <iostream>
21+
#include "StringHelper.h"
2022
#include "platform/PlatformHelper.h"
21-
2223
namespace AEHelper {
2324

2425
AEGP_PluginID PluginID = 0L;
2526
std::shared_ptr<AEGP_SuiteHandler> Suites = nullptr;
2627
std::string DocumentsFolderPath = "";
2728
std::string AeVersion = "";
2829

30+
int32_t MAJORVERSION = 23;
31+
2932
void SetSuitesAndPluginID(SPBasicSuite* basicSuite, AEGP_PluginID id) {
3033
Suites = std::make_shared<AEGP_SuiteHandler>(basicSuite);
3134
PluginID = id;
@@ -114,4 +117,141 @@ void RunScriptPreWarm() {
114117
}
115118
}
116119

120+
bool CheckAeVersion() {
121+
int32_t majorVersion = 0;
122+
if (AeVersion.empty()) {
123+
return false;
124+
}
125+
try {
126+
size_t dotPos = AeVersion.find('.');
127+
if (dotPos == std::string::npos) {
128+
std::cerr << "Invalid version format" << std::endl;
129+
return false;
130+
}
131+
std::string versionStr = AeVersion.substr(0, dotPos);
132+
majorVersion = std::stoi(versionStr);
133+
} catch (const std::invalid_argument& e) {
134+
std::cerr << "Invalid argument: " << e.what() << std::endl;
135+
return false;
136+
} catch (const std::out_of_range& e) {
137+
std::cerr << "Out of range: " << e.what() << std::endl;
138+
return false;
139+
}
140+
if (majorVersion >= MAJORVERSION) {
141+
return true;
142+
}
143+
return false;
144+
}
145+
146+
std::string GetItemName(const AEGP_ItemH& itemH) {
147+
std::string itemName;
148+
if (itemH == nullptr) {
149+
return itemName;
150+
}
151+
const auto& suites = GetSuites();
152+
auto pluginID = GetPluginID();
153+
AEGP_MemHandle nameMemory = nullptr;
154+
suites->ItemSuite8()->AEGP_GetItemName(pluginID, itemH, &nameMemory);
155+
if (!nameMemory) {
156+
return itemName;
157+
}
158+
itemName = StringHelper::AeMemoryHandleToString(nameMemory);
159+
suites->MemorySuite1()->AEGP_FreeMemHandle(nameMemory);
160+
161+
itemName = StringHelper::DeleteLastSpace(itemName);
162+
return itemName;
163+
}
164+
165+
std::string GetLayerName(const AEGP_LayerH& layerH) {
166+
std::string layerName;
167+
if (layerH == nullptr) {
168+
return layerName;
169+
}
170+
const auto& suites = GetSuites();
171+
auto pluginID = GetPluginID();
172+
AEGP_MemHandle layerNameHandle = nullptr;
173+
AEGP_MemHandle sourceNameHandle = nullptr;
174+
suites->LayerSuite6()->AEGP_GetLayerName(pluginID, layerH, &layerNameHandle, &sourceNameHandle);
175+
if (!layerNameHandle || !sourceNameHandle) {
176+
return layerName;
177+
}
178+
layerName = StringHelper::AeMemoryHandleToString(layerNameHandle);
179+
if (layerName.empty()) {
180+
layerName = StringHelper::AeMemoryHandleToString(sourceNameHandle);
181+
}
182+
suites->MemorySuite1()->AEGP_FreeMemHandle(layerNameHandle);
183+
suites->MemorySuite1()->AEGP_FreeMemHandle(sourceNameHandle);
184+
185+
layerName = StringHelper::DeleteLastSpace(layerName);
186+
return layerName;
187+
}
188+
189+
AEGP_ItemH GetItemFromComp(const AEGP_CompH& compH) {
190+
const auto& suites = GetSuites();
191+
AEGP_ItemH itemH = nullptr;
192+
if (compH != nullptr) {
193+
suites->CompSuite6()->AEGP_GetItemFromComp(compH, &itemH);
194+
}
195+
return itemH;
196+
}
197+
198+
std::string GetCompName(const AEGP_CompH& compH) {
199+
if (compH == nullptr) {
200+
return "";
201+
}
202+
auto itemH = GetItemFromComp(compH);
203+
return GetItemName(itemH);
204+
}
205+
206+
void SelectItem(const AEGP_ItemH& itemH) {
207+
const auto& suites = GetSuites();
208+
if (itemH != nullptr) {
209+
suites->ItemSuite6()->AEGP_SelectItem(itemH, true, true);
210+
suites->CommandSuite1()->AEGP_DoCommand(
211+
3061); // 3061: Open selection, ignoring any modifier keys.
212+
}
213+
}
214+
215+
void SelectItem(const AEGP_ItemH& itemH, const AEGP_LayerH& layerH) {
216+
const auto& suites = GetSuites();
217+
auto pluginID = GetPluginID();
218+
if (itemH == nullptr) {
219+
return;
220+
}
221+
bool hasLayer = (layerH != nullptr);
222+
AEGP_CollectionItemV2 collectionItem;
223+
AEGP_StreamRefH streamH;
224+
if (hasLayer) {
225+
suites->DynamicStreamSuite4()->AEGP_GetNewStreamRefForLayer(pluginID, layerH, &streamH);
226+
collectionItem.type = AEGP_CollectionItemType_LAYER;
227+
collectionItem.u.layer.layerH = layerH;
228+
collectionItem.stream_refH = streamH;
229+
}
230+
231+
suites->ItemSuite6()->AEGP_SelectItem(itemH, true, true);
232+
if (!hasLayer) {
233+
suites->CommandSuite1()->AEGP_DoCommand(
234+
3061); // 3061: Open selection, ignoring any modifier keys.
235+
return;
236+
}
237+
238+
auto compH = GetCompFromItem(itemH);
239+
AEGP_Collection2H collectionH = nullptr;
240+
suites->CollectionSuite2()->AEGP_NewCollection(pluginID, &collectionH);
241+
suites->CollectionSuite2()->AEGP_CollectionPushBack(collectionH, &collectionItem);
242+
suites->CompSuite6()->AEGP_SetSelection(compH, collectionH);
243+
suites->CommandSuite1()->AEGP_DoCommand(
244+
3061); // 3061: Open selection, ignoring any modifier keys.
245+
suites->CollectionSuite2()->AEGP_DisposeCollection(collectionH);
246+
}
247+
248+
AEGP_CompH GetCompFromItem(const AEGP_ItemH& itemH) {
249+
const auto& suites = GetSuites();
250+
AEGP_CompH compH = nullptr;
251+
if (itemH != nullptr) {
252+
suites->CompSuite6()->AEGP_GetCompFromItem(itemH, &compH);
253+
}
254+
return compH;
255+
}
256+
117257
} // namespace AEHelper

exporter/src/utils/AEHelper.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ std::string RunScript(std::shared_ptr<AEGP_SuiteHandler> suites, AEGP_PluginID p
3737

3838
void RunScriptPreWarm();
3939

40+
bool CheckAeVersion();
41+
42+
std::string GetItemName(const AEGP_ItemH& itemH);
43+
44+
std::string GetCompName(const AEGP_CompH& compH);
45+
46+
std::string GetLayerName(const AEGP_LayerH& layerH);
47+
48+
AEGP_CompH GetCompFromItem(const AEGP_ItemH& itemH);
49+
50+
void SelectItem(const AEGP_ItemH& itemH);
51+
52+
void SelectItem(const AEGP_ItemH& itemH, const AEGP_LayerH& layerH);
53+
4054
const std::string TextDocumentScript = R"(
4155
if (typeof PAG !== 'object') {
4256
PAG = {};

0 commit comments

Comments
 (0)