Skip to content

Commit

Permalink
Тестовый вариант
Browse files Browse the repository at this point in the history
  • Loading branch information
kuvbur committed Aug 27, 2024
1 parent 93136e0 commit a776ead
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 59 deletions.
24 changes: 12 additions & 12 deletions Sources/AddOn/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2289,7 +2289,7 @@ void ParamHelpers::WriteGDLValues (const API_Guid& elemGuid, ParamDictValue& par
API_AddParType& actualParam = (*apiParams.params)[i];
GS::UniString name = actualParam.name;
GS::UniString rawname = "{@gdl:" + name.ToLowerCase () + "}";
if (params.ContainsKey (rawname)) {
if (params.ContainsKey (rawname) && actualParam.typeMod == API_ParSimple) {
ParamValueData paramfrom = params.Get (rawname).val;
BNZeroMemory (&chgParam, sizeof (API_ChangeParamType));
chgParam.index = actualParam.index;
Expand Down Expand Up @@ -3330,16 +3330,16 @@ bool ParamHelpers::ReadGDLValues (const API_Element& element, const API_Elem_Hea
paramnamearray.Get (rawName).Push (param.rawName);
if (param.fromGDLdescription && eltype == API_ObjectID) {
paramBydescription.Add (rawName, param);
} else {
} else {
if (param.fromGDLparam) paramByName.Add (rawName, param);
}
}
}
if (param.fromGDLdescription && eltype == API_ObjectID) {
paramBydescription.Add (param.rawName, param);
} else {
if (param.fromGDLparam) paramByName.Add (param.rawName, param);
}
}
}
if (paramBydescription.IsEmpty () && paramByName.IsEmpty ()) return false;

// Поиск по описанию
Expand Down Expand Up @@ -3597,9 +3597,9 @@ bool ParamHelpers::ReadMaterial (const API_Element& element, ParamDictValue& par
if (ParamHelpers::GetAttributeValues (constrinx, paramsAdd, paramsAdd_1)) {
flag = true;
existsmaterial.Add (constrinx, true);
}
}
}
}
if (flag) {
for (GS::HashTable<GS::UniString, ParamValue>::PairIterator cIt = paramsAdd.EnumeratePairs (); cIt != NULL; ++cIt) {
#if defined(AC_28)
Expand All @@ -3609,9 +3609,9 @@ bool ParamHelpers::ReadMaterial (const API_Element& element, ParamDictValue& par
#endif
}
}
}
}
}
}
bool flag_add = false;

// Если есть строка-шаблон - заполним её
Expand Down Expand Up @@ -3820,13 +3820,13 @@ bool ParamHelpers::ConvertToParamValue (ParamValueData& pvalue, const API_AddPar
param_int = (GS::Int32) param_real;
if (param_int / 1 < param_real) param_int += 1;
pvalue.canCalculate = true;
} else {
} else {
if (param_bool) {
param_int = 1;
param_real = 1.0;
}
}
} else {
} else {
param_real = round (param_real * 100000) / 100000;
if (preal - param_real > 0.00001) param_real += 0.00001;
param_int = (GS::Int32) param_real;
Expand Down Expand Up @@ -4035,7 +4035,7 @@ bool ParamHelpers::ConvertToParamValue (ParamValue& pvalue, const API_AddParType
pvalue.fromGDLparam = true;
pvalue.isValid = true;
return true;
}
}

// -----------------------------------------------------------------------------
// Конвертация свойства в ParamValue
Expand Down Expand Up @@ -4709,14 +4709,14 @@ bool ParamHelpers::ComponentsProfileStructure (ProfileVectorImage& profileDescri
}
}
}
} else {
} else {
DBPrintf ("== SMSTF ERR == syHatch.ToPolygon2D ====================\n");
}
}
}
break;
}
++profileDescriptionIt1;
}
}
if (hasData) {
for (GS::HashTable<GS::UniString, ParamValue>::PairIterator cIt = paramlayers.EnumeratePairs (); cIt != NULL; ++cIt) {
#if defined(AC_28)
Expand Down
185 changes: 138 additions & 47 deletions Sources/AddOn/Spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ACAPinc.h"
#include "APIEnvir.h"
#include "Spec.hpp"
#include "Sync.hpp"

namespace Spec
{
Expand Down Expand Up @@ -89,7 +90,6 @@ GSErrCode SpecArray (const SyncSettings& syncSettings, GS::Array<API_Guid>& guid
#else
i = 1; ACAPI_Interface (APIIo_SetNextProcessPhaseID, &subtitle, &i);
#endif

int dummymode = IsDummyModeOn ();
GSErrCode err = NoError;
SpecRuleDict rules;
Expand Down Expand Up @@ -174,7 +174,16 @@ GSErrCode SpecArray (const SyncSettings& syncSettings, GS::Array<API_Guid>& guid
#else
ACAPI_Interface (APIIo_CloseProcessWindowID, nullptr, nullptr);
#endif

GS::Array<API_Guid> guidArraysync;
for (GS::HashTable<API_Guid, ParamDictValue>::PairIterator cIt = paramOut.EnumeratePairs (); cIt != NULL; ++cIt) {
#if defined(AC_28)
API_Guid elemGuid = cIt->key;
#else
API_Guid elemGuid = *cIt->key;
#endif
guidArraysync.Push (elemGuid);
}
SyncArray (syncSettings, guidArraysync, systemdict);
return err;
}

Expand Down Expand Up @@ -429,12 +438,12 @@ SpecRule GetRuleFromDescription (GS::UniString& description)
for (Int32 inx_row = 1; inx_row < n_row; inx_row++) {
GS::UniString rawName_ = rawName;
rawName_.ReplaceAll ("}", GS::UniString::Printf ("@arr_%d_%d_%d_%d_%d", inx_row, inx_row, 1, 1, ARRAY_UNIC) + "}");
if (part == 0) rule.out_sum_paramrawname.Push (rawName_);
if (part == 1) rule.out_unic_paramrawname.Push (rawName_);
if (part == 1) rule.out_sum_paramrawname.Push (rawName_);
if (part == 0) rule.out_unic_paramrawname.Push (rawName_);
}
} else {
if (part == 0) rule.out_sum_paramrawname.Push (rawName);
if (part == 1) rule.out_unic_paramrawname.Push (rawName);
if (part == 1) rule.out_sum_paramrawname.Push (rawName);
if (part == 0) rule.out_unic_paramrawname.Push (rawName);
}
}
}
Expand Down Expand Up @@ -501,7 +510,7 @@ SpecRule GetRuleFromDescription (GS::UniString& description)
}
if (min_row > 0) {
// создаём группы для параметров с массивами
for (Int32 jj = 1; jj < min_row; jj++) {
for (Int32 jj = 1; jj <= min_row; jj++) {
GroupSpec group_add;

for (UInt32 i = 0; i < group.unic_paramrawname.GetSize (); i++) {
Expand Down Expand Up @@ -542,26 +551,26 @@ SpecRule GetRuleFromDescription (GS::UniString& description)

GSErrCode PlaceElements (GS::Array<ElementDict>& elementstocreate, ParamDictValue& paramToWrite, ParamDictElement& paramOut, Point2D& startpos)
{
API_Element element = {};
API_ElementMemo memo = {};
API_Element elementt = {};
API_ElementMemo memot = {};
#if defined AC_26 || defined AC_27 || defined AC_28
element.header.type.typeID = API_ObjectID;
elementt.header.type.typeID = API_ObjectID;
#else
element.header.typeID = API_ObjectID;
elementt.header.typeID = API_ObjectID;
#endif
GSErrCode err = ACAPI_Element_GetDefaults (&element, &memo);
GSErrCode err = ACAPI_Element_GetDefaults (&elementt, &memot);
if (err != NoError) {
ACAPI_DisposeElemMemoHdls (&memo);
msg_rep ("Spec::PlaceElements", "ACAPI_ElementGroup_Create", err, APINULLGuid);
ACAPI_DisposeElemMemoHdls (&memot);
msg_rep ("Spec::PlaceElements", "ACAPI_Element_GetDefaults", err, APINULLGuid);
return err;
}
double dx = 0; double dy = 0;
GS::Array <API_AddParType> params;
GS::Array <API_Elem_Head> elemsheader;
const GSSize nParams = BMGetHandleSize ((GSHandle) memo.params) / sizeof (API_AddParType);
const GSSize nParams = BMGetHandleSize ((GSHandle) memot.params) / sizeof (API_AddParType);
for (GSIndex ii = 0; ii < nParams; ++ii) {
API_AddParType& actParam = (*memo.params)[ii];
params.Push ((*memo.params)[ii]);
API_AddParType& actParam = (*memot.params)[ii];
params.Push ((*memot.params)[ii]);
const GS::String name (actParam.name);
if (name.IsEqual ("A")) {
dx = actParam.value.real;
Expand All @@ -570,6 +579,8 @@ GSErrCode PlaceElements (GS::Array<ElementDict>& elementstocreate, ParamDictValu
dy = actParam.value.real;
}
}
ACAPI_DisposeElemMemoHdls (&memot);

API_Coord pos = { startpos.x, startpos.y };
ACAPI_CallUndoableCommand ("Create Element", [&]() -> GSErrCode {
int n_elem = 0;
Expand All @@ -581,6 +592,20 @@ GSErrCode PlaceElements (GS::Array<ElementDict>& elementstocreate, ParamDictValu
#else
Element el = *cIt.value;
#endif

API_Element element = {};
API_ElementMemo memo = {};
#if defined AC_26 || defined AC_27 || defined AC_28
element.header.type.typeID = API_ObjectID;
#else
element.header.typeID = API_ObjectID;
#endif
err = ACAPI_Element_GetDefaults (&element, &memo);
if (err != NoError) {
ACAPI_DisposeElemMemoHdls (&memo);
msg_rep ("Spec::PlaceElements", "ACAPI_Element_GetDefaults", err, APINULLGuid);
return err;
}
// Запись параметров
ParamDictValue param;
if (!el.subguid_paramrawname.IsEmpty ()) {
Expand Down Expand Up @@ -622,46 +647,112 @@ GSErrCode PlaceElements (GS::Array<ElementDict>& elementstocreate, ParamDictValu
}
for (GSIndex ii = 0; ii < nParams; ++ii) {
API_AddParType& actParam = (*memo.params)[ii];
actParam = params[ii];
const GS::String name (actParam.name);
GS::UniString rawname = "{@gdl:" + name.ToLowerCase () + "}";
if (param.ContainsKey (rawname)) {
GS::UniString rawname = "";
bool flag_find = false;
if (actParam.typeMod == API_ParSimple) {
rawname = "{@gdl:" + name.ToLowerCase () + "}";
flag_find = param.ContainsKey (rawname);
}
if (actParam.typeMod == API_ParArray) {
for (Int32 kdim1 = 0; kdim1 < actParam.dim1; kdim1++) {
for (Int32 jdim2 = 0; jdim2 < actParam.dim2; jdim2++) {
rawname = "{@gdl:" + name.ToLowerCase () + GS::UniString::Printf ("@arr_%d_%d_%d_%d_%d", kdim1 + 1, kdim1 + 1, jdim2 + 1, jdim2 + 1, ARRAY_UNIC) + "}";
if (param.ContainsKey (rawname)) {
flag_find = true;
}
}
}
}
if (actParam.typeMod == API_ParSimple && flag_find) {
ParamValueData paramfrom = param.Get (rawname).val;
if (actParam.typeMod == API_ParSimple) {
switch (actParam.typeID) {
case APIParT_ColRGB:
case APIParT_Intens:
case APIParT_Length:
case APIParT_RealNum:
case APIParT_Angle:
actParam.value.real = paramfrom.doubleValue; break;
case APIParT_Boolean:
actParam.value.real = paramfrom.doubleValue; break;
case APIParT_Integer:
case APIParT_PenCol:
case APIParT_LineTyp:
case APIParT_Mater:
case APIParT_FillPat:
case APIParT_BuildingMaterial:
case APIParT_Profile:
actParam.value.real = paramfrom.intValue; break;
case APIParT_CString:
case APIParT_Title:
switch (actParam.typeID) {
case APIParT_ColRGB:
case APIParT_Intens:
case APIParT_Length:
case APIParT_RealNum:
case APIParT_Angle:
if (actParam.typeMod == API_ParSimple) actParam.value.real = paramfrom.doubleValue;
if (actParam.typeMod == API_ParArray) {
double** arrHdl = reinterpret_cast<double**>(actParam.value.array);
for (Int32 kdim1 = 0; kdim1 < actParam.dim1; kdim1++) {
for (Int32 jdim2 = 0; jdim2 < actParam.dim2; jdim2++) {
if (kdim1 == paramfrom.array_row_start && kdim1 == paramfrom.array_row_start) {
(*arrHdl)[kdim1 * actParam.dim2 + jdim2] = paramfrom.doubleValue;
}
}
}
}
break;
case APIParT_Boolean:
if (actParam.typeMod == API_ParSimple) actParam.value.real = paramfrom.doubleValue;
break;
case APIParT_Integer:
case APIParT_PenCol:
case APIParT_LineTyp:
case APIParT_Mater:
case APIParT_FillPat:
case APIParT_BuildingMaterial:
case APIParT_Profile:
if (actParam.typeMod == API_ParSimple) actParam.value.real = paramfrom.intValue;
break;
case APIParT_CString:
case APIParT_Title:
if (actParam.typeMod == API_ParSimple) {
GS::ucscpy (actParam.value.uStr, paramfrom.uniStringValue.ToUStr (0, GS::Min (paramfrom.uniStringValue.GetLength (), (USize) API_UAddParStrLen)).Get ());
default:
case APIParT_Dictionary:
break;
}
param.Delete (rawname);
}
break;
default:
case APIParT_Dictionary:
break;
}
param.Delete (rawname);
}
/* if (actParam.typeMod == API_ParArray && flag_find) {
double** arrHdl = reinterpret_cast<double**>(actParam.value.array);
switch (actParam.typeID) {
case APIParT_ColRGB:
case APIParT_Intens:
case APIParT_Length:
case APIParT_RealNum:
case APIParT_Angle:
for (Int32 kdim1 = 0; kdim1 < actParam.dim1; kdim1++) {
for (Int32 jdim2 = 0; jdim2 < actParam.dim2; jdim2++) {
rawname = "{@gdl:" + name.ToLowerCase () + GS::UniString::Printf ("@arr_%d_%d_%d_%d_%d", kdim1 + 1, kdim1 + 1, jdim2 + 1, jdim2 + 1, ARRAY_UNIC) + "}";
if (param.ContainsKey (rawname)) {
(*arrHdl)[kdim1 * actParam.dim2 + jdim2] = param.Get (rawname).val.doubleValue;
}
}
}
break;
case APIParT_Boolean:
break;
case APIParT_Integer:
case APIParT_PenCol:
case APIParT_LineTyp:
case APIParT_Mater:
case APIParT_FillPat:
case APIParT_BuildingMaterial:
case APIParT_Profile:
break;
case APIParT_CString:
case APIParT_Title:
break;
default:
case APIParT_Dictionary:
break;
}
}*/
}
element.object.pos = pos;
err = ACAPI_Element_Create (&element, &memo);
if (err == NoError) {
elemsheader.Push (element.header);
n_elem += 1;
if (n_elem % 5 == 0) {
if (n_elem % 8 == 0) {
pos.x = startpos.x;
pos.y += dy;
} else {
Expand All @@ -672,6 +763,7 @@ GSErrCode PlaceElements (GS::Array<ElementDict>& elementstocreate, ParamDictValu
} else {
msg_rep ("Spec::PlaceElements", "ACAPI_Element_Create", err, APINULLGuid);
}
ACAPI_DisposeElemMemoHdls (&memo);
}
pos.y += 2 * dy;
API_Guid groupGuid = APINULLGuid;
Expand All @@ -684,7 +776,6 @@ GSErrCode PlaceElements (GS::Array<ElementDict>& elementstocreate, ParamDictValu
}
return NoError;
});
ACAPI_DisposeElemMemoHdls (&memo);
for (UInt32 i = 0; i < elemsheader.GetSize (); i++) {
#if defined(AC_27) || defined(AC_28)
err = ACAPI_LibraryManagement_RunGDLParScript (&elemsheader[i], 0);
Expand Down

0 comments on commit a776ead

Please sign in to comment.