From 426242306d6e59a304524e63627891667fae7f3c Mon Sep 17 00:00:00 2001 From: Pasukhin Dmitry Date: Sat, 1 Nov 2025 17:42:53 +0000 Subject: [PATCH] Data Exchange, STEP - Refactor StepType selection (#786) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - Removed static `lastvalue` variable and mutex-based synchronization, replacing them with a mutable member field `theLastValue` - Restructured logic with early returns to reduce nesting and improve readability - Updated variable naming to follow OCCT conventions (e.g., `module` → `aModule`, `CN` → `aCN`) --- .../StepSelect/StepSelect_StepType.cxx | 96 ++++++++++--------- .../StepSelect/StepSelect_StepType.hxx | 8 +- 2 files changed, 59 insertions(+), 45 deletions(-) diff --git a/src/DataExchange/TKDESTEP/StepSelect/StepSelect_StepType.cxx b/src/DataExchange/TKDESTEP/StepSelect/StepSelect_StepType.cxx index 3714f2646a..0f25016874 100644 --- a/src/DataExchange/TKDESTEP/StepSelect/StepSelect_StepType.cxx +++ b/src/DataExchange/TKDESTEP/StepSelect/StepSelect_StepType.cxx @@ -25,8 +25,6 @@ IMPLEMENT_STANDARD_RTTIEXT(StepSelect_StepType, IFSelect_Signature) -static TCollection_AsciiString lastvalue; - StepSelect_StepType::StepSelect_StepType() : IFSelect_Signature("Step Type") { @@ -49,59 +47,69 @@ void StepSelect_StepType::SetProtocol(const Handle(Interface_Protocol)& proto) Standard_CString StepSelect_StepType::Value(const Handle(Standard_Transient)& ent, const Handle(Interface_InterfaceModel)& model) const { - static Standard_Mutex aMutex; - Standard_Mutex::Sentry aSentry(aMutex); - lastvalue.Clear(); - Handle(StepData_ReadWriteModule) module; - Standard_Integer CN; - Standard_Boolean ok = thelib.Select(ent, module, CN); - if (!ok) + std::lock_guard aLock(myMutex); + + Handle(StepData_ReadWriteModule) aModule; + Standard_Integer aCN; + if (!thelib.Select(ent, aModule, aCN)) { - lastvalue.AssignCat("..NOT FROM SCHEMA "); - lastvalue.AssignCat(theproto->SchemaName(model)); - lastvalue.AssignCat(".."); + // Build error message for unrecognized entity + theLastValue = "..NOT FROM SCHEMA "; + theLastValue += theproto->SchemaName(model); + theLastValue += ".."; + return theLastValue.ToCString(); } - else + + // Handle simple (non-complex) type - return direct reference from module + if (!aModule->IsComplex(aCN)) + return aModule->StepType(aCN).ToCString(); + + // Handle complex type from module + TColStd_SequenceOfAsciiString aList; + if (aModule->ComplexType(aCN, aList)) { - Standard_Boolean plex = module->IsComplex(CN); - if (!plex) - lastvalue = module->StepType(CN); + Standard_Integer aNb = aList.Length(); + if (aNb == 0) + { + theLastValue = "(..COMPLEX TYPE..)"; + } else { - lastvalue.AssignCat("("); - TColStd_SequenceOfAsciiString list; - module->ComplexType(CN, list); - Standard_Integer nb = list.Length(); - if (nb == 0) - lastvalue.AssignCat("..COMPLEX TYPE.."); - for (Standard_Integer i = 1; i <= nb; i++) + theLastValue = "("; + for (Standard_Integer i = 1; i <= aNb; i++) { if (i > 1) - lastvalue.AssignCat(","); - lastvalue.AssignCat(list.Value(i).ToCString()); + theLastValue += ","; + theLastValue += aList.Value(i); } - lastvalue.AssignCat(")"); + theLastValue += ")"; } + return theLastValue.ToCString(); } - if (lastvalue.Length() > 0) - return lastvalue.ToCString(); - DeclareAndCast(StepData_UndefinedEntity, und, ent); - if (und.IsNull()) - return lastvalue.ToCString(); - if (und->IsComplex()) + // Fallback: check for undefined entity + DeclareAndCast(StepData_UndefinedEntity, anUnd, ent); + if (anUnd.IsNull()) { - lastvalue.AssignCat("("); - while (!und.IsNull()) - { - lastvalue.AssignCat(und->StepType()); - und = und->Next(); - if (!und.IsNull()) - lastvalue.AssignCat(","); - } - lastvalue.AssignCat(")"); + theLastValue.Clear(); + return theLastValue.ToCString(); + } + + if (!anUnd->IsComplex()) + return anUnd->StepType(); // Direct return from entity's internal storage + + // Build complex type from undefined entity + theLastValue = "("; + Standard_Boolean isFirst = Standard_True; + while (!anUnd.IsNull()) + { + if (!isFirst) + theLastValue += ","; + theLastValue += anUnd->StepType(); + anUnd = anUnd->Next(); + isFirst = Standard_False; } - else - return und->StepType(); - return lastvalue.ToCString(); + theLastValue += ")"; + + return theLastValue.ToCString(); } diff --git a/src/DataExchange/TKDESTEP/StepSelect/StepSelect_StepType.hxx b/src/DataExchange/TKDESTEP/StepSelect/StepSelect_StepType.hxx index 2d3793540a..1c876f503a 100644 --- a/src/DataExchange/TKDESTEP/StepSelect/StepSelect_StepType.hxx +++ b/src/DataExchange/TKDESTEP/StepSelect/StepSelect_StepType.hxx @@ -23,6 +23,10 @@ #include #include #include +#include + +#include + class StepData_Protocol; class Interface_Protocol; class Standard_Transient; @@ -65,7 +69,9 @@ protected: StepData_WriterLib thelib; private: - Handle(StepData_Protocol) theproto; + Handle(StepData_Protocol) theproto; + mutable TCollection_AsciiString theLastValue; + mutable std::mutex myMutex; }; #endif // _StepSelect_StepType_HeaderFile -- 2.39.5