Skip to content

Commit

Permalink
Merge branch 'main' into fem_2d_quad8
Browse files Browse the repository at this point in the history
  • Loading branch information
FEA-eng authored Mar 8, 2024
2 parents 38b7d71 + eb5a1b3 commit ba8d750
Show file tree
Hide file tree
Showing 525 changed files with 21,590 additions and 23,564 deletions.
1 change: 0 additions & 1 deletion src/App/ComplexGeoData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,6 @@ unsigned int ComplexGeoData::getMemSize() const
return 0;
}


void ComplexGeoData::setMappedChildElements(const std::vector<Data::ElementMap::MappedChildElements> & children)
{
// DO NOT reset element map if there is one. Because we allow mixing child
Expand Down
16 changes: 14 additions & 2 deletions src/App/ComplexGeoData.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,20 @@ class AppExport ComplexGeoData: public Base::Persistence, public Base::Handled
virtual bool checkElementMapVersion(const char * ver) const;

/// Check if the given sub-name only contains an element name
static bool isElementName(const char *subName) {
return (subName != nullptr) && (*subName != 0) && findElementName(subName)==subName;
static bool isElementName(const char* subName)
{
return (subName != nullptr) && (*subName != 0) && findElementName(subName) == subName;
}

/** Iterate through the history of the give element name with a given callback
*
* @param name: the input element name
* @param cb: trace callback with call signature.
* @sa TraceCallback
*/
void traceElement(const MappedName& name, TraceCallback cb) const
{
_elementMap->traceElement(name, Tag, cb);
}

/** Flush an internal buffering for element mapping */
Expand Down
6 changes: 3 additions & 3 deletions src/App/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ Document::Document(const char* documentName)
#ifdef FC_LOGUPDATECHAIN
Console().Log("+App::Document: %p\n", this);
#endif
std::string CreationDateString = Base::TimeInfo::currentDateTimeString();
std::string CreationDateString = Base::Tools::currentDateTimeString();
std::string Author = App::GetApplication()
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/Document")
->GetASCII("prefAuthor", "");
Expand Down Expand Up @@ -1606,7 +1606,7 @@ bool Document::save ()
TipName.setValue(Tip.getValue()->getNameInDocument());
}

std::string LastModifiedDateString = Base::TimeInfo::currentDateTimeString();
std::string LastModifiedDateString = Base::Tools::currentDateTimeString();
LastModifiedDate.setValue(LastModifiedDateString.c_str());
// set author if needed
bool saveAuthor = App::GetApplication().GetParameterGroupByPath
Expand Down Expand Up @@ -1799,7 +1799,7 @@ class BackupPolicy {
if (useFCBakExtension) {
std::stringstream str;
Base::TimeInfo ti = fi.lastModified();
time_t s =ti.getSeconds();
time_t s = ti.getTime_t();
struct tm * timeinfo = localtime(& s);

Check warning on line 1803 in src/App/Document.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Consider using localtime_r(...) instead of localtime(...) for improved thread safety. [runtime/threadsafe_fn] [2]
char buffer[100];

Expand Down
91 changes: 91 additions & 0 deletions src/App/ElementMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "App/Application.h"
#include "Base/Console.h"
#include "Document.h"
#include "DocumentObject.h"

#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
Expand Down Expand Up @@ -1348,5 +1350,94 @@ long ElementMap::getElementHistory(const MappedName& name, long masterTag, Mappe
}
}

void ElementMap::traceElement(const MappedName& name, long masterTag, TraceCallback cb) const
{
long encodedTag = 0;
int len = 0;

auto pos = name.findTagInElementName(&encodedTag, &len, nullptr, nullptr, true);
if (cb(name, len, encodedTag, masterTag) || pos < 0) {
return;
}

if (name.startsWith(POSTFIX_EXTERNAL_TAG, len)) {
return;
}

std::set<long> tagSet;

std::vector<MappedName> names;
if (masterTag) {
tagSet.insert(std::abs(masterTag));
}
if (encodedTag) {
tagSet.insert(std::abs(encodedTag));
}
names.push_back(name);

masterTag = encodedTag;
MappedName tmp;
bool first = true;

// TODO: element tracing without object is inherently unsafe, because of
// possible external linking object which means the element may be encoded
// using external string table. Looking up the wrong table may accidentally
// cause circular mapping, and is actually quite easy to reproduce. See
//
// https://github.com/realthunder/FreeCAD_assembly3/issues/968
//
// An arbitrary depth limit is set here to not waste time. 'tagSet' above is
// also used for early detection of 'recursive' mapping.

for (int index = 0; index < 50; ++index) {
if (!len || len > pos) {
return;
}
if (first) {
first = false;
size_t offset = 0;
if (name.startsWith(ELEMENT_MAP_PREFIX)) {
offset = ELEMENT_MAP_PREFIX_SIZE;
}
tmp = MappedName(name, offset, len);
}
else {
tmp = MappedName(tmp, 0, len);
}
tmp = dehashElementName(tmp);
names.push_back(tmp);
encodedTag = 0;
pos = tmp.findTagInElementName(&encodedTag, &len, nullptr, nullptr, true);
if (pos >= 0 && tmp.startsWith(POSTFIX_EXTERNAL_TAG, len)) {
break;
}

if (encodedTag && masterTag != std::abs(encodedTag)
&& !tagSet.insert(std::abs(encodedTag)).second) {
if (FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG)) {
FC_WARN("circular element mapping");
if (FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_TRACE)) {
auto doc = App::GetApplication().getActiveDocument();
if (doc) {
auto obj = doc->getObjectByID(masterTag);
if (obj) {
FC_LOG("\t" << obj->getFullName() << obj->getFullName() << "." << name);
}
}
for (auto& errname : names) {
FC_ERR("\t" << errname);
}
}
}
break;
}

if (cb(tmp, len, encodedTag, masterTag) || pos < 0) {
return;
}
masterTag = encodedTag;
}
}


}// Namespace Data
24 changes: 24 additions & 0 deletions src/App/ElementMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ namespace Data
class ElementMap;
using ElementMapPtr = std::shared_ptr<ElementMap>;

/** Element trace callback
*
* The callback has the following call signature
* (const std::string &name, size_t offset, long encodedTag, long tag) -> bool
*
* @param name: the current element name.
* @param offset: the offset skipping the encoded element name for the next iteration.
* @param encodedTag: the tag encoded inside the current element, which is usually the tag
* of the previous step in the shape history.
* @param tag: the tag of the current shape element.
*
* @sa traceElement()
*/
typedef std::function<bool(const MappedName&, int, long, long)> TraceCallback;

/* This class provides for ComplexGeoData's ability to provide proper naming.
* Specifically, ComplexGeoData uses this class for it's `_id` property.
* Most of the operations work with the `indexedNames` and `mappedNames` maps.
Expand Down Expand Up @@ -185,6 +200,15 @@ class AppExport ElementMap: public std::enable_shared_from_this<ElementMap> //TO
long masterTag,
MappedName *original=nullptr, std::vector<MappedName> *history=nullptr) const;

/** Iterate through the history of the give element name with a given callback
*
* @param name: the input element name
* @param cb: trace callback with call signature.
* @sa TraceCallback
*/
void traceElement(const MappedName& name, long masterTag, TraceCallback cb) const;


private:
/** Serialize this map
* @param stream: serialized stream
Expand Down
1 change: 0 additions & 1 deletion src/Base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ SET(FreeCADBase_CPP_SRCS
Stream.cpp
Swap.cpp
${SWIG_SRCS}
TimeInfo.cpp
Tools.cpp
Tools2D.cpp
Tools3D.cpp
Expand Down
1 change: 1 addition & 0 deletions src/Base/PreCompiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <cassert>
#include <ctime>
#include <cfloat>
#include <chrono>
#ifdef FC_OS_WIN32
#define _USE_MATH_DEFINES
#endif // FC_OS_WIN32
Expand Down
6 changes: 3 additions & 3 deletions src/Base/Resources/translations/Base_nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<message>
<location filename="../../UnitsApi.cpp" line="69"/>
<source>Standard (mm, kg, s, °)</source>
<translation type="unfinished">Standard (mm, kg, s, °)</translation>
<translation>Standaard (mm, kg, s, graden)</translation>
</message>
<message>
<location filename="../../UnitsApi.cpp" line="71"/>
<source>MKS (m, kg, s, °)</source>
<translation type="unfinished">MKS (m, kg, s, °)</translation>
<translation>MKS (m, kg, s, graden)</translation>
</message>
<message>
<location filename="../../UnitsApi.cpp" line="73"/>
Expand Down Expand Up @@ -41,7 +41,7 @@
<message>
<location filename="../../UnitsApi.cpp" line="83"/>
<source>Imperial for Civil Eng (ft, ft/s)</source>
<translation type="unfinished">Imperial for Civil Eng (ft, ft/s)</translation>
<translation>Engelse eenheden voor Civiele Engineering (ft, ft/sec)</translation>
</message>
<message>
<location filename="../../UnitsApi.cpp" line="85"/>
Expand Down
113 changes: 0 additions & 113 deletions src/Base/TimeInfo.cpp

This file was deleted.

Loading

0 comments on commit ba8d750

Please sign in to comment.