Compare commits

...

95 Commits

Author SHA1 Message Date
Zheng Lei 140236c774 Merge pull request #8124 from jerome992/development/toponaming
Fix selection in sketcher development/toponaming
2023-01-08 09:59:00 +08:00
Jerome cc3d7dfbf0 Fix selection in sketcher
https://forum.freecadweb.org/viewtopic.php?p=650988#p650988

* The function ViewProviderSketch::isSelected should not modifiy its
  incoming parameter
* ViewProviderSketch::rmvSelection, ViewProviderSketch::addSelection,
  ViewProviderSketch::addSelection2 have not called the convertSubName
  function.
* Should the the convertSubName not be called inside the function
  ViewProviderSketch::mouseButtonPressed, because now the convertSubName
  is called two times?
2023-01-03 22:18:44 +01:00
Zheng, Lei 112c15ed75 App: fix lost of element reference tracking on undo/redo 2022-12-12 10:47:16 +01:00
Uwe a08b04a079 [Part] TopoShapeEx.cpp: fix some whitespace issues
- as reported by the CI
2022-11-29 03:32:34 +01:00
Zheng Lei 811bf87d0e Topo Naming accumulated fixes (#7792)
* Part: fix Part.sortEdges()
 (Fixes realthunder/fcad_pcb#61)
* App: fix indexed element name parsing
* Part: avoid unnecessary wire making in TopoShape::makELoft/makEPipeShell()
2022-11-29 01:57:07 +01:00
Uwe 93c3ef7b2f [skip ci] .clang-format: shorthand loops
- disallow as we did before we had this format file
2022-11-22 03:13:17 +01:00
Uwe ad94f88217 [skip ci] [.clang] set pointer style to left
- since we added the .clang-format file we used Left for the pointer asterisk. It is annoying to get now all the time automatic diffs because the -clang file uses Right.
2022-11-11 05:20:33 +01:00
Uwe c2f7d03413 [.clang] use line break after case
- we used in the past line breaks after a case statements to better overview. This should be kept.
2022-11-11 05:20:33 +01:00
Zheng, Lei f2b2c8b4e7 Part: fix AttachEngine sub-element auto fix 2022-11-03 22:23:52 +01:00
Zheng, Lei f9688fbde7 Part: fix missing topo naming in FeatureExtrusion 2022-11-03 22:23:52 +01:00
Zheng, Lei 51621458b5 Change topo naming branch version in cmake
Limit the change only in src/Main
2022-10-28 07:42:54 +08:00
Uwe c25ed7e162 set version number to 0.20
- there was some confusion.
 Toponaming is FreeCAD 0.20.0 + toponaming, so neither 0.20.1 nor 0.21/master
2022-10-27 15:37:41 +02:00
Zheng, Lei 2a4335302f Remove special toponaming version string to avoid test failure 2022-10-27 15:53:44 +08:00
Zheng, Lei 69ed88ac2c Add new build option FREECAD_TOPONAMING_BRANDING
For differentiating releases of toponaming and master branch, with
branding_toponaming.xml specifying customized window icon, title, and
version number.

The build option is default ON in toponaming branch. For future merge
into master, change this option to OFF by default.
2022-10-27 09:44:19 +08:00
Zheng, Lei 1f946e6c9a Part: fix TopoShape::isLinearEdge() transformation 2022-10-26 17:08:37 +08:00
Zheng, Lei ac76ba280d Fix build warning
Build warning on MacOS homebrew caused by missing Standard_Version.hxx
2022-10-26 15:04:49 +08:00
Zheng, Lei ceab748ba1 Part: fix element mapping in TopoShape::fix()
Also change makEWires() to use fix()
2022-10-26 11:05:45 +08:00
wmayer e1232a5e6e CMake: [skip ci] fix deprecation warning about policy CMP0072 2022-10-26 02:51:27 +02:00
Zheng, Lei 5cc0693e61 Temporarily hardcode application name for TopoNaming branch 2022-10-23 11:08:12 +08:00
Uwe 387b19eed9 [.github] port recent changes from master 2022-10-22 15:45:33 +02:00
looooo 18ff9bcf26 add_definitions(-DSALOME_USE_64BIT_IDS) for smesh via config 2022-10-22 01:34:02 +02:00
looooo 5da8804871 extend find_package(SMESH) 2022-10-22 01:27:28 +02:00
Scott Mudge dbeb4d2f5d Fixed external SMESH cmake scripts, allowing netgen and gmsh compatibility with VTK 9
- moved base SMESH cmake logic to respective cmake script.
- allow BUILD_SMESH, regardless of external SMESH usage, for testing and so on.
2022-10-22 01:27:28 +02:00
Zheng, Lei d2d0b7f018 Fix build warning with OCC 7.6 2022-10-18 22:27:15 +08:00
Zheng, Lei c28d5659a0 Fix build error on MacOS 2022-10-18 22:27:15 +08:00
Uwe 812c1e0f56 [.clang] change a setting back to our "default"
- we used (since I am at FreeCAD) a line break after an if statement for better readability. I noticed that this rule on not in our .clang format causing unwanted diffs when using it (e.g. when coding using the Visual Studio IDE:)
2022-10-03 05:45:47 +02:00
Uwe 99f719e81c sync .gitignore with master 2022-10-01 06:03:52 +02:00
Uwe da58eb2681 StringHasher: some more Clang formattings 2022-10-01 06:00:34 +02:00
Uwe c084eef7a3 sync .clang and .github with master 2022-10-01 05:47:34 +02:00
Uwe 24036a8046 StringHasher: sanitize includes
- fix CI warning "parameter name 'a' is too short, expected at least 3 characters"
- fix some CI whitespace warnings
- some Clang formatting
2022-10-01 05:35:17 +02:00
Uwe db8729ec74 StringHasher: sanitize includes
- try to fix CI warning "Found C system header after other header."
- remove unneeded includes
- sort includes
2022-10-01 05:14:05 +02:00
Zheng, Lei 015d6396ff App: improve code quality of StringHasher 2022-10-01 04:49:07 +02:00
Zheng, Lei 6df100f5b7 Base: expose underlying_type in Flags 2022-10-01 04:49:07 +02:00
Zheng, Lei 7cb9ba470c Sketcher: fix various topo naming related problem 2022-09-25 20:25:25 +02:00
Zheng, Lei 1e6f84a59c App: suppress useless warning message 2022-09-25 20:25:25 +02:00
Zheng, Lei 2292eecb4e App: revert ComplexGeoData::getSubElementByName() 2022-09-25 20:25:25 +02:00
Zheng, Lei 5fc5203ff7 Part: fix tapered extrusion backward compatibility 2022-09-25 20:25:25 +02:00
Zheng, Lei e8547f7588 Gui: prompt user for recompute on recompute topo naming
Expose it as a preference option in

  General -> Document -> Do not prompt for recompute on restore.
2022-09-25 20:25:25 +02:00
Zheng, Lei eade03c006 Base: fix crash on logging Python call frame 2022-09-25 20:25:25 +02:00
Uwe cef5e6f4ab [Import] eventually fix compilation on MSVC 2022-09-16 15:53:09 +02:00
Uwe 9331c0d939 [import] attempt to fix compilation
- patch by @realthunder
- does not fix the problem, though
2022-09-16 02:40:20 +02:00
Uwe decc354b80 fix compiler warning 2022-09-16 02:39:15 +02:00
Zheng, Lei f24c64c96c Fix build warning 2022-09-15 13:37:39 +02:00
Zheng, Lei 689f6595fb Fix typo 2022-09-15 13:37:39 +02:00
Zheng, Lei 3a2e799300 Fix typo 2022-09-15 13:37:39 +02:00
Zheng, Lei c643e5e340 Sketcher: improve task panel for elements and constraints 2022-09-15 13:37:39 +02:00
Zheng, Lei 8ee6153f4b Sketcher: support new topo naming 2022-09-15 13:37:39 +02:00
Zheng, Lei bf38d42f15 Sketcher: add some icons 2022-09-15 13:37:39 +02:00
Zheng, Lei 6fa8bba4fd Part/Sketcher: change geometry extensions APIs for topo naming support 2022-09-15 13:37:39 +02:00
Zheng, Lei 33c85ba1f2 Part: improve efficiency of PropertyGeometryList 2022-09-15 13:37:39 +02:00
Zheng, Lei 9f200d4404 App/Part: add API Property::isSameContent()
A generate implementation of comparing property of any type.

Note, in the future, isSame() will be promoted to be an abstract API in
Property, and every type of property will have to provide an
implementation. isSameContent() can be used as a not so efficient
fallback.
2022-09-15 13:37:39 +02:00
Uwe 50f6650fac [skip CI] fix 2 typos reported by spellchecker 2022-09-14 14:22:29 +02:00
Zheng, Lei 5db5fc3886 Fix build error
error: ambiguous overload for ‘operator==’ (operand types are ‘App::StringHasher* const’ and ‘const StringHasherRef’ {aka ‘const Base::Reference<App::StringHasher>’})
2022-09-05 12:06:06 +05:00
Zheng, Lei 28ca0cf7b1 Fix typo 2022-09-05 12:06:06 +05:00
Zheng, Lei b470cfeaf1 Fix build for OCC < 7.6 2022-09-05 12:06:06 +05:00
Zheng, Lei 352678f4e2 Part: fix history tracing in static function getElementColor() 2022-09-05 12:06:06 +05:00
Zheng, Lei f87ed0c454 PartDesign: retag external bound shape in SubShapeBinder 2022-09-05 12:06:06 +05:00
Zheng, Lei c42a4cb21c App: force retag shape of linked object
The re-tagging is necessary for trace geometry element history to linked
object, which is required for Part::ViewProviderPartExt color mapping.
2022-09-05 12:06:06 +05:00
Zheng, Lei f638619964 Import: improve STEP color support using topo naming 2022-09-05 12:06:06 +05:00
Zheng, Lei 8dc3b71989 Part: improve per geometry element coloring through topo naming 2022-09-05 12:06:06 +05:00
Zheng, Lei 4984bd9f05 Gui: add API ViewProvider::updateColors()
Used in TaskElementColors for general handling of per geometry element
coloring.
2022-09-05 12:06:06 +05:00
Zheng, Lei 27c893f71f Part: support new topo naming in Part features
Most of the new topo naming code can be disabled by defining Macro
FC_NO_ELEMENT_MAP
2022-09-05 12:06:06 +05:00
Zheng, Lei 6c51bebf14 Part: improve Attacher with new topo naming
Make use of the shadow subname (i.e. the new topo naming) stored inside
PropertyLinkSubList for more robust geometry element referecing. And
rely on Part::Feature::getRelatedElements() to deduce missing geometry
elements.
2022-09-05 12:06:06 +05:00
Zheng, Lei 32d45ac97d App/Part: fix App::Link visibility detection in PartFeature::getTopoShape() 2022-09-05 12:06:06 +05:00
Zheng, Lei a46cc55da1 App/Gui: add APIs for for efficient extension iteration
ExtensionContainer::foreach/query/callExtension()
2022-09-05 12:06:06 +05:00
Zheng, Lei d11bec9688 App: change API signature DocumentObjectExtension::extensionIsElementVisible 2022-09-05 12:06:06 +05:00
Zheng, Lei 0069419c8b Part: re-enable topo naming version checking 2022-09-05 12:06:06 +05:00
Zheng, Lei b06c0ccd86 Fix typo 2022-09-05 12:06:06 +05:00
Zheng, Lei c85023415a Fix build error for OCC < 7.6 2022-09-03 00:36:31 +05:00
Zheng, Lei db858e1f0a Fix typos 2022-09-03 00:36:31 +05:00
Zheng, Lei 010a632e5d Part: change exception type for TopoShape::getSubTopoShape()
Same for TopoShapePy.getElement()
2022-09-03 00:36:31 +05:00
Zheng, Lei 9d7793ecb9 App: change main StringHasher storage policy
Only save to XML if asked explicitly
2022-09-03 00:36:31 +05:00
Zheng, Lei 418ebb7958 Part: change topo naming storage policy
Only save to XML if asked explicitly
2022-09-03 00:36:31 +05:00
Zheng, Lei e30f7bf920 Gui: fix tree view expansion restore 2022-09-03 00:36:31 +05:00
Zheng, Lei 1b26292d3c Part: Temporarily disable topo naming version check 2022-09-03 00:36:31 +05:00
Zheng, Lei 0afcf099df Part: refactor TopoShape to support new topological naming
The topological naming aware member functions are all located in a new
source file TopoShapeEx.cpp. The core algorithm of generate the names is
in TopoShape::makESHAPE(). Check out the following wiki article for more
details.

https://github.com/realthunder/FreeCAD_assembly3/wiki/Topological-Naming-Algorithm

Note that the actual name encoding is slightly changed to improve
efficiency, but the algorithm is mostly the same.
2022-09-03 00:36:31 +05:00
Zheng, Lei 691c0709be App: improve convenience class SubObjectT 2022-09-03 00:36:31 +05:00
Zheng, Lei 05d35e1e6f Part: move legacy ShapeHistory code 2022-09-03 00:36:31 +05:00
Zheng, Lei 1edab5611b Part: add API Geometry::isSame()
For comparing if two geometries are the same. Exposed to Python with a
method of the same name. The API will be used by TopoShape to search
shape by geometry to make topological naming more robust.
2022-09-03 00:36:31 +05:00
Zheng, Lei e5beb5ab2b App: add APIs in ComplexGeoData for element name mapping
These are the fundation for storing and querying the new topological
naming of geometry element.

To get an overview of this fundation, please check out the following article
https://github.com/realthunder/FreeCAD_assembly3/wiki/Topological-Naming

There are some changes in topo naming internal storage, which changes
from plain string to two dedicated class IndexedName (for indexed
geometry element name) and MappedName. These two classes are created to
improve topological naming performance in terms of speed, runtime
memory, and persistence storage size.
2022-09-03 00:36:31 +05:00
Zheng, Lei c67d9b0ee9 App: change API signature ComplexGeoData::getElementTypes() 2022-09-03 00:36:31 +05:00
Zheng, Lei 6ce250ddf8 App: add API PropertyContainer::onEarlyChange()
Also add DocumentObject::signalEarlyChanged, triggered before
Document::signalChangedObject
2022-09-03 00:36:31 +05:00
Zheng, Lei 75acf045a6 App: add API beforeSave()
Added in class Property and class PropertyContainer to allow customized
processing before saving.
2022-09-03 00:36:31 +05:00
Zheng, Lei 2a254e937f App/Gui: add convenience API getFullName/getOwnerDocument()
in App::Property and App::PropertyContainer, implemented in
App::Document/DocumentObject, and Gui::ViewProviderDocumentObject
2022-09-03 00:36:31 +05:00
Zheng, Lei 444de2c8af App: add string table
General purpose string table to avoid saving duplicated text string
multiple times.. Mainly used by topological naming to compress model
histroy. But can be used for other purpose as well, e.g.  to strore
documentation of dynamic property.
2022-09-03 00:36:31 +05:00
Zheng, Lei fd60f29965 Cloud: fix file save/restore due to Base::Reader/Writer changes 2022-09-03 00:36:31 +05:00
Zheng, Lei 217c8630f6 Base: support saving/restoring binary/text stream inside xml
This commit is split out from realthunder/FreeCAD#a2579bff, which
introduced support of saving FreeCAD document as directory. This commit
only include relavent changes for efficient storage of topological
naming. Full support of directory saving will be added in another PR.

The specific changes needed for topological naming storge is the proper
support of XML characters content in Base::XMLReader and Base::Writer.
Use XMLReader::beginCharStream() to stream either binary or text data.
Binary data will be base64 encoded on the fly with user defined line
size. The base64 string is stored as plain character content inside the
current XML element. Text data is stored inside CDATA section with
automatic detection and handling of CDATA end tag inside the text. Be
WARNED though, there is no validation of text character yet. The caller
must ensure the input text is valid UTF8.

Topological naming uses text stream. The change introduced here also
affects App::PropertyFileIncluded, Gui::TreeWidget (for persistence of
tree item expansion status), Path::Toolpath, Points::PointKernel, and
Spreadsheet::Cell. The changes by right shouldn't cause any backward
compatibility issue.

Another relatively small change that is not so relavant to topo naming
is the support of hierarchical XMLReader, which allows the top level
reader to centralize control of mult-file-reading that might be added by
lower level xml reader. This change is included here because of
difficulty in splitting the functionality apart from the streaming
changes.  Note that this change breaks Mod/Cloud module, which will be
fixed in follow up patches.
2022-09-03 00:36:31 +05:00
Zheng, Lei dc48c5debd Base: improve class 'Handle' efficiency
By replacing dynamic allocated QAtomicInt with std::atomic and making
most code inlined.
2022-09-03 00:36:31 +05:00
Uwe a8606ce05c [.github] try to get the checks also for the 0-20 branch 2022-07-24 06:13:47 +02:00
Uwe adbe29f1dc [.github] disable tidy checks for now
- as requested in https://github.com/FreeCAD/FreeCAD/pull/7152#issuecomment-1193176866
2022-07-24 06:13:47 +02:00
Uwe 3b09334501 [.github] disable clang checks for now
see https://github.com/FreeCAD/FreeCAD/pull/7152#issuecomment-1193167296
2022-07-24 06:13:47 +02:00
Floriansimmer e909322fb9 Github: basic check CI Run (#7152)
* Github: basic check CI Run

- trailing Whitespace
- tab
- string based QT connections
- Cpplint
- pylint
- Black
- clang-format
- Codespell
- clang-tidy
- clazy (+QT6 Checks)
- Report
2022-07-24 06:13:47 +02:00
mosfet80 a304bcc59a Git ignore hidden files with defined exceptions (#7108)
* git ignore all hidden files

* Removal file with non-existent link

* git Ignore all hidden files except .gitignore

* Set exceptions in gitignore
2022-07-24 06:13:47 +02:00
luz paz 83d0fa6730 README: added revisions
[skip ci]
2022-07-02 16:43:56 +02:00
luzpaz 9d54041102 TPN: Modify README.md of toponaming branch to help orientate testers (#7049)
Co-authored-by: luzpaz <luzpaz@github.com>  
Co-authored-by: Ajinkya Dahale <AjinkyaDahale@users.noreply.github.com>
2022-07-01 03:42:44 +02:00
251 changed files with 40487 additions and 6309 deletions
+7 -7
View File
@@ -8,12 +8,12 @@ AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: MultiLine
BreakBeforeBraces: Custom
BraceWrapping:
@@ -33,7 +33,7 @@ BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
ColumnLimit: 100
CompactNamespaces: false
ContinuationIndentWidth: 4
IndentCaseLabels: true
@@ -44,13 +44,13 @@ MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
PointerAlignment: Left
ReflowComments: false
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: false
SpaceBeforeParens: ControlStatements
+490
View File
@@ -0,0 +1,490 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,boost-*,bugprone-*,
performance-*,readability-*,portability-*,modernize-*,cppcoreguidelines-*,
concurrency-*,-modernize-use-trailing-return-type, -modernize-use-nodiscard'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: file
User: florians
CheckOptions:
- key: readability-suspicious-call-argument.PrefixSimilarAbove
value: '30'
- key: cppcoreguidelines-no-malloc.Reallocations
value: '::realloc'
- key: cppcoreguidelines-owning-memory.LegacyResourceConsumers
value: '::free;::realloc;::freopen;::fclose'
- key: bugprone-reserved-identifier.Invert
value: 'false'
- key: bugprone-narrowing-conversions.PedanticMode
value: 'false'
- key: bugprone-unused-return-value.CheckedFunctions
value: '::std::async;::std::launder;::std::remove;::std::remove_if;::std::unique;::std::unique_ptr::release;::std::basic_string::empty;::std::vector::empty;::std::back_inserter;::std::distance;::std::find;::std::find_if;::std::inserter;::std::lower_bound;::std::make_pair;::std::map::count;::std::map::find;::std::map::lower_bound;::std::multimap::equal_range;::std::multimap::upper_bound;::std::set::count;::std::set::find;::std::setfill;::std::setprecision;::std::setw;::std::upper_bound;::std::vector::at;::bsearch;::ferror;::feof;::isalnum;::isalpha;::isblank;::iscntrl;::isdigit;::isgraph;::islower;::isprint;::ispunct;::isspace;::isupper;::iswalnum;::iswprint;::iswspace;::isxdigit;::memchr;::memcmp;::strcmp;::strcoll;::strncmp;::strpbrk;::strrchr;::strspn;::strstr;::wcscmp;::access;::bind;::connect;::difftime;::dlsym;::fnmatch;::getaddrinfo;::getopt;::htonl;::htons;::iconv_open;::inet_addr;::isascii;::isatty;::mmap;::newlocale;::openat;::pathconf;::pthread_equal;::pthread_getspecific;::pthread_mutex_trylock;::readdir;::readlink;::recvmsg;::regexec;::scandir;::semget;::setjmp;::shm_open;::shmget;::sigismember;::strcasecmp;::strsignal;::ttyname'
- key: modernize-use-auto.MinTypeNameLength
value: '5'
- key: cppcoreguidelines-macro-usage.CheckCapsOnly
value: 'false'
- key: readability-inconsistent-declaration-parameter-name.Strict
value: 'false'
- key: readability-suspicious-call-argument.DiceDissimilarBelow
value: '60'
- key: bugprone-assert-side-effect.IgnoredFunctions
value: __builtin_expect
- key: readability-suspicious-call-argument.Equality
value: 'true'
- key: bugprone-easily-swappable-parameters.QualifiersMix
value: 'false'
- key: bugprone-suspicious-string-compare.WarnOnImplicitComparison
value: 'true'
- key: bugprone-argument-comment.CommentNullPtrs
value: '0'
- key: cppcoreguidelines-narrowing-conversions.WarnOnFloatingPointNarrowingConversion
value: 'true'
- key: cppcoreguidelines-init-variables.IncludeStyle
value: llvm
- key: modernize-use-nodiscard.ReplacementString
value: '[[nodiscard]]'
- key: modernize-loop-convert.MakeReverseRangeHeader
value: ''
- key: readability-suspicious-call-argument.SuffixSimilarAbove
value: '30'
- key: cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion
value: 'true'
- key: bugprone-easily-swappable-parameters.IgnoredParameterNames
value: '"";iterator;Iterator;begin;Begin;end;End;first;First;last;Last;lhs;LHS;rhs;RHS'
- key: modernize-loop-convert.UseCxx20ReverseRanges
value: 'true'
- key: cppcoreguidelines-prefer-member-initializer.UseAssignment
value: 'false'
- key: performance-type-promotion-in-math-fn.IncludeStyle
value: llvm
- key: readability-function-cognitive-complexity.DescribeBasicIncrements
value: 'true'
- key: bugprone-suspicious-include.ImplementationFileExtensions
value: 'c;cc;cpp;cxx'
- key: modernize-loop-convert.MakeReverseRangeFunction
value: ''
- key: readability-inconsistent-declaration-parameter-name.IgnoreMacros
value: 'true'
- key: bugprone-suspicious-missing-comma.SizeThreshold
value: '5'
- key: readability-identifier-naming.IgnoreFailedSplit
value: 'false'
- key: readability-qualified-auto.AddConstToQualified
value: 'true'
- key: bugprone-sizeof-expression.WarnOnSizeOfThis
value: 'true'
- key: bugprone-string-constructor.WarnOnLargeLength
value: 'true'
- key: cppcoreguidelines-explicit-virtual-functions.OverrideSpelling
value: override
- key: readability-uppercase-literal-suffix.IgnoreMacros
value: 'true'
- key: modernize-make-shared.IgnoreMacros
value: 'true'
- key: bugprone-dynamic-static-initializers.HeaderFileExtensions
value: ';h;hh;hpp;hxx'
- key: bugprone-suspicious-enum-usage.StrictMode
value: 'false'
- key: performance-unnecessary-copy-initialization.AllowedTypes
value: ''
- key: bugprone-suspicious-missing-comma.MaxConcatenatedTokens
value: '5'
- key: modernize-use-transparent-functors.SafeMode
value: 'false'
- key: readability-suspicious-call-argument.Levenshtein
value: 'true'
- key: bugprone-not-null-terminated-result.WantToUseSafeFunctions
value: 'true'
- key: bugprone-string-constructor.LargeLengthThreshold
value: '8388608'
- key: readability-simplify-boolean-expr.ChainedConditionalAssignment
value: 'false'
- key: cppcoreguidelines-avoid-magic-numbers.IgnoreAllFloatingPointValues
value: 'false'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: 'false'
- key: bugprone-exception-escape.FunctionsThatShouldNotThrow
value: ''
- key: performance-inefficient-vector-operation.EnableProto
value: 'false'
- key: modernize-make-shared.MakeSmartPtrFunction
value: 'std::make_shared'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: readability-suspicious-call-argument.PrefixDissimilarBelow
value: '25'
- key: readability-function-size.LineThreshold
value: '4294967295'
- key: bugprone-easily-swappable-parameters.MinimumLength
value: '2'
- key: portability-simd-intrinsics.Suggest
value: 'false'
- key: cppcoreguidelines-pro-bounds-constant-array-index.GslHeader
value: ''
- key: modernize-use-override.IgnoreDestructors
value: 'false'
- key: modernize-make-shared.MakeSmartPtrFunctionHeader
value: '<memory>'
- key: bugprone-sizeof-expression.WarnOnSizeOfConstant
value: 'true'
- key: readability-redundant-string-init.StringNames
value: '::std::basic_string_view;::std::basic_string'
- key: modernize-make-unique.IgnoreDefaultInitialization
value: 'true'
- key: modernize-use-emplace.ContainersWithPushBack
value: '::std::vector;::std::list;::std::deque'
- key: readability-magic-numbers.IgnoreBitFieldsWidths
value: 'true'
- key: modernize-make-unique.IncludeStyle
value: llvm
- key: modernize-use-override.OverrideSpelling
value: override
- key: readability-suspicious-call-argument.LevenshteinDissimilarBelow
value: '50'
- key: bugprone-argument-comment.CommentStringLiterals
value: '0'
- key: concurrency-mt-unsafe.FunctionSet
value: any
- key: readability-identifier-length.IgnoredExceptionVariableNames
value: '^[e]$'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: bugprone-reserved-identifier.AllowedIdentifiers
value: ''
- key: cppcoreguidelines-pro-type-member-init.IgnoreArrays
value: 'false'
- key: readability-else-after-return.WarnOnUnfixable
value: 'true'
- key: cppcoreguidelines-avoid-magic-numbers.IgnoredFloatingPointValues
value: '1.0;100.0;'
- key: modernize-use-emplace.IgnoreImplicitConstructors
value: 'false'
- key: cppcoreguidelines-macro-usage.IgnoreCommandLineMacros
value: 'true'
- key: readability-suspicious-call-argument.Substring
value: 'true'
- key: modernize-use-equals-delete.IgnoreMacros
value: 'true'
- key: readability-identifier-length.IgnoredVariableNames
value: ''
- key: readability-magic-numbers.IgnoreAllFloatingPointValues
value: 'false'
- key: cppcoreguidelines-pro-bounds-constant-array-index.IncludeStyle
value: llvm
- key: readability-suspicious-call-argument.Abbreviations
value: 'arr=array;cnt=count;idx=index;src=source;stmt=statement;cpy=copy;dest=destination;dist=distancedst=distance;ptr=pointer;wdth=width;str=string;ln=line;srv=server;attr=attribute;ref=reference;buf=buffer;col=column;nr=number;vec=vector;len=length;elem=element;val=value;i=index;var=variable;hght=height;cl=client;num=number;pos=position;lst=list;addr=address'
- key: bugprone-misplaced-widening-cast.CheckImplicitCasts
value: 'false'
- key: readability-uppercase-literal-suffix.NewSuffixes
value: ''
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: performance-unnecessary-value-param.AllowedTypes
value: ''
- key: readability-uniqueptr-delete-release.PreferResetCall
value: 'false'
- key: readability-identifier-length.MinimumExceptionNameLength
value: '2'
- key: cppcoreguidelines-avoid-magic-numbers.IgnorePowersOf2IntegerValues
value: 'false'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: cppcoreguidelines-avoid-magic-numbers.IgnoreBitFieldsWidths
value: 'true'
- key: cppcoreguidelines-avoid-magic-numbers.IgnoredIntegerValues
value: '1;2;3;4;'
- key: cppcoreguidelines-no-malloc.Allocations
value: '::malloc;::calloc'
- key: bugprone-narrowing-conversions.IgnoreConversionFromTypes
value: ''
- key: readability-function-size.BranchThreshold
value: '4294967295'
- key: bugprone-suspicious-missing-comma.RatioThreshold
value: '0.200000'
- key: readability-implicit-bool-conversion.AllowIntegerConditions
value: 'false'
- key: readability-identifier-length.IgnoredParameterNames
value: '^[n]$'
- key: readability-function-size.StatementThreshold
value: '800'
- key: readability-identifier-naming.IgnoreMainLikeFunctions
value: 'false'
- key: cppcoreguidelines-init-variables.MathHeader
value: '<math.h>'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: bugprone-reserved-identifier.AggressiveDependentMemberLookup
value: 'false'
- key: readability-suspicious-call-argument.DiceSimilarAbove
value: '70'
- key: modernize-use-equals-default.IgnoreMacros
value: 'true'
- key: readability-suspicious-call-argument.Abbreviation
value: 'true'
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: 'false'
- key: readability-identifier-length.MinimumLoopCounterNameLength
value: '2'
- key: modernize-use-emplace.SmartPointers
value: '::std::shared_ptr;::std::unique_ptr;::std::auto_ptr;::std::weak_ptr'
- key: cppcoreguidelines-no-malloc.Deallocations
value: '::free'
- key: bugprone-dangling-handle.HandleClasses
value: 'std::basic_string_view;std::experimental::basic_string_view'
- key: readability-magic-numbers.IgnorePowersOf2IntegerValues
value: 'false'
- key: readability-suspicious-call-argument.JaroWinklerSimilarAbove
value: '85'
- key: readability-simplify-subscript-expr.Types
value: '::std::basic_string;::std::basic_string_view;::std::vector;::std::array'
- key: performance-unnecessary-copy-initialization.ExcludedContainerTypes
value: ''
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: 'true'
- key: readability-static-accessed-through-instance.NameSpecifierNestingThreshold
value: '3'
- key: readability-function-size.VariableThreshold
value: '4294967295'
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: bugprone-narrowing-conversions.WarnOnFloatingPointNarrowingConversion
value: 'true'
- key: readability-identifier-naming.GetConfigPerFile
value: 'true'
- key: modernize-use-default-member-init.UseAssignment
value: 'false'
- key: readability-function-size.NestingThreshold
value: '4294967295'
- key: modernize-use-override.AllowOverrideAndFinal
value: 'false'
- key: cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes
value: ''
- key: readability-function-size.ParameterThreshold
value: '4294967295'
- key: modernize-pass-by-value.ValuesOnly
value: 'false'
- key: readability-function-cognitive-complexity.IgnoreMacros
value: 'false'
- key: modernize-loop-convert.IncludeStyle
value: llvm
- key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons
value: 'false'
- key: bugprone-narrowing-conversions.WarnWithinTemplateInstantiation
value: 'false'
- key: cert-err33-c.CheckedFunctions
value: '::aligned_alloc;::asctime_s;::at_quick_exit;::atexit;::bsearch;::bsearch_s;::btowc;::c16rtomb;::c32rtomb;::calloc;::clock;::cnd_broadcast;::cnd_init;::cnd_signal;::cnd_timedwait;::cnd_wait;::ctime_s;::fclose;::fflush;::fgetc;::fgetpos;::fgets;::fgetwc;::fopen;::fopen_s;::fprintf;::fprintf_s;::fputc;::fputs;::fputwc;::fputws;::fread;::freopen;::freopen_s;::fscanf;::fscanf_s;::fseek;::fsetpos;::ftell;::fwprintf;::fwprintf_s;::fwrite;::fwscanf;::fwscanf_s;::getc;::getchar;::getenv;::getenv_s;::gets_s;::getwc;::getwchar;::gmtime;::gmtime_s;::localtime;::localtime_s;::malloc;::mbrtoc16;::mbrtoc32;::mbsrtowcs;::mbsrtowcs_s;::mbstowcs;::mbstowcs_s;::memchr;::mktime;::mtx_init;::mtx_lock;::mtx_timedlock;::mtx_trylock;::mtx_unlock;::printf_s;::putc;::putwc;::raise;::realloc;::remove;::rename;::scanf;::scanf_s;::setlocale;::setvbuf;::signal;::snprintf;::snprintf_s;::sprintf;::sprintf_s;::sscanf;::sscanf_s;::strchr;::strerror_s;::strftime;::strpbrk;::strrchr;::strstr;::strtod;::strtof;::strtoimax;::strtok;::strtok_s;::strtol;::strtold;::strtoll;::strtoul;::strtoull;::strtoumax;::strxfrm;::swprintf;::swprintf_s;::swscanf;::swscanf_s;::thrd_create;::thrd_detach;::thrd_join;::thrd_sleep;::time;::timespec_get;::tmpfile;::tmpfile_s;::tmpnam;::tmpnam_s;::tss_create;::tss_get;::tss_set;::ungetc;::ungetwc;::vfprintf;::vfprintf_s;::vfscanf;::vfscanf_s;::vfwprintf;::vfwprintf_s;::vfwscanf;::vfwscanf_s;::vprintf_s;::vscanf;::vscanf_s;::vsnprintf;::vsnprintf_s;::vsprintf;::vsprintf_s;::vsscanf;::vsscanf_s;::vswprintf;::vswprintf_s;::vswscanf;::vswscanf_s;::vwprintf_s;::vwscanf;::vwscanf_s;::wcrtomb;::wcschr;::wcsftime;::wcspbrk;::wcsrchr;::wcsrtombs;::wcsrtombs_s;::wcsstr;::wcstod;::wcstof;::wcstoimax;::wcstok;::wcstok_s;::wcstol;::wcstold;::wcstoll;::wcstombs;::wcstombs_s;::wcstoul;::wcstoull;::wcstoumax;::wcsxfrm;::wctob;::wctrans;::wctype;::wmemchr;::wprintf_s;::wscanf;::wscanf_s;'
- key: bugprone-suspicious-string-compare.WarnOnLogicalNotComparison
value: 'false'
- key: readability-redundant-smartptr-get.IgnoreMacros
value: 'true'
- key: cppcoreguidelines-explicit-virtual-functions.AllowOverrideAndFinal
value: 'false'
- key: readability-identifier-naming.AggressiveDependentMemberLookup
value: 'false'
- key: readability-identifier-length.MinimumParameterNameLength
value: '2'
- key: modernize-use-emplace.TupleTypes
value: '::std::pair;::std::tuple'
- key: modernize-use-emplace.TupleMakeFunctions
value: '::std::make_pair;::std::make_tuple'
- key: bugprone-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion
value: 'true'
- key: cppcoreguidelines-owning-memory.LegacyResourceProducers
value: '::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile'
- key: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether
value: 'true'
- key: bugprone-argument-comment.StrictMode
value: '0'
- key: modernize-replace-random-shuffle.IncludeStyle
value: llvm
- key: modernize-use-bool-literals.IgnoreMacros
value: 'true'
- key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField
value: 'true'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: bugprone-suspicious-string-compare.StringCompareLikeFunctions
value: ''
- key: modernize-avoid-bind.PermissiveParameterList
value: 'false'
- key: bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityTreshold
value: '1'
- key: readability-suspicious-call-argument.Suffix
value: 'true'
- key: readability-suspicious-call-argument.JaroWinklerDissimilarBelow
value: '75'
- key: modernize-use-noexcept.ReplacementString
value: ''
- key: modernize-use-override.FinalSpelling
value: final
- key: modernize-use-using.IgnoreMacros
value: 'true'
- key: cppcoreguidelines-explicit-virtual-functions.FinalSpelling
value: final
- key: readability-suspicious-call-argument.MinimumIdentifierNameLength
value: '3'
- key: bugprone-narrowing-conversions.WarnOnIntegerNarrowingConversion
value: 'true'
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: cppcoreguidelines-pro-type-member-init.UseAssignment
value: 'false'
- key: bugprone-suspicious-include.HeaderFileExtensions
value: ';h;hh;hpp;hxx'
- key: performance-no-automatic-move.AllowedTypes
value: ''
- key: readability-suspicious-call-argument.SubstringDissimilarBelow
value: '40'
- key: bugprone-argument-comment.CommentIntegerLiterals
value: '0'
- key: bugprone-stringview-nullptr.IncludeStyle
value: llvm
- key: performance-for-range-copy.WarnOnAllAutoCopies
value: 'false'
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: bugprone-argument-comment.CommentFloatLiterals
value: '0'
- key: bugprone-too-small-loop-variable.MagnitudeBitsUpperLimit
value: '16'
- key: readability-simplify-boolean-expr.ChainedConditionalReturn
value: 'false'
- key: readability-else-after-return.WarnOnConditionVariables
value: 'true'
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
- key: readability-suspicious-call-argument.SuffixDissimilarBelow
value: '25'
- key: bugprone-argument-comment.CommentCharacterLiterals
value: '0'
- key: cppcoreguidelines-macro-usage.AllowedRegexp
value: '^DEBUG_*'
- key: readability-suspicious-call-argument.LevenshteinSimilarAbove
value: '66'
- key: cppcoreguidelines-narrowing-conversions.PedanticMode
value: 'false'
- key: modernize-make-shared.IgnoreDefaultInitialization
value: 'true'
- key: readability-suspicious-call-argument.JaroWinkler
value: 'true'
- key: bugprone-implicit-widening-of-multiplication-result.UseCXXHeadersInCppSources
value: 'true'
- key: modernize-make-shared.IncludeStyle
value: llvm
- key: readability-suspicious-call-argument.Prefix
value: 'true'
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions
value: 'false'
- key: bugprone-implicit-widening-of-multiplication-result.UseCXXStaticCastsInCppSources
value: 'true'
- key: bugprone-signed-char-misuse.CharTypdefsToIgnore
value: ''
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: 'false'
- key: modernize-make-unique.IgnoreMacros
value: 'true'
- key: performance-for-range-copy.AllowedTypes
value: ''
- key: bugprone-argument-comment.CommentBoolLiterals
value: '0'
- key: readability-braces-around-statements.ShortStatementLines
value: '0'
- key: bugprone-argument-comment.CommentUserDefinedLiterals
value: '0'
- key: readability-magic-numbers.IgnoredFloatingPointValues
value: '1.0;100.0;'
- key: performance-inefficient-string-concatenation.StrictMode
value: 'false'
- key: readability-redundant-declaration.IgnoreMacros
value: 'true'
- key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes
value: 'bool;Bool;_Bool;it;It;iterator;Iterator;inputit;InputIt;forwardit;ForwardIt;bidirit;BidirIt;constiterator;const_iterator;Const_Iterator;Constiterator;ConstIterator;RandomIt;randomit;random_iterator;ReverseIt;reverse_iterator;reverse_const_iterator;ConstReverseIterator;Const_Reverse_Iterator;const_reverse_iterator;Constreverseiterator;constreverseiterator'
- key: modernize-make-unique.MakeSmartPtrFunction
value: 'std::make_unique'
- key: portability-restrict-system-includes.Includes
value: '*'
- key: readability-implicit-bool-conversion.AllowPointerConditions
value: 'true'
- key: modernize-make-unique.MakeSmartPtrFunctionHeader
value: '<memory>'
- key: bugprone-signal-handler.AsyncSafeFunctionSet
value: POSIX
- key: bugprone-easily-swappable-parameters.ModelImplicitConversions
value: 'true'
- key: readability-suspicious-call-argument.SubstringSimilarAbove
value: '50'
- key: cppcoreguidelines-narrowing-conversions.WarnWithinTemplateInstantiation
value: 'false'
- key: readability-identifier-length.MinimumVariableNameLength
value: '2'
- key: cppcoreguidelines-narrowing-conversions.WarnOnEquivalentBitWidth
value: 'true'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnorePublicMemberVariables
value: 'false'
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted
value: 'false'
- key: modernize-use-noexcept.UseNoexceptFalse
value: 'true'
- key: readability-function-cognitive-complexity.Threshold
value: '25'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: 'true'
- key: bugprone-argument-comment.IgnoreSingleArgument
value: '0'
- key: bugprone-narrowing-conversions.WarnOnEquivalentBitWidth
value: 'true'
- key: bugprone-sizeof-expression.WarnOnSizeOfIntegerExpression
value: 'false'
- key: performance-faster-string-find.StringLikeClasses
value: '::std::basic_string;::std::basic_string_view'
- key: cppcoreguidelines-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion
value: 'true'
- key: bugprone-assert-side-effect.CheckFunctionCalls
value: 'false'
- key: bugprone-string-constructor.StringNames
value: '::std::basic_string;::std::basic_string_view'
- key: bugprone-assert-side-effect.AssertMacros
value: assert,NSAssert,NSCAssert
- key: bugprone-exception-escape.IgnoredExceptions
value: ''
- key: bugprone-signed-char-misuse.DiagnoseSignedUnsignedCharComparisons
value: 'true'
- key: modernize-use-default-member-init.IgnoreMacros
value: 'true'
- key: llvm-qualified-auto.AddConstToQualified
value: 'false'
- key: llvm-else-after-return.WarnOnConditionVariables
value: 'false'
- key: bugprone-sizeof-expression.WarnOnSizeOfCompareToConstant
value: 'true'
- key: modernize-raw-string-literal.DelimiterStem
value: lit
- key: readability-suspicious-call-argument.Dice
value: 'true'
- key: readability-identifier-length.IgnoredLoopCounterNames
value: '^[ijk_]$'
- key: modernize-raw-string-literal.ReplaceShorterLiterals
value: 'false'
- key: readability-magic-numbers.IgnoredIntegerValues
value: '1;2;3;4;'
- key: performance-inefficient-vector-operation.VectorLikeClasses
value: '::std::vector'
- key: modernize-use-auto.RemoveStars
value: 'false'
- key: bugprone-implicit-widening-of-multiplication-result.IncludeStyle
value: llvm
- key: portability-simd-intrinsics.Std
value: ''
- key: performance-unnecessary-value-param.IncludeStyle
value: llvm
- key: readability-redundant-member-init.IgnoreBaseInCopyConstructors
value: 'false'
- key: modernize-replace-disallow-copy-and-assign-macro.MacroName
value: DISALLOW_COPY_AND_ASSIGN
- key: llvm-else-after-return.WarnOnUnfixable
value: 'false'
...
+1 -1
View File
@@ -9,6 +9,6 @@ Thank you for creating a pull request to contribute to FreeCAD! To ease integrat
- [ ] Commit messages include `issue #<id>` or `fixes #<id>` where `<id>` is the issue ID number from our [Issues database](https://github.com/FreeCAD/FreeCAD/issues) in case a particular commit solves or is related to an existing issue. Ex: `Draft: fix typos - fixes #4805`
And please remember to update the Wiki with the features added or changed once this PR is merged.
**Note**: If you don't have wiki access, then please mention your contribution on the [0.20 Changelog Forum Thread](https://forum.freecadweb.org/viewtopic.php?f=10&t=56135).
**Note**: If you don't have wiki access, then please mention your contribution on the [1.0 Changelog Forum Thread](https://forum.freecad.org/viewtopic.php?f=10&t=69438).
---
+4
View File
@@ -33,6 +33,7 @@ hist
indicies
inout
ist
itsel
lod
mantatory
mata
@@ -43,6 +44,7 @@ nin
normale
normaly
numer
oce
ontop
ot
parm
@@ -54,6 +56,7 @@ recurrance
rougly
seh
serie
siz
som
strack
substraction
@@ -62,6 +65,7 @@ te
thist
tread
ue
upto
uptodate
usind
vas
+15
View File
@@ -0,0 +1,15 @@
{
"problemMatcher": [
{
"owner": "black-warning",
"severity": "warning",
"pattern": [
{
"regexp": "^(would reformat (.*))$",
"file": 2,
"message": 1
}
]
}
]
}
+17
View File
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "clang",
"pattern": [
{
"regexp": "^(.+):([0-9]+):([0-9]+): (error|warning|note): (.+)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
]
}
]
}
+16
View File
@@ -0,0 +1,16 @@
{
"problemMatcher": [
{
"owner": "codespell-matcher",
"severity": "warning",
"pattern": [
{
"regexp": "^(.+):(\\d+):\\s+(.+)$",
"file": 1,
"line": 2,
"message": 3
}
]
}
]
}
+16
View File
@@ -0,0 +1,16 @@
{
"problemMatcher": [
{
"owner": "cpplint",
"severity": "warning",
"pattern": [
{
"regexp": "^(.+):([0-9]+): (.+)$",
"file": 1,
"line": 2,
"message": 3
}
]
}
]
}
@@ -0,0 +1,16 @@
{
"problemMatcher": [
{
"owner": "grepMatcher-warning",
"severity": "warning",
"pattern": [
{
"regexp": "^(.+):([0-9]+):(.+)$",
"file": 1,
"line": 2,
"message": 3
}
]
}
]
}
+18
View File
@@ -0,0 +1,18 @@
{
"problemMatcher": [
{
"owner": "pylint-error",
"severity": "error",
"pattern": [
{
"regexp": "^(.+?):([0-9]+):([0-9]+): ([([E|F][0-9]+): (.*)$",
"file": 1,
"line": 2,
"column": 3,
"code": 4,
"message": 5
}
]
}
]
}
+18
View File
@@ -0,0 +1,18 @@
{
"problemMatcher": [
{
"owner": "pylint-warning",
"severity": "warning",
"pattern": [
{
"regexp": "^(.+?):([0-9]+):([0-9]+): ([^E|F][0-9]+): (.*)$",
"file": 1,
"line": 2,
"column": 3,
"code": 4,
"message": 5
}
]
}
]
}
File diff suppressed because it is too large Load Diff
+5 -4
View File
@@ -1,5 +1,9 @@
# file types to ignore
.*
!/.gitignore
!/.clang-format
!/.git-blame-ignore-revs
!/.gitattributes
*.DS_Store
*.pyc
*.obj
@@ -34,10 +38,7 @@ install_manifest.txt
/src/Tools/offlinedoc/localwiki/
/src/Tools/offlinedoc/*.txt
OpenSCAD_rc.py
/\.idea/
.tags
tags
/\.vscode/
# crowdin file
src/Tools/freecad.zip
+614
View File
@@ -0,0 +1,614 @@
[MAIN]
# Analyse import fallback blocks. This can be used to support both Python 2 and
# 3 compatible code, which means that the block might have code that exists
# only in one or another interpreter, leading to false positives when analysed.
analyse-fallback-blocks=no
# Load and enable all available extensions. Use --list-extensions to see a list
# all available extensions.
#enable-all-extensions=
# In error mode, messages with a category besides ERROR or FATAL are
# suppressed, and no reports are done by default. Error mode is compatible with
# disabling specific errors.
#errors-only=
# Always return a 0 (non-error) status code, even if lint errors are found.
# This is primarily useful in continuous integration scripts.
#exit-zero=
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-allow-list=
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code. (This is an alternative name to extension-pkg-allow-list
# for backward compatibility.)
extension-pkg-whitelist=
# Return non-zero exit code if any of these messages/categories are detected,
# even if score is above --fail-under value. Syntax same as enable. Messages
# specified are enabled, while categories only check already-enabled messages.
fail-on=
# Specify a score threshold to be exceeded before program exits with error.
fail-under=10
# Interpret the stdin as a python script, whose filename needs to be passed as
# the module_or_package argument.
#from-stdin=
# Files or directories to be skipped. They should be base names, not paths.
ignore=CVS
# Add files or directories matching the regex patterns to the ignore-list. The
# regex matches against paths and can be in Posix or Windows format.
ignore-paths=
# Files or directories matching the regex patterns are skipped. The regex
# matches against base names, not paths. The default value ignores Emacs file
# locks
ignore-patterns=^\.#
# List of module names for which member attributes should not be checked
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis). It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=
# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
# number of processors available to use, and will cap the count on Windows to
# avoid hangs.
jobs=1
# Control the amount of potential inferred values when inferring a single
# object. This can help the performance when dealing with large functions or
# complex, nested conditions.
limit-inference-results=100
# List of plugins (as comma separated values of python module names) to load,
# usually to register additional checkers.
load-plugins=
# Pickle collected data for later comparisons.
persistent=yes
# Minimum Python version to use for version dependent checks. Will default to
# the version used to run pylint.
py-version=3.10
# Discover python modules and packages in the file system subtree.
recursive=no
# When enabled, pylint would attempt to guess common misconfiguration and emit
# user-friendly hints instead of false-positive error messages.
suggestion-mode=yes
# Allow loading of arbitrary C extensions. Extensions are imported into the
# active Python interpreter and may run arbitrary code.
unsafe-load-any-extension=no
# In verbose mode, extra non-checker-related info will be displayed.
#verbose=
[REPORTS]
# Python expression which should return a score less than or equal to 10. You
# have access to the variables 'fatal', 'error', 'warning', 'refactor',
# 'convention', and 'info' which contain the number of messages in each
# category, as well as 'statement' which is the total number of statements
# analyzed. This score is used by the global evaluation report (RP0004).
evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10))
# Template used to display messages. This is a python new-style format string
# used to format the message information. See doc for all details.
msg-template=
# Set the output format. Available formats are text, parseable, colorized, json
# and msvs (visual studio). You can also give a reporter class, e.g.
# mypackage.mymodule.MyReporterClass.
#output-format=
# Tells whether to display a full report or only the messages.
reports=yes
# Activate the evaluation score.
score=yes
[MESSAGES CONTROL]
# Only show warnings with the listed confidence levels. Leave empty to show
# all. Valid levels: HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE,
# UNDEFINED.
confidence=HIGH,
CONTROL_FLOW,
INFERENCE,
INFERENCE_FAILURE,
UNDEFINED
# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifiers separated by comma (,) or put this
# option multiple times (only on the command line, not in the configuration
# file where it should appear only once). You can also use "--disable=all" to
# disable everything first and then re-enable specific checks. For example, if
# you want to run only the similarities checker, you can use "--disable=all
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable=raw-checker-failed,
bad-inline-option,
locally-disabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
invalid-name,
wrong-import-order,
import-error,
undefined-variable
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once). See also the "--disable" option for examples.
enable=c-extension-no-member
[BASIC]
# Naming style matching correct argument names.
argument-naming-style=snake_case
# Regular expression matching correct argument names. Overrides argument-
# naming-style. If left empty, argument names will be checked with the set
# naming style.
#argument-rgx=
# Naming style matching correct attribute names.
attr-naming-style=snake_case
# Regular expression matching correct attribute names. Overrides attr-naming-
# style. If left empty, attribute names will be checked with the set naming
# style.
#attr-rgx=
# Bad variable names which should always be refused, separated by a comma.
bad-names=foo,
bar,
baz,
toto,
tutu,
tata
# Bad variable names regexes, separated by a comma. If names match any regex,
# they will always be refused
bad-names-rgxs=
# Naming style matching correct class attribute names.
class-attribute-naming-style=any
# Regular expression matching correct class attribute names. Overrides class-
# attribute-naming-style. If left empty, class attribute names will be checked
# with the set naming style.
#class-attribute-rgx=
# Naming style matching correct class constant names.
class-const-naming-style=UPPER_CASE
# Regular expression matching correct class constant names. Overrides class-
# const-naming-style. If left empty, class constant names will be checked with
# the set naming style.
#class-const-rgx=
# Naming style matching correct class names.
class-naming-style=PascalCase
# Regular expression matching correct class names. Overrides class-naming-
# style. If left empty, class names will be checked with the set naming style.
#class-rgx=
# Naming style matching correct constant names.
const-naming-style=UPPER_CASE
# Regular expression matching correct constant names. Overrides const-naming-
# style. If left empty, constant names will be checked with the set naming
# style.
#const-rgx=
# Minimum line length for functions/classes that require docstrings, shorter
# ones are exempt.
docstring-min-length=-1
# Naming style matching correct function names.
function-naming-style=snake_case
# Regular expression matching correct function names. Overrides function-
# naming-style. If left empty, function names will be checked with the set
# naming style.
#function-rgx=
# Good variable names which should always be accepted, separated by a comma.
good-names=i,
j,
k,
ex,
Run,
_
# Good variable names regexes, separated by a comma. If names match any regex,
# they will always be accepted
good-names-rgxs=
# Include a hint for the correct naming format with invalid-name.
include-naming-hint=no
# Naming style matching correct inline iteration names.
inlinevar-naming-style=any
# Regular expression matching correct inline iteration names. Overrides
# inlinevar-naming-style. If left empty, inline iteration names will be checked
# with the set naming style.
#inlinevar-rgx=
# Naming style matching correct method names.
method-naming-style=snake_case
# Regular expression matching correct method names. Overrides method-naming-
# style. If left empty, method names will be checked with the set naming style.
#method-rgx=
# Naming style matching correct module names.
module-naming-style=snake_case
# Regular expression matching correct module names. Overrides module-naming-
# style. If left empty, module names will be checked with the set naming style.
#module-rgx=
# Colon-delimited sets of names that determine each other's naming style when
# the name regexes allow several styles.
name-group=
# Regular expression which should only match function or class names that do
# not require a docstring.
no-docstring-rgx=^_
# List of decorators that produce properties, such as abc.abstractproperty. Add
# to this list to register other decorators that produce valid properties.
# These decorators are taken in consideration only for invalid-name.
property-classes=abc.abstractproperty
# Regular expression matching correct type variable names. If left empty, type
# variable names will be checked with the set naming style.
#typevar-rgx=
# Naming style matching correct variable names.
variable-naming-style=snake_case
# Regular expression matching correct variable names. Overrides variable-
# naming-style. If left empty, variable names will be checked with the set
# naming style.
#variable-rgx=
[CLASSES]
# Warn about protected attribute access inside special methods
check-protected-access-in-special-methods=no
# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,
__new__,
setUp,
__post_init__
# List of member names, which should be excluded from the protected access
# warning.
exclude-protected=_asdict,
_fields,
_replace,
_source,
_make
# List of valid names for the first argument in a class method.
valid-classmethod-first-arg=cls
# List of valid names for the first argument in a metaclass class method.
valid-metaclass-classmethod-first-arg=cls
[REFACTORING]
# Maximum number of nested blocks for function / method body
max-nested-blocks=5
# Complete name of functions that never returns. When checking for
# inconsistent-return-statements if a never returning function is called then
# it will be considered as an explicit return statement and no message will be
# printed.
never-returning-functions=sys.exit,argparse.parse_error
[DESIGN]
# List of regular expressions of class ancestor names to ignore when counting
# public methods (see R0903)
exclude-too-few-public-methods=
# List of qualified class names to ignore when counting class parents (see
# R0901)
ignored-parents=
# Maximum number of arguments for function / method.
max-args=5
# Maximum number of attributes for a class (see R0902).
max-attributes=7
# Maximum number of boolean expressions in an if statement (see R0916).
max-bool-expr=5
# Maximum number of branch for function / method body.
max-branches=12
# Maximum number of locals for function / method body.
max-locals=15
# Maximum number of parents for a class (see R0901).
max-parents=7
# Maximum number of public methods for a class (see R0904).
max-public-methods=20
# Maximum number of return / yield for function / method body.
max-returns=6
# Maximum number of statements in function / method body.
max-statements=50
# Minimum number of public methods for a class (see R0903).
min-public-methods=2
[EXCEPTIONS]
# Exceptions that will emit a warning when caught.
overgeneral-exceptions=BaseException,
Exception
[FORMAT]
# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
expected-line-ending-format=
# Regexp for a line that is allowed to be longer than the limit.
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
# Number of spaces of indent required inside a hanging or continued line.
indent-after-paren=4
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
# tab).
indent-string=' '
# Maximum number of characters on a single line.
max-line-length=100
# Maximum number of lines in a module.
max-module-lines=1000
# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
single-line-class-stmt=no
# Allow the body of an if to be on the same line as the test if there is no
# else.
single-line-if-stmt=no
[IMPORTS]
# List of modules that can be imported at any level, not just the top level
# one.
allow-any-import-level=
# Allow wildcard imports from modules that define __all__.
allow-wildcard-with-all=no
# Deprecated modules which should not be used, separated by a comma.
deprecated-modules=
# Output a graph (.gv or any supported image format) of external dependencies
# to the given file (report RP0402 must not be disabled).
ext-import-graph=
# Output a graph (.gv or any supported image format) of all (i.e. internal and
# external) dependencies to the given file (report RP0402 must not be
# disabled).
import-graph=
# Output a graph (.gv or any supported image format) of internal dependencies
# to the given file (report RP0402 must not be disabled).
int-import-graph=
# Force import order to recognize a module as part of the standard
# compatibility libraries.
known-standard-library=
# Force import order to recognize a module as part of a third party library.
known-third-party=enchant
# Couples of modules and preferred modules, separated by a comma.
preferred-modules=
[LOGGING]
# The type of string formatting that logging methods do. `old` means using %
# formatting, `new` is for `{}` formatting.
logging-format-style=old
# Logging modules to check that the string format arguments are in logging
# function parameter format.
logging-modules=logging
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
notes=FIXME,
XXX,
TODO
# Regular expression of note tags to take in consideration.
notes-rgx=
[SIMILARITIES]
# Comments are removed from the similarity computation
ignore-comments=yes
# Docstrings are removed from the similarity computation
ignore-docstrings=yes
# Imports are removed from the similarity computation
ignore-imports=yes
# Signatures are removed from the similarity computation
ignore-signatures=yes
# Minimum lines number of a similarity.
min-similarity-lines=4
[SPELLING]
# Limits count of emitted suggestions for spelling mistakes.
max-spelling-suggestions=4
# Spelling dictionary name. Available dictionaries: none. To make it work,
# install the 'python-enchant' package.
spelling-dict=
# List of comma separated words that should be considered directives if they
# appear at the beginning of a comment and should not be checked.
spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy:
# List of comma separated words that should not be checked.
spelling-ignore-words=
# A path to a file that contains the private dictionary; one word per line.
spelling-private-dict-file=
# Tells whether to store unknown words to the private dictionary (see the
# --spelling-private-dict-file option) instead of raising a message.
spelling-store-unknown-words=no
[STRING]
# This flag controls whether inconsistent-quotes generates a warning when the
# character used as a quote delimiter is used inconsistently within a module.
check-quote-consistency=no
# This flag controls whether the implicit-str-concat should generate a warning
# on implicit string concatenation in sequences defined over several lines.
check-str-concat-over-line-jumps=no
[TYPECHECK]
# List of decorators that produce context managers, such as
# contextlib.contextmanager. Add to this list to register other decorators that
# produce valid context managers.
contextmanager-decorators=contextlib.contextmanager
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
# expressions are accepted.
generated-members=
# Tells whether to warn about missing members when the owner of the attribute
# is inferred to be None.
ignore-none=yes
# This flag controls whether pylint should warn about no-member and similar
# checks whenever an opaque object is returned when inferring. The inference
# can return multiple potential results while evaluating a Python object, but
# some branches might not be evaluated, which results in partial inference. In
# that case, it might be useful to still emit no-member and other checks for
# the rest of the inferred objects.
ignore-on-opaque-inference=yes
# List of symbolic message names to ignore for Mixin members.
ignored-checks-for-mixins=no-member,
not-async-context-manager,
not-context-manager,
attribute-defined-outside-init
# List of class names for which member attributes should not be checked (useful
# for classes with dynamically set attributes). This supports the use of
# qualified names.
ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace
# Show a hint with possible names when a member name was not found. The aspect
# of finding the hint is based on edit distance.
missing-member-hint=yes
# The minimum edit distance a name should have in order to be considered a
# similar match for a missing member name.
missing-member-hint-distance=1
# The total number of similar names that should be taken in consideration when
# showing a hint for a missing member.
missing-member-max-choices=1
# Regex pattern to define which classes are considered mixins.
mixin-class-rgx=.*[Mm]ixin
# List of decorators that change the signature of a decorated function.
signature-mutators=
[VARIABLES]
# List of additional names supposed to be defined in builtins. Remember that
# you should avoid defining new builtins when possible.
additional-builtins=
# Tells whether unused global variables should be treated as a violation.
allow-global-unused-variables=yes
# List of names allowed to shadow builtins
allowed-redefined-builtins=
# List of strings which can identify a callback function by name. A callback
# name must start or end with one of those strings.
callbacks=cb_,
_cb
# A regular expression matching the name of dummy variables (i.e. expected to
# not be used).
dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_
# Argument names that match this expression will be ignored. Default to name
# with leading underscore.
ignored-argument-names=_.*|^ignored_|^unused_
# Tells whether we should check for unused import in __init__ files.
init-import=no
# List of qualified module names which can have objects that can redefine
# builtins.
redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io
+2 -1
View File
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
# relates to FindOpenGL module
# and cache variables OPENGL_gl_LIBRARY, OPENGL_glu_LIBRARY
if (POLICY CMP0072)
cmake_policy(SET CMP0072 OLD)
set(OpenGL_GL_PREFERENCE LEGACY)
endif(POLICY CMP0072)
find_program(CCACHE_PROGRAM ccache) #This check should occur before project()
@@ -20,6 +20,7 @@ set(PACKAGE_VERSION_MAJOR "0")
set(PACKAGE_VERSION_MINOR "21")
set(PACKAGE_VERSION_PATCH "0")
set(PACKAGE_VERSION_SUFFIX "dev") # either "dev" for development snapshot or "" (empty string)
set(FREECAD_VERSION_PATCH "0") # number of patch release (e.g. "4" for the 0.18.4 release)
set(FREECAD_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}")
Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

+47 -2
View File
@@ -1,7 +1,50 @@
![Logo](https://www.freecadweb.org/images/logo.png)
<h6 align="center"><img src="FreeCAD-toponaming-logo.png"/></h6>
### Your own 3D parametric modeler
<h1 align="center">FreeCAD Topological Naming (toponaming) Branch</h1>
### About
This branch is dedicated to integrating code that improves the [topological naming problem](https://wiki.freecad.org/Topological_naming_problem) in FreeCAD. There have been several attempts to address it over the years within FreeCAD. In reality, toponaming is an issue that no modern CAD software is fully immune to. This is because the solutions are complex.
Thanks to an independent developer named Zheng Lei ('realthunder'), who has gone the farthest in the effort of fixing toponaming in FreeCAD, and has provided a proof of concept fix in his own branch named 'Link' branch.
* [@Realthunder](https://github.com/realthunder)'s Link branch: https://github.com/realthunder/FreeCAD
* Official FreeCAD main ('master') branch: https://github.com/FreeCAD/FreeCAD/
* Official FreeCAD toponaming git repository: https://github.com/FreeCAD/FreeCAD/tree/development/toponaming
### Objective
Per the FreeCAD developer meetings that occurred during the pre-release of v0.20, 'toponaming' was identified as one of the main targets for merge in the v0.21/v1.0 release cycle.
### Contributing
During this development cycle there will be nightly builds provided for testers to test and report results back to the developers.
<details>
<summary>Expand this section to learn about testing toponaming on different platforms/distros</summary>
#### Linux
##### Snap packages
A nightly Snap package of the 'toponaming' branch will be available to testers. Refer to the [Snap wiki page](https://wiki.freecad.org/Ubuntu_Snap#Notes)
#### Windows
TBD
#### macOS
TBD
#### FreeBSD
N/A
</details>
<!--
[Website](https://www.freecadweb.org) •
[Documentation](https://wiki.freecadweb.org) •
[Forum](https://forum.freecadweb.org/) •
@@ -126,3 +169,5 @@ learning to use FreeCAD.
<img src="https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/SVG/DO_Logo_horizontal_blue.svg" width="91px">
</a> and <a href="https://www.kipro-pcb.com/">KiCad Services Corp.</a>
</p>
-->
+39 -9
View File
@@ -5,28 +5,55 @@
# SMESH_INCLUDE_DIR - where the Salome SMESH include directory can be found
# SMESH_LIBRARIES - Link this to use Salome SMESH
#
# SMESH needs VTK
find_package(VTK REQUIRED)
# If this definition is not set, linker errors will occur against SMESH on 64 bit machines.
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_definitions(-DSALOME_USE_64BIT_IDS)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
IF (CMAKE_COMPILER_IS_GNUCC)
FIND_PATH(SMESH_INCLUDE_DIR SMESH_Mesh.hxx
# These are default search paths, why specify them?
# /usr/include
# /usr/local/include
PATH_SUFFIXES smesh
)
FIND_LIBRARY(SMESH_LIBRARY SMESH
# /usr/lib
# /usr/local/lib
PATH_SUFFIXES smesh SMESH smesh/SMESH
)
FIND_LIBRARY(SMESH_LIBRARY SMESH)
ELSE (CMAKE_COMPILER_IS_GNUCC)
# Not yet implemented
ENDIF (CMAKE_COMPILER_IS_GNUCC)
IF(SMESH_INCLUDE_DIR)
SET(SMESH_INC_ROOT "${SMESH_INCLUDE_DIR}/..")
# Append extra include dirs
SET(SMESH_INCLUDE_DIR
"${SMESH_INCLUDE_DIR};
${SMESH_INC_ROOT}/Controls;
${SMESH_INC_ROOT}/Driver;
${SMESH_INC_ROOT}/DriverDAT;
${SMESH_INC_ROOT}/DriverGMF;
${SMESH_INC_ROOT}/DriverSTL;
${SMESH_INC_ROOT}/DriverUNV;
${SMESH_INC_ROOT}/Geom;
${SMESH_INC_ROOT}/Kernel;
${SMESH_INC_ROOT}/MEFISTO2;
${SMESH_INC_ROOT}/MeshVSLink;
${SMESH_INC_ROOT}/Netgen;
${SMESH_INC_ROOT}/NETGENPlugin;
${SMESH_INC_ROOT}/SMDS;
${SMESH_INC_ROOT}/SMESHDS;
${SMESH_INC_ROOT}/SMESHUtils;
${SMESH_INC_ROOT}/StdMeshers;")
ELSE(SMESH_INCLUDE_DIR)
message(FATAL_ERROR "SMESH include directories not found!")
ENDIF(SMESH_INCLUDE_DIR)
SET(SMESH_FOUND FALSE)
IF(SMESH_LIBRARY)
SET(SMESH_FOUND TRUE)
GET_FILENAME_COMPONENT(SMESH_LIBRARY_DIR ${SMESH_LIBRARY} PATH)
set(SMESH_LIBRARIES
set(SMESH_LIBRARIES
${SMESH_LIBRARY_DIR}/libDriver.so
${SMESH_LIBRARY_DIR}/libDriverDAT.so
${SMESH_LIBRARY_DIR}/libDriverSTL.so
@@ -36,5 +63,8 @@ IF(SMESH_LIBRARY)
${SMESH_LIBRARY_DIR}/libSMESHDS.so
${SMESH_LIBRARY_DIR}/libStdMeshers.so
)
set(EXTERNAL_SMESH_LIBS ${SMESH_LIBRARIES})
ELSE(SMESH_LIBRARY)
message(FATAL_ERROR "SMESH libraries NOT FOUND!")
ENDIF(SMESH_LIBRARY)
@@ -10,6 +10,7 @@ macro(InitializeFreeCADBuildOptions)
option(FREECAD_USE_EXTERNAL_KDL "Use system installed orocos-kdl instead of the bundled." OFF)
option(FREECAD_USE_FREETYPE "Builds the features using FreeType libs" ON)
option(FREECAD_BUILD_DEBIAN "Prepare for a build of a Debian package" OFF)
option(FREECAD_TOPONAMING_BRANDING "Enable branding for TopoNaming branch" ON)
option(BUILD_WITH_CONDA "Set ON if you build FreeCAD with conda" OFF)
option(BUILD_DYNAMIC_LINK_PYTHON "If OFF extension-modules do not link against python-libraries" ON)
option(INSTALL_TO_SITEPACKAGES "If ON the freecad root namespace (python) is installed into python's site-packages" OFF)
+13 -5
View File
@@ -119,13 +119,21 @@ macro(SetupSalomeSMESH)
else(NOT FREECAD_USE_EXTERNAL_SMESH)
find_package(SMESH CONFIG)
# If this definition is not set, linker errors will occur against SMESH on 64 bit machines.
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_definitions(-DSALOME_USE_64BIT_IDS)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
if(NOT SMESH_FOUND)
find_package(SMESH REQUIRED)
if(NOT SMESH_FOUND)
message(ERROR "================\n"
"SMESH not found.\n"
"================\n")
endif()
endif()
set (SMESH_INCLUDE_DIR ${SMESH_INCLUDE_PATH})
set(EXTERNAL_SMESH_LIBS ${SMESH_LIBRARIES})
if(NOT SMESH_FOUND)
message(ERROR "================\n"
"SMESH not found.\n"
"================\n")
endif()
include_directories(${SMESH_INCLUDE_DIR})
endif()
+7
View File
@@ -102,6 +102,7 @@
#include "OriginFeature.h"
#include "OriginGroupExtension.h"
#include "OriginGroupExtensionPy.h"
#include "StringHasherPy.h"
#include "Part.h"
#include "PartPy.h"
#include "Placement.h"
@@ -277,6 +278,7 @@ void Application::setupPythonTypes()
Base::Interpreter().addType(&Base::PlacementPy::Type, pAppModule, "Placement");
Base::Interpreter().addType(&Base::RotationPy::Type, pAppModule, "Rotation");
Base::Interpreter().addType(&Base::AxisPy::Type, pAppModule, "Axis");
Base::Interpreter().addType(&App::StringHasherPy::Type, pAppModule, "StringHasher");
// Note: Create an own module 'Base' which should provide the python
// binding classes from the base module. At a later stage we should
@@ -1904,6 +1906,9 @@ void Application::initTypes()
Data::ComplexGeoData ::init();
Data::Segment ::init();
App::StringID ::init();
App::StringHasher ::init();
// Properties
App ::Property ::init();
App ::PropertyContainer ::init();
@@ -2463,6 +2468,8 @@ void Application::initConfig(int argc, char ** argv)
Branding brand;
QString binDir = QString::fromUtf8((mConfig["AppHomePath"] + "bin").c_str());
QFileInfo fi(binDir, QString::fromLatin1("branding.xml"));
if (!fi.exists())
fi = QFileInfo(binDir, QString::fromLatin1("branding_toponaming.xml"));
if (fi.exists() && brand.readFile(fi.absoluteFilePath())) {
Branding::XmlConfig cfg = brand.getUserDefines();
for (Branding::XmlConfig::iterator it = cfg.begin(); it != cfg.end(); ++it) {
+1
View File
@@ -50,6 +50,7 @@ Branding::Branding()
filter.push_back("SplashAlignment");
filter.push_back("SplashTextColor");
filter.push_back("SplashInfoColor");
filter.push_back("SplashInfoVersion");
filter.push_back("StartWorkbench");
+12
View File
@@ -87,6 +87,8 @@ else()
)
endif()
generate_from_xml(StringIDPy)
generate_from_xml(StringHasherPy)
generate_from_xml(DocumentPy)
generate_from_xml(DocumentObjectPy)
generate_from_xml(ExtensionPy)
@@ -109,6 +111,8 @@ generate_from_py(FreeCADInit InitScript.h)
generate_from_py(FreeCADTest TestScript.h)
SET(FreeCADApp_XML_SRCS
StringIDPy.xml
StringHasherPy.xml
ExtensionPy.xml
ExtensionContainerPy.xml
DocumentObjectExtensionPy.xml
@@ -131,7 +135,11 @@ SOURCE_GROUP("XML" FILES ${FreeCADApp_XML_SRCS})
# The document stuff
SET(Document_CPP_SRCS
Annotation.cpp
StringHasher.cpp
StringHasherPyImp.cpp
StringIDPyImp.cpp
Document.cpp
DocumentParams.cpp
DocumentObject.cpp
Extension.cpp
ExtensionPyImp.cpp
@@ -178,7 +186,9 @@ SET(Document_CPP_SRCS
SET(Document_HPP_SRCS
Annotation.h
StringHasher.h
Document.h
DocumentParams.h
DocumentObject.h
Extension.h
ExtensionContainer.h
@@ -263,6 +273,7 @@ SET(FreeCADApp_CPP_SRCS
AutoTransaction.cpp
Branding.cpp
ColorModel.cpp
MappedElement.cpp
ComplexGeoData.cpp
ComplexGeoDataPyImp.cpp
Enumeration.cpp
@@ -279,6 +290,7 @@ SET(FreeCADApp_HPP_SRCS
AutoTransaction.h
Branding.h
ColorModel.h
MappedElement.h
ComplexGeoData.h
Enumeration.h
Material.h
+2104 -16
View File
File diff suppressed because it is too large Load Diff
+269 -2
View File
@@ -24,9 +24,17 @@
#ifndef _AppComplexGeoData_h_
#define _AppComplexGeoData_h_
#include <cstring>
#include <memory>
#include <cctype>
#include <functional>
#include <QVector>
#include <Base/Handle.h>
#include <Base/Matrix.h>
#include <Base/Persistence.h>
#include "StringHasher.h"
#ifdef __GNUC__
# include <cstdint>
@@ -44,6 +52,16 @@ typedef BoundBox3<double> BoundBox3d;
namespace Data
{
class ElementMap;
typedef std::shared_ptr<ElementMap> ElementMapPtr;
typedef QVector<App::StringIDRef> ElementIDRefs;
class IndexedName;
class MappedName;
struct MappedElement;
struct MappedChildElements;
/** Segments
* Subelement type of the ComplexGeoData type
* It is used to split an object in further sub-parts.
@@ -83,7 +101,7 @@ public:
* List of different subelement types
* its NOT a list of the subelements itself
*/
virtual std::vector<const char*> getElementTypes() const=0;
virtual const std::vector<const char*>& getElementTypes() const=0;
virtual unsigned long countSubElements(const char* Type) const=0;
/// get the subelement by type and number
virtual Segment* getSubElement(const char* Type, unsigned long) const=0;
@@ -165,8 +183,12 @@ public:
//@{
/// Special prefix to mark the beginning of a mapped sub-element name
static const std::string &elementMapPrefix();
/// Special postfix to mark the following tag
/// Special postfix to mark the following tag encoded as hex number
static const std::string &tagPostfix();
/// Special postfix to mark the following tag encoded as decimal number
static const std::string &decTagPostfix();
/// Special postfix to mark the name includes encoding from an external object
static const std::string &externalTagPostfix();
/// Special postfix to mark the index of an array element
static const std::string &indexPostfix();
/// Special prefix to mark a missing element
@@ -191,12 +213,246 @@ public:
/// Find the start of an element name in a subname
static const char *findElementName(const char *subname);
/// Check if the given subname contains element name
static bool hasElementName(const char *subname) {
subname = findElementName(subname);
return subname && *subname;
}
/// Return the element name portion of the subname without mapping prefix
static inline const char *hasMappedElementName(const char *subname) {
return isMappedElement(findElementName(subname));
}
/** Get element indexed name
*
* @param name: the input name
* @param sid: optional output of and App::StringID involved forming this mapped name
*
* @return Returns an indexed name.
*/
IndexedName getIndexedName(const MappedName & name,
ElementIDRefs *sid = nullptr) const;
/** Get element mapped name
*
* @param name: the input name
* @param allowUnmapped: If the queried element is not mapped, then return
* an empty name if \c allowUnmapped is false, or
* else, return the indexed name.
* @param sid: optional output of and App::StringID involved forming this mapped name
* @return Returns the mapped name.
*/
MappedName getMappedName(const IndexedName & element,
bool allowUnmapped = false,
ElementIDRefs *sid = nullptr) const;
/** Return a pair of indexed name and mapped name
*
* @param name: the input name.
* @param sid: optional output of and App::StringID involved forming this
* mapped name
* @param copy: if true, copy the name string, or else use it as constant
* string, and caller must make sure the memory is not freed.
*
* @return Returns the MappedElement which contains both the indexed and
* mapped name.
*
* This function guesses whether the input name is an indexed name or
* mapped, and perform a lookup and return the names found. If the input
* name contains only alphabets and underscore followed by optional digits,
* it will be treated as indexed name. Or else, it will be treated as
* mapped name.
*/
MappedElement getElementName(const char * name,
ElementIDRefs *sid = nullptr,
bool copy = false) const;
/** Get mapped element with a given prefix */
std::vector<MappedElement> getElementNamesWithPrefix(const char *prefix) const;
/** Get mapped element names
*
* @param element: original element name with \c Type + \c Index
* @param needUnmapped: if true, return the original element name if no
* mapping is found
*
* @return a list of mapped names of the give element along with their
* associated string ID references
*/
std::vector<std::pair<MappedName, ElementIDRefs> >
getElementMappedNames(const IndexedName & element, bool needUnmapped=false) const;
/** Add a sub-element name mapping.
*
* @param element: the original \c Type + \c Index element name
* @param name: the mapped sub-element name. May or may not start with
* elementMapPrefix().
* @param sid: in case you use a hasher to hash the element name, pass in
* the string id reference using this parameter. You can have more than one
* string id associated with the same name.
* @param overwrite: if true, it will overwrite existing names
*
* @return Returns the stored mapped element name.
*
* An element can have multiple mapped names. However, a name can only be
* mapped to one element
*/
MappedName setElementName(const IndexedName & element,
const MappedName & name,
const ElementIDRefs * sid = nullptr,
bool overwrite = false);
void setMappedChildElements(const std::vector<MappedChildElements> & children);
std::vector<MappedChildElements> getMappedChildElements() const;
/** Convenience method to hash the main element name
*
* @param name: main element name
* @param sid: store any output string ID references
* @return the hashed element name;
*/
MappedName hashElementName(const MappedName & name, ElementIDRefs &sid) const;
/// Hash the child element map postfixes to shorten element name from hierarchical maps
void hashChildMaps();
/// Check if there is child element map
bool hasChildElementMap() const;
/// Reverse hashElementName()
MappedName dehashElementName(const MappedName & name) const;
/// Append the Tag (if and only if it is non zero) into the element map
virtual void reTagElementMap(long tag, App::StringHasherRef hasher, const char *postfix=0) {
(void)tag;
(void)hasher;
(void)postfix;
}
long getElementHistory(const char *name,
MappedName *original=0, std::vector<MappedName> *history=0) const;
long getElementHistory(const MappedName & name,
MappedName *original=0, std::vector<MappedName> *history=0) const;
void encodeElementName(char element_type, MappedName & name, std::ostringstream &ss,
ElementIDRefs *sids, const char* postfix=0, long tag=0, bool forceTag=false) const;
char elementType(const Data::MappedName &) const;
char elementType(const Data::IndexedName &) const;
char elementType(const char *name) const;
/** Reset/swap the element map
*
* @param elementMap: optional new element map
*
* @return Returns the existing element map.
*/
virtual ElementMapPtr resetElementMap(ElementMapPtr elementMap=ElementMapPtr()) {
_ElementMap.swap(elementMap);
return elementMap;
}
/// Get the entire element map
std::vector<MappedElement> getElementMap() const;
/// Set the entire element map
void setElementMap(const std::vector<MappedElement> &elements);
/// Get the current element map size
size_t getElementMapSize(bool flush=true) const;
/// Return the higher level element names of the given element
virtual std::vector<IndexedName> getHigherElements(const char *name, bool silent=false) const;
/// Return the current element map version
virtual std::string getElementMapVersion() const;
/// Return true to signal element map version change
virtual bool checkElementMapVersion(const char * ver) const;
/// Check if the given subname only contains an element name
static bool isElementName(const char *subname) {
return subname && *subname && findElementName(subname)==subname;
}
/** Extract tag and other information from a encoded element name
*
* @param name: encoded element name
* @param tag: optional pointer to receive the extracted tag
* @param len: optional pointer to receive the length field after the tag field.
* This gives the length of the previous hashsed element name starting
* from the beginning of the give element name.
* @param postfix: optional pointer to receive the postfix starting at the found tag field.
* @param type: optional pointer to receive the element type character
* @param negative: return negative tag as it is. If disabled, then always return positive tag.
* Negative tag is sometimes used for element disambiguation.
* @param recursive: recursively find the last non-zero tag
*
* @return Return the end position of the tag field, or return -1 if not found.
*/
static int findTagInElementName(const MappedName & name,
long *tag=0,
int *len=0,
std::string *postfix=0,
char *type=0,
bool negative=false,
bool recursive=true);
/** 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;
/** 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;
/** Flush an internal buffering for element mapping */
virtual void flushElementMap() const;
virtual unsigned long getElementMapReserve() const { return 0; }
//@}
/** @name Save/restore */
//@{
void Save (Base::Writer &writer) const;
void Restore(Base::XMLReader &reader);
void SaveDocFile(Base::Writer &writer) const;
void RestoreDocFile(Base::Reader &reader);
unsigned int getMemSize (void) const;
void setPersistenceFileName(const char *name) const;
virtual void beforeSave() const;
bool isRestoreFailed() const { return _restoreFailed; }
void resetRestoreFailure() const { _restoreFailed = true; }
//@}
public:
/// String hasher for element name shortening
mutable App::StringHasherRef Hasher;
protected:
virtual MappedName renameDuplicateElement(int index,
const IndexedName & element,
const IndexedName & element2,
const MappedName & name,
ElementIDRefs &sids);
void restoreStream(std::istream &s, std::size_t count);
/// from local to outside
inline Base::Vector3d transformToOutside(const Base::Vector3f& vec) const
@@ -215,8 +471,19 @@ protected:
static_cast<float>(tmp.y),
static_cast<float>(tmp.z));
}
public:
mutable long Tag;
protected:
ElementMapPtr elementMap(bool flush=true) const;
protected:
mutable std::string _PersistenceName;
mutable bool _restoreFailed = false;
private:
ElementMapPtr _ElementMap;
};
} //namespace App
+61
View File
@@ -64,6 +64,37 @@
<UserDocu>Apply a transformation to the underlying geometry</UserDocu>
</Documentation>
</Methode>
<Methode Name="setElementName" Keyword="true">
<Documentation>
<UserDocu>
setElementName(element,name=None,postfix=None,overwrite=False,sid=None), Set an element name
element : the original element name, e.g. Edge1, Vertex2
name : the new name for the element, None to remove the mapping
postfix : postfix of the name that will not be hashed
overwrite: if true, it will overwrite exiting name
sid : to hash the name any way you want, provide your own string id(s) in this parameter
An element can have multiple mapped names. However, a name can only be mapped
to one element
</UserDocu>
</Documentation>
</Methode>
<Methode Name="getElementName" Const="true">
<Documentation>
<UserDocu>getElementName(name,direction=0) - Return a mapped element name or reverse</UserDocu>
</Documentation>
</Methode>
<Methode Name="getElementIndexedName" Const="true">
<Documentation>
<UserDocu>getElementIndexedName(name) - Return the indexed element name</UserDocu>
</Documentation>
</Methode>
<Methode Name="getElementMappedName" Const="true">
<Documentation>
<UserDocu>getElementMappedName(name) - Return the mapped element name</UserDocu>
</Documentation>
</Methode>
<Attribute Name="BoundBox" ReadOnly="true">
<Documentation>
<UserDocu>Get the BoundBox of the object</UserDocu>
@@ -88,5 +119,35 @@
</Documentation>
<Parameter Name="Tag" Type="Int"/>
</Attribute>
<Attribute Name="Hasher">
<Documentation>
<UserDocu>Get/Set the string hasher of this object</UserDocu>
</Documentation>
<Parameter Name="Hasher" Type="Object" />
</Attribute>
<Attribute Name="ElementMapSize" ReadOnly="true">
<Documentation>
<UserDocu>Get the current element map size</UserDocu>
</Documentation>
<Parameter Name="ElementMapSize" Type="Int" />
</Attribute>
<Attribute Name="ElementMap">
<Documentation>
<UserDocu>Get/Set a dict of element mapping</UserDocu>
</Documentation>
<Parameter Name="ElementMap" Type="Dict" />
</Attribute>
<Attribute Name="ElementReverseMap" ReadOnly="true">
<Documentation>
<UserDocu>Get a dict of element reverse mapping</UserDocu>
</Documentation>
<Parameter Name="ElementReverseMap" Type="Dict" />
</Attribute>
<Attribute Name="ElementMapVersion" ReadOnly="true">
<Documentation>
<UserDocu>Element map version</UserDocu>
</Documentation>
<Parameter Name="ElementMapVersion" Type="String" />
</Attribute>
</PythonExport>
</GenerateModel>
+187 -3
View File
@@ -27,6 +27,7 @@
#endif
#include "ComplexGeoData.h"
#include "MappedElement.h"
// inclusion of the generated files (generated out of ComplexGeoDataPy.xml)
#include <App/ComplexGeoDataPy.h>
@@ -36,6 +37,8 @@
#include <Base/PlacementPy.h>
#include <Base/VectorPy.h>
#include <Base/GeometryPyCXX.h>
#include <App/StringHasherPy.h>
#include <App/StringIDPy.h>
using namespace Data;
using namespace Base;
@@ -51,10 +54,9 @@ PyObject* ComplexGeoDataPy::getElementTypes(PyObject *args)
if (!PyArg_ParseTuple(args, ""))
return nullptr;
std::vector<const char*> types = getComplexGeoDataPtr()->getElementTypes();
Py::List list;
for (auto it : types) {
list.append(Py::String(it));
for (const auto &type : getComplexGeoDataPtr()->getElementTypes()) {
list.append(Py::String(type));
}
return Py::new_reference_to(list);
}
@@ -302,6 +304,183 @@ PyObject* ComplexGeoDataPy::transformGeometry(PyObject *args)
}
}
PyObject* ComplexGeoDataPy::getElementName(PyObject *args)
{
char* input;
int direction = 0;
if (!PyArg_ParseTuple(args, "s|i", &input,&direction))
return NULL;
Data::MappedElement res = getComplexGeoDataPtr()->getElementName(input);
std::string s;
if (direction == 1)
return Py::new_reference_to(Py::String(res.name.toString(s)));
else if (direction == 0)
return Py::new_reference_to(Py::String(res.index.toString(s)));
else if (Data::IndexedName(input))
return Py::new_reference_to(Py::String(res.name.toString(s)));
else
return Py::new_reference_to(Py::String(res.index.toString(s)));
}
PyObject* ComplexGeoDataPy::getElementIndexedName(PyObject *args)
{
char* input;
PyObject *returnID = Py_False;
if (!PyArg_ParseTuple(args, "s|O", &input,&returnID))
return NULL;
ElementIDRefs ids;
Data::MappedElement res = getComplexGeoDataPtr()->getElementName(
input, PyObject_IsTrue(returnID)?&ids:nullptr);
std::string s;
Py::String name(res.index.toString(s));
if (!PyObject_IsTrue(returnID))
return Py::new_reference_to(name);
Py::List list;
for (auto &id : ids)
list.append(Py::Long(id.value()));
return Py::new_reference_to(Py::TupleN(name, list));
}
PyObject* ComplexGeoDataPy::getElementMappedName(PyObject *args)
{
char* input;
PyObject *returnID = Py_False;
if (!PyArg_ParseTuple(args, "s|O", &input,&returnID))
return NULL;
ElementIDRefs ids;
Data::MappedElement res = getComplexGeoDataPtr()->getElementName(
input, PyObject_IsTrue(returnID)?&ids:nullptr);
std::string s;
Py::String name(res.name.toString(s));
if (!PyObject_IsTrue(returnID))
return Py::new_reference_to(name);
Py::List list;
for (auto &id : ids)
list.append(Py::Long(id.value()));
return Py::new_reference_to(Py::TupleN(name, list));
}
PyObject *ComplexGeoDataPy::setElementName(PyObject *args, PyObject *kwds) {
const char *element;
const char *name = 0;
const char *postfix = 0;
int tag = 0;
PyObject *pySid = Py_None;
PyObject *overwrite = Py_False;
static char *kwlist[] = {"element", "name", "postfix", "overwrite", "sid", "tag", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|sssOOi", kwlist,
&element,&name,&postfix,&overwrite,&pySid,&tag))
return NULL;
ElementIDRefs sids;
if(pySid != Py_None) {
if(PyObject_TypeCheck(pySid,&App::StringIDPy::Type))
sids.push_back(static_cast<App::StringIDPy*>(pySid)->getStringIDPtr());
else if(PySequence_Check(pySid)) {
Py::Sequence seq(pySid);
for(auto it=seq.begin();it!=seq.end();++it) {
auto ptr = (*it).ptr();
if(PyObject_TypeCheck(ptr,&App::StringIDPy::Type))
sids.push_back(static_cast<App::StringIDPy*>(ptr)->getStringIDPtr());
else
throw Py::TypeError("expect StringID in sid sequence");
}
} else
throw Py::TypeError("expect sid to contain either StringID or sequence of StringID");
}
PY_TRY {
Data::IndexedName index(element, getComplexGeoDataPtr()->getElementTypes());
Data::MappedName mapped = Data::MappedName::fromRawData(name);
std::ostringstream ss;
getComplexGeoDataPtr()->encodeElementName(getComplexGeoDataPtr()->elementType(index),
mapped, ss, &sids, postfix, tag);
Data::MappedName res = getComplexGeoDataPtr()->setElementName(
index, mapped, &sids, PyObject_IsTrue(overwrite));
return Py::new_reference_to(Py::String(res.toString(0)));
}PY_CATCH
}
Py::Object ComplexGeoDataPy::getHasher() const {
auto self = getComplexGeoDataPtr();
if(!self->Hasher)
return Py::None();
return Py::Object(self->Hasher->getPyObject(),true);
}
Py::Dict ComplexGeoDataPy::getElementMap() const {
Py::Dict ret;
std::string s;
for(auto &v : getComplexGeoDataPtr()->getElementMap()) {
s.clear();
ret.setItem(v.name.toString(0), Py::String(v.index.toString(s)));
}
return ret;
}
void ComplexGeoDataPy::setElementMap(Py::Dict dict) {
std::vector<Data::MappedElement> map;
const auto & types = getComplexGeoDataPtr()->getElementTypes();
for(auto it=dict.begin();it!=dict.end();++it) {
const auto &value = *it;
if(!value.first.isString() || !value.second.isString())
throw Py::TypeError("expect only strings in the dict");
map.emplace_back(Data::MappedName(value.first.as_string().c_str()),
Data::IndexedName(Py::Object(value.second).as_string().c_str(), types));
}
getComplexGeoDataPtr()->setElementMap(map);
}
Py::Dict ComplexGeoDataPy::getElementReverseMap() const {
Py::Dict ret;
std::string s;
for(auto &v : getComplexGeoDataPtr()->getElementMap()) {
s.clear();
auto value = ret[Py::String(v.index.toString(s))];
Py::Object item(value);
if(item.isNone()) {
s.clear();
value = Py::String(v.name.toString(s));
} else if(item.isList()) {
Py::List list(item);
s.clear();
list.append(Py::String(v.name.toString(s)));
} else {
Py::List list;
list.append(item);
s.clear();
list.append(Py::String(v.name.toString(s)));
value = list;
}
}
return ret;
}
Py::Int ComplexGeoDataPy::getElementMapSize() const {
return Py::Int((long)getComplexGeoDataPtr()->getElementMapSize());
}
void ComplexGeoDataPy::setHasher(Py::Object obj) {
auto self = getComplexGeoDataPtr();
if(obj.isNone()) {
if(self->Hasher) {
self->Hasher = App::StringHasherRef();
self->resetElementMap();
}
}else if(PyObject_TypeCheck(obj.ptr(),&App::StringHasherPy::Type)) {
App::StringHasherRef ref(static_cast<App::StringHasherPy*>(obj.ptr())->getStringHasherPtr());
if(self->Hasher != ref) {
self->Hasher = ref;
self->resetElementMap();
}
}else
throw Py::TypeError("invalid type");
}
Py::Object ComplexGeoDataPy::getBoundBox() const
{
return Py::BoundingBox(getComplexGeoDataPtr()->getBoundBox());
@@ -334,6 +513,11 @@ void ComplexGeoDataPy::setPlacement(Py::Object arg)
}
}
Py::String ComplexGeoDataPy::getElementMapVersion() const
{
return Py::String(getComplexGeoDataPtr()->getElementMapVersion());
}
Py::Int ComplexGeoDataPy::getTag() const
{
return Py::Int(getComplexGeoDataPtr()->Tag);
+210 -33
View File
@@ -65,6 +65,7 @@ recompute path. Also, it enables more complicated dependencies beyond trees.
#include <boost/algorithm/string.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/bimap.hpp>
#include <boost/graph/strong_components.hpp>
#ifdef USE_OLD_DAG
@@ -95,6 +96,7 @@ recompute path. Also, it enables more complicated dependencies beyond trees.
#include <Base/Stream.h>
#include "Document.h"
#include "DocumentParams.h"
#include "Application.h"
#include "AutoTransaction.h"
#include "DocumentObserver.h"
@@ -106,6 +108,7 @@ recompute path. Also, it enables more complicated dependencies beyond trees.
#include "MergeDocuments.h"
#include "Origin.h"
#include "OriginGroupExtension.h"
#include "StringHasher.h"
#include "Transactions.h"
#ifdef _MSC_VER
@@ -116,7 +119,6 @@ recompute path. Also, it enables more complicated dependencies beyond trees.
#include <zipios++/zipoutputstream.h>
#include <zipios++/meta-iostreams.h>
FC_LOG_LEVEL_INIT("App", true, true, true)
using Base::Console;
@@ -151,8 +153,10 @@ typedef std::vector <size_t> Path;
namespace App {
typedef boost::bimap<StringHasherRef,int> HasherMap;
static bool _IsRestoring;
static bool _IsRelabeling;
// Pimpl class
struct DocumentP
{
@@ -178,6 +182,7 @@ struct DocumentP
unsigned int UndoMemSize;
unsigned int UndoMaxStackSize;
std::string programVersion;
mutable HasherMap hashers;
#ifdef USE_OLD_DAG
DependencyList DepList;
std::map<DocumentObject*,Vertex> VertexObjectList;
@@ -186,7 +191,15 @@ struct DocumentP
std::multimap<const App::DocumentObject*,
std::unique_ptr<App::DocumentObjectExecReturn> > _RecomputeLog;
StringHasherRef Hasher;
// restored files
std::set<std::string> files;
DocumentP() {
#ifdef FC_NO_RANDOM_ID
lastObjectId = 10;
#else
static std::random_device _RD;
static std::mt19937 _RGEN(_RD());
static std::uniform_int_distribution<> _RDIST(0,5000);
@@ -194,6 +207,8 @@ struct DocumentP
// copying shape from other document. It is probably better to randomize
// on each object ID.
lastObjectId = _RDIST(_RGEN);
#endif
Hasher.reset(new StringHasher);
activeObject = nullptr;
activeUndoTransaction = nullptr;
iTransactionMode = 0;
@@ -1466,7 +1481,6 @@ void Document::onChanged(const Property* prop)
// the Name property is a label for display purposes
if (prop == &Label) {
Base::FlagToggler<> flag(_IsRelabeling);
App::GetApplication().signalRelabelDocument(*this);
} else if(prop == &ShowHidden) {
App::GetApplication().signalShowHidden(*this);
@@ -1501,6 +1515,12 @@ void Document::onChanged(const Property* prop)
// recursive call of onChanged()
this->Uid.setValue(id);
}
} else if(prop == &UseHasher) {
for(auto obj : d->objectArray) {
auto geofeature = dynamic_cast<GeoFeature*>(obj);
if(geofeature && geofeature->getPropertyOfGeometry())
geofeature->enforceRecompute();
}
}
}
@@ -1508,8 +1528,8 @@ void Document::onBeforeChangeProperty(const TransactionalObject *Who, const Prop
{
if(Who->isDerivedFrom(App::DocumentObject::getClassTypeId()))
signalBeforeChangeObject(*static_cast<const App::DocumentObject*>(Who), *What);
if(!d->rollback && !_IsRelabeling) {
_checkTransaction(nullptr,What,__LINE__);
if(!d->rollback) {
_checkTransaction(nullptr, What, __LINE__);
if (d->activeUndoTransaction)
d->activeUndoTransaction->addObjectChange(Who,What);
}
@@ -1544,10 +1564,8 @@ Document::Document(const char *name)
Console().Log("+App::Document: %p\n",this);
#endif
std::string CreationDateString = Base::TimeInfo::currentDateTimeString();
std::string Author = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/Document")->GetASCII("prefAuthor","");
std::string AuthorComp = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/Document")->GetASCII("prefCompany","");
std::string Author = DocumentParams::getprefAuthor();
std::string AuthorComp = DocumentParams::getprefCompany();
ADD_PROPERTY_TYPE(Label,("Unnamed"),0,Prop_None,"The name of the document");
ADD_PROPERTY_TYPE(FileName,(""),0,PropertyType(Prop_Transient|Prop_ReadOnly),"The path to the file where the document is saved to");
ADD_PROPERTY_TYPE(CreatedBy,(Author.c_str()),0,Prop_None,"The creator of the document");
@@ -1568,8 +1586,7 @@ Document::Document(const char *name)
ADD_PROPERTY_TYPE(LicenseURL,("http://creativecommons.org/licenses/by/3.0/"),0,Prop_None,"URL to the license text/contract");
// license stuff
int licenseId = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/Document")->GetInt("prefLicenseType",0);
int licenseId = DocumentParams::getprefLicenseType();
std::string license;
std::string licenseUrl;
switch (licenseId) {
@@ -1614,13 +1631,17 @@ Document::Document(const char *name)
break;
}
licenseUrl = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/Document")->GetASCII("prefLicenseUrl", licenseUrl.c_str());
if(DocumentParams::getprefLicenseUrl().empty())
licenseUrl = DocumentParams::getprefLicenseUrl();
ADD_PROPERTY_TYPE(License,(license.c_str()),0,Prop_None,"License string of the Item");
ADD_PROPERTY_TYPE(LicenseURL,(licenseUrl.c_str()),0,Prop_None,"URL to the license text/contract");
ADD_PROPERTY_TYPE(ShowHidden,(false), 0,PropertyType(Prop_None),
"Whether to show hidden object items in the tree view");
ADD_PROPERTY_TYPE(UseHasher,(true), 0,PropertyType(Prop_Hidden),
"Whether to use hasher on topological naming");
if(!DocumentParams::getUseHasher())
UseHasher.setValue(false);
// this creates and sets 'TransientDir' in onChanged()
ADD_PROPERTY_TYPE(TransientDir,(""),0,PropertyType(Prop_Transient|Prop_ReadOnly),
@@ -1690,11 +1711,31 @@ std::string Document::getTransientDirectoryName(const std::string& uuid, const s
void Document::Save (Base::Writer &writer) const
{
d->hashers.clear();
addStringHasher(d->Hasher);
writer.Stream() << "<Document SchemaVersion=\"4\" ProgramVersion=\""
<< App::Application::Config()["BuildVersionMajor"] << "."
<< App::Application::Config()["BuildVersionMinor"] << "R"
<< App::Application::Config()["BuildRevision"]
<< "\" FileVersion=\"" << writer.getFileVersion() << "\">" << endl;
<< "\" FileVersion=\"" << writer.getFileVersion()
<< "\" Uid=\"" << Uid.getValueStr()
<< "\" StringHasher=\"1\">\n";
writer.incInd();
if (writer.isForceXML())
d->Hasher->setPersistenceFileName(0);
else
d->Hasher->setPersistenceFileName("StringHasher.Table");
for (auto o : d->objectArray)
o->beforeSave();
beforeSave();
d->Hasher->Save(writer);
writer.decInd();
PropertyContainer::Save(writer);
@@ -1706,7 +1747,12 @@ void Document::Save (Base::Writer &writer) const
void Document::Restore(Base::XMLReader &reader)
{
int i,Cnt;
d->hashers.clear();
d->touchedObjs.clear();
addStringHasher(d->Hasher);
Base::ReaderContext rctx(getName());
setStatus(Document::PartialDoc,false);
reader.readElement("Document");
@@ -1723,6 +1769,11 @@ void Document::Restore(Base::XMLReader &reader)
reader.FileVersion = 0;
}
if (reader.hasAttribute("StringHasher")) {
Base::ReaderContext rctx("StringHasher");
d->Hasher->Restore(reader);
} else
d->Hasher->clear();
// When this document was created the FileName and Label properties
// were set to the absolute path or file name, respectively. To save
// the document to the file it was loaded from or to show the file name
@@ -1765,6 +1816,7 @@ void Document::Restore(Base::XMLReader &reader)
for (i=0 ;i<Cnt ;i++) {
reader.readElement("Feature");
string name = reader.getAttribute("name");
Base::ReaderContext rctx(name);
DocumentObject* pObj = getObject(name.c_str());
if (pObj) { // check if this feature has been registered
pObj->setStatus(ObjectStatus::Restore, true);
@@ -1787,6 +1839,36 @@ void Document::Restore(Base::XMLReader &reader)
reader.readEndElement("Document");
}
std::pair<bool,int> Document::addStringHasher(const StringHasherRef & hasher) const {
if (!hasher)
return std::make_pair(false, 0);
auto ret = d->hashers.left.insert(HasherMap::left_map::value_type(hasher,(int)d->hashers.size()));
if (ret.second)
hasher->clearMarks();
return std::make_pair(ret.second,ret.first->second);
}
StringHasherRef Document::getHasher() const {
return d->Hasher;
}
StringHasherRef Document::getStringHasher(int idx) const {
StringHasherRef hasher;
if(idx<0) {
if(UseHasher.getValue())
return d->Hasher;
return hasher;
}
auto it = d->hashers.right.find(idx);
if(it == d->hashers.right.end()) {
hasher = new StringHasher;
d->hashers.right.insert(HasherMap::right_map::value_type(idx,hasher));
}else
hasher = it->second;
return hasher;
}
struct DocExportStatus {
Document::ExportStatus status;
std::set<const App::DocumentObject*> objs;
@@ -1823,6 +1905,7 @@ Document::ExportStatus Document::isExporting(const App::DocumentObject *obj) con
void Document::exportObjects(const std::vector<App::DocumentObject*>& obj, std::ostream& out) {
DocumentExporting exporting(obj);
d->hashers.clear();
if(FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG)) {
for(auto o : obj) {
@@ -1859,6 +1942,7 @@ void Document::exportObjects(const std::vector<App::DocumentObject*>& obj, std::
// write additional files
writer.writeFiles();
d->hashers.clear();
}
#define FC_ATTR_DEPENDENCIES "Dependencies"
@@ -2162,14 +2246,16 @@ Document::readObjects(Base::XMLReader& reader)
void Document::addRecomputeObject(DocumentObject *obj) {
if(testStatus(Status::Restoring) && obj) {
setStatus(Status::RecomputeOnRestore, true);
d->touchedObjs.insert(obj);
obj->touch();
obj->enforceRecompute();
}
}
std::vector<App::DocumentObject*>
Document::importObjects(Base::XMLReader& reader)
{
d->hashers.clear();
Base::FlagToggler<> flag(_IsRestoring,false);
Base::ObjectStatusLocker<Status, Document> restoreBit(Status::Restoring, this);
Base::ObjectStatusLocker<Status, Document> restoreBit2(Status::Importing, this);
@@ -2188,6 +2274,7 @@ Document::importObjects(Base::XMLReader& reader)
reader.FileVersion = 0;
}
Base::ReaderContext rctx(getName());
std::vector<App::DocumentObject*> objs = readObjects(reader);
for(auto o : objs) {
if(o && o->getNameInDocument()) {
@@ -2220,7 +2307,7 @@ Document::importObjects(Base::XMLReader& reader)
if(o && o->getNameInDocument())
o->setStatus(App::ObjImporting,false);
}
d->hashers.clear();
return objs;
}
@@ -2233,6 +2320,8 @@ unsigned int Document::getMemSize (void) const
for (it = d->objectArray.begin(); it != d->objectArray.end(); ++it)
size += (*it)->getMemSize();
size += d->Hasher->getMemSize();
// size of the document properties...
size += PropertyContainer::getMemSize();
@@ -2699,6 +2788,37 @@ bool Document::saveToFile(const char* filename) const
return true;
}
void Document::save(Base::Writer &writer, bool archive) const {
(void)archive;
writer.putNextEntry("Document.xml");
auto hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Document");
if (hGrp->GetBool("SaveBinaryBrep", false)) {
writer.setMode("BinaryBrep");
writer.setPreferBinary(true);
} else if(writer.getFileVersion() > 1)
writer.setPreferBinary(false);
writer.Stream() << "<?xml version='1.0' encoding='utf-8'?>\n"
<< "<!--\n"
<< " FreeCAD Document, see http://www.freecadweb.org for more information...\n"
<< "-->\n";
Document::Save(writer);
// Special handling for Gui document.
signalSaveDocument(writer);
// write additional files
writer.writeFiles();
if (writer.hasErrors()) {
throw Base::FileException("Failed to write all data to file");
}
GetApplication().signalSaveDocument(*this);
}
bool Document::isAnyRestoring() {
return _IsRestoring;
}
@@ -2707,8 +2827,48 @@ bool Document::isAnyRestoring() {
void Document::restore (const char *filename,
bool delaySignal, const std::vector<std::string> &objNames)
{
if(!filename)
filename = FileName.getValue();
Base::FileInfo fi(filename);
if(fi.isDir()) {
fi.setFile(std::string(filename)+'/'+"Document.xml");
if(!fi.exists())
throw Base::FileException("Project file not found",fi.filePath());
}
std::unique_ptr<Base::Reader> _reader;
std::unique_ptr<Base::XMLReader> _xmlReader;
std::unique_ptr<zipios::ZipInputStream> zipstream;
std::string dirname;
if(fi.fileNamePure() == "Document" && fi.hasExtension("xml")) {
Base::FileInfo di(fi.dirPath());
_reader.reset(new Base::FileReader(fi,di.fileName()+"/Document.xml"));
_xmlReader.reset(new Base::XMLReader(*_reader));
} else {
// file.open(fi, std::ios::in | std::ios::binary);
// std::streambuf* buf = file.rdbuf();
// std::streamoff size = buf->pubseekoff(0, std::ios::end, std::ios::in);
// buf->pubseekoff(0, std::ios::beg, std::ios::in);
// if (size < 22) // an empty zip archive has 22 bytes
// throw Base::FileException("Invalid project file",filename);
zipstream.reset(new zipios::ZipInputStream(filename));
_reader.reset(new Base::ZipReader(*zipstream,filename));
_xmlReader.reset(new Base::XMLReader(*_reader));
}
restore(*_xmlReader, delaySignal, objNames);
}
void Document::restore(Base::XMLReader &reader,
bool delaySignal, const std::vector<std::string> &objNames)
{
if (!reader.isValid())
throw Base::FileException("Error reading project file", FileName.getValue());
clearUndos();
d->activeObject = nullptr;
d->files.clear();
bool signal = false;
Document *activeDoc = GetApplication().getActiveDocument();
@@ -2734,21 +2894,6 @@ void Document::restore (const char *filename,
GetApplication().setActiveDocument(this);
}
if(!filename)
filename = FileName.getValue();
Base::FileInfo fi(filename);
Base::ifstream file(fi, std::ios::in | std::ios::binary);
std::streambuf* buf = file.rdbuf();
std::streamoff size = buf->pubseekoff(0, std::ios::end, std::ios::in);
buf->pubseekoff(0, std::ios::beg, std::ios::in);
if (size < 22) // an empty zip archive has 22 bytes
throw Base::FileException("Invalid project file",filename);
zipios::ZipInputStream zipstream(file);
Base::XMLReader reader(filename, zipstream);
if (!reader.isValid())
throw Base::FileException("Error reading compression file",filename);
GetApplication().signalStartRestoreDocument(*this);
setStatus(Document::Restoring, true);
@@ -2758,6 +2903,8 @@ void Document::restore (const char *filename,
d->partialLoadObjects.emplace(name,true);
try {
Document::Restore(reader);
} catch (const Base::XMLParseException &) {
throw;
} catch (const Base::Exception& e) {
Base::Console().Error("Invalid Document.xml: %s\n", e.what());
setStatus(Document::RestoreError, true);
@@ -2771,7 +2918,13 @@ void Document::restore (const char *filename,
// Note: This file doesn't need to be available if the document has been created
// without GUI. But if available then follow after all data files of the App document.
signalRestoreDocument(reader);
reader.readFiles(zipstream);
reader.readFiles();
for(auto &f : reader.getFilenames()) {
FC_TRACE("document " << getName() << " file: " << f);
d->files.insert(f);
}
if (reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestore)) {
setStatus(Document::PartialRestore, true);
@@ -2919,10 +3072,19 @@ const char* Document::getName() const
return myName.c_str();
}
std::string Document::getFullName() const {
std::string Document::getFullName(bool python) const {
if(python) {
std::ostringstream ss;
ss << "FreeCAD.getDocument('" << myName << "')";
return ss.str();
}
return myName;
}
App::Document *Document::getOwnerDocument() const {
return const_cast<App::Document*>(this);
}
const char* Document::getProgramVersion() const
{
return d->programVersion.c_str();
@@ -3762,6 +3924,21 @@ const char * Document::getErrorDescription(const App::DocumentObject*Obj) const
return d->findRecomputeLog(Obj);
}
void Document::setErrorDescription(App::DocumentObject *Obj, const char *msg)
{
if (msg && msg[0] && Obj)
d->addRecomputeLog(msg, Obj);
}
void Document::setErrorDescription(App::Property *Prop, const char *msg)
{
if (msg && msg[0] && Prop) {
auto obj = Base::freecad_dynamic_cast<DocumentObject>(Prop->getContainer());
if (obj)
d->addRecomputeLog(msg, obj);
}
}
// call the recompute of the Feature and handle the exceptions and errors.
int Document::_recomputeFeature(DocumentObject* Feat)
{
+60 -3
View File
@@ -23,13 +23,22 @@
#ifndef APP_DOCUMENT_H
#define APP_DOCUMENT_H
#include <CXX/Objects.hxx>
#include <Base/Observer.h>
#include <Base/Persistence.h>
#include <Base/Type.h>
#include <Base/Handle.h>
#include "PropertyContainer.h"
#include "PropertyLinks.h"
#include "PropertyStandard.h"
#include <memory>
#include <map>
#include <vector>
class QByteArray;
namespace Base {
class Writer;
}
@@ -43,6 +52,8 @@ namespace App
class DocumentPy; // the python document class
class Application;
class Transaction;
class StringHasher;
typedef Base::Reference<StringHasher> StringHasherRef;
}
namespace App
@@ -68,6 +79,7 @@ public:
RestoreError = 10,
LinkStampChanged = 11, // Indicates during restore time if any linked document's time stamp has changed
IgnoreErrorOnRecompute = 12, // Don't report errors if the recompute failed
RecomputeOnRestore = 13, // Mark pending recompute on restore for migration purpose
};
/** @name Properties */
@@ -109,6 +121,8 @@ public:
PropertyString TipName;
/// Whether to show hidden items in TreeView
PropertyBool ShowHidden;
/// Whether to use hasher on topological naming
PropertyBool UseHasher;
//@}
/** @name Signals of the document */
@@ -186,11 +200,13 @@ public:
bool save (void);
bool saveAs(const char* file);
bool saveCopy(const char* file) const;
void save(Base::Writer &writer, bool archive) const;
/// Restore the document from the file in Property Path
void restore (const char *filename=nullptr,
bool delaySignal=false, const std::vector<std::string> &objNames={});
bool afterRestore(bool checkPartial=false);
bool afterRestore(const std::vector<App::DocumentObject *> &, bool checkPartial=false);
/// Restore the document from a pre-constructed xml reader
void restore (Base::XMLReader &xmlReader,
bool delaySignal=false, const std::vector<std::string> &objNames={});
enum ExportStatus {
NotExporting,
Exporting,
@@ -343,6 +359,10 @@ public:
bool recomputeFeature(DocumentObject* Feat,bool recursive=false);
/// get the text of the error of a specified object
const char* getErrorDescription(const App::DocumentObject*) const;
/// set the text of the error of a specified object
void setErrorDescription(App::DocumentObject *, const char *);
/// set the text of the error of a specified object
void setErrorDescription(App::Property *, const char *);
/// return the status bits
bool testStatus(Status pos) const;
/// set the status bits
@@ -467,6 +487,38 @@ public:
(const App::DocumentObject* from, const App::DocumentObject* to) const;
//@}
/** Called by property during properly save its containing StringHasher
*
* @param hasher: the input hasher
* @return Returns a pair<bool,int>. Boolean member indicate if the
* StringHasher has been saved before. The Integer is the hasher index.
*
* The StringHasher object is designed to be shared among multiple objects.
* So, we must not save duplicate copies of the same hasher. And must be
* able to restore with the same sharing relationship. This function returns
* whether the hasher has been saved before by other objects, and the index
* of the hasher. If the hasher has not been saved before, the object must
* save the hasher by calling StringHasher::Save
*/
std::pair<bool,int> addStringHasher(const StringHasherRef & hasher) const;
/** Called by property to restore its containing StringHasher
*
* @param index: the index previously returned by calling addStringHasher()
* during save. Or if is negative, then return document's own string hasher
* if UseHasher is True
*
* @return Return the resulting string hasher.
*
* The caller is responsible to restore the hasher itself if it is the first
* owner of the hasher, i.e. return addStringHasher() returns true during
* save
*/
StringHasherRef getStringHasher(int index=-1) const;
/// Return the document's own hasher regardless of UseHasher
StringHasherRef getHasher() const;
/** Return the links to a given object
*
* @param links: holds the links found
@@ -493,7 +545,9 @@ public:
virtual PyObject *getPyObject(void) override;
virtual std::string getFullName() const override;
virtual std::string getFullName(bool python=false) const override;
virtual App::Document *getOwnerDocument() const override;
/// Indicate if there is any document restoring/importing
static bool isAnyRestoring();
@@ -512,6 +566,9 @@ protected:
/// Construction
Document(const char *name = "");
bool afterRestore(bool checkPartial=false);
bool afterRestore(const std::vector<App::DocumentObject *> &, bool checkPartial=false);
void _removeObject(DocumentObject* pcObject);
void _addObject(DocumentObject* pcObject, const char* pObjectName);
/// checks if a valid transaction is open
+76 -74
View File
@@ -165,14 +165,13 @@ App::DocumentObjectExecReturn* DocumentObject::executeExtensions()
{
//execute extensions but stop on error
this->setStatus(App::RecomputeExtension, false); // reset the flag
auto vector = getExtensionsDerivedFromType<App::DocumentObjectExtension>();
for(auto ext : vector) {
auto ret = ext->extensionExecute();
if (ret != StdReturn)
return ret;
}
App::DocumentObjectExecReturn *res = StdReturn;
foreachExtension<DocumentObjectExtension>([&res](DocumentObjectExtension *ext) {
res = ext->extensionExecute();
return res != StdReturn;
});
return StdReturn;
return res;
}
bool DocumentObject::recomputeFeature(bool recursive)
@@ -234,16 +233,10 @@ bool DocumentObject::mustRecompute(void) const
short DocumentObject::mustExecute(void) const
{
if (ExpressionEngine.isTouched())
if (ExpressionEngine.isTouched()
|| queryExtension(&DocumentObjectExtension::extensionMustExecute))
return 1;
//ask all extensions
auto vector = getExtensionsDerivedFromType<App::DocumentObjectExtension>();
for(auto ext : vector) {
if (ext->extensionMustExecute())
return 1;
}
return 0;
}
@@ -259,13 +252,24 @@ const char* DocumentObject::getStatusString(void) const
return "Valid";
}
std::string DocumentObject::getFullName() const {
if(!getDocument() || !pcNameInDocument)
return "?";
std::string name(getDocument()->getName());
name += '#';
name += *pcNameInDocument;
return name;
std::string DocumentObject::getFullName(bool python) const {
if(!getDocument() || !pcNameInDocument) {
if(python)
return std::string("None");
return std::string("?") + Base::Tools::getIdentifier(oldLabel);
}
std::ostringstream ss;
if(python) {
ss << "FreeCAD.getDocument('" << getDocument()->getName()
<< "').getObject('" << *pcNameInDocument << "')";
}else
ss << getDocument()->getName() << '#' << *pcNameInDocument;
return ss.str();
}
App::Document *DocumentObject::getOwnerDocument() const {
return _pDoc;
}
const char *DocumentObject::getNameInDocument() const
@@ -723,9 +727,9 @@ bool DocumentObject::removeDynamicProperty(const char* name)
App::Property* DocumentObject::addDynamicProperty(
const char* type, const char* name, const char* group, const char* doc,
short attr, bool ro, bool hidden)
short attr, bool readonly, bool hidden)
{
auto prop = TransactionalObject::addDynamicProperty(type,name,group,doc,attr,ro,hidden);
auto prop = TransactionalObject::addDynamicProperty(type,name,group,doc,attr,readonly,hidden);
if(prop && _pDoc)
_pDoc->addOrRemovePropertyOfObject(this, prop, true);
return prop;
@@ -744,8 +748,7 @@ void DocumentObject::onBeforeChange(const Property* prop)
signalBeforeChange(*this,*prop);
}
/// get called by the container when a Property was changed
void DocumentObject::onChanged(const Property* prop)
void DocumentObject::onEarlyChange(const Property *prop)
{
if(GetApplication().isClosingAll())
return;
@@ -763,6 +766,15 @@ void DocumentObject::onChanged(const Property* prop)
}
}
signalEarlyChanged(*this, *prop);
}
/// get called by the container when a Property was changed
void DocumentObject::onChanged(const Property* prop)
{
if(GetApplication().isClosingAll())
return;
// Delay signaling view provider until the document object has handled the
// change
// if (_pDoc)
@@ -814,14 +826,13 @@ DocumentObject *DocumentObject::getSubObject(const char *subname,
PyObject **pyObj, Base::Matrix4D *mat, bool transform, int depth) const
{
DocumentObject *ret = nullptr;
auto exts = getExtensionsDerivedFromType<App::DocumentObjectExtension>();
for(auto ext : exts) {
if(ext->extensionGetSubObject(ret,subname,pyObj,mat,transform, depth))
return ret;
}
if(queryExtension(&DocumentObjectExtension::extensionGetSubObject, ret, subname, pyObj, mat, transform, depth))
return ret;
std::string name;
const char *dot=nullptr;
while(subname && *subname=='.')
++subname; // skip leading .
if(!subname || !(dot=strchr(subname,'.'))) {
ret = const_cast<DocumentObject*>(this);
}else if(subname[0]=='$') {
@@ -879,11 +890,7 @@ std::vector<DocumentObject*> DocumentObject::getSubObjectList(const char *subnam
std::vector<std::string> DocumentObject::getSubObjects(int reason) const {
std::vector<std::string> ret;
auto exts = getExtensionsDerivedFromType<App::DocumentObjectExtension>();
for(auto ext : exts) {
if(ext->extensionGetSubObjects(ret,reason))
return ret;
}
callExtension(&DocumentObjectExtension::extensionGetSubObjects,ret,reason);
return ret;
}
@@ -919,11 +926,8 @@ DocumentObject *DocumentObject::getLinkedObject(
bool recursive, Base::Matrix4D *mat, bool transform, int depth) const
{
DocumentObject *ret = nullptr;
auto exts = getExtensionsDerivedFromType<App::DocumentObjectExtension>();
for(auto ext : exts) {
if(ext->extensionGetLinkedObject(ret,recursive,mat,transform,depth))
return ret;
}
if(queryExtension(&DocumentObjectExtension::extensionGetLinkedObject, ret, recursive, mat, transform, depth))
return ret;
if(transform && mat) {
auto pla = dynamic_cast<PropertyPlacement*>(getPropertyByName("Placement"));
if(pla)
@@ -934,8 +938,6 @@ DocumentObject *DocumentObject::getLinkedObject(
void DocumentObject::Save (Base::Writer &writer) const
{
if (this->getNameInDocument())
writer.ObjectName = this->getNameInDocument();
App::ExtensionContainer::Save(writer);
}
@@ -991,9 +993,7 @@ void DocumentObject::renameObjectIdentifiers(const std::map<ObjectIdentifier, Ob
void DocumentObject::onDocumentRestored()
{
//call all extensions
auto vector = getExtensionsDerivedFromType<App::DocumentObjectExtension>();
for(auto ext : vector)
ext->onExtendedDocumentRestored();
callExtension(&DocumentObjectExtension::onExtendedDocumentRestored);
if(Visibility.testStatus(Property::Output))
Visibility.setStatus(Property::NoModify,true);
}
@@ -1006,25 +1006,19 @@ void DocumentObject::onUndoRedoFinished()
void DocumentObject::onSettingDocument()
{
//call all extensions
auto vector = getExtensionsDerivedFromType<App::DocumentObjectExtension>();
for(auto ext : vector)
ext->onExtendedSettingDocument();
callExtension(&DocumentObjectExtension::onExtendedSettingDocument);
}
void DocumentObject::setupObject()
{
//call all extensions
auto vector = getExtensionsDerivedFromType<App::DocumentObjectExtension>();
for(auto ext : vector)
ext->onExtendedSetupObject();
callExtension(&DocumentObjectExtension::onExtendedSetupObject);
}
void DocumentObject::unsetupObject()
{
//call all extensions
auto vector = getExtensionsDerivedFromType<App::DocumentObjectExtension>();
for(auto ext : vector)
ext->onExtendedUnsetupObject();
callExtension(&DocumentObjectExtension::onExtendedUnsetupObject);
}
void App::DocumentObject::_removeBackLink(DocumentObject* rmvObj)
@@ -1054,31 +1048,25 @@ void App::DocumentObject::_addBackLink(DocumentObject* newObj)
}
int DocumentObject::setElementVisible(const char *element, bool visible) {
for(auto ext : getExtensionsDerivedFromType<DocumentObjectExtension>()) {
int ret = ext->extensionSetElementVisible(element,visible);
if(ret>=0)
return ret;
}
return -1;
int res = -1;
foreachExtension<DocumentObjectExtension>([&res,element,visible](DocumentObjectExtension *ext) {
res = ext->extensionSetElementVisible(element,visible);
return res>=0;
});
return res;
}
int DocumentObject::isElementVisible(const char *element) const {
for(auto ext : getExtensionsDerivedFromType<DocumentObjectExtension>()) {
int ret = ext->extensionIsElementVisible(element);
if(ret>=0)
return ret;
}
return -1;
int res = -1;
foreachExtension<DocumentObjectExtension>([&res,element](DocumentObjectExtension *ext) {
res = ext->extensionIsElementVisible(element);
return res>=0;
});
return res;
}
bool DocumentObject::hasChildElement() const {
for(auto ext : getExtensionsDerivedFromType<DocumentObjectExtension>()) {
if(ext->extensionHasChildElement())
return true;
}
return false;
return queryExtension(&DocumentObjectExtension::extensionHasChildElement);
}
DocumentObject *DocumentObject::resolve(const char *subname,
@@ -1253,6 +1241,20 @@ bool DocumentObject::adjustRelativeLinks(
return touched;
}
std::string DocumentObject::getElementMapVersion(const App::Property *_prop, bool restored) const {
auto prop = Base::freecad_dynamic_cast<const PropertyComplexGeoData>(_prop);
if(!prop)
return std::string();
return prop->getElementMapVersion(restored);
}
bool DocumentObject::checkElementMapVersion(const App::Property *_prop, const char *ver) const {
auto prop = Base::freecad_dynamic_cast<const PropertyComplexGeoData>(_prop);
if(!prop)
return false;
return prop->checkElementMapVersion(ver);
}
const std::string &DocumentObject::hiddenMarker() {
static std::string marker("!hide");
return marker;
+21 -3
View File
@@ -66,7 +66,6 @@ enum ObjectStatus {
NoAutoExpand = 17, // disable tree item auto expand on selection for this object
PendingTransactionUpdate = 18, // mark that the object expects a call to onUndoRedoFinished() after transaction is finished.
RecomputeExtension = 19, // mark the object to recompute its extensions
TouchOnColorChange = 20, // inform view provider touch object on color change
};
/** Return object for feature execution
@@ -110,6 +109,8 @@ public:
boost::signals2::signal<void (const App::DocumentObject&, const App::Property&)> signalBeforeChange;
/// signal on changed property of this object
boost::signals2::signal<void (const App::DocumentObject&, const App::Property&)> signalChanged;
/// signal on changed property of this object before document scoped signalChangedObject
boost::signals2::signal<void (const App::DocumentObject&, const App::Property&)> signalEarlyChanged;
/// returns the type name of the ViewProvider
virtual const char* getViewProviderName(void) const {
@@ -139,7 +140,8 @@ public:
/// returns the name that is safe to be exported to other document
std::string getExportName(bool forced=false) const;
/// Return the object full name of the form DocName#ObjName
virtual std::string getFullName() const override;
virtual std::string getFullName(bool python=false) const override;
virtual App::Document *getOwnerDocument() const override;
virtual bool isAttachedToDocument() const override;
virtual const char* detachFromDocument() override;
/// gets the document in which this Object is handled
@@ -287,6 +289,20 @@ public:
bool testIfLinkDAGCompatible(App::PropertyLinkSubList &linksTo) const;
bool testIfLinkDAGCompatible(App::PropertyLinkSub &linkTo) const;
/** Return the element map version of the geometry data stored in the given property
*
* @param prop: the geometry property to query for element map version
* @param restored: whether to query for the restored element map version.
* In case of version upgrade, the restored version may
* be different from the current version.
*
* @return Return the element map version string.
*/
virtual std::string getElementMapVersion(const App::Property *prop, bool restored=false) const;
/// Return true to signal re-generation of geometry element names
virtual bool checkElementMapVersion(const App::Property *prop, const char *ver) const;
public:
/** mustExecute
* We call this method to check if the object was modified to
@@ -442,7 +458,7 @@ public:
virtual App::Property* addDynamicProperty(
const char* type, const char* name=nullptr,
const char* group=nullptr, const char* doc=nullptr,
short attr=0, bool ro=false, bool hidden=false) override;
short attr=0, bool readonly=false, bool hidden=false) override;
/** Resolve the last document object referenced in the subname
*
@@ -600,6 +616,8 @@ protected:
virtual void onBeforeChange(const Property* prop) override;
/// get called by the container when a property was changed
virtual void onChanged(const Property* prop) override;
/// get called by the container when a property was changed
virtual void onEarlyChange(const Property* prop) override;
/// get called after a document has been fully restored
virtual void onDocumentRestored();
/// get called after an undo/redo transaction is finished
+1 -1
View File
@@ -96,7 +96,7 @@ public:
Base::Matrix4D *mat, bool transform, int depth) const;
virtual int extensionSetElementVisible(const char *, bool) {return -1;}
virtual int extensionIsElementVisible(const char *) {return -1;}
virtual int extensionIsElementVisible(const char *) const {return -1;}
virtual bool extensionHasChildElement() const {return false;}
};
+205 -22
View File
@@ -24,10 +24,12 @@
#include "PreCompiled.h"
#include <Base/Tools.h>
#include <Base/Interpreter.h>
#include <App/DocumentObjectPy.h>
#include "Application.h"
#include "ComplexGeoData.h"
#include "Document.h"
#include "DocumentObject.h"
#include "DocumentObserver.h"
#include "GeoFeature.h"
@@ -199,6 +201,18 @@ bool DocumentObjectT::operator==(const DocumentObjectT &other) const {
&& property == other.property;
}
bool DocumentObjectT::operator<(const DocumentObjectT &other) const {
if(getDocumentName() < other.getDocumentName())
return true;
if(getDocumentName() > other.getDocumentName())
return false;
if(getObjectName() < other.getObjectName())
return true;
if(getObjectName() > other.getObjectName())
return false;
return getPropertyName() < other.getPropertyName();
}
Document* DocumentObjectT::getDocument() const
{
return GetApplication().getDocument(document.c_str());
@@ -298,6 +312,44 @@ SubObjectT::SubObjectT(const char *docName, const char *objName, const char *s)
{
}
SubObjectT::SubObjectT(const std::vector<App::DocumentObject*> &objs, const char *s)
{
if (objs.empty())
return;
static_cast<DocumentObjectT&>(*this) = objs.front();
std::ostringstream ss;
for (auto it = objs.begin()+1; it!=objs.end(); ++it) {
auto obj = *it;
if (!obj || !obj->getNameInDocument())
continue;
ss << obj->getNameInDocument() << ".";
}
if (s)
ss << s;
subname = ss.str();
}
SubObjectT::SubObjectT(std::vector<App::DocumentObject*>::const_iterator begin,
std::vector<App::DocumentObject*>::const_iterator end,
const char *s)
{
if (begin == end)
return;
static_cast<DocumentObjectT&>(*this) = *begin;
std::ostringstream ss;
for (auto it = begin+1; it != end; ++it) {
auto obj = *it;
if (!obj || !obj->getNameInDocument())
continue;
ss << obj->getNameInDocument() << ".";
}
if (s)
ss << s;
subname = ss.str();
}
bool SubObjectT::operator<(const SubObjectT &other) const {
if(getDocumentName() < other.getDocumentName())
return true;
@@ -357,45 +409,107 @@ void SubObjectT::setSubName(const char *s) {
subname = s?s:"";
}
bool SubObjectT::normalize()
{
std::ostringstream ss;
auto objs = getSubObjectList();
for (unsigned i=1; i<objs.size(); ++i)
ss << objs[i]->getNameInDocument() << ".";
if (objs.front()->getSubObject(ss.str().c_str()) != objs.back()) {
// something went wrong
return false;
}
ss << getOldElementName();
std::string sub = ss.str();
if (subname != sub) {
subname = std::move(sub);
return true;
}
return false;
}
SubObjectT App::SubObjectT::normalized() const
{
SubObjectT res(*this);
res.normalize();
return res;
}
const std::string &SubObjectT::getSubName() const {
return subname;
}
std::string SubObjectT::getSubNameNoElement() const {
return Data::ComplexGeoData::noElementName(subname.c_str());
std::string SubObjectT::getSubNameNoElement(bool withObjName) const {
if (!withObjName)
return Data::ComplexGeoData::noElementName(subname.c_str());
std::string res(getObjectName());
res += ".";
const char * element = Data::ComplexGeoData::findElementName(subname.c_str());
if(element)
return res.insert(res.size(), subname.c_str(), element - subname.c_str());
return res;
}
const char *SubObjectT::getElementName() const {
return Data::ComplexGeoData::findElementName(subname.c_str());
}
std::string SubObjectT::getNewElementName() const {
std::pair<std::string, std::string> element;
auto obj = getObject();
if(!obj)
return std::string();
GeoFeature::resolveElement(obj,subname.c_str(),element);
return std::move(element.first);
bool SubObjectT::hasSubObject() const {
return Data::ComplexGeoData::findElementName(subname.c_str()) != subname.c_str();
}
std::string SubObjectT::getOldElementName(int *index) const {
bool SubObjectT::hasSubElement() const {
auto element = getElementName();
return element && element[0];
}
std::string SubObjectT::getNewElementName(bool fallback) const {
const char *elementName = Data::ComplexGeoData::findElementName(subname.c_str());
if (!elementName || !elementName[0])
return std::string();
std::string name = Data::ComplexGeoData::newElementName(elementName);
if (name.size())
return name;
std::pair<std::string, std::string> element;
auto obj = getObject();
if(!obj)
return std::string();
GeoFeature::resolveElement(obj,subname.c_str(),element);
if(!index)
return std::move(element.second);
std::size_t pos = element.second.find_first_of("0123456789");
if(pos == std::string::npos)
*index = -1;
else {
*index = std::atoi(element.second.c_str()+pos);
element.second.resize(pos);
}
if (!element.first.empty() || !fallback)
return std::move(element.first);
return std::move(element.second);
}
std::string SubObjectT::getOldElementName(int *index, bool fallback) const {
const char *elementName = Data::ComplexGeoData::findElementName(subname.c_str());
if (!elementName || !elementName[0])
return std::string();
std::string name = Data::ComplexGeoData::oldElementName(elementName);
if (name.empty()) {
std::pair<std::string, std::string> element;
auto obj = getObject();
if(!obj)
return std::string();
GeoFeature::resolveElement(obj,subname.c_str(),element);
if (!element.second.empty())
name = std::move(element.second);
else if (fallback && !element.first.empty())
name = std::move(element.first);
else
return std::string();
}
if(index) {
std::size_t pos = name.find_first_of("0123456789");
if(pos == std::string::npos)
*index = -1;
else {
*index = std::atoi(name.c_str()+pos);
name.resize(pos);
}
}
return name;
}
App::DocumentObject *SubObjectT::getSubObject() const {
auto obj = getObject();
if(obj)
@@ -407,8 +521,8 @@ std::string SubObjectT::getSubObjectPython(bool force) const {
if(!force && subname.empty())
return getObjectPython();
std::stringstream str;
str << "(" << getObjectPython() << ",u'"
<< Base::Tools::escapedUnicodeFromUtf8(subname.c_str()) << "')";
str << "(" << getObjectPython() << ", '"
<< Base::Tools::escapeEncodeString(normalized().subname) << "')";
return str.str();
}
@@ -419,6 +533,38 @@ std::vector<App::DocumentObject*> SubObjectT::getSubObjectList() const {
return {};
}
SubObjectT SubObjectT::getParent() const {
const char *pos = Data::ComplexGeoData::findElementName(subname.c_str());
if (!pos || pos == subname.c_str())
return SubObjectT();
if(*pos != '.')
--pos;
if(--pos <= subname.c_str())
return SubObjectT();
bool found = false;
for(;pos!=subname.c_str();--pos) {
if(*pos != '.') {
found = true;
continue;
}
if(found)
return SubObjectT(getDocumentName().c_str(),
getObjectName().c_str(), std::string(subname.c_str(), pos+1).c_str());
}
return SubObjectT(getDocumentName().c_str(), getObjectName().c_str(), nullptr);
}
SubObjectT SubObjectT::getChild(const App::DocumentObject *child) const
{
if (getObjectName().empty())
return SubObjectT(child);
SubObjectT res = *this;
res.setSubName(getSubNameNoElement() + child->getNameInDocument() + ".");
return res;
}
std::string SubObjectT::getObjectFullName(const char *docName) const
{
std::ostringstream ss;
@@ -456,6 +602,43 @@ std::string SubObjectT::getSubObjectFullName(const char *docName) const
return ss.str();
}
PyObject *SubObjectT::getPyObject() const
{
auto obj = getObject();
if (!obj)
return Py::new_reference_to(Py::Object());
if (subname.empty())
return obj->getPyObject();
return Py::new_reference_to(Py::TupleN(
Py::asObject(obj->getPyObject()), Py::String(subname)));
}
void SubObjectT::setPyObject(PyObject *pyobj)
{
try {
if (!pyobj)
throw Base::ValueError("Invalid object");
if (PyObject_TypeCheck(pyobj, &App::DocumentObjectPy::Type)) {
this->operator=(static_cast<App::DocumentObjectPy*>(pyobj)->getDocumentObjectPtr());
return;
} else if (PySequence_Check(pyobj) && PySequence_Size(pyobj)==2) {
Py::Sequence seq(pyobj);
App::DocumentObject *obj;
PropertyString tmp;
if (PyObject_TypeCheck(seq[0].ptr(), &App::DocumentObjectPy::Type)) {
obj = static_cast<App::DocumentObjectPy*>(seq[0].ptr())->getDocumentObjectPtr();
tmp.setPyObject(seq[1].ptr());
this->operator=(App::SubObjectT(obj, tmp.getValue()));
return;
}
}
} catch (Py::Exception &) {
Base::PyException e;
} catch (...) {
}
throw Base::ValueError("Expect either document object or tuple(obj, subname)");
}
// -----------------------------------------------------------------------------
PropertyLinkT::PropertyLinkT()
+48 -4
View File
@@ -118,6 +118,8 @@ public:
void operator=(const Property*);
/*! Equality operator */
bool operator==(const DocumentObjectT&) const;
/*! Less than operator */
bool operator<(const DocumentObjectT &other) const;
/*! Get a pointer to the document or 0 if it doesn't exist any more. */
Document* getDocument() const;
@@ -182,6 +184,14 @@ public:
/*! Constructor */
SubObjectT(const char *docName, const char *objName, const char *subname);
/*! Constructor */
SubObjectT(const std::vector<App::DocumentObject*> & objs, const char *subname = nullptr);
/*! Constructor */
SubObjectT(std::vector<App::DocumentObject*>::const_iterator begin,
std::vector<App::DocumentObject*>::const_iterator end,
const char *subname = nullptr);
/*! Assignment operator */
SubObjectT &operator=(const SubObjectT&);
@@ -219,19 +229,32 @@ public:
* if it is different then the given 'doc'.
*/
std::string getSubObjectFullName(const char *docName=nullptr) const;
/// Return the subname path without sub-element
std::string getSubNameNoElement() const;
std::string getSubNameNoElement(bool withObjName=false) const;
/// Return the sub-element (Face, Edge, etc) of the subname path
const char *getElementName() const;
/// Return the new style sub-element name
std::string getNewElementName() const;
/// Check if there is any sub object reference
bool hasSubObject() const;
/// Check if there is any sub element reference
bool hasSubElement() const;
/** Return the new style sub-element name
*
* @param fallback: if true, then fallback to old style element name if
* there is no new style name.
*/
std::string getNewElementName(bool fallback=true) const;
/** Return the old style sub-element name
* @param index: if given, then return the element type, and extract the index
* @param fallback: if true, then fallback to new style element name if
* there is no old style name.
*/
std::string getOldElementName(int *index=nullptr) const;
std::string getOldElementName(int *index=nullptr, bool fallback=true) const;
/// Return the sub-object
DocumentObject *getSubObject() const;
@@ -241,8 +264,29 @@ public:
bool operator<(const SubObjectT &other) const;
/** Obtain a string to access the sub object using DocumentObject.getSubObject() API
*
* @param force: whether to call getSubObject() even if there is no subname
*/
std::string getSubObjectPython(bool force=true) const;
/** Normalize the subname path to use only the object internal name and old style element name
* @return Return whether the subname has been changed
*/
bool normalize();
/// Return a normalize copy of itself
SubObjectT normalized() const;
/// Return the parent object
SubObjectT getParent() const;
/// Return the child object
SubObjectT getChild(const App::DocumentObject *) const;
PyObject *getPyObject() const;
void setPyObject(PyObject *);
private:
std::string subname;
};
File diff suppressed because it is too large Load Diff
+359
View File
@@ -0,0 +1,359 @@
/****************************************************************************
* Copyright (c) 2022 Zheng Lei (realthunder) <realthunder.dev@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
****************************************************************************/
#ifndef DOCUMENT_PARAMS_H
#define DOCUMENT_PARAMS_H
/*[[[cog
import DocumentParams
DocumentParams.declare()
]]]*/
// Auto generated code (Tools/params_utils.py:68)
#include <Base/Parameter.h>
#include <boost_signals2.hpp>
// Auto generated code (Tools/params_utils.py:74)
namespace App {
/** Convenient class to obtain App::Document related parameters
* The parameters are under group "User parameter:BaseApp/Preferences/Document"
*
* This class is auto generated by App/DocumentParams.py. Modify that file
* instead of this one, if you want to add any parameter. You need
* to install Cog Python package for code generation:
* @code
* pip install cogapp
* @endcode
*
* Once modified, you can regenerate the header and the source file,
* @code
* python3 -m cogapp -r App/DocumentParams.h App/DocumentParams.cpp
* @endcode
*
* You can add a new parameter by adding lines in App/DocumentParams.py. Available
* parameter types are 'Int, UInt, String, Bool, Float'. For example, to add
* a new Int type parameter,
* @code
* ParamInt(parameter_name, default_value, documentation, on_change=False)
* @endcode
*
* If there is special handling on parameter change, pass in on_change=True.
* And you need to provide a function implementation in App/DocumentParams.cpp with
* the following signature.
* @code
* void DocumentParams:on<parameter_name>Changed()
* @endcode
*/
class AppExport DocumentParams {
public:
static ParameterGrp::handle getHandle();
static boost::signals2::signal<void (const char*)> &signalParamChanged();
static void signalAll();
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter prefAuthor
static const std::string & getprefAuthor();
static const std::string & defaultprefAuthor();
static void removeprefAuthor();
static void setprefAuthor(const std::string &v);
static const char *docprefAuthor();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter prefSetAuthorOnSave
static const bool & getprefSetAuthorOnSave();
static const bool & defaultprefSetAuthorOnSave();
static void removeprefSetAuthorOnSave();
static void setprefSetAuthorOnSave(const bool &v);
static const char *docprefSetAuthorOnSave();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter prefCompany
static const std::string & getprefCompany();
static const std::string & defaultprefCompany();
static void removeprefCompany();
static void setprefCompany(const std::string &v);
static const char *docprefCompany();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter prefLicenseType
static const long & getprefLicenseType();
static const long & defaultprefLicenseType();
static void removeprefLicenseType();
static void setprefLicenseType(const long &v);
static const char *docprefLicenseType();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter prefLicenseUrl
static const std::string & getprefLicenseUrl();
static const std::string & defaultprefLicenseUrl();
static void removeprefLicenseUrl();
static void setprefLicenseUrl(const std::string &v);
static const char *docprefLicenseUrl();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter CompressionLevel
static const long & getCompressionLevel();
static const long & defaultCompressionLevel();
static void removeCompressionLevel();
static void setCompressionLevel(const long &v);
static const char *docCompressionLevel();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter CheckExtension
static const bool & getCheckExtension();
static const bool & defaultCheckExtension();
static void removeCheckExtension();
static void setCheckExtension(const bool &v);
static const char *docCheckExtension();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter ForceXML
static const long & getForceXML();
static const long & defaultForceXML();
static void removeForceXML();
static void setForceXML(const long &v);
static const char *docForceXML();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter SplitXML
static const bool & getSplitXML();
static const bool & defaultSplitXML();
static void removeSplitXML();
static void setSplitXML(const bool &v);
static const char *docSplitXML();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter PreferBinary
static const bool & getPreferBinary();
static const bool & defaultPreferBinary();
static void removePreferBinary();
static void setPreferBinary(const bool &v);
static const char *docPreferBinary();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter AutoRemoveFile
static const bool & getAutoRemoveFile();
static const bool & defaultAutoRemoveFile();
static void removeAutoRemoveFile();
static void setAutoRemoveFile(const bool &v);
static const char *docAutoRemoveFile();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter BackupPolicy
static const bool & getBackupPolicy();
static const bool & defaultBackupPolicy();
static void removeBackupPolicy();
static void setBackupPolicy(const bool &v);
static const char *docBackupPolicy();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter CreateBackupFiles
static const bool & getCreateBackupFiles();
static const bool & defaultCreateBackupFiles();
static void removeCreateBackupFiles();
static void setCreateBackupFiles(const bool &v);
static const char *docCreateBackupFiles();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter UseFCBakExtension
static const bool & getUseFCBakExtension();
static const bool & defaultUseFCBakExtension();
static void removeUseFCBakExtension();
static void setUseFCBakExtension(const bool &v);
static const char *docUseFCBakExtension();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter SaveBackupDateFormat
static const std::string & getSaveBackupDateFormat();
static const std::string & defaultSaveBackupDateFormat();
static void removeSaveBackupDateFormat();
static void setSaveBackupDateFormat(const std::string &v);
static const char *docSaveBackupDateFormat();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter CountBackupFiles
static const long & getCountBackupFiles();
static const long & defaultCountBackupFiles();
static void removeCountBackupFiles();
static void setCountBackupFiles(const long &v);
static const char *docCountBackupFiles();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter OptimizeRecompute
static const bool & getOptimizeRecompute();
static const bool & defaultOptimizeRecompute();
static void removeOptimizeRecompute();
static void setOptimizeRecompute(const bool &v);
static const char *docOptimizeRecompute();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter CanAbortRecompute
static const bool & getCanAbortRecompute();
static const bool & defaultCanAbortRecompute();
static void removeCanAbortRecompute();
static void setCanAbortRecompute(const bool &v);
static const char *docCanAbortRecompute();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter UseHasher
static const bool & getUseHasher();
static const bool & defaultUseHasher();
static void removeUseHasher();
static void setUseHasher(const bool &v);
static const char *docUseHasher();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter ViewObjectTransaction
static const bool & getViewObjectTransaction();
static const bool & defaultViewObjectTransaction();
static void removeViewObjectTransaction();
static void setViewObjectTransaction(const bool &v);
static const char *docViewObjectTransaction();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter WarnRecomputeOnRestore
static const bool & getWarnRecomputeOnRestore();
static const bool & defaultWarnRecomputeOnRestore();
static void removeWarnRecomputeOnRestore();
static void setWarnRecomputeOnRestore(const bool &v);
static const char *docWarnRecomputeOnRestore();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter NoPartialLoading
static const bool & getNoPartialLoading();
static const bool & defaultNoPartialLoading();
static void removeNoPartialLoading();
static void setNoPartialLoading(const bool &v);
static const char *docNoPartialLoading();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter ThumbnailNoBackground
static const bool & getThumbnailNoBackground();
static const bool & defaultThumbnailNoBackground();
static void removeThumbnailNoBackground();
static void setThumbnailNoBackground(const bool &v);
static const char *docThumbnailNoBackground();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter ThumbnailSampleSize
static const long & getThumbnailSampleSize();
static const long & defaultThumbnailSampleSize();
static void removeThumbnailSampleSize();
static void setThumbnailSampleSize(const long &v);
static const char *docThumbnailSampleSize();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter DuplicateLabels
static const bool & getDuplicateLabels();
static const bool & defaultDuplicateLabels();
static void removeDuplicateLabels();
static void setDuplicateLabels(const bool &v);
static const char *docDuplicateLabels();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter TransactionOnRecompute
static const bool & getTransactionOnRecompute();
static const bool & defaultTransactionOnRecompute();
static void removeTransactionOnRecompute();
static void setTransactionOnRecompute(const bool &v);
static const char *docTransactionOnRecompute();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter RelativeStringID
static const bool & getRelativeStringID();
static const bool & defaultRelativeStringID();
static void removeRelativeStringID();
static void setRelativeStringID(const bool &v);
static const char *docRelativeStringID();
//@}
// Auto generated code (Tools/params_utils.py:118)
//@{
/// Accessor for parameter EnableMaterialEdit
static const bool & getEnableMaterialEdit();
static const bool & defaultEnableMaterialEdit();
static void removeEnableMaterialEdit();
static void setEnableMaterialEdit(const bool &v);
static const char *docEnableMaterialEdit();
//@}
// Auto generated code (Tools/params_utils.py:146)
}; // class DocumentParams
} // namespace App
//[[[end]]]
#endif // DOCUMENT_PARAMS_H
+63 -1
View File
@@ -132,12 +132,74 @@ public:
return static_cast<ExtensionT*>(getExtension(ExtensionT::getExtensionClassTypeId(),derived,no_except));
}
/** Helpers for iterator over extensions of a given type */
//@{
/** Helper structs to deduce the class type of a class function pointer type */
//@{
template<typename T> struct ClassOf {};
template<typename R, typename C>
struct ClassOf<R (C::*)>{ using type = C; };
//@}
/** Call an extension member function for each extension of the given type
* @param f: the member function pointer of some extension class
* @param args: variadic parameters passed to the member function
*/
template<typename F, class... Args>
void callExtension(F&& f, Args&&... args) const {
for (const auto &entry : _extensions) {
if(entry.first.isDerivedFrom(ClassOf<F>::type::getExtensionClassTypeId()))
(static_cast<typename ClassOf<F>::type*>(entry.second)->*f)(std::forward<Args>(args)...);
}
}
/** Query using an extension member function
* @param f: the member function pointer of some extension class
* @param args: variadic parameters passed to the member function
*
* @return Returns true if the iteratorion is terminated prematurely, or else false.
*
* The iteration over the contained extensions is terminated as soon as the
* extension method call returns true.
*/
template<typename F, class... Args>
bool queryExtension(F&& f, Args&&... args) const {
for (const auto &entry : _extensions) {
if(entry.first.isDerivedFrom(ClassOf<F>::type::getExtensionClassTypeId())) {
if((static_cast<typename ClassOf<F>::type*>(entry.second)->*f)(std::forward<Args>(args)...))
return true;
}
}
return false;
}
/** Invoke a callable for each extension of a given type
* @param f: the callable that accepts one argument of an extension, and
* returns any value that is convertible to boolean.
*
* @return Returns true if the iteratorion is terminated prematurely, or else false.
*
* The iteration over the contained extensions is terminated as soon as the
* extension method call returns true.
*/
template<typename T, typename F>
bool foreachExtension(F f) const {
for (const auto &entry : _extensions) {
if(entry.first.isDerivedFrom(T::getExtensionClassTypeId())) {
if(f(static_cast<T*>(entry.second)))
return true;
}
}
return false;
}
//get all extensions which have the given base class
std::vector<Extension*> getExtensionsDerivedFrom(Base::Type type) const;
template<typename ExtensionT>
std::vector<ExtensionT*> getExtensionsDerivedFromType() const {
std::vector<ExtensionT*> typevec;
for(auto entry : _extensions) {
for (const auto &entry : _extensions) {
if(entry.first.isDerivedFrom(ExtensionT::getExtensionClassTypeId()))
typevec.push_back(static_cast<ExtensionT*>(entry.second));
}
+129 -8
View File
@@ -25,10 +25,15 @@
#include <App/GeoFeaturePy.h>
#include <Base/Console.h>
#include <App/Link.h>
#include "ComplexGeoData.h"
#include "Document.h"
#include "GeoFeature.h"
#include "GeoFeatureGroupExtension.h"
#include "ComplexGeoData.h"
#include "MappedElement.h"
FC_LOG_LEVEL_INIT("GeoFeature",true,true)
using namespace App;
@@ -43,6 +48,8 @@ PROPERTY_SOURCE(App::GeoFeature, App::DocumentObject)
GeoFeature::GeoFeature(void)
{
ADD_PROPERTY_TYPE(Placement,(Base::Placement()),nullptr,Prop_NoRecompute,nullptr);
ADD_PROPERTY_TYPE(_ElementMapVersion,(""),"Base",
(App::PropertyType)(Prop_Output|Prop_Hidden|Prop_Transient),"");
}
GeoFeature::~GeoFeature(void)
@@ -81,16 +88,48 @@ PyObject* GeoFeature::getPyObject(void)
}
std::pair<std::string,std::string> GeoFeature::getElementName(
const char *name, ElementNameType type) const
std::pair<std::string,std::string>
GeoFeature::getElementName(const char *name, ElementNameType type) const
{
(void)type;
std::pair<std::string,std::string> ret;
if(!name)
if(!name)
return ret;
ret.second = name;
auto prop = getPropertyOfGeometry();
if(!prop) return std::make_pair("", name);
auto geo = prop->getComplexData();
if(!geo) return std::make_pair("", name);
return _getElementName(name, geo->getElementName(name));
}
std::pair<std::string,std::string>
GeoFeature::_getElementName(const char *name, const Data::MappedElement &mapped) const
{
std::pair<std::string,std::string> ret;
if (mapped.index && mapped.name) {
std::ostringstream ss;
ss << Data::ComplexGeoData::elementMapPrefix()
<< mapped.name << '.' << mapped.index;
ret.first = ss.str();
mapped.index.toString(ret.second);
} else if (mapped.name) {
FC_TRACE("element mapped name " << name << " not found in " << getFullName());
ret.first = name;
const char *dot = strrchr(name,'.');
if(dot) {
// deliberately mangle the old style element name to signal a
// missing reference
ret.second = Data::ComplexGeoData::missingPrefix();
ret.second += dot+1;
}
} else {
mapped.index.toString(ret.second);
}
return ret;
}
@@ -99,6 +138,8 @@ DocumentObject *GeoFeature::resolveElement(DocumentObject *obj, const char *subn
ElementNameType type, const DocumentObject *filter,
const char **_element, GeoFeature **geoFeature)
{
elementName.first.clear();
elementName.second.clear();
if(!obj || !obj->getNameInDocument())
return nullptr;
if(!subname)
@@ -108,11 +149,16 @@ DocumentObject *GeoFeature::resolveElement(DocumentObject *obj, const char *subn
auto sobj = obj->getSubObject(subname);
if(!sobj)
return nullptr;
obj = sobj->getLinkedObject(true);
auto geo = dynamic_cast<GeoFeature*>(obj);
auto linked = sobj->getLinkedObject(true);
auto geo = Base::freecad_dynamic_cast<GeoFeature>(linked);
if(!geo && linked) {
auto ext = linked->getExtensionByType<LinkBaseExtension>(true);
if(ext)
geo = Base::freecad_dynamic_cast<GeoFeature>(ext->getTrueLinkedObject(true));
}
if(geoFeature)
*geoFeature = geo;
if(!obj || (filter && obj!=filter))
if(filter && geo!=filter)
return nullptr;
if(!element || !element[0]) {
if(append)
@@ -139,3 +185,78 @@ DocumentObject *GeoFeature::resolveElement(DocumentObject *obj, const char *subn
return sobj;
}
bool GeoFeature::hasMissingElement(const char *subname) {
return Data::ComplexGeoData::hasMissingElement(subname);
if(!subname)
return false;
auto dot = strrchr(subname,'.');
if(!dot)
return subname[0]=='?';
return dot[1]=='?';
}
void GeoFeature::updateElementReference() {
auto prop = getPropertyOfGeometry();
if(!prop) return;
auto geo = prop->getComplexData();
if(!geo) return;
bool reset = false;
auto version = getElementMapVersion(prop);
if(_ElementMapVersion.getStrValue().empty())
_ElementMapVersion.setValue(version);
else if(_ElementMapVersion.getStrValue()!=version) {
reset = true;
_ElementMapVersion.setValue(version);
}
PropertyLinkBase::updateElementReferences(this,reset);
}
void GeoFeature::onChanged(const Property *prop) {
if(prop==getPropertyOfGeometry()) {
if(getDocument() && !getDocument()->testStatus(Document::Restoring)
&& !getDocument()->isPerformingTransaction())
{
updateElementReference();
}
}
DocumentObject::onChanged(prop);
}
void GeoFeature::onDocumentRestored() {
if(!getDocument()->testStatus(Document::Status::Importing))
_ElementMapVersion.setValue(getElementMapVersion(getPropertyOfGeometry(),true));
DocumentObject::onDocumentRestored();
}
const std::vector<std::string>&
GeoFeature::searchElementCache(const std::string &element,
bool checkGeometry,
double tol,
double atol) const
{
static std::vector<std::string> none;
(void)element;
(void)checkGeometry;
(void)tol;
(void)atol;
return none;
}
const std::vector<const char *>&
GeoFeature::getElementTypes(bool /*all*/) const
{
static std::vector<const char *> nil;
auto prop = getPropertyOfGeometry();
if (!prop)
return nil;
return prop->getComplexData()->getElementTypes();
}
std::vector<Data::IndexedName>
GeoFeature::getHigherElements(const char *element, bool silent) const
{
auto prop = getPropertyOfGeometry();
if (!prop)
return {};
return prop->getComplexData()->getHigherElements(element, silent);
}
+55 -3
View File
@@ -24,7 +24,9 @@
#ifndef APP_GEOFEATURE_H
#define APP_GEOFEATURE_H
#include <memory>
#include "DocumentObject.h"
#include "MappedElement.h"
#include "PropertyGeo.h"
@@ -40,6 +42,7 @@ class AppExport GeoFeature : public App::DocumentObject
public:
PropertyPlacement Placement;
PropertyString _ElementMapVersion;
/// Constructor
GeoFeature(void);
@@ -80,10 +83,17 @@ public:
* @param name: input name
* @param type: desired element name type to return
*
* @return a pair(newName,oldName). New element name may be empty.
* This function relies on ComplexGeoData::elementMapPrefix() to decide
* whether it is a forward query, i.e. mapped -> original, or reverse
* query. The reason being that, unlike ComplexGeoData who deals with the
* actual element map data, GeoFeature here sits at a higher level.
* GeoFeature should be dealing with whatever various PropertyLinkSub(s) is
* assigned.
*
* This function currently is does nothing. The new style element name
* generation will be added in the next batch of patches.
* This function is made virtual, so that inherited class can do something
* unusual, such as Sketcher::SketcherObject, which uses this to expose its
* private geometries without a corresponding TopoShape, and yet being
* source code compatible.
*/
virtual std::pair<std::string,std::string> getElementName(
const char *name, ElementNameType type=Normal) const;
@@ -107,6 +117,8 @@ public:
bool append=false, ElementNameType type=Normal,
const DocumentObject *filter=nullptr,const char **element=nullptr, GeoFeature **geo=nullptr);
static bool hasMissingElement(const char *subname);
/**
* @brief Calculates the placement in the global reference coordinate system
*
@@ -120,6 +132,46 @@ public:
* @return Base::Placement The transformation from the global reference coordinate system
*/
Base::Placement globalPlacement() const;
/** Search sub element using internal cached geometry
*
* @param element: element name
* @param checkGeometry: search element by comparing geometry
* @param tol: coordinate tolerance
* @param atol: angle tolerance
*
* @return Returns a list of found element reference to the new goemetry.
* The returned value will be invalidated when the geometry is changed.
*
* Before changing the property of geometry, GeoFeature will internally
* make a snapshot of all referenced element geometry. After change, user
* code may call this function to search for the new element name that
* reference to the same geometry of the old element.
*/
virtual const std::vector<std::string>& searchElementCache(const std::string &element,
bool checkGeometry = true,
double tol = 1e-7,
double atol = 1e-10) const;
/// Return the object that owns the shape that contains the give element name
virtual DocumentObject *getElementOwner(const Data::MappedName & /*name*/) const
{return nullptr;}
virtual const std::vector<const char *>& getElementTypes(bool all=true) const;
/// Return the higher level element names of the given element
virtual std::vector<Data::IndexedName> getHigherElements(const char *name, bool silent=false) const;
protected:
virtual void onChanged(const Property* prop);
virtual void onDocumentRestored();
void updateElementReference();
std::pair<std::string,std::string> _getElementName(const char *name, const Data::MappedElement &mapped) const;
private:
std::vector<Data::MappedElement> _elementMapCache;
std::string _elementMapVersion;
};
} //namespace App
+75 -10
View File
@@ -905,7 +905,6 @@ void LinkBaseExtension::monitorOnChangeCopyObjects(
if (getLinkCopyOnChangeValue() == CopyOnChangeDisabled)
return;
for(auto obj : objs) {
obj->setStatus(App::ObjectStatus::TouchOnColorChange, true);
copyOnChangeSrcConns.push_back(obj->signalChanged.connect(
[this](const DocumentObject &, const Property &) {
if (auto prop = this->getLinkCopyOnChangeTouchedProperty()) {
@@ -1012,7 +1011,7 @@ int LinkBaseExtension::extensionSetElementVisible(const char *element, bool visi
return -1;
}
int LinkBaseExtension::extensionIsElementVisible(const char *element) {
int LinkBaseExtension::extensionIsElementVisible(const char *element) const {
int index = _getShowElementValue()?getElementIndex(element):getArrayIndex(element);
if(index>=0) {
auto propElementVis = getVisibilityListProperty();
@@ -1409,12 +1408,21 @@ bool LinkBaseExtension::extensionGetSubObject(DocumentObject *&ret, const char *
void LinkBaseExtension::checkGeoElementMap(const App::DocumentObject *obj,
const App::DocumentObject *linked, PyObject **pyObj, const char *postfix) const
{
if(!pyObj || !*pyObj || (!postfix && obj->getDocument()==linked->getDocument()) ||
!PyObject_TypeCheck(*pyObj, &Data::ComplexGeoDataPy::Type))
if(!pyObj || !*pyObj || !PyObject_TypeCheck(*pyObj, &Data::ComplexGeoDataPy::Type))
return;
// auto geoData = static_cast<Data::ComplexGeoDataPy*>(*pyObj)->getComplexGeoDataPtr();
// geoData->reTagElementMap(obj->getID(),obj->getDocument()->Hasher,postfix);
auto geoData = static_cast<Data::ComplexGeoDataPy*>(*pyObj)->getComplexGeoDataPtr();
std::string _postfix;
if (linked && obj && linked->getDocument() != obj->getDocument()) {
_postfix = Data::ComplexGeoData::externalTagPostfix();
if (postfix) {
if (!boost::starts_with(postfix, Data::ComplexGeoData::elementMapPrefix()))
_postfix += Data::ComplexGeoData::elementMapPrefix();
_postfix += postfix;
}
postfix = _postfix.c_str();
}
geoData->reTagElementMap(obj->getID(),obj->getDocument()->getStringHasher(),postfix);
}
void LinkBaseExtension::onExtendedUnsetupObject() {
@@ -2177,10 +2185,12 @@ void LinkBaseExtension::expandSubname(std::string &subname) const {
}
static bool isExcludedProperties(const char *name) {
#define CHECK_EXCLUDE_PROP(_name) if(strcmp(name,#_name)==0) return true;
CHECK_EXCLUDE_PROP(Shape);
CHECK_EXCLUDE_PROP(Proxy);
CHECK_EXCLUDE_PROP(Placement);
if (boost::equals(name, "Shape"))
return true;
if (boost::equals(name, "Proxy"))
return true;
if (boost::equals(name, "Placement"))
return true;
return false;
}
@@ -2204,6 +2214,61 @@ Property *LinkBaseExtension::extensionGetPropertyByName(const char* name) const
return nullptr;
}
std::vector<std::string> LinkBaseExtension::getHiddenSubnames(
const App::DocumentObject *obj, const char *prefix)
{
std::vector<std::string> res;
if(!obj || !obj->getNameInDocument())
return res;
PropertyLinkSubHidden *prop;
int depth=0;
while((prop=Base::freecad_dynamic_cast<PropertyLinkSubHidden>(
obj->getPropertyByName("ColoredElements"))))
{
for(auto &v : prop->getShadowSubs()) {
if(prefix && !boost::starts_with(v.first,prefix) && !boost::starts_with(v.second,prefix))
continue;
auto &s = v.second;
if(boost::ends_with(s,DocumentObject::hiddenMarker()))
res.push_back(s.substr(0,s.size()-DocumentObject::hiddenMarker().size()));
}
auto o = Base::freecad_dynamic_cast<DocumentObject>(prop->getContainer());
if(!o)
break;
o = o->getLinkedObject(false);
if(o==obj || !GetApplication().checkLinkDepth(++depth,true))
break;
obj = o;
}
return res;
}
bool LinkBaseExtension::isSubnameHidden(const App::DocumentObject *obj, const char *subname)
{
if(!obj || !obj->getNameInDocument() || !subname || !subname[0])
return false;
PropertyLinkSubHidden *prop;
int depth=0;
while((prop=Base::freecad_dynamic_cast<PropertyLinkSubHidden>(
obj->getPropertyByName("ColoredElements"))))
{
for(auto &v : prop->getShadowSubs()) {
if((boost::starts_with(v.first,subname) || boost::starts_with(v.second,subname))
&& boost::ends_with(v.second, DocumentObject::hiddenMarker()))
return true;
}
auto o = Base::freecad_dynamic_cast<DocumentObject>(prop->getContainer());
if(!o)
break;
o = o->getLinkedObject(false);
if(o==obj || !GetApplication().checkLinkDepth(++depth,true))
break;
obj = o;
}
return false;
}
bool LinkBaseExtension::isLinkMutated() const
{
return getLinkCopyOnChangeValue() != CopyOnChangeDisabled
+6 -1
View File
@@ -293,7 +293,7 @@ public:
virtual void onExtendedDocumentRestored() override;
virtual int extensionSetElementVisible(const char *, bool) override;
virtual int extensionIsElementVisible(const char *) override;
virtual int extensionIsElementVisible(const char *) const override;
virtual bool extensionHasChildElement() const override;
virtual PyObject* getExtensionPyObject(void) override;
@@ -304,6 +304,11 @@ public:
int getElementIndex(const char *subname, const char **psubname=nullptr) const;
void elementNameFromIndex(int idx, std::ostream &ss) const;
static std::vector<std::string> getHiddenSubnames(
const App::DocumentObject *obj, const char *prefix=0);
static bool isSubnameHidden(const App::DocumentObject *obj, const char *subname);
DocumentObject *getContainer();
const DocumentObject *getContainer() const;
+258
View File
@@ -0,0 +1,258 @@
/****************************************************************************
* Copyright (c) 2022 Zheng, Lei (realthunder) <realthunder.dev@gmail.com>*
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
****************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <cstdlib>
# include <unordered_set>
#endif
#include <QHash>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/functional/hash.hpp>
#include "DocumentObject.h"
#include "MappedElement.h"
using namespace Data;
struct ByteArray
{
ByteArray(const QByteArray &b)
:bytes(b)
{}
ByteArray(const ByteArray &other)
:bytes(other.bytes)
{}
ByteArray(ByteArray &&other)
:bytes(std::move(other.bytes))
{}
void mutate() const
{
QByteArray copy;
copy.append(bytes.constData(), bytes.size());
bytes = copy;
}
bool operator==(const ByteArray & other) const {
return bytes == other.bytes;
}
mutable QByteArray bytes;
};
struct ByteArrayHasher
{
std::size_t operator()(const ByteArray &bytes) const
{
return qHash(bytes.bytes);
}
std::size_t operator()(const QByteArray &bytes) const
{
return qHash(bytes);
}
};
void IndexedName::set(const char *name,
int len,
const std::vector<const char*> &types,
bool allowOthers)
{
static std::unordered_set<ByteArray, ByteArrayHasher> NameSet;
if (len < 0)
len = static_cast<int>(std::strlen(name));
int i;
for (i=len-1; i>=0; --i) {
if (name[i]<'0' || name[i]>'9')
break;
}
++i;
this->index = std::atoi(name+i);
for (int j=0; j<i; ++j) {
if (name[j] == '_'
|| (name[j] >= 'a' && name[j] <= 'z' )
|| (name[j] >= 'A' && name[j] <= 'Z'))
continue;
this->type = "";
return;
}
for (const char * type : types) {
int j=0;
for (const char *n=name, *t=type; *n; ++n) {
if (*n != *t || j >= i)
break;
++j;
++t;
if (!*t) {
this->type = type;
return;
}
}
}
if (allowOthers) {
auto res = NameSet.insert(QByteArray::fromRawData(name, i));
if (res.second)
res.first->mutate();
this->type = res.first->bytes.constData();
} else
this->type = "";
}
void MappedName::compact() const
{
auto self = const_cast<MappedName*>(this);
if (this->raw) {
self->data = QByteArray(self->data.constData(), self->data.size());
self->raw = false;
}
#if 0
static std::unordered_set<QByteArray, ByteArrayHasher> PostfixSet;
if (this->postfix.size()) {
auto res = PostfixSet.insert(this->postfix);
if (!res.second)
self->postfix = *res.first;
}
#endif
}
bool ElementNameComp::operator()(const MappedName &a, const MappedName &b) const {
size_t size = std::min(a.size(),b.size());
if(!size)
return a.size()<b.size();
size_t i=0;
if(b[0] == '#') {
if(a[0]!='#')
return true;
// If both string starts with '#', compare the following hex digits by
// its integer value.
int res = 0;
for(i=1;i<size;++i) {
unsigned char ac = (unsigned char)a[i];
unsigned char bc = (unsigned char)b[i];
if(std::isxdigit(bc)) {
if(!std::isxdigit(ac))
return true;
if(res==0) {
if(ac<bc)
res = -1;
else if(ac>bc)
res = 1;
}
}else if(std::isxdigit(ac))
return false;
else
break;
}
if(res < 0)
return true;
else if(res > 0)
return false;
for (; i<size; ++i) {
char ac = a[i];
char bc = b[i];
if (ac < bc)
return true;
if (ac > bc)
return false;
}
return a.size()<b.size();
}
else if (a[0] == '#')
return false;
// If the string does not start with '#', compare the non-digits prefix
// using lexical order.
for(i=0;i<size;++i) {
unsigned char ac = (unsigned char)a[i];
unsigned char bc = (unsigned char)b[i];
if(!std::isdigit(bc)) {
if(std::isdigit(ac))
return true;
if(ac<bc)
return true;
if(ac>bc)
return false;
} else if(!std::isdigit(ac)) {
return false;
} else
break;
}
// Then compare the following digits part by integer value
int res = 0;
for(;i<size;++i) {
unsigned char ac = (unsigned char)a[i];
unsigned char bc = (unsigned char)b[i];
if(std::isdigit(bc)) {
if(!std::isdigit(ac))
return true;
if(res==0) {
if(ac<bc)
res = -1;
else if(ac>bc)
res = 1;
}
}else if(std::isdigit(ac))
return false;
else
break;
}
if(res < 0)
return true;
else if(res > 0)
return false;
// Finally, compare the remaining tail using lexical order
for (; i<size; ++i) {
char ac = a[i];
char bc = b[i];
if (ac < bc)
return true;
if (ac > bc)
return false;
}
return a.size()<b.size();
}
HistoryItem::HistoryItem(App::DocumentObject *obj, const Data::MappedName &name)
:obj(obj),tag(0),element(name)
{
if(obj)
tag = obj->getID();
}
const std::string & MappedChildElements::prefix()
{
static std::string _prefix(ComplexGeoData::elementMapPrefix() + ":R");
return _prefix;
}
+847
View File
@@ -0,0 +1,847 @@
/****************************************************************************
* Copyright (c) 2022 Zheng, Lei (realthunder) <realthunder.dev@gmail.com>*
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
****************************************************************************/
#ifndef _AppMappedElement_h_
#define _AppMappedElement_h_
#include <cstring>
#include <memory>
#include <cctype>
#include <boost/algorithm/string/predicate.hpp>
#include <QByteArray>
#include <QHash>
#include "ComplexGeoData.h"
#include "StringHasher.h"
namespace App
{
class DocumentObject;
}
namespace Data
{
class AppExport IndexedName {
public:
explicit IndexedName(const char *name = nullptr, int _index = 0)
: index(0)
{
if (!name)
this->type = "";
else {
set(name);
if (_index)
this->index = _index;
}
}
IndexedName(const char *name,
const std::vector<const char*> & types,
bool allowOthers=true)
{
set(name, -1, types, allowOthers);
}
explicit IndexedName(const QByteArray & data)
{
set(data.constData(), data.size());
}
IndexedName(const IndexedName &other)
: type(other.type), index(other.index)
{}
static IndexedName fromConst(const char *name, int index) {
IndexedName res;
res.type = name;
res.index = index;
return res;
}
IndexedName & operator=(const IndexedName & other)
{
this->index = other.index;
this->type = other.type;
return *this;
}
friend std::ostream & operator<<(std::ostream & s, const IndexedName & e)
{
s << e.type;
if (e.index > 0)
s << e.index;
return s;
}
bool operator==(const IndexedName & other) const
{
return this->index == other.index
&& (this->type == other.type
|| std::strcmp(this->type, other.type)==0);
}
IndexedName & operator+=(int offset)
{
this->index += offset;
assert(this->index >= 0);
return *this;
}
IndexedName & operator++()
{
++this->index;
return *this;
}
IndexedName & operator--()
{
--this->index;
assert(this->index >= 0);
return *this;
}
bool operator!=(const IndexedName & other) const
{
return !(this->operator==(other));
}
const char * toString(std::string & s) const
{
// Note! s is not cleared on purpose.
std::size_t offset = s.size();
s += this->type;
if (this->index > 0)
s += std::to_string(this->index);
return s.c_str() + offset;
}
int compare(const IndexedName & other) const
{
int res = std::strcmp(this->type, other.type);
if (res)
return res;
if (this->index < other.index)
return -1;
if (this->index > other.index)
return 1;
return 0;
}
bool operator<(const IndexedName & other) const
{
return compare(other) < 0;
}
char operator[](int index) const
{
return this->type[index];
}
const char * getType() const { return this->type; }
int getIndex() const { return this->index; }
void setIndex(int index) { assert(index>=0); this->index = index; }
bool isNull() const { return !this->type[0]; }
explicit operator bool() const { return !isNull(); }
protected:
void set(const char *,
int len = -1,
const std::vector<const char *> &types = {},
bool allowOthers = true);
private:
const char * type;
int index;
};
class AppExport MappedName
{
public:
MappedName()
:raw(false)
{}
#if QT_VERSION >= 0x050200
MappedName(MappedName &&other)
:data(std::move(other.data))
,postfix(std::move(other.postfix))
,raw(other.raw)
{}
MappedName & operator=(MappedName &&other)
{
this->data = std::move(other.data);
this->postfix = std::move(other.postfix);
this->raw = other.raw;
return *this;
}
#endif
explicit MappedName(const char * name, int size = -1)
:raw(false)
{
if (!name) return;
if (boost::starts_with(name, ComplexGeoData::elementMapPrefix()))
name += ComplexGeoData::elementMapPrefix().size();
if (size < 0)
data = QByteArray(name);
else
data = QByteArray(name, size);
}
explicit MappedName(const std::string & name)
{
int size = name.size();
const char *n = name.c_str();
if (boost::starts_with(name, ComplexGeoData::elementMapPrefix())) {
n += ComplexGeoData::elementMapPrefix().size();
size -= ComplexGeoData::elementMapPrefix().size();
}
data = QByteArray(n, size);
}
explicit MappedName(const IndexedName & element)
:data(element.getType()), raw(false)
{
if (element.getIndex() > 0)
data += QByteArray::number(element.getIndex());
}
explicit MappedName(const App::StringIDRef & sid)
:raw(false)
{
sid.toBytes(this->data);
}
MappedName(const MappedName & other)
:data(other.data), postfix(other.postfix), raw(other.raw)
{}
MappedName(const MappedName & other, int from, int size = -1)
: raw(false)
{
append(other, from, size);
}
MappedName(const MappedName & other, const char *postfix)
:data(other.data + other.postfix)
,postfix(postfix)
,raw(false)
{}
static MappedName fromRawData(const char * name, int size = -1)
{
MappedName res;
if (name) {
res.data = QByteArray::fromRawData(name,
size>=0 ? size: qstrlen(name));
res.raw = true;
}
return res;
}
static MappedName fromRawData(const QByteArray & data)
{
return fromRawData(data.constData(), data.size());
}
static MappedName fromRawData(const MappedName &other, int from, int size = -1)
{
if (from < 0)
from = 0;
if (from >= other.size())
return MappedName();
if (from >= other.data.size())
return MappedName(other, from, size);
MappedName res;
res.raw = true;
if (size < 0)
size = other.size() - from;
if (size < other.data.size()-from)
res.data = QByteArray::fromRawData(
other.data.constData()+from, size);
else {
res.data = QByteArray::fromRawData(
other.data.constData()+from, other.data.size()-from);
size -= other.data.size() - from;
if (size == other.postfix.size())
res.postfix = other.postfix;
else if (size)
res.postfix.append(other.postfix.constData(), size);
}
return res;
}
MappedName & operator=(const MappedName & other)
{
this->data = other.data;
this->postfix = other.postfix;
this->raw = other.raw;
return *this;
}
MappedName & operator=(const std::string & other)
{
*this = MappedName(other);
return *this;
}
MappedName & operator=(const char * other)
{
*this = MappedName(other);
return *this;
}
friend std::ostream & operator<<(std::ostream & s, const MappedName & n)
{
s.write(n.data.constData(), n.data.size());
s.write(n.postfix.constData(), n.postfix.size());
return s;
}
bool operator==(const MappedName & other) const
{
if (this->size() != other.size())
return false;
if (this->data.size() == other.data.size())
return this->data == other.data && this->postfix == other.postfix;
const auto &a = this->data.size() < other.data.size() ? *this : other;
const auto &b = this->data.size() < other.data.size() ? other: *this;
if (!b.data.startsWith(a.data))
return false;
QByteArray tmp = QByteArray::fromRawData(
b.data.constData() + a.data.size(),
b.data.size() - a.data.size());
if (!a.postfix.startsWith(tmp))
return false;
tmp = QByteArray::fromRawData(
a.postfix.constData() + tmp.size(),
a.postfix.size() - tmp.size());
return tmp == b.postfix;
}
bool operator!=(const MappedName & other) const
{
return !(this->operator==(other));
}
MappedName operator+(const MappedName & other) const
{
MappedName res(*this);
res += other;
return res;
}
MappedName operator+(const char * other) const
{
MappedName res(*this);
res += other;
return res;
}
MappedName operator+(const std::string & other) const
{
MappedName res(*this);
res += other;
return res;
}
MappedName operator+(const QByteArray & other) const
{
MappedName res(*this);
res += other;
return res;
}
MappedName & operator+=(const char * other)
{
if (other && other[0])
this->postfix.append(other, -1);
return *this;
}
MappedName & operator+=(const std::string & other)
{
if (other.size()) {
this->postfix.reserve(this->postfix.size() + other.size());
this->postfix.append(other.c_str(), other.size());
}
return *this;
}
MappedName & operator+=(const QByteArray & other)
{
this->postfix += other;
return *this;
}
MappedName & operator+=(const MappedName & other)
{
append(other);
return *this;
}
void append(const char * d, int size = -1)
{
if (d && size) {
if (size < 0)
size = qstrlen(d);
if (empty())
this->data.append(d, size);
else
this->postfix.append(d, size);
}
}
void append(const MappedName & other, int from = 0, int size = -1)
{
if (from < 0)
from = 0;
else if (from > other.size())
return;
if (size < 0 || size + from > other.size())
size = other.size() - from;
int count = size;
if (from < other.data.size()) {
if (count > other.data.size() - from)
count = other.data.size() - from;
if (from == 0 && count == other.data.size() && this->empty()) {
this->data = other.data;
this->raw = other.raw;
} else
append(other.data.constData() + from, count);
from = 0;
size -= count;
} else
from -= other.data.size();
if (size) {
if (from == 0 && size == other.postfix.size()) {
if (this->empty())
this->data = other.postfix;
else if (this->postfix.isEmpty())
this->postfix = other.postfix;
else
this->postfix += other.postfix;
} else
append(other.postfix.constData() + from, size);
}
}
std::string toString(int from, int len=-1) const
{
std::string res;
return toString(res, from, len);
}
const char * toString(std::string &s, int from=0, int len=-1) const
{
std::size_t offset = s.size();
int count = this->size();
if (from < 0)
from = 0;
else if (from >= count)
return s.c_str()+s.size();
if (len < 0 || len > count - from)
len = count - from;
s.reserve(s.size() + len);
if (from < this->data.size()) {
count = this->data.size() - from;
if (len < count)
count = len;
s.append(this->data.constData()+from, count);
len -= count;
}
s.append(this->postfix.constData(), len);
return s.c_str() + offset;
}
const char * toConstString(int offset, int &size) const
{
if (offset < 0)
offset = 0;
if (offset > this->data.size()) {
offset -= this->data.size();
if (offset > this->postfix.size()) {
size = 0;
return "";
}
size = this->postfix.size() - offset;
return this->postfix.constData() + offset;
}
size = this->data.size() - offset;
return this->data.constData() + offset;
}
QByteArray toRawBytes(int offset=0, int size=-1) const
{
if (offset < 0)
offset = 0;
if (offset >= this->size())
return QByteArray();
if (size < 0 || size > this->size() - offset)
size = this->size() - offset;
if (offset >= this->data.size()) {
offset -= this->data.size();
return QByteArray::fromRawData(this->postfix.constData()+offset, size);
}
if (size <= this->data.size() - offset)
return QByteArray::fromRawData(this->data.constData()+offset, size);
QByteArray res(this->data.constData()+offset, this->data.size()-offset);
res.append(this->postfix.constData(), size - this->data.size() + offset);
return res;
}
const QByteArray & dataBytes() const
{
return this->data;
}
const QByteArray & postfixBytes() const
{
return this->postfix;
}
const char * constPostfix() const
{
return this->postfix.constData();
}
// No constData() because 'data' is allow to contain raw data, which may
// not end with 0.
#if 0
void char * constData() const
{
return this->data.constData();
}
#endif
QByteArray toBytes() const
{
if (this->postfix.isEmpty())
return this->data;
if (this->data.isEmpty())
return this->postfix;
return this->data + this->postfix;
}
IndexedName toIndexedName() const
{
if (this->postfix.isEmpty())
return IndexedName(this->data);
return IndexedName();
}
std::string toPrefixedString() const
{
std::string res;
toPrefixedString(res);
return res;
}
const char *toPrefixedString(std::string &buf) const
{
if (!toIndexedName())
buf += ComplexGeoData::elementMapPrefix();
toString(buf);
return buf.c_str();
}
int compare(const MappedName &other) const
{
int asize = this->size();
int bsize = other.size();
for (int i=0, count=std::min(asize, bsize); i<count; ++i) {
char a = this->operator[](i);
char b = other[i];
if (a < b)
return -1;
if (a > b)
return 1;
}
if (asize < bsize)
return -1;
if (asize > bsize)
return 1;
return 0;
}
bool operator<(const MappedName & other) const
{
return compare(other) < 0;
}
char operator[](int index) const
{
if (index >= this->data.size())
return this->postfix[index - this->data.size()];
return this->data[index];
}
int size() const
{
return this->data.size() + this->postfix.size();
}
bool empty() const
{
return this->data.isEmpty() && this->postfix.isEmpty();
}
bool isRaw() const
{
return this->raw;
}
MappedName copy() const
{
if (!this->raw)
return *this;
MappedName res;
res.data.append(this->data.constData(), this->data.size());
res.postfix = this->postfix;
return res;
}
void compact() const;
explicit operator bool() const
{
return !empty();
}
void clear()
{
this->data.clear();
this->postfix.clear();
this->raw = false;
}
int find(const char *d, int from = 0) const
{
if (!d)
return -1;
if (from < 0)
from = 0;
if (from < this->data.size()) {
int res = this->data.indexOf(d, from);
if (res >= 0)
return res;
from = 0;
} else
from -= this->data.size();
int res = this->postfix.indexOf(d, from);
if (res < 0)
return res;
return res + this->data.size();
}
int find(const std::string &d, int from = 0) const
{
return find(d.c_str(), from);
}
int rfind(const char *d, int from = -1) const
{
if (!d)
return -1;
if (from < 0 || from > this->postfix.size()) {
if (from > postfix.size())
from -= postfix.size();
int res = this->postfix.lastIndexOf(d, from);
if (res >= 0)
return res + this->data.size();
from = -1;
}
return this->data.lastIndexOf(d, from);
}
int rfind(const std::string &d, int from = -1) const
{
return rfind(d.c_str(), from);
}
bool endsWith(const char *s) const
{
if (!s)
return false;
if (this->postfix.size())
return this->postfix.endsWith(s);
return this->data.endsWith(s);
}
bool endsWith(const std::string &s) const
{
return endsWith(s.c_str());
}
bool startsWith(const QByteArray & s, int offset = 0) const
{
if (s.size() > size() - offset)
return false;
if (offset || (this->data.size() && this->data.size() < s.size()))
return toRawBytes(offset, s.size()) == s;
if (this->data.size())
return this->data.startsWith(s);
return this->postfix.startsWith(s);
}
bool startsWith(const char *s, int offset = 0) const
{
if (!s)
return false;
return startsWith(QByteArray::fromRawData(s, qstrlen(s)), offset);
}
bool startsWith(const std::string &s, int offset = 0) const
{
return startsWith(QByteArray::fromRawData(s.c_str(), s.size()), offset);
}
std::size_t hash() const
{
#if QT_VERSION >= 0x050000
return qHash(data, qHash(postfix));
#else
return qHash(data) ^ qHash(postfix);
#endif
}
private:
QByteArray data;
QByteArray postfix;
bool raw;
};
struct AppExport MappedElement
{
IndexedName index;
MappedName name;
MappedElement()
{}
MappedElement(const IndexedName & idx, const MappedName & n)
: index(idx), name(n)
{}
MappedElement(const MappedName & n, const IndexedName & idx)
: index(idx), name(n)
{}
MappedElement(const MappedElement & other)
: index(other.index), name(other.name)
{}
MappedElement(MappedElement && other)
: index(std::move(other.index)), name(std::move(other.name))
{}
MappedElement & operator=(MappedElement && other)
{
this->index = std::move(other.index);
this->name = std::move(other.name);
return *this;
}
MappedElement & operator=(const MappedElement & other)
{
this->index = other.index;
this->name = other.name;
return *this;
}
bool operator==(const MappedElement &other) const
{
return this->index == other.index && this->name == other.name;
}
bool operator!=(const MappedElement &other) const
{
return this->index != other.index || this->name != other.name;
}
bool operator<(const MappedElement &other) const
{
int res = this->index.compare(other.index);
if (res < 0)
return true;
if (res > 0)
return false;
return this->name < other.name;
}
};
struct AppExport HistoryItem {
App::DocumentObject *obj;
long tag;
Data::MappedName element;
Data::IndexedName index;
std::vector<Data::MappedName> intermediates;
HistoryItem(App::DocumentObject *obj, const Data::MappedName &name);
};
struct AppExport ElementNameComp {
/** Comparison function to make topo name more stable
*
* The sorting decompose the name into either of the following two forms
* '#' + hex_digits + tail
* non_digits + digits + tail
*
* The non-digits part is compared lexically, while the digits part is
* compared by its integer value.
*
* The reason for this is to prevent name with bigger digits (usually means
* comes late in history) comes early when sorting.
*/
bool operator()(const MappedName &a, const MappedName &b) const;
};
typedef QVector<App::StringIDRef> ElementIDRefs;
struct AppExport MappedChildElements
{
IndexedName indexedName;
int count;
int offset;
long tag;
ElementMapPtr elementMap;
QByteArray postfix;
ElementIDRefs sids;
static const std::string & prefix();
};
} //namespace Data
#endif
+5 -4
View File
@@ -41,8 +41,8 @@ namespace App {
class XMLMergeReader : public Base::XMLReader
{
public:
XMLMergeReader(std::map<std::string, std::string>& name, const char* FileName, std::istream& str)
: Base::XMLReader(FileName, str), nameMap(name)
XMLMergeReader(std::map<std::string, std::string>& name, Base::Reader &reader)
: Base::XMLReader(reader), nameMap(name)
{}
void addName(const char* s1, const char* s2)
@@ -152,7 +152,8 @@ MergeDocuments::importObjects(std::istream& input)
{
this->nameMap.clear();
this->stream = new zipios::ZipInputStream(input);
XMLMergeReader reader(this->nameMap,"<memory>", *stream);
Base::ZipReader zreader(*this->stream,std::string("<memory>"));
XMLMergeReader reader(this->nameMap, zreader);
reader.setVerbose(isVerbose());
std::vector<App::DocumentObject*> objs = appdoc->importObjects(reader);
@@ -166,7 +167,7 @@ void MergeDocuments::importObject(const std::vector<App::DocumentObject*>& o, Ba
{
objects = o;
Restore(r);
r.readFiles(*this->stream);
r.readFiles();
}
void MergeDocuments::exportObject(const std::vector<App::DocumentObject*>& o, Base::Writer & w)
+52 -14
View File
@@ -28,15 +28,18 @@
#endif
#include <atomic>
#include <Base/Exception.h>
#include <Base/Tools.h>
#include <Base/Writer.h>
#include <CXX/Objects.hxx>
#include "Application.h"
#include "Document.h"
#include "DocumentObject.h"
#include "Property.h"
#include "ObjectIdentifier.h"
#include "PropertyContainer.h"
using namespace App;
@@ -78,17 +81,40 @@ bool Property::isValidName(const char* name)
return name && name[0] != '\0';
}
std::string Property::getFullName() const {
std::string name;
if(myName) {
if(father)
name = father->getFullName() + ".";
void Property::SetRestoreError(const char * msg)
{
if (auto doc = father->getOwnerDocument())
doc->setErrorDescription(this, msg);
}
std::string Property::getFullName(bool python) const {
if(!myName || (python && !father))
return std::string(python?"None":"?");
std::ostringstream ss;
if(father)
ss << father->getFullName(python)
<< '.' << father->getPropertyPrefix();
ss << myName;
return ss.str();
}
std::string Property::getFileName(const char *postfix, const char *prefix) const {
std::ostringstream ss;
if(prefix)
ss << prefix;
if(!myName)
ss << "Property";
else {
std::string name = getFullName();
auto pos = name.find('#');
if(pos == std::string::npos)
ss << name;
else
name = "?.";
name += myName;
}else
return "?";
return name;
ss << (name.c_str()+pos+1);
}
if(postfix)
ss << postfix;
return ss.str();
}
short Property::getType(void) const
@@ -213,10 +239,15 @@ void Property::destroy(Property *p) {
void Property::touch()
{
if(GetApplication().isClosingAll())
return;
PropertyCleaner guard(this);
if (father)
father->onChanged(this);
StatusBits.set(Touched);
if (getName() && father) {
father->onEarlyChange(this);
father->onChanged(this);
}
}
void Property::setReadOnly(bool readOnly)
@@ -291,13 +322,20 @@ void Property::setStatus(Status pos, bool on) {
}
bool Property::isSame(const Property &other) const {
return isSameContent(other);
}
bool Property::isSameContent(const Property &other) const {
if(&other == this)
return true;
if(other.getTypeId() != getTypeId() || getMemSize() != other.getMemSize())
return false;
Base::StringWriter writer,writer2;
FC_STATIC Base::StringWriter writer,writer2;
writer.clear();
Save(writer);
writer2.clear();
other.Save(writer2);
return writer.getString() == writer2.getString();
}
+18 -1
View File
@@ -32,6 +32,10 @@
#include <string>
#include <FCGlobal.h>
// NOTE! define this to static thread_local if FreeCAD ever decides to use
// multi-threading recomputation.
#define FC_STATIC static
namespace Py {
class Object;
}
@@ -132,7 +136,10 @@ public:
*/
static bool isValidName(const char* name);
std::string getFullName() const;
/** Return a fully qualified property name that include its own's name
* @param python: if true, then return an expression for accessing this property in Python
*/
virtual std::string getFullName(bool python=false) const;
/// Get the class name of the associated property editor item
virtual const char* getEditorName(void) const { return ""; }
@@ -251,6 +258,8 @@ public:
/// Compare if this property has the same content as the given one
virtual bool isSame(const Property &other) const;
virtual void SetRestoreError(const char *) override;
/** Return a unique ID for the property
*
* The ID of a property is generated from a monotonically increasing
@@ -261,6 +270,11 @@ public:
*/
int64_t getID() const {return _id;}
/// Compare property by comparing their XML content
bool isSameContent(const Property &other) const;
virtual void beforeSave() const {}
friend class PropertyContainer;
friend struct PropertyData;
friend class DynamicProperty;
@@ -286,6 +300,9 @@ protected:
/// Verify a path for the current property
virtual void verifyPath(const App::ObjectIdentifier & p) const;
/// Return a file name suitable for saving this property
std::string getFileName(const char *postfix=0, const char *prefix=0) const;
private:
// forbidden
Property(const Property&);
+100 -28
View File
@@ -69,15 +69,15 @@ unsigned int PropertyContainer::getMemSize (void) const
App::Property* PropertyContainer::addDynamicProperty(
const char* type, const char* name, const char* group, const char* doc,
short attr, bool ro, bool hidden)
short attr, bool readonly, bool hidden)
{
return dynamicProps.addDynamicProperty(*this,type,name,group,doc,attr,ro,hidden);
return dynamicProps.addDynamicProperty(*this,type,name,group,doc,attr,readonly,hidden);
}
Property *PropertyContainer::getPropertyByName(const char* name) const
{
auto prop = dynamicProps.getDynamicPropertyByName(name);
if(prop)
if(prop)
return prop;
return getPropertyData().getPropertyByName(this,name);
}
@@ -121,7 +121,7 @@ short PropertyContainer::getPropertyType(const char *name) const
const char* PropertyContainer::getPropertyGroup(const Property* prop) const
{
auto group = dynamicProps.getPropertyGroup(prop);
if(group)
if(group)
return group;
return getPropertyData().getGroup(this,prop);
}
@@ -129,7 +129,7 @@ const char* PropertyContainer::getPropertyGroup(const Property* prop) const
const char* PropertyContainer::getPropertyGroup(const char *name) const
{
auto group = dynamicProps.getPropertyGroup(name);
if(group)
if(group)
return group;
return getPropertyData().getGroup(this,name);
}
@@ -137,7 +137,7 @@ const char* PropertyContainer::getPropertyGroup(const char *name) const
const char* PropertyContainer::getPropertyDocumentation(const Property* prop) const
{
auto doc = dynamicProps.getPropertyDocumentation(prop);
if(doc)
if(doc)
return doc;
return getPropertyData().getDocumentation(this,prop);
}
@@ -145,7 +145,7 @@ const char* PropertyContainer::getPropertyDocumentation(const Property* prop) co
const char* PropertyContainer::getPropertyDocumentation(const char *name) const
{
auto doc = dynamicProps.getPropertyDocumentation(name);
if(doc)
if(doc)
return doc;
return getPropertyData().getDocumentation(this,name);
}
@@ -221,15 +221,52 @@ void PropertyContainer::handleChangedPropertyType(XMLReader &reader, const char
PropertyData PropertyContainer::propertyData;
void PropertyContainer::Save (Base::Writer &writer) const
namespace App {
class PropertyContainerP
{
std::map<std::string,Property*> Map;
public:
std::map<std::string, Property*> propertyMap;
std::vector<Property*> transients;
void clear()
{
propertyMap.clear();
transients.clear();
}
};
struct PropertyContainerPGuard
{
PropertyContainerPGuard(PropertyContainerP & priv)
:priv(priv)
{}
~PropertyContainerPGuard()
{
priv.clear();
}
PropertyContainerP & priv;
};
}
void PropertyContainer::beforeSave() const
{
if (!_pimpl)
_pimpl.reset(new PropertyContainerP);
else
_pimpl->clear();
auto & Map = _pimpl->propertyMap;
auto & transients = _pimpl->transients;
getPropertyMap(Map);
std::vector<Property*> transients;
for(auto it=Map.begin();it!=Map.end();) {
auto prop = it->second;
if(prop->testStatus(Property::PropNoPersist)) {
if (prop->getContainer() != this
|| prop->testStatus(Property::PropNoPersist))
{
it = Map.erase(it);
continue;
}
@@ -239,9 +276,22 @@ void PropertyContainer::Save (Base::Writer &writer) const
{
transients.push_back(prop);
it = Map.erase(it);
}else
} else {
prop->beforeSave();
++it;
}
}
}
void PropertyContainer::Save (Base::Writer &writer) const
{
if (!_pimpl || _pimpl->propertyMap.empty())
beforeSave();
PropertyContainerPGuard guard(*_pimpl);
auto & Map = _pimpl->propertyMap;
auto & transients = _pimpl->transients;
writer.incInd(); // indentation for 'Properties Count'
writer.Stream() << writer.ind() << "<Properties Count=\"" << Map.size()
@@ -275,8 +325,8 @@ void PropertyContainer::Save (Base::Writer &writer) const
if(it->second->testStatus(Property::Transient)
|| it->second->getType() & Prop_Transient)
{
writer.Stream() << "</Property>\n";
writer.decInd();
writer.Stream() << "</Property>" << std::endl;
continue;
}
@@ -326,14 +376,21 @@ void PropertyContainer::Restore(Base::XMLReader &reader)
reader.readElement("_Property");
Property* prop = getPropertyByName(reader.getAttribute("name"));
if(prop)
FC_TRACE("restore transient '" << prop->getName() << "'");
if(prop && reader.hasAttribute("status"))
prop->setStatusValue(reader.getAttributeAsUnsigned("status"));
FC_TRACE("restore transient '" << prop->getFullName() << "'");
if(prop && reader.hasAttribute("status")) {
decltype(Property::StatusBits) status(reader.getAttributeAsUnsigned("status"));
status.reset(Property::User1);
status.reset(Property::User2);
status.reset(Property::User3);
prop->setStatusValue(status.to_ulong());
}
}
for (int i=0 ;i<Cnt ;i++) {
reader.readElement("Property");
int guard;
reader.readElement("Property",&guard);
std::string PropName = reader.getAttribute("name");
Base::ReaderContext rctx(PropName);
std::string TypeName = reader.getAttribute("type");
// NOTE: We must also check the type of the current property because a
// subclass of PropertyContainer might change the type of a property but
@@ -346,7 +403,13 @@ void PropertyContainer::Restore(Base::XMLReader &reader)
decltype(Property::StatusBits) status;
if(reader.hasAttribute("status")) {
status = decltype(status)(reader.getAttributeAsUnsigned("status"));
status = decltype(Property::StatusBits)(reader.getAttributeAsUnsigned("status"));
// User1~3 are currently reserved for various temporary usage.
// To avoid some potential problems, no persistence at the moment.
status.reset(Property::User1);
status.reset(Property::User2);
status.reset(Property::User3);
if(prop)
prop->setStatusValue(status.to_ulong());
}
@@ -357,10 +420,10 @@ void PropertyContainer::Restore(Base::XMLReader &reader)
&& !status.test(Property::PropTransient)
&& !prop->testStatus(Property::PropTransient))
{
FC_TRACE("restore property '" << prop->getName() << "'");
FC_TRACE("restoring property " << prop->getFullName());
prop->Restore(reader);
}else
FC_TRACE("skip transient '" << prop->getName() << "'");
FC_TRACE("skip transient " << prop->getFullName());
}
// name matches but not the type
else if (prop) {
@@ -377,29 +440,38 @@ void PropertyContainer::Restore(Base::XMLReader &reader)
reader.clearPartialRestoreProperty();
}
}
catch (const Base::XMLParseException&) {
catch (Base::XMLParseException &e) {
FC_ERR(e.what() << " while parsing " << getFullName() << '.' << PropName);
e.setReported(true);
throw; // re-throw
}
catch (const Base::RestoreError &) {
catch (const Base::RestoreError &e) {
e.ReportException();
reader.setPartialRestore(true);
reader.clearPartialRestoreProperty();
Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName.c_str(),TypeName.c_str());
FC_ERR(getFullName() << '.' << PropName << " (" << TypeName
<< "): was subject to a partial restore.");
}
catch (const Base::Exception &e) {
Base::Console().Error("%s\n", e.what());
e.ReportException();
FC_ERR(getFullName() << '.' << PropName << " (" << TypeName
<< ") restore error.");
}
catch (const std::exception &e) {
Base::Console().Error("%s\n", e.what());
FC_ERR(getFullName() << '.' << PropName << " (" << TypeName
<< ") restore error: " << e.what());
}
catch (const char* e) {
Base::Console().Error("%s\n", e);
FC_ERR(getFullName() << '.' << PropName << " (" << TypeName
<< ") restore error: " << e);
}
#ifndef FC_DEBUG
catch (...) {
Base::Console().Error("PropertyContainer::Restore: Unknown C++ exception thrown\n");
FC_ERR(getFullName() << '.' << PropName << " (" << TypeName
<< ") restore error: Unknown C++ exception thrown\n");
}
#endif
reader.readEndElement("Property");
reader.readEndElement("Property",&guard);
}
reader.readEndElement("Properties");
}
+25 -4
View File
@@ -40,6 +40,7 @@ namespace App
class Property;
class PropertyContainer;
class DocumentObject;
class Document;
class Extension;
enum PropertyType
@@ -135,6 +136,7 @@ struct AppExport PropertyData
void split(PropertyData *other);
};
class PropertyContainerP;
/** Base class of all classes with properties
*/
@@ -158,7 +160,17 @@ public:
virtual unsigned int getMemSize (void) const;
virtual std::string getFullName() const {return std::string();}
/** Return a fully qualified name for this container
* @param python: if true, then return an expression for accessing this container in Python
*/
virtual std::string getFullName(bool python=false) const {
(void)python;
return std::string();
}
/// Return owner document of this container
virtual App::Document *getOwnerDocument() const
{return nullptr;}
/// find a property by its name
virtual Property *getPropertyByName(const char* name) const;
@@ -196,7 +208,7 @@ public:
virtual App::Property* addDynamicProperty(
const char* type, const char* name=nullptr,
const char* group=nullptr, const char* doc=nullptr,
short attr=0, bool ro=false, bool hidden=false);
short attr=0, bool readonly=false, bool hidden=false);
DynamicProperty::PropData getDynamicPropertyData(const Property* prop) const {
return dynamicProps.getDynamicPropertyData(prop);
@@ -220,6 +232,7 @@ public:
virtual void Save (Base::Writer &writer) const;
virtual void Restore(Base::XMLReader &reader);
virtual void beforeSave() const;
virtual void editProperty(const char * /*propName*/) {}
@@ -236,6 +249,11 @@ public:
protected:
/** get called by the container when a property has changed
*
* This function is called before onChanged()
*/
virtual void onEarlyChange(const Property* /*prop*/){}
/// get called by the container when a property has changed
virtual void onChanged(const Property* /*prop*/){}
/// get called before the value is changed
@@ -256,9 +274,12 @@ private:
protected:
DynamicProperty dynamicProps;
private:
private:
std::string _propertyPrefix;
static PropertyData propertyData;
static PropertyData propertyData;
mutable std::unique_ptr<PropertyContainerP> _pimpl;
};
/// Property define
+9 -18
View File
@@ -354,19 +354,17 @@ void PropertyFileIncluded::Save (Base::Writer &writer) const
_cValue = fi.filePath();
}
if (writer.isForceXML()) {
if (writer.isForceXML()>3) {
if (!_cValue.empty()) {
Base::FileInfo file(_cValue.c_str());
writer.Stream() << writer.ind() << "<FileIncluded data=\""
<< file.fileName() << "\">" << std::endl;
<< encodeAttribute(file.fileName()) << "\">\n";
// write the file in the XML stream
writer.incInd();
writer.insertBinFile(_cValue.c_str());
writer.decInd();
writer.Stream() << writer.ind() <<"</FileIncluded>" << endl;
writer.Stream() << writer.ind() <<"</FileIncluded>\n";
}
else {
writer.Stream() << writer.ind() << "<FileIncluded data=\"\"/>" << std::endl;
writer.Stream() << writer.ind() << "<FileIncluded data=\"\"/>\n";
}
}
else {
@@ -406,7 +404,7 @@ void PropertyFileIncluded::Restore(Base::XMLReader &reader)
// is in the document transient path
aboutToSetValue();
_cValue = getDocTransientPath() + "/" + file;
reader.readBinFile(_cValue.c_str());
reader.readCharacters(_cValue.c_str(),true);
reader.readEndElement("FileIncluded");
_BaseFileName = file;
// set read-only after restoring the file
@@ -427,12 +425,7 @@ void PropertyFileIncluded::SaveDocFile (Base::Writer &writer) const
throw Base::FileSystemError(str.str());
}
// copy plain data
unsigned char c;
std::ostream& to = writer.Stream();
while (from.get((char&)c)) {
to.put((char)c);
}
writer.Stream() << from.rdbuf();
}
void PropertyFileIncluded::RestoreDocFile(Base::Reader &reader)
@@ -443,7 +436,7 @@ void PropertyFileIncluded::RestoreDocFile(Base::Reader &reader)
// same file of another object (e.g. for copy&paste of objects inside the same document).
return;
}
Base::ofstream to(fi, std::ios::out | std::ios::binary);
Base::ofstream to(fi, std::ios::out | std::ios::binary | std::ios::trunc);
if (!to) {
std::stringstream str;
str << "PropertyFileIncluded::RestoreDocFile(): "
@@ -453,10 +446,8 @@ void PropertyFileIncluded::RestoreDocFile(Base::Reader &reader)
// copy plain data
aboutToSetValue();
unsigned char c;
while (reader.get((char&)c)) {
to.put((char)c);
}
reader >> to.rdbuf();
to.close();
// set read-only after restoring the file
+59 -3
View File
@@ -23,19 +23,30 @@
#include "PreCompiled.h"
#include <Base/MatrixPy.h>
#include <Base/PlacementPy.h>
#include <Base/Reader.h>
#ifndef _PreComp_
# include <assert.h>
#endif
#include <boost/algorithm/string/predicate.hpp>
/// Here the FreeCAD includes sorted by Base,App,Gui......
#include <Base/Exception.h>
#include <Base/MatrixPy.h>
#include <Base/Reader.h>
#include <Base/PlacementPy.h>
#include <Base/Quantity.h>
#include <Base/QuantityPy.h>
#include <Base/Rotation.h>
#include <Base/RotationPy.h>
#include <Base/Stream.h>
#include <Base/Tools.h>
#include <Base/Writer.h>
#include <Base/VectorPy.h>
#include <Base/Writer.h>
#include "Document.h"
#include "DocumentObject.h"
#include "PropertyGeo.h"
#include "Placement.h"
#include "ObjectIdentifier.h"
@@ -1136,3 +1147,48 @@ PropertyComplexGeoData::~PropertyComplexGeoData()
{
}
std::string PropertyComplexGeoData::getElementMapVersion(bool) const {
auto data = getComplexData();
if(!data)
return std::string();
auto owner = Base::freecad_dynamic_cast<DocumentObject>(getContainer());
std::ostringstream ss;
if(owner && owner->getDocument()
&& owner->getDocument()->getStringHasher()==data->Hasher)
ss << "1.";
else
ss << "0.";
ss << data->getElementMapVersion();
return ss.str();
}
bool PropertyComplexGeoData::checkElementMapVersion(const char * ver) const
{
auto data = getComplexData();
if(!data)
return false;
auto owner = Base::freecad_dynamic_cast<DocumentObject>(getContainer());
std::ostringstream ss;
const char *prefix;
if(owner && owner->getDocument()
&& owner->getDocument()->getStringHasher() == data->Hasher)
prefix = "1.";
else
prefix = "0.";
if (!boost::starts_with(ver, prefix))
return true;
return data->checkElementMapVersion(ver+2);
}
void PropertyComplexGeoData::afterRestore()
{
auto data = getComplexData();
if (data && data->isRestoreFailed()) {
data->resetRestoreFailure();
auto owner = Base::freecad_dynamic_cast<DocumentObject>(getContainer());
if (owner && owner->getDocument() && !owner->getDocument()->testStatus(App::Document::PartialDoc))
owner->getDocument()->addRecomputeObject(owner);
}
PropertyGeometry::afterRestore();
}
+12
View File
@@ -541,6 +541,18 @@ public:
virtual const Data::ComplexGeoData* getComplexData() const = 0;
virtual Base::BoundBox3d getBoundingBox() const = 0;
//@}
/** Return the element map version
*
* @param persisted: if true, return the restored element map version. Or
* else, return the current element map version
*/
virtual std::string getElementMapVersion(bool restored=false) const;
/// Return true to signal element map version change
virtual bool checkElementMapVersion(const char * ver) const;
virtual void afterRestore();
};
} // namespace App
+353 -116
View File
@@ -26,21 +26,28 @@
#include <QDir>
#include <QFileInfo>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/iostreams/device/array.hpp>
#include <boost/iostreams/stream.hpp>
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Reader.h>
#include <Base/Writer.h>
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Tools.h>
#include "PropertyLinks.h"
#include "Application.h"
#include "Document.h"
#include "DocumentObject.h"
#include "DocumentObjectPy.h"
#include "DocumentObserver.h"
#include "GeoFeature.h"
#include "ObjectIdentifier.h"
FC_LOG_LEVEL_INIT("PropertyLinks",true,true)
FC_LOG_LEVEL_INIT("App",true,true)
using namespace App;
using namespace Base;
@@ -55,6 +62,9 @@ namespace bp = boost::placeholders;
TYPESYSTEM_SOURCE_ABSTRACT(App::PropertyLinkBase , App::Property)
static std::unordered_map<std::string, std::set<PropertyLinkBase*> > _LabelMap;
static std::unordered_map<App::DocumentObject *, std::unordered_set<PropertyLinkBase*> > _ElementRefMap;
PropertyLinkBase::PropertyLinkBase()
{}
@@ -67,6 +77,11 @@ void PropertyLinkBase::setAllowExternal(bool allow) {
setFlag(LinkAllowExternal,allow);
}
void PropertyLinkBase::setReturnNewElement(bool enable)
{
setFlag(LinkNewElement, enable);
}
void PropertyLinkBase::hasSetValue() {
auto owner = dynamic_cast<DocumentObject*>(getContainer());
if(owner)
@@ -98,6 +113,15 @@ bool PropertyLinkBase::isSame(const Property &other) const
}
void PropertyLinkBase::unregisterElementReference() {
for(auto obj : _ElementRefs) {
auto it = _ElementRefMap.find(obj);
if(it != _ElementRefMap.end()) {
it->second.erase(this);
if(it->second.empty())
_ElementRefMap.erase(it);
}
}
_ElementRefs.clear();
}
void PropertyLinkBase::unregisterLabelReferences()
@@ -202,39 +226,76 @@ static std::string propertyName(const Property *prop) {
return prop->getFullName();
}
std::vector<App::SubObjectT>
PropertyLinkBase::linkedElementsT(bool all) const
{
std::vector<App::DocumentObject*> objs;
std::vector<std::string> subs;
getLinks(objs,all,&subs,true);
std::vector<App::SubObjectT> res;
res.reserve(objs.size());
assert(objs.size() == subs.size());
for (unsigned i=0; i<objs.size(); ++i)
res.emplace_back(objs[i], subs[i].c_str());
return res;
}
const std::unordered_set<PropertyLinkBase*>&
PropertyLinkBase::getElementReferences(DocumentObject *feature)
{
static std::unordered_set<PropertyLinkBase*> none;
auto it = _ElementRefMap.find(feature);
if(it == _ElementRefMap.end())
return none;
return it->second;
}
void PropertyLinkBase::updateElementReferences(DocumentObject *feature, bool reverse) {
(void)feature;
(void)reverse;
if(!feature || !feature->getNameInDocument())
return;
auto it = _ElementRefMap.find(feature);
if(it == _ElementRefMap.end())
return;
std::vector<PropertyLinkBase*> props;
props.reserve(it->second.size());
props.insert(props.end(),it->second.begin(),it->second.end());
for(auto prop : props) {
if(prop->getContainer()) {
try {
prop->updateElementReference(feature,reverse,true);
}catch(Base::Exception &e) {
e.ReportException();
FC_ERR("Failed to update element reference of " << propertyName(prop));
}catch(std::exception &e) {
FC_ERR("Failed to update element reference of " << propertyName(prop)
<< ": " << e.what());
}
}
}
}
void PropertyLinkBase::_registerElementReference(App::DocumentObject *obj, std::string &sub, ShadowSub &shadow)
{
(void)obj;
(void)sub;
(void)shadow;
if(!obj || !obj->getNameInDocument() || sub.empty())
return;
if(shadow.first.empty()) {
_updateElementReference(0,obj,sub,shadow,false);
return;
}
GeoFeature *geo = 0;
const char *element = 0;
std::pair<std::string, std::string> elementName;
GeoFeature::resolveElement(obj,sub.c_str(), elementName,true,
GeoFeature::ElementNameType::Export,0,&element,&geo);
if(!geo || !element || !element[0])
return;
if(_ElementRefs.insert(geo).second)
_ElementRefMap[geo].insert(this);
}
class StringGuard {
public:
StringGuard(char *c)
:c(c)
{
v1 = c[0];
v2 = c[1];
c[0] = '.';
c[1] = 0;
}
~StringGuard()
{
c[0] = v1;
c[1] = v2;
}
char *c;
char v1;
char v2;
};
void PropertyLinkBase::restoreLabelReference(const DocumentObject *obj,
std::string &subname, ShadowSub *shadow)
{
@@ -276,12 +337,139 @@ bool PropertyLinkBase::_updateElementReference(DocumentObject *feature,
App::DocumentObject *obj, std::string &sub, ShadowSub &shadow,
bool reverse, bool notify)
{
(void)feature;
(void)obj;
(void)reverse;
(void)notify;
shadow.second = sub;
return false;
if(!obj || !obj->getNameInDocument()) return false;
ShadowSub elementName;
const char *subname;
if(shadow.first.size())
subname = shadow.first.c_str();
else if(shadow.second.size())
subname = shadow.second.c_str();
else
subname = sub.c_str();
GeoFeature *geo = 0;
const char *element=0;
auto ret = GeoFeature::resolveElement(obj,subname, elementName,true,
GeoFeature::ElementNameType::Export,feature,&element,&geo);
if(!ret || !geo || !element || !element[0]) {
if(elementName.second.size())
shadow.second.swap(elementName.second);
return false;
}
if(_ElementRefs.insert(geo).second)
_ElementRefMap[geo].insert(this);
if (!reverse) {
if (elementName.first.empty()) {
shadow.second.swap(elementName.second);
return false;
}
if(shadow==elementName)
return false;
}
bool missing = GeoFeature::hasMissingElement(elementName.second.c_str());
if (feature == geo && (missing || reverse)) {
// If the referenced element is missing, or we are generating element
// map for the first time, or we are re-generating the element map due
// to version change, i.e. 'reverse', try search by geometry first
const char *oldElement = Data::ComplexGeoData::findElementName(shadow.second.c_str());
if(!Data::ComplexGeoData::hasMissingElement(oldElement)) {
const auto &names = geo->searchElementCache(oldElement);
if(names.size()) {
missing = false;
std::string newsub(subname, strlen(subname) - strlen(element));
newsub += names.front();
GeoFeature::resolveElement(obj, newsub.c_str(), elementName,true,
GeoFeature::ElementNameType::Export,feature);
const auto &oldSub = shadow.first.size()?shadow.first:shadow.second;
const auto &newSub = elementName.first.size()?elementName.first:elementName.second;
if (oldSub != newSub) {
FC_WARN(propertyName(this)
<< " auto change element reference " << ret->getFullName() << " "
<< oldSub << " -> " << newSub);
}
}
// Note: the following code proves to be too risky. There is no way
// (so far) to ensure the recompute do not change the geometry. If
// the geometry does remain the same, the above geometry search
// should be able to find the new reference any way!
#if 0
else if (missing && reverse && shadow.first.size()) {
// reverse means we are trying to either generate the element
// name for the first time, or upgrade to a new map version. In
// case of upgrading, we still consult the original mapped name
// in first try. Here means the first try failed, and the
// geometry search cannot find any match, so we try the
// non-mapped name as a last resort.
//
// WARNING! We are assuming the recomputation is done with no
// actual property change, and the resulting geometry remains
// the same. If this condition is not met, the result may be
// undesirable. TODO: find a way to ensure this condition.
GeoFeature::resolveElement(obj, shadow.second.c_str(), elementName, true,
GeoFeature::ElementNameType::Export,feature);
if(!elementName.second.empty()) {
missing = Data::ComplexGeoData::hasMissingElement(elementName.second.c_str());
if (!missing) {
FC_WARN(propertyName(this)
<< " element reference changed " << ret->getFullName() << " "
<< shadow.first << " -> " << elementName.first);
}
}
}
#endif
}
}
if(notify)
aboutToSetValue();
if(missing) {
FC_WARN(propertyName(this)
<< " missing element reference " << ret->getFullName() << " "
<< (elementName.first.size()?elementName.first:elementName.second));
shadow.second.swap(elementName.second);
} else {
FC_TRACE(propertyName(this)
<< " element reference shadow update " << ret->getFullName() << " "
<< shadow.first << " -> " << elementName.first);
shadow.swap(elementName);
if(shadow.first.size() && Data::ComplexGeoData::hasMappedElementName(sub.c_str()))
sub = shadow.first;
}
if(reverse) {
if(shadow.first.size() && Data::ComplexGeoData::hasMappedElementName(sub.c_str()))
sub = shadow.first;
else
sub = shadow.second;
return true;
}
if (missing) {
if (sub != shadow.first)
sub = shadow.second;
return true;
}
auto pos2 = shadow.first.rfind('.');
if(pos2 == std::string::npos)
return true;
++pos2;
auto pos = sub.rfind('.');
if(pos == std::string::npos)
pos = 0;
else
++pos;
if(pos==pos2) {
if(sub.compare(pos,sub.size()-pos,&shadow.first[pos2])!=0) {
FC_LOG("element reference update " << sub << " -> " << shadow.first);
sub.replace(pos,sub.size()-pos,&shadow.first[pos2]);
}
} else if(sub!=shadow.second) {
FC_LOG("element reference update " << sub << " -> " << shadow.second);
sub = shadow.second;
}
return true;
}
std::pair<DocumentObject*, std::string>
@@ -290,6 +478,8 @@ PropertyLinkBase::tryReplaceLink(const PropertyContainer *owner, DocumentObject
{
std::pair<DocumentObject*, std::string> res;
res.first = 0;
if (!obj)
return res;
if(oldObj == obj) {
if(owner == parent) {
@@ -309,6 +499,11 @@ PropertyLinkBase::tryReplaceLink(const PropertyContainer *owner, DocumentObject
return res;
}
return res;
} else if (newObj == obj) {
// This means the new object is already sub-object of this parent
// (consider a case of swapping the tool and base object of the Cut
// feature). We'll swap the old and new object.
return tryReplaceLink(owner, obj, parent, newObj, oldObj, subname);
}
if(!subname || !subname[0])
return res;
@@ -319,6 +514,8 @@ PropertyLinkBase::tryReplaceLink(const PropertyContainer *owner, DocumentObject
for(auto pos=sub.find('.');pos!=std::string::npos;pos=sub.find('.',pos)) {
++pos;
char c = sub[pos];
if (c == '.')
continue;
sub[pos] = 0;
auto sobj = obj->getSubObject(sub.c_str());
sub[pos] = c;
@@ -343,6 +540,8 @@ PropertyLinkBase::tryReplaceLink(const PropertyContainer *owner, DocumentObject
return res;
}
break;
}else if(sobj == newObj) {
return tryReplaceLink(owner, obj, parent, newObj, oldObj, subname);
}else if(prev == parent)
break;
prev = sobj;
@@ -358,6 +557,8 @@ PropertyLinkBase::tryReplaceLinkSubs(const PropertyContainer *owner,
{
std::pair<DocumentObject*,std::vector<std::string> > res;
res.first = 0;
if (!obj)
return res;
auto r = tryReplaceLink(owner,obj,parent,oldObj,newObj);
if(r.first) {
@@ -917,7 +1118,7 @@ TYPESYSTEM_SOURCE(App::PropertyLinkSubHidden, App::PropertyLinkSub)
PropertyLinkSub::PropertyLinkSub()
: _pcLinkSub(nullptr), _restoreLabel(false)
: _pcLinkSub(nullptr)
{
}
@@ -974,9 +1175,10 @@ void PropertyLinkSub::setValue(App::DocumentObject * lValue,
#endif
_pcLinkSub=lValue;
_cSubList=std::move(subs);
if(shadows.size()==_cSubList.size())
if(shadows.size()==_cSubList.size()) {
_ShadowSubList = std::move(shadows);
else
onContainerRestored(); // re-register element references
} else
updateElementReference(nullptr);
checkLabelReferences(_cSubList);
hasSetValue();
@@ -993,13 +1195,22 @@ const std::vector<std::string>& PropertyLinkSub::getSubValues(void) const
}
static inline const std::string &getSubNameWithStyle(const std::string &subName,
const PropertyLinkBase::ShadowSub &shadow, bool newStyle)
const PropertyLinkBase::ShadowSub &shadow, bool newStyle, std::string &tmp)
{
if(!newStyle) {
if(shadow.second.size())
return shadow.second;
}else if(shadow.first.size())
}else if(shadow.first.size()) {
if (Data::ComplexGeoData::hasMissingElement(shadow.second.c_str())) {
auto pos = shadow.first.rfind('.');
if (pos != std::string::npos) {
tmp = shadow.first.substr(0, pos+1);
tmp += shadow.second;
return tmp;
}
}
return shadow.first;
}
return subName;
}
@@ -1007,20 +1218,24 @@ std::vector<std::string> PropertyLinkSub::getSubValues(bool newStyle) const {
assert(_cSubList.size() == _ShadowSubList.size());
std::vector<std::string> ret;
ret.reserve(_cSubList.size());
std::string tmp;
for(size_t i=0;i<_ShadowSubList.size();++i)
ret.push_back(getSubNameWithStyle(_cSubList[i],_ShadowSubList[i],newStyle));
ret.push_back(getSubNameWithStyle(_cSubList[i],_ShadowSubList[i],newStyle,tmp));
return ret;
}
std::vector<std::string> PropertyLinkSub::getSubValuesStartsWith(const char* starter, bool newStyle) const
{
(void)newStyle;
std::vector<std::string> temp;
for(std::vector<std::string>::const_iterator it=_cSubList.begin();it!=_cSubList.end();++it)
if(strncmp(starter,it->c_str(),strlen(starter))==0)
temp.push_back(*it);
return temp;
assert(_cSubList.size() == _ShadowSubList.size());
std::vector<std::string> ret;
std::string tmp;
for(size_t i=0;i<_ShadowSubList.size();++i) {
const auto &sub = getSubNameWithStyle(_cSubList[i],_ShadowSubList[i],newStyle,tmp);
auto element = Data::ComplexGeoData::findElementName(sub.c_str());
if(element && boost::starts_with(element,starter))
ret.emplace_back(element);
}
return ret;
}
App::DocumentObject * PropertyLinkSub::getValue(Base::Type t) const
@@ -1035,8 +1250,9 @@ PyObject *PropertyLinkSub::getPyObject(void)
if (_pcLinkSub) {
_pcLinkSub->getPyObject();
tup[0] = Py::asObject(_pcLinkSub->getPyObject());
for(unsigned int i = 0;i<_cSubList.size(); i++)
list[i] = Py::String(_cSubList[i]);
int i = 0;
for (auto &sub : getSubValues(testFlag(LinkNewElement)))
list[i++] = Py::String(sub);
tup[1] = list;
return Py::new_reference_to(tup);
}
@@ -1309,12 +1525,9 @@ std::string PropertyLinkBase::tryImportSubName(const App::DocumentObject *obj, c
return std::string();
}
#define ATTR_SHADOWED "shadowed"
#define ATTR_SHADOW "shadow"
#define ATTR_MAPPED "mapped"
// We do not have topo naming yet, ignore shadow sub for now
#define IGNORE_SHADOW true
static const char *AttrShadowed = "shadowed";
static const char *AttrShadow = "shadow";
static const char *AttrMapped = "mapped";
void PropertyLinkSub::Save (Base::Writer &writer) const
{
@@ -1327,7 +1540,7 @@ void PropertyLinkSub::Save (Base::Writer &writer) const
internal_name = _pcLinkSub->getExportName();
writer.Stream() << writer.ind() << "<LinkSub value=\""
<< internal_name <<"\" count=\"" << _cSubList.size();
writer.Stream() << "\">" << std::endl;
writer.Stream() << "\">\n";
writer.incInd();
auto owner = dynamic_cast<DocumentObject*>(getContainer());
bool exporting = owner && owner->isExporting();
@@ -1342,18 +1555,18 @@ void PropertyLinkSub::Save (Base::Writer &writer) const
std::string exportName;
writer.Stream() << encodeAttribute(exportSubName(exportName,_pcLinkSub,sub.c_str()));
if(shadow.second.size() && shadow.first == _cSubList[i])
writer.Stream() << "\" " ATTR_MAPPED "=\"1";
writer.Stream() << "\" " << AttrMapped << "=\"1";
} else {
writer.Stream() << encodeAttribute(sub);
if(_cSubList[i].size()) {
if(sub!=_cSubList[i]) {
// Stores the actual value that is shadowed. For new version FC,
// we will restore this shadowed value instead.
writer.Stream() << "\" " ATTR_SHADOWED "=\"" << encodeAttribute(_cSubList[i]);
writer.Stream() << "\" " << AttrShadowed << "=\"" << encodeAttribute(_cSubList[i]);
}else if(shadow.first.size()){
// Here means the user set value is old style element name.
// We shall then store the shadow somewhere else.
writer.Stream() << "\" " ATTR_SHADOW "=\"" << encodeAttribute(shadow.first);
writer.Stream() << "\" " << AttrShadow << "=\"" << encodeAttribute(shadow.first);
}
}
}
@@ -1394,15 +1607,15 @@ void PropertyLinkSub::Restore(Base::XMLReader &reader)
for (int i = 0; i < count; i++) {
reader.readElement("Sub");
shadows[i].second = importSubName(reader,reader.getAttribute("value"),restoreLabel);
if(reader.hasAttribute(ATTR_SHADOWED) && !IGNORE_SHADOW) {
if(reader.hasAttribute(AttrShadowed)) {
values[i] = shadows[i].first =
importSubName(reader,reader.getAttribute(ATTR_SHADOWED),restoreLabel);
importSubName(reader,reader.getAttribute(AttrShadowed),restoreLabel);
} else {
values[i] = shadows[i].second;
if(reader.hasAttribute(ATTR_SHADOW) && !IGNORE_SHADOW)
shadows[i].first = importSubName(reader,reader.getAttribute(ATTR_SHADOW),restoreLabel);
if(reader.hasAttribute(AttrShadow))
shadows[i].first = importSubName(reader,reader.getAttribute(AttrShadow),restoreLabel);
}
if(reader.hasAttribute(ATTR_MAPPED))
if(reader.hasAttribute(AttrMapped))
mapped.push_back(i);
}
setFlag(LinkRestoreLabel,restoreLabel);
@@ -1502,6 +1715,7 @@ Property *PropertyLinkSub::Copy(void) const
PropertyLinkSub *p= new PropertyLinkSub();
p->_pcLinkSub = _pcLinkSub;
p->_cSubList = _cSubList;
p->_ShadowSubList = _ShadowSubList;
return p;
}
@@ -1772,9 +1986,10 @@ void PropertyLinkSubList::setValues(std::vector<DocumentObject*>&& lValue,
aboutToSetValue();
_lValueList = std::move(lValue);
_lSubList = std::move(lSubNames);
if(ShadowSubList.size()==_lSubList.size())
if(ShadowSubList.size()==_lSubList.size()) {
_ShadowSubList = std::move(ShadowSubList);
else
onContainerRestored(); // re-register element references
} else
updateElementReference(nullptr);
checkLabelReferences(_lSubList);
hasSetValue();
@@ -1999,7 +2214,7 @@ std::vector<PropertyLinkSubList::SubSet> PropertyLinkSubList::getSubListValues(b
PyObject *PropertyLinkSubList::getPyObject(void)
{
#if 1
std::vector<SubSet> subLists = getSubListValues();
std::vector<SubSet> subLists = getSubListValues(testFlag(LinkNewElement));
std::size_t count = subLists.size();
#if 0//FIXME: Should switch to tuple
Py::Tuple sequence(count);
@@ -2190,18 +2405,18 @@ void PropertyLinkSubList::Save (Base::Writer &writer) const
std::string exportName;
writer.Stream() << encodeAttribute(exportSubName(exportName,obj,sub.c_str()));
if(shadow.second.size() && _lSubList[i]==shadow.first)
writer.Stream() << "\" " ATTR_MAPPED "=\"1";
writer.Stream() << "\" " << AttrMapped << "=\"1";
} else {
writer.Stream() << encodeAttribute(sub);
if(_lSubList[i].size()) {
if(sub!=_lSubList[i]) {
// Stores the actual value that is shadowed. For new version FC,
// we will restore this shadowed value instead.
writer.Stream() << "\" " ATTR_SHADOWED "=\"" << encodeAttribute(_lSubList[i]);
writer.Stream() << "\" " << AttrShadowed << "=\"" << encodeAttribute(_lSubList[i]);
}else if(shadow.first.size()) {
// Here means the user set value is old style element name.
// We shall then store the shadow somewhere else.
writer.Stream() << "\" " ATTR_SHADOW "=\"" << encodeAttribute(shadow.first);
writer.Stream() << "\" " << AttrShadow << "=\"" << encodeAttribute(shadow.first);
}
}
}
@@ -2242,15 +2457,15 @@ void PropertyLinkSubList::Restore(Base::XMLReader &reader)
shadows.emplace_back();
auto &shadow = shadows.back();
shadow.second = importSubName(reader,reader.getAttribute("sub"),restoreLabel);
if(reader.hasAttribute(ATTR_SHADOWED) && !IGNORE_SHADOW) {
shadow.first = importSubName(reader,reader.getAttribute(ATTR_SHADOWED),restoreLabel);
if(reader.hasAttribute(AttrShadowed)) {
shadow.first = importSubName(reader,reader.getAttribute(AttrShadowed),restoreLabel);
SubNames.push_back(shadow.first);
}else{
SubNames.push_back(shadow.second);
if(reader.hasAttribute(ATTR_SHADOW) && !IGNORE_SHADOW)
shadow.first = importSubName(reader,reader.getAttribute(ATTR_SHADOW),restoreLabel);
if(reader.hasAttribute(AttrShadow))
shadow.first = importSubName(reader,reader.getAttribute(AttrShadow),restoreLabel);
}
if(reader.hasAttribute(ATTR_MAPPED))
if(reader.hasAttribute(AttrMapped))
mapped.push_back(i);
} else if (reader.isVerbose())
Base::Console().Warning("Lost link to '%s' while loading, maybe "
@@ -2261,7 +2476,7 @@ void PropertyLinkSubList::Restore(Base::XMLReader &reader)
reader.readEndElement("LinkSubList");
// assignment
setValues(values,SubNames,std::move(shadows));
setValues(values,std::move(SubNames),std::move(shadows));
_mapped.swap(mapped);
}
@@ -2450,6 +2665,7 @@ Property *PropertyLinkSubList::Copy(void) const
PropertyLinkSubList *p = new PropertyLinkSubList();
p->_lValueList = _lValueList;
p->_lSubList = _lSubList;
p->_ShadowSubList = _ShadowSubList;
return p;
}
@@ -2473,8 +2689,9 @@ std::vector<std::string> PropertyLinkSubList::getSubValues(bool newStyle) const
assert(_lSubList.size() == _ShadowSubList.size());
std::vector<std::string> ret;
ret.reserve(_ShadowSubList.size());
std::string tmp;
for(size_t i=0;i<_ShadowSubList.size();++i)
ret.push_back(getSubNameWithStyle(_lSubList[i],_ShadowSubList[i],newStyle));
ret.push_back(getSubNameWithStyle(_lSubList[i],_ShadowSubList[i],newStyle,tmp));
return ret;
}
@@ -2627,7 +2844,7 @@ public:
App::Document *pDoc,PropertyXLink *l, const char *objName)
{
QString path;
l->filePath = getDocPath(filename,pDoc,true,&path);
l->filePath = getDocPath(filename,pDoc,false,&path);
FC_LOG("finding doc " << filename);
@@ -2978,6 +3195,7 @@ PropertyXLink::PropertyXLink(bool _allowPartial, PropertyLinkBase *parent)
setAllowPartial(_allowPartial);
setAllowExternal(true);
setSyncSubObject(true);
// setReturnNewElement(true);
if(parent)
setContainer(parent->getContainer());
}
@@ -3009,18 +3227,27 @@ void PropertyXLink::detach() {
}
}
std::string PropertyXLink::getFullName(bool python) const {
if((getName() && getName()[0]) || python || !parentProp)
return inherited::getFullName(python);
std::ostringstream ss;
ss << parentProp->getFullName() << ":" << this;
return ss.str();
}
void PropertyXLink::aboutToSetValue() {
if(parentProp)
parentProp->aboutToSetChildValue(*this);
else
PropertyLinkBase::aboutToSetValue();
inherited::aboutToSetValue();
}
void PropertyXLink::hasSetValue() {
if(parentProp)
parentProp->hasSetChildValue(*this);
else
PropertyLinkBase::hasSetValue();
inherited::hasSetValue();
}
void PropertyXLink::setSubName(const char *subname)
@@ -3034,13 +3261,14 @@ void PropertyXLink::setSubName(const char *subname)
}
void PropertyXLink::setSubValues(std::vector<std::string> &&subs,
std::vector<ShadowSub> &&shadows)
std::vector<ShadowSub> &&shadows)
{
_SubList = std::move(subs);
_ShadowSubList.clear();
if(shadows.size() == _SubList.size())
if(shadows.size() == _SubList.size()) {
_ShadowSubList = std::move(shadows);
else
onContainerRestored(); // re-register element references
} else
updateElementReference(nullptr);
checkLabelReferences(_SubList);
}
@@ -3329,9 +3557,11 @@ void PropertyXLink::Save (Base::Writer &writer) const {
}else
FC_WARN("PropertyXLink export without saving the document");
}
if(_path.size())
path = _path.c_str();
}
} else if (filePath.size())
_path = DocInfo::getDocPath(filePath.c_str(),owner->getDocument(),true);
if(_path.size())
path = _path.c_str();
writer.Stream() << writer.ind()
<< "<XLink file=\"" << encodeAttribute(path)
<< "\" stamp=\"" << (docInfo&&docInfo->pcDoc?docInfo->pcDoc->LastModifiedDate.getValue():"")
@@ -3352,14 +3582,14 @@ void PropertyXLink::Save (Base::Writer &writer) const {
writer.Stream() << "\" sub=\"" <<
encodeAttribute(exportSubName(exportName,_pcLink,sub.c_str()));
if(shadowSub.second.size() && shadowSub.first==subName)
writer.Stream() << "\" " ATTR_MAPPED "=\"1";
writer.Stream() << "\" " << AttrMapped << "=\"1";
}else{
writer.Stream() << "\" sub=\"" << encodeAttribute(sub);
if(sub.size()) {
if(sub!=subName)
writer.Stream() << "\" " ATTR_SHADOWED "=\"" << encodeAttribute(subName);
writer.Stream() << "\" " << AttrShadowed << "=\"" << encodeAttribute(subName);
else if(shadowSub.first.size())
writer.Stream() << "\" " ATTR_SHADOW "=\"" << encodeAttribute(shadowSub.first);
writer.Stream() << "\" " << AttrShadow << "=\"" << encodeAttribute(shadowSub.first);
}
}
writer.Stream() << "\"/>" << std::endl;
@@ -3377,14 +3607,14 @@ void PropertyXLink::Save (Base::Writer &writer) const {
std::string exportName;
writer.Stream() << encodeAttribute(exportSubName(exportName,_pcLink,sub.c_str()));
if(shadow.second.size() && shadow.first == _SubList[i])
writer.Stream() << "\" " ATTR_MAPPED "=\"1";
writer.Stream() << "\" " << AttrMapped << "=\"1";
} else {
writer.Stream() << encodeAttribute(sub);
if(_SubList[i].size()) {
if(sub!=_SubList[i])
writer.Stream() << "\" " ATTR_SHADOWED "=\"" << encodeAttribute(_SubList[i]);
writer.Stream() << "\" " << AttrShadowed << "=\"" << encodeAttribute(_SubList[i]);
else if(shadow.first.size())
writer.Stream() << "\" " ATTR_SHADOW "=\"" << encodeAttribute(shadow.first);
writer.Stream() << "\" " << AttrShadow << "=\"" << encodeAttribute(shadow.first);
}
}
writer.Stream()<<"\"/>" << endl;
@@ -3431,19 +3661,19 @@ void PropertyXLink::Restore(Base::XMLReader &reader)
std::vector<int> mapped;
bool restoreLabel = false;
if(reader.hasAttribute("sub")) {
if(reader.hasAttribute(ATTR_MAPPED))
if(reader.hasAttribute(AttrMapped))
mapped.push_back(0);
subs.emplace_back();
auto &subname = subs.back();
shadows.emplace_back();
auto &shadow = shadows.back();
shadow.second = importSubName(reader,reader.getAttribute("sub"),restoreLabel);
if(reader.hasAttribute(ATTR_SHADOWED) && !IGNORE_SHADOW)
subname = shadow.first = importSubName(reader,reader.getAttribute(ATTR_SHADOWED),restoreLabel);
if(reader.hasAttribute(AttrShadowed))
subname = shadow.first = importSubName(reader,reader.getAttribute(AttrShadowed),restoreLabel);
else {
subname = shadow.second;
if(reader.hasAttribute(ATTR_SHADOW) && !IGNORE_SHADOW)
shadow.first = importSubName(reader,reader.getAttribute(ATTR_SHADOW),restoreLabel);
if(reader.hasAttribute(AttrShadow))
shadow.first = importSubName(reader,reader.getAttribute(AttrShadow),restoreLabel);
}
}else if(reader.hasAttribute("count")) {
int count = reader.getAttributeAsInteger("count");
@@ -3452,15 +3682,15 @@ void PropertyXLink::Restore(Base::XMLReader &reader)
for (int i = 0; i < count; i++) {
reader.readElement("Sub");
shadows[i].second = importSubName(reader,reader.getAttribute("value"),restoreLabel);
if(reader.hasAttribute(ATTR_SHADOWED) && !IGNORE_SHADOW)
subs[i] = shadows[i].first =
importSubName(reader,reader.getAttribute(ATTR_SHADOWED),restoreLabel);
if(reader.hasAttribute(AttrShadowed))
subs[i] = shadows[i].first =
importSubName(reader,reader.getAttribute(AttrShadowed),restoreLabel);
else {
subs[i] = shadows[i].second;
if(reader.hasAttribute(ATTR_SHADOW) && !IGNORE_SHADOW)
shadows[i].first = importSubName(reader,reader.getAttribute(ATTR_SHADOW),restoreLabel);
if(reader.hasAttribute(AttrShadow))
shadows[i].first = importSubName(reader,reader.getAttribute(AttrShadow),restoreLabel);
}
if(reader.hasAttribute(ATTR_MAPPED))
if(reader.hasAttribute(AttrMapped))
mapped.push_back(i);
}
reader.readEndElement("XLink");
@@ -3541,8 +3771,10 @@ void PropertyXLink::copyTo(PropertyXLink &other,
}
if(subs)
other._SubList = std::move(*subs);
else
else {
other._SubList = _SubList;
other._ShadowSubList = _ShadowSubList;
}
other._Flags = _Flags;
}
@@ -3661,7 +3893,7 @@ PyObject *PropertyXLink::getPyObject(void)
{
if(!_pcLink)
Py_Return;
const auto &subs = getSubValues(false);
const auto &subs = getSubValues(testFlag(LinkNewElement));
if(subs.empty())
return _pcLink->getPyObject();
Py::Tuple ret(2);
@@ -3725,7 +3957,7 @@ void PropertyXLink::setPyObject(PyObject *value) {
const char *PropertyXLink::getSubName(bool newStyle) const {
if(_SubList.empty() || _ShadowSubList.empty())
return "";
return getSubNameWithStyle(_SubList[0],_ShadowSubList[0],newStyle).c_str();
return getSubNameWithStyle(_SubList[0],_ShadowSubList[0],newStyle,tmpShadow).c_str();
}
void PropertyXLink::getLinks(std::vector<App::DocumentObject *> &objs,
@@ -3756,20 +3988,24 @@ std::vector<std::string> PropertyXLink::getSubValues(bool newStyle) const {
assert(_SubList.size() == _ShadowSubList.size());
std::vector<std::string> ret;
ret.reserve(_SubList.size());
std::string tmp;
for(size_t i=0;i<_ShadowSubList.size();++i)
ret.push_back(getSubNameWithStyle(_SubList[i],_ShadowSubList[i],newStyle));
ret.push_back(getSubNameWithStyle(_SubList[i],_ShadowSubList[i],newStyle,tmp));
return ret;
}
std::vector<std::string> PropertyXLink::getSubValuesStartsWith(const char* starter, bool newStyle) const
{
(void)newStyle;
std::vector<std::string> temp;
for(std::vector<std::string>::const_iterator it=_SubList.begin();it!=_SubList.end();++it)
if(strncmp(starter,it->c_str(),strlen(starter))==0)
temp.push_back(*it);
return temp;
assert(_SubList.size() == _ShadowSubList.size());
std::vector<std::string> ret;
std::string tmp;
for(size_t i=0;i<_ShadowSubList.size();++i) {
const auto &sub = getSubNameWithStyle(_SubList[i],_ShadowSubList[i],newStyle,tmp);
auto element = Data::ComplexGeoData::findElementName(sub.c_str());
if(element && boost::starts_with(element,starter))
ret.emplace_back(element);
}
return ret;
}
void PropertyXLink::setAllowPartial(bool enable) {
@@ -3825,7 +4061,7 @@ PyObject *PropertyXLinkSub::getPyObject(void)
Py_Return;
Py::Tuple ret(2);
ret.setItem(0,Py::Object(_pcLink->getPyObject(),true));
const auto &subs = getSubValues(false);
const auto &subs = getSubValues(testFlag(LinkNewElement));
Py::List list(subs.size());
int i = 0;
PropertyString propString;
@@ -3851,6 +4087,7 @@ PropertyXLinkSubList::PropertyXLinkSubList()
{
_pcScope = LinkScope::Global;
setSyncSubObject(true);
// setReturnNewElement(true);
}
PropertyXLinkSubList::~PropertyXLinkSubList()
@@ -4086,7 +4323,7 @@ PyObject *PropertyXLinkSubList::getPyObject(void)
Py::Tuple tup(2);
tup[0] = Py::asObject(obj->getPyObject());
const auto &subs = link.getSubValues();
const auto &subs = link.getSubValues(testFlag(LinkNewElement));
Py::Tuple items(subs.size());
for (std::size_t j = 0; j < subs.size(); j++) {
items[j] = Py::String(subs[j]);
@@ -4106,7 +4343,7 @@ void PropertyXLinkSubList::setPyObject(PyObject *value)
this->setValue(dummy.getValue(), dummy.getSubValues());
return;
}
catch (Base::Exception&) {}
catch (Base::TypeError&) {}
if (!PyTuple_Check(value) && !PyList_Check(value))
throw Base::TypeError("Invalid type. Accepts (DocumentObject, (subname...)) or sequence of such type.");
+19 -4
View File
@@ -26,8 +26,11 @@
#include <list>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include "Property.h"
namespace Base {
@@ -38,6 +41,8 @@ namespace App
{
class DocumentObject;
class Document;
class GeoFeature;
class SubObjectT;
class DocInfo;
typedef std::shared_ptr<DocInfo> DocInfoPtr;
@@ -254,7 +259,7 @@ public:
/// Helper function to return linked objects using an std::inserter
template<class T>
void getLinkedObjects(T &inserter, bool all=false) const {
void getLinkedObjects(T inserter, bool all=false) const {
std::vector<App::DocumentObject*> ret;
getLinks(ret,all);
std::copy(ret.begin(),ret.end(),inserter);
@@ -262,7 +267,7 @@ public:
/// Helper function to return a map of linked object and its subname references
void getLinkedElements(std::map<App::DocumentObject*, std::vector<std::string> > &elements,
bool newStyle=true, bool all=true) const
bool newStyle=true, bool all=false) const
{
std::vector<App::DocumentObject*> ret;
std::vector<std::string> subs;
@@ -275,12 +280,14 @@ public:
/// Helper function to return a map of linked object and its subname references
std::map<App::DocumentObject*, std::vector<std::string> >
linkedElements(bool newStyle=true, bool all=true) const
linkedElements(bool newStyle=true, bool all=false) const
{
std::map<App::DocumentObject*, std::vector<std::string> > ret;
getLinkedElements(ret,newStyle,all);
return ret;
}
std::vector<App::SubObjectT> linkedElementsT(bool all) const;
//@}
virtual bool isSame(const Property &other) const override;
@@ -346,6 +353,8 @@ public:
/// Update all element references in all link properties of \a feature
static void updateElementReferences(DocumentObject *feature, bool reverse=false);
/// Obtain link properties that contain element references to a given object
static const std::unordered_set<PropertyLinkBase*>& getElementReferences(DocumentObject *);
/** Helper function for update individual element reference
*
@@ -538,6 +547,7 @@ public:
LinkAllowPartial,
LinkRestoreLabel,
LinkSyncSubObject, // used by DlgPropertyLink
LinkNewElement, // return new element name in getPyObject
};
inline bool testFlag(int flag) const {
return _Flags.test((std::size_t)flag);
@@ -545,6 +555,8 @@ public:
virtual void setAllowPartial(bool enable) { (void)enable; }
void setReturnNewElement(bool enable);
protected:
virtual void hasSetValue() override;
@@ -1052,6 +1064,7 @@ class PropertyXLinkSubList;
class AppExport PropertyXLink : public PropertyLinkGlobal
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
typedef PropertyLinkGlobal inherited;
public:
PropertyXLink(bool allowPartial=false, PropertyLinkBase *parent=nullptr);
@@ -1137,6 +1150,7 @@ public:
virtual void setAllowPartial(bool enable) override;
virtual std::string getFullName(bool python=false) const override;
const char *getFilePath() const {
return filePath.c_str();
}
@@ -1169,6 +1183,7 @@ protected:
std::vector<ShadowSub> _ShadowSubList;
std::vector<int> _mapped;
PropertyLinkBase *parentProp;
mutable std::string tmpShadow;
};
@@ -1198,10 +1213,10 @@ class AppExport PropertyXLinkSubList: public PropertyLinkBase
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
typedef typename AtomicPropertyChangeInterface<PropertyXLinkSubList>::AtomicPropertyChange atomic_change;
friend atomic_change;
public:
PropertyXLinkSubList();
virtual ~PropertyXLinkSubList();
+749
View File
@@ -0,0 +1,749 @@
/****************************************************************************
* Copyright (c) 2022 Zheng Lei (realthunder) <realthunder.dev@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
****************************************************************************/
#include "PreCompiled.h"
#include <deque>
#include <QCryptographicHash>
#include <QHash>
#include <Base/Reader.h>
#include <Base/Writer.h>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/bimap.hpp>
#include <boost/bimap/set_of.hpp>
#include <boost/bimap/unordered_set_of.hpp>
#include <boost/iostreams/stream.hpp>
#include "StringHasher.h"
#include "StringHasherPy.h"
#include "DocumentParams.h"
#include "MappedElement.h"
#include "StringIDPy.h"
FC_LOG_LEVEL_INIT("App",true,true)
namespace bio = boost::iostreams;
using namespace App;
///////////////////////////////////////////////////////////
struct StringIDHasher {
std::size_t operator()(const StringID *sid) const {
if (!sid)
return 0;
return qHash(sid->data(), qHash(sid->postfix()));
}
bool operator()(const StringID *IDa, const StringID *IDb) const {
if (IDa == IDb)
return true;
if (!IDa || !IDb)
return false;
return IDa->data() == IDb->data() && IDa->postfix() == IDb->postfix();
}
};
typedef boost::bimap<
boost::bimaps::unordered_set_of<StringID *,
StringIDHasher,
StringIDHasher>,
boost::bimaps::set_of<long>>
HashMapBase;
class StringHasher::HashMap: public HashMapBase
{
public:
bool SaveAll = false;
int Threshold = 0;
};
///////////////////////////////////////////////////////////
TYPESYSTEM_SOURCE_ABSTRACT(App::StringID, Base::BaseClass)
StringID::~StringID()
{
if (_hasher)
_hasher->_hashes->right.erase(_id);
}
PyObject *StringID::getPyObject() {
return new StringIDPy(this);
}
PyObject *StringID::getPyObjectWithIndex(int index) {
auto res = new StringIDPy(this);
res->_index = index;
return res;
}
std::string StringID::toString(int index) const {
std::ostringstream ss;
ss << '#' << std::hex << value();
if (index)
ss << ':' << index;
return ss.str();
}
StringID::IndexID StringID::fromString(const char *name, bool eof, int size) {
IndexID res;
res.id = 0;
res.index = 0;
if (!name) {
res.id = -1;
return res;
}
if (size < 0)
size = std::strlen(name);
bio::stream<bio::array_source> iss(name, size);
char sep = 0;
char sep2 = 0;
iss >> sep >> std::hex >> res.id >> sep2 >> res.index;
if ((eof && !iss.eof()) || sep != '#' || (sep2 != 0 && sep2 != ':')) {
res.id = -1;
return res;
}
return res;
}
std::string StringID::dataToText(int index) const {
if(isHashed() || isBinary())
return _data.toBase64().constData();
std::string res(_data.constData());
if (index)
res += std::to_string(index);
if (_postfix.size())
res += _postfix.constData();
return res;
}
void StringID::mark() const
{
if (isMarked())
return;
_flags.setFlag(Flag::Marked);
for (auto &sid : _sids)
sid.deref().mark();
}
///////////////////////////////////////////////////////////
TYPESYSTEM_SOURCE(App::StringHasher, Base::Persistence)
StringHasher::StringHasher()
:_hashes(new HashMap)
{}
StringHasher::~StringHasher() {
clear();
}
void StringHasher::setSaveAll(bool enable) {
if (_hashes->SaveAll == enable)
return;
_hashes->SaveAll = enable;
compact();
}
void StringHasher::compact()
{
if (_hashes->SaveAll)
return;
std::deque<StringIDRef> pendings;
for (auto &v : _hashes->right) {
if (!v.second->isPersistent() && v.second->getRefCount() == 1)
pendings.emplace_back(v.second);
}
while (pendings.size()) {
StringIDRef sid = pendings.front();
pendings.pop_front();
if (!_hashes->right.erase(sid.value()))
continue;
sid._sid->_hasher = nullptr;
sid._sid->unref();
for (auto &s : sid._sid->_sids) {
if (s._sid->_hasher == this
&& !s._sid->isPersistent()
&& s._sid->getRefCount() == 2)
pendings.push_back(s);
}
}
}
bool StringHasher::getSaveAll() const {
return _hashes->SaveAll;
}
void StringHasher::setThreshold(int threshold) {
_hashes->Threshold = threshold;
}
int StringHasher::getThreshold() const {
return _hashes->Threshold;
}
long StringHasher::lastID() const {
if(_hashes->right.empty())
return 0;
auto it = _hashes->right.end();
--it;
return it->first;
}
StringIDRef StringHasher::getID(const char *text, int len, bool hashable) {
if (len < 0)
len = strlen(text);
return getID(QByteArray::fromRawData(text, len), hashable ? Option::Hashable : Option::None);
}
StringIDRef StringHasher::getID(const QByteArray &data, Options options)
{
bool binary = options.testFlag(Option::Binary);
bool hashable = options.testFlag(Option::Hashable);
bool nocopy = options.testFlag(Option::NoCopy);
bool hashed = hashable && _hashes->Threshold > 0
&& (int)data.size() > _hashes->Threshold;
StringID dataID;
if (hashed) {
QCryptographicHash hasher(QCryptographicHash::Sha1);
hasher.addData(data);
dataID._data = hasher.result();
}
else
dataID._data = data;
auto it = _hashes->left.find(&dataID);
if (it != _hashes->left.end())
return StringIDRef(it->first);
if (!hashed && !nocopy)
// if not hashed, make a deep copy of the data
dataID._data = QByteArray(data.constData(), data.size());
StringID::Flags flags(StringID::Flag::None);
if (binary)
flags.setFlag(StringID::Flag::Binary);
if (hashed)
flags.setFlag(StringID::Flag::Hashed);
StringIDRef sid(new StringID(lastID() + 1, dataID._data, flags));
return StringIDRef(insert(sid));
}
StringIDRef StringHasher::getID(const Data::MappedName &name,
const QVector<StringIDRef> & sids)
{
StringID anID;
anID._postfix = name.postfixBytes();
Data::IndexedName indexed;
if (!anID._postfix.size())
indexed = Data::IndexedName(name.dataBytes());
if (indexed)
anID._data = QByteArray::fromRawData(indexed.getType(), strlen(indexed.getType()));
else
anID._data = name.dataBytes();
auto it = _hashes->left.find(&anID);
if (it != _hashes->left.end()) {
auto res = StringIDRef(it->first);
if (indexed)
res._index = indexed.getIndex();
return res;
}
if (!indexed && name.isRaw())
anID._data = QByteArray(name.dataBytes().constData(),
name.dataBytes().size());
StringIDRef postfixRef;
if (anID._postfix.size() && anID._postfix.indexOf("#") < 0) {
postfixRef = getID(anID._postfix);
postfixRef.toBytes(anID._postfix);
}
StringIDRef indexRef;
if (indexed)
indexRef = getID(anID._data);
StringIDRef sid(new StringID(lastID() + 1, anID._data));
StringID &id = *sid._sid;
if (anID._postfix.size()) {
id._flags.setFlag(StringID::Flag::Postfixed);
id._postfix = anID._postfix;
}
int count = 0;
for (auto &sid : sids) {
if (sid && sid._sid->_hasher == this)
++count;
}
int extra = (postfixRef ? 1 : 0) + (indexRef ? 1 : 0);
if (count == sids.size() && !postfixRef && !indexRef)
id._sids = sids;
else {
id._sids.reserve(count + extra);
if (postfixRef) {
id._flags.setFlag(StringID::Flag::PostfixEncoded);
id._sids.push_back(postfixRef);
}
if (indexRef) {
id._flags.setFlag(StringID::Flag::Indexed);
id._sids.push_back(indexRef);
}
for (auto &s : sids) {
if (s && s._sid->_hasher == this)
id._sids.push_back(s);
}
}
if (id._sids.size() > 10) {
std::sort(id._sids.begin() + extra, id._sids.end());
id._sids.erase(std::unique(id._sids.begin() + extra, id._sids.end()), id._sids.end());
}
if (id._postfix.size() && !indexed) {
StringID::IndexID res = StringID::fromString(id._data);
if (res.id > 0) {
int offset = id.isPostfixEncoded() ? 1 : 0;
for (int i = offset; i < id._sids.size(); ++i) {
if (id._sids[i].value() == res.id) {
if (i!=offset)
std::swap(id._sids[offset], id._sids[i]);
if (res.index != 0)
id._flags.setFlag(StringID::Flag::PrefixIDIndex);
else
id._flags.setFlag(StringID::Flag::PrefixID);
break;
}
}
}
}
return StringIDRef(insert(sid), indexed.getIndex());
}
StringIDRef StringHasher::getID(long id, int index) const {
if (id<=0)
return StringIDRef();
auto it = _hashes->right.find(id);
if (it == _hashes->right.end())
return StringIDRef();
StringIDRef res(it->second);
res._index = index;
return res;
}
void StringHasher::setPersistenceFileName(const char *filename) const {
if (!filename)
filename = "";
_filename = filename;
}
const std::string &StringHasher::getPersistenceFileName() const {
return _filename;
}
void StringHasher::Save(Base::Writer &writer) const {
size_t count;
if (_hashes->SaveAll)
count = _hashes->size();
else {
count = 0;
for (auto &v : _hashes->right) {
if (v.second->isMarked() || v.second->isPersistent())
++count;
}
}
writer.Stream() << writer.ind()
<< "<StringHasher saveall=\"" << _hashes->SaveAll
<< "\" threshold=\"" << _hashes->Threshold << "\"";
if (!count) {
writer.Stream() << " count=\"0\"></StringHasher>\n";
return;
}
writer.Stream() << " count=\"0\" new=\"1\"/>\n";
writer.Stream() << writer.ind() << "<StringHasher2 ";
if (_filename.size()) {
writer.Stream() << " file=\""
<< writer.addFile(_filename + ".txt", this)
<< "\"/>\n";
return;
}
writer.Stream() << " count=\"" << count << "\">\n";
saveStream(writer.beginCharStream(false) << '\n');
writer.endCharStream() << '\n';
writer.Stream() << writer.ind() << "</StringHasher2>\n";
}
void StringHasher::SaveDocFile(Base::Writer &writer) const {
std::size_t count = _hashes->SaveAll?this->size():this->count();
writer.Stream() << "StringTableStart v1 " << count << '\n';
saveStream(writer.Stream());
}
void StringHasher::saveStream(std::ostream &s) const {
Base::OutputStream str(s,false);
boost::io::ios_flags_saver ifs(s);
s << std::hex;
bool allowRealtive = DocumentParams::getRelativeStringID();
long anchor = 0;
const StringID *last = nullptr;
long lastid = 0;
bool relative = false;
for (auto &v : _hashes->right) {
auto &d = *v.second;
long id = d._id;
if (!_hashes->SaveAll && !d.isMarked() && !d.isPersistent())
continue;
if (!allowRealtive)
s << id;
else {
// We use relative coding to save space. But in order to have some
// minimum protection against corruption, write an absolute value every
// once a while.
relative = (id - anchor) < 1000;
if (relative)
s << '-' << id - lastid;
else {
anchor = id;
s << id;
}
lastid = id;
}
int offset = d.isPostfixEncoded() ? 1 : 0;
StringID::IndexID prefixid;
prefixid.id = 0;
prefixid.index = 0;
if (d.isPrefixID()) {
assert(d._sids.size() > offset);
prefixid.id = d._sids[offset].value();
}
else if (d.isPrefixIDIndex()) {
prefixid = StringID::fromString(d._data);
assert(d._sids.size() > offset && d._sids[offset].value() == prefixid.id);
}
auto flags = d._flags;
flags.setFlag(StringID::Flag::Marked, false);
s << '.' << flags.toUnderlyingType();
int i = 0;
if (!relative) {
for (; i < d._sids.size(); ++i)
s << '.' << d._sids[i].value();
}
else {
if (last) {
for (; i < d._sids.size() && i < last->_sids.size(); ++i) {
long m = last->_sids[i].value();
long n = d._sids[i].value();
if (n < m)
s << ".-" << m-n;
else
s << '.' << n - m;
}
}
for (; i < d._sids.size(); ++i)
s << '.' << id - d._sids[i].value();
}
last = &d;
// Having postfix means it is a geometry element name, which
// guarantees to be a single line without space. So it is safe to
// store in raw stream.
if (d.isPostfixed()) {
if (d.isPrefixIDIndex())
s << ' ' << prefixid.index;
else if (!d.isIndexed() && !d.isPrefixID())
s << ' ' << d._data.constData();
if (!d.isPostfixEncoded())
s << ' ' << d._postfix.constData();
s << '\n';
}
else {
// Reaching here means the string may contain space and newlines
// We rely on OutputStream (i.e. str) to save the string.
s << ' ';
str << d._data.constData();
}
}
}
void StringHasher::RestoreDocFile(Base::Reader &reader) {
std::string marker, ver;
reader >> marker;
std::size_t count;
_hashes->clear();
if (marker == "StringTableStart") {
reader >> ver >> count;
if (ver != "v1")
FC_WARN("Unknown string table format");
restoreStreamNew(reader, count);
return;
}
count = atoi(marker.c_str());
restoreStream(reader, count);
}
void StringHasher::restoreStreamNew(std::istream &s, std::size_t count) {
Base::InputStream str(s, false);
_hashes->clear();
std::string content;
boost::io::ios_flags_saver ifs(s);
s >> std::hex;
std::vector<std::string> tokens;
long lastid = 0;
const StringID *last = nullptr;
std::string tmp;
for (uint32_t i = 0; i < count; ++i) {
if (!(s >> tmp))
FC_THROWM(Base::RuntimeError, "Invalid string table");
tokens.clear();
boost::split(tokens, tmp, boost::is_any_of("."));
if (tokens.size() < 2)
FC_THROWM(Base::RuntimeError, "Invalid string table");
long id;
bool relative = false;
if (tokens[0][0] == '-') {
relative = true;
id = lastid + strtol(tokens[0].c_str() + 1, nullptr, 16);
}
else
id = strtol(tokens[0].c_str(), nullptr, 16);
lastid = id;
unsigned long flag = strtol(tokens[1].c_str(), nullptr, 16);
StringIDRef sid(new StringID(id, QByteArray(), static_cast<StringID::Flag>(flag)));
StringID &d = *sid._sid;
d._sids.reserve(tokens.size() - 2);
int j = 2;
if (relative && last) {
for (; j < (int)tokens.size() && j - 2 < last->_sids.size(); ++j) {
long m = last->_sids[j - 2].value();
long n;
if (tokens[j][0] == '-')
n = -strtol(&tokens[j][1], nullptr, 16);
else
n = strtol(&tokens[j][0], nullptr, 16);
StringIDRef sid = getID(m + n);
if (!sid)
FC_THROWM(Base::RuntimeError, "Invalid string id reference");
d._sids.push_back(sid);
}
}
for (; j < (int)tokens.size(); ++j) {
long n = strtol(&tokens[j][0], nullptr, 16);
StringIDRef sid = getID(relative ? id - n : n);
if (!sid)
FC_THROWM(Base::RuntimeError, "Invalid string id reference");
d._sids.push_back(sid);
}
if (!d.isPostfixed()) {
str >> content;
if (d.isHashed() || d.isBinary())
d._data = QByteArray::fromBase64(content.c_str());
else
d._data = content.c_str();
}
else {
int offset = 0;
if (d.isPostfixEncoded()) {
offset = 1;
if (d._sids.empty())
FC_THROWM(Base::RuntimeError, "Missing string postfix");
d._postfix = d._sids[0]._sid->_data;
}
if (d.isIndexed()) {
if (d._sids.size() <= offset)
FC_THROWM(Base::RuntimeError, "Missing string prefix");
d._data = d._sids[offset]._sid->_data;
}
else if (d.isPrefixID() || d.isPrefixIDIndex()) {
if (d._sids.size() <= offset)
FC_THROWM(Base::RuntimeError, "Missing string prefix id");
int index = 0;
if (d.isPrefixIDIndex()) {
if (!(s >> index))
FC_THROWM(Base::RuntimeError, "Missing string prefix index");
}
d._data = d._sids[offset]._sid->toString(index).c_str();
}
else {
s >> content;
d._data = content.c_str();
}
if (!d.isPostfixEncoded()) {
s >> content;
d._postfix = content.c_str();
}
}
last = insert(sid);
}
}
StringID *StringHasher::insert(const StringIDRef &sid)
{
assert(sid && sid._sid->_hasher == nullptr);
auto &d = *sid._sid;
d._hasher = this;
d.ref();
auto res = _hashes->right.insert(_hashes->right.end(),
HashMap::right_map::value_type(sid.value(), &d));
if (res->second != &d) {
d._hasher = nullptr;
d.unref();
}
return res->second;
}
void StringHasher::restoreStream(std::istream &s, std::size_t count) {
Base::InputStream str(s, false);
_hashes->clear();
std::string content;
for (uint32_t i = 0; i < count; ++i) {
int32_t id;
uint8_t type;
str >> id >> type >> content;
StringIDRef sid = new StringID(id, QByteArray(), static_cast<StringID::Flag>(type));
if (sid.isHashed() || sid.isBinary())
sid._sid->_data = QByteArray::fromBase64(content.c_str());
else
sid._sid->_data = QByteArray(content.c_str());
insert(sid);
}
}
void StringHasher::clear() {
for (auto & v : _hashes->right) {
v.second->_hasher = nullptr;
v.second->unref();
}
_hashes->clear();
}
size_t StringHasher::size() const {
return _hashes->size();
}
size_t StringHasher::count() const {
size_t count = 0;
for (auto &v : _hashes->right)
if (v.second->getRefCount() > 1)
++count;
return count;
}
void StringHasher::Restore(Base::XMLReader &reader) {
clear();
reader.readElement("StringHasher");
_hashes->SaveAll = reader.getAttributeAsInteger("saveall") ? true : false;
_hashes->Threshold = reader.getAttributeAsInteger("threshold");
bool newtag = false;
if (reader.getAttributeAsInteger("new", "0") > 0) {
reader.readElement("StringHasher2");
newtag = true;
}
if (reader.hasAttribute("file")) {
const char *file = reader.getAttribute("file");
if(*file)
reader.addFile(file, this);
return;
}
std::size_t count = reader.getAttributeAsUnsigned("count");
if (newtag) {
restoreStreamNew(reader.beginCharStream(false), count);
reader.readEndElement("StringHasher2");
return;
}
else if (count && reader.FileVersion > 1)
restoreStream(reader.beginCharStream(false), count);
else {
for (std::size_t i = 0; i < count; ++i) {
reader.readElement("Item");
StringIDRef sid;
long id = reader.getAttributeAsInteger("id");
bool hashed = reader.hasAttribute("hash");
if (hashed || reader.hasAttribute("data")) {
const char *value = hashed ? reader.getAttribute("hash") : reader.getAttribute("data");
sid = new StringID(id, QByteArray::fromBase64(value), StringID::Flag::Hashed);
}
else
sid = new StringID(id, QByteArray(reader.getAttribute("text")));
insert(sid);
}
}
reader.readEndElement("StringHasher");
}
unsigned int StringHasher::getMemSize (void) const {
return (_hashes->SaveAll?size():count()) * 10;
}
PyObject *StringHasher::getPyObject() {
return new StringHasherPy(this);
}
std::map<long, StringIDRef> StringHasher::getIDMap() const {
std::map<long,StringIDRef> ret;
for (auto &v : _hashes->right)
ret.emplace_hint(ret.end(), v.first, StringIDRef(v.second));
return ret;
}
void StringHasher::clearMarks() const
{
for (auto &v : _hashes->right)
v.second->_flags.setFlag(StringID::Flag::Marked, false);
}
+680
View File
@@ -0,0 +1,680 @@
/****************************************************************************
* Copyright (c) 2022 Zheng Lei (realthunder) <realthunder.dev@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
****************************************************************************/
#ifndef APP_STRINGID_H
#define APP_STRINGID_H
#include <bitset>
#include <memory>
#include <QByteArray>
#include <QVector>
#include <Base/Bitmask.h>
#include <Base/Handle.h>
#include <Base/Persistence.h>
#include <CXX/Objects.hxx>
namespace Data{
class MappedName;
}
namespace App {
class StringHasher;
class StringID;
class StringIDRef;
typedef Base::Reference<StringHasher> StringHasherRef;
/** Class to store a string
*
* The main purpose of this class is to provide an efficient storage of the
* mapped geometry element name (i.e. the new Topological Naming), but it can
* also be used as a general purpose string table.
*
* The StringID is to be stored in a string table (StringHasher), and be
* referred to by an integer ID. The stored data can be optionally divided into
* two parts, prefix and postfix. This is because a new mapped name is often
* created by adding some common postfix to an existing name, so data sharing
* can be improved using the following techniques:
*
* a) reference count (through QByteArray) the main data part,
*
* b) (recursively) encode prefix and/or postfix as an integer (in the
* format of #<hex>, e.g. #1b) that references another StringID,
*
* c) Check index based name in prefix, e.g. Edge1, Vertex2, and encode
* only the text part as StringID. The index is stored separately in
* reference class StringIDRef to maximize data sharing.
*/
class AppExport StringID: public Base::BaseClass, public Base::Handled {
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
/// Flag of the stored string data
enum class Flag {
/// No flag
None = 0,
/// The stored data is binary
Binary = 1 << 0,
/// The stored data is the sha1 hash of the original content
Hashed = 1 << 1,
/** Postfix is encoded as #<hex>, e.g. #1b, where the hex integer part
* refers to another StringID.
*/
PostfixEncoded = 1 << 2,
/// The data is splited as prefix and postfix
Postfixed = 1 << 3,
/// The prefix data is split as text + index
Indexed = 1 << 4,
/** The prefix data is encoded as #<hex>, e.g. #1b, where the hex
* integer part refers to another StringID.
*/
PrefixID = 1 << 5,
/** The prefix split as text + index, where the text is encoded
* using another StringID.
*/
PrefixIDIndex = 1 << 6,
/// The string ID is persistent regardless of internal mark */
Persistent = 1 << 7,
/// Internal marked used to check if the string ID is used
Marked = 1 << 8,
};
typedef Base::Flags<Flag> Flags;
/** Constructor
* @param id: integer ID of this StringID
* @param data: input data
* @param flags: flags describes the data
*
* User code is not supposed to create StringID directly, but through StringHasher::getID()
*/
StringID(long id, const QByteArray &data, const Flags &flags=Flag::None)
:_id(id),_data(data),_flags(flags)
{}
/// Constructs an empty StringID
StringID()
:_id(0), _flags(Flag::None)
{}
virtual ~StringID();
/// Returns the ID of this StringID
long value() const {return _id;}
/// Returns all related StringIDs that used to encode this StringID
const QVector<StringIDRef> &relatedIDs() const {return _sids;}
/// @name Flag accessors
//@{
bool isBinary() const;
bool isHashed() const;
bool isPostfixed() const;
bool isPostfixEncoded() const;
bool isIndexed() const;
bool isPrefixID() const;
bool isPrefixIDIndex() const;
bool isMarked() const;
bool isPersistent() const;
//@}
/// Checks if this StringID is from the input hasher
bool isFromSameHasher(const StringHasherRef & hasher) const
{
return this->_hasher == hasher;
}
/// Returns the owner hasher
StringHasherRef getHasher() const
{
return StringHasherRef(_hasher);
}
/// Returns the data (prefix)
const QByteArray data() const {return _data;}
/// Returns the postfix
const QByteArray postfix() const {return _postfix;}
virtual PyObject *getPyObject() override;
/// Returns a Python tuple containing both the text and index
PyObject *getPyObjectWithIndex(int index);
/** Convert to string represtation of this StringID
* @param index: optional index
*
* The format is #<id>. And if index is non zero, then #<id>:<index>. Both
* <id> and <index> are in hex format.
*/
std::string toString(int index) const;
/// Light weight structure of holding a string ID and associated index
struct IndexID {
long id;
int index;
explicit operator bool() const {
return id > 0;
}
friend std::ostream & operator << (std::ostream &s, const IndexID & id) {
s << id.id;
if (id.index)
s << ':' << id.index;
return s;
}
};
/** Parse string to get ID and index
* @param name: input string
* @param eof: Whether to check the end of string. If true, then the input
* string must contain only the string representation of this
* StringID
* @param size: input string size, or -1 if the input string is zero terminated.
* @return Return the integer ID and index.
*
* The input string is expected to be in the format of #<id> or with index
* #<id>:<index>, where both id and index are in hex digits.
*/
static IndexID fromString(const char *name, bool eof=true, int size = -1);
/** Parse string to get ID and index
* @param bytes: input data
* @param eof: Whether to check the end of string. If true, then the input
* string must contain only the string representation of this
* StringID
*
* The input string is expected to be in the format of #<id> or with index
* #<id>:<index>, where both id and index are in hex digits.
*/
static IndexID fromString(const QByteArray &bytes, bool eof=true) {
return fromString(bytes.constData(), eof, bytes.size());
}
/** Get the text content of this StringID
* @param index: optional index
* @return Return the text content of this StringID. If the data is binary,
* then output in base64 encoded string.
*/
std::string dataToText(int index) const;
/** Get the content of this StringID as QByteArray
* @param bytes: output bytes
* @param index: opttional index.
*/
void toBytes(QByteArray &bytes, int index) const {
if (_postfix.size())
bytes = _data + _postfix;
else if (index)
bytes = _data + QByteArray::number(index);
else
bytes = _data;
}
/// Mark this StringID as used
void mark() const;
/// Mark the StringID as persistent regardless of usage mark
void setPersistent(bool enable);
bool operator<(const StringID &other) const {
return compare(other) < 0;
}
/** Compare StringID
* @param other: the other StringID for comparison
* @return Returns -1 if less than the other StringID, 1 if greater, or 0 if equal
*/
int compare(const StringID &other) const {
if (_hasher < other._hasher)
return -1;
if (_hasher > other._hasher)
return 1;
if (_id < other._id)
return -1;
if (_id > other._id)
return 1;
return 0;
}
friend class StringHasher;
private:
long _id;
QByteArray _data;
QByteArray _postfix;
StringHasher *_hasher = nullptr;
mutable Flags _flags;
mutable QVector<StringIDRef> _sids;
};
//////////////////////////////////////////////////////////////////////////
/** Counted reference to a StringID instance
*/
class StringIDRef
{
public:
StringIDRef()
:_sid(nullptr), _index(0)
{}
StringIDRef(StringID* p, int index=0)
: _sid(p), _index(index)
{
if (_sid)
_sid->ref();
}
StringIDRef(const StringIDRef & other)
: _sid(other._sid)
, _index(other._index)
{
if (_sid)
_sid->ref();
}
StringIDRef(StringIDRef && other)
: _sid(other._sid)
, _index(other._index)
{
other._sid = nullptr;
}
StringIDRef(const StringIDRef & other, int index)
: _sid(other._sid)
, _index(index)
{
if (_sid)
_sid->ref();
}
~StringIDRef()
{
if (_sid)
_sid->unref();
}
void reset(const StringIDRef & p = StringIDRef()) {
*this = p;
}
void reset(const StringIDRef &p, int index) {
*this = p;
this->_index = index;
}
void swap(StringIDRef &p) {
if(*this != p) {
auto tmp = p;
p = *this;
*this = tmp;
}
}
StringIDRef & operator=(StringID* p) {
if (_sid == p)
return *this;
if (_sid)
_sid->unref();
_sid = p;
if (_sid)
_sid->ref();
this->_index = 0;
return *this;
}
StringIDRef & operator=(const StringIDRef & p) {
if (_sid != p._sid) {
if (_sid)
_sid->unref();
_sid = p._sid;
if (_sid)
_sid->ref();
}
this->_index = p._index;
return *this;
}
StringIDRef & operator=(StringIDRef && p) {
if (_sid != p._sid) {
if (_sid)
_sid->unref();
_sid = p._sid;
p._sid = nullptr;
}
this->_index = p._index;
return *this;
}
bool operator<(const StringIDRef & p) const {
if (!_sid)
return true;
if (!p._sid)
return false;
int res = _sid->compare(*p._sid);
if (res < 0)
return true;
if (res > 0)
return false;
return _index < p._index;
}
bool operator==(const StringIDRef & p) const {
return _sid == p._sid && _index == p._index;
}
bool operator!=(const StringIDRef & p) const {
return _sid != p._sid || _index != p._index;
}
explicit operator bool() const {
return _sid != nullptr;
}
int getRefCount(void) const {
if (_sid)
return _sid->getRefCount();
return 0;
}
std::string toString() const {
if (_sid)
return _sid->toString(_index);
return std::string();
}
std::string dataToText() const {
if (_sid)
return _sid->dataToText(_index);
return std::string();
}
const char * constData() const {
if (_sid) {
assert(_index == 0);
assert(_sid->postfix().isEmpty());
return _sid->data().constData();
}
return "";
}
const StringID & deref() const {
return *_sid;
}
long value() const {
if (_sid)
return _sid->value();
return 0;
}
QVector<StringIDRef> relatedIDs() const {
if (_sid)
return _sid->relatedIDs();
return QVector<StringIDRef>();
}
bool isBinary() const {
if (_sid)
return _sid->isBinary();
return false;
}
bool isHashed() const {
if (_sid)
return _sid->isHashed();
return false;
}
void toBytes(QByteArray &bytes) const {
if (_sid)
_sid->toBytes(bytes, _index);
}
PyObject *getPyObject(void) {
if (_sid)
return _sid->getPyObjectWithIndex(_index);
Py_INCREF(Py_None);
return Py_None;
}
void mark() const {
if (_sid)
_sid->mark();
}
bool isMarked() const {
return _sid && _sid->isMarked();
}
bool isFromSameHasher(const StringHasherRef & hasher) const
{
return _sid && _sid->isFromSameHasher(hasher);
}
StringHasherRef getHasher() const
{
if (_sid)
return _sid->getHasher();
return StringHasherRef();
}
void setPersistent(bool enable)
{
if (_sid)
_sid->setPersistent(enable);
}
friend class StringHasher;
private:
StringID *_sid;
int _index;
};
/// A String table to map string from/to a unique integer
class AppExport StringHasher: public Base::Persistence, public Base::Handled {
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
StringHasher();
virtual ~StringHasher();
virtual unsigned int getMemSize (void) const override;
virtual void Save (Base::Writer &/*writer*/) const override;
virtual void Restore(Base::XMLReader &/*reader*/) override;
virtual void SaveDocFile (Base::Writer &/*writer*/) const override;
virtual void RestoreDocFile (Base::Reader &/*reader*/) override;
void setPersistenceFileName(const char *name) const;
const std::string &getPersistenceFileName() const;
/** Maps an arbitrary string to an integer
*
* @param text: input string.
* @param len: length of the string, or -1 if the string is 0 terminated.
* @param hashable: whether the string is hashable.
* @return Return a shared pointer to the internally stored StringID.
*
* The function maps an arbitrary text string to a unique integer ID, which
* is returned as a shared pointer to reference count the ID so that it is
* possible to prune any unused strings.
*
* If \c hashable is true and the string is longer than the threshold
* setting of this StringHasher, it will be sha1 hashed before storing, and
* the original content of the string is discarded. If else, the string is
* copied and stored inside a StringID instance.
*
* The purpose of function is to provide a short form of a stable string
* identification.
*/
StringIDRef getID(const char *text, int len=-1, bool hashable=false);
/// Option for string string data
enum class Option {
/// No option
None = 0,
/// The input data is binary
Binary = 1 << 0,
/** The input data is hashable. If the data length is longer than the
* threshold setting of the StringHasher, it will be sha1 hashed before
* storing, and the original content of the string is discarded.
*/
Hashable = 1 << 1,
/// Do not copy the data, assuming the data is constant. If this option
//is not set, the data will be copied before storing.
NoCopy = 1 << 2,
};
typedef Base::Flags<Option> Options;
/** Map text or binary data to an integer
*
* @param data: input data.
* @param options: options describing how to store the data. @sa Option.
* @return Return a shared pointer to the internally stored StringID.
*
* The function maps an arbitrary text string to a unique integer ID, which
* is returned as a shared pointer to reference count the ID so that it is
* possible to prune any unused strings.
*
* The purpose of function is to provide a short form of a stable string
* identification.
*/
StringIDRef getID(const QByteArray & data, Options options=Option::Hashable);
/** Map geometry element name to an integer */
StringIDRef getID(const Data::MappedName & name,
const QVector<StringIDRef> & sids);
/** Obtain the reference counted StringID object from numerical id
*
* @param id: string ID
* @param index: optional index of the string ID
* @return Return a shared pointer to the internally stored StringID.
*
* This function exists because the stored string may be one way hashed,
* and the original text is not persistent. The caller use this function to
* retrieve the reference count ID object after restore
*/
StringIDRef getID(long id, int index = 0) const;
/** Obtain the reference counted StringID object from numerical id and index
*
* @param id: string ID with index
* @return Return a shared pointer to the internally stored StringID.
*/
StringIDRef getID(const StringID::IndexID &id) const {
return getID(id.id, id.index);
}
std::map<long,StringIDRef> getIDMap() const;
/// Clear all string hashes
void clear();
/// Size of the hash table
size_t size() const;
/// Return the number of hashes that are used by others
size_t count() const;
virtual PyObject *getPyObject(void) override;
/** Enable/disable saving all string ID
*
* If disabled, then only save string ID that are used.
*/
void setSaveAll(bool enable);
bool getSaveAll() const;
/** Set threshold of string hashing
*
* For hashable string that are longer than the threshold, the string will
* be replaced by its sha1 hash.
*/
void setThreshold(int threshold);
int getThreshold() const;
/** Clear internal marks
*
* The internal marks on internally stored StringID instances are used to
* check if the StringID is used.
*/
void clearMarks() const;
/// Compact string storage
void compact();
class HashMap;
friend class StringID;
protected:
StringID * insert(const StringIDRef & sid);
long lastID() const;
void saveStream(std::ostream &s) const;
void restoreStream(std::istream &s, std::size_t count);
void restoreStreamNew(std::istream &s, std::size_t count);
private:
std::unique_ptr<HashMap> _hashes;
mutable std::string _filename;
};
} //namespace App
ENABLE_BITMASK_OPERATORS(App::StringID::Flag)
ENABLE_BITMASK_OPERATORS(App::StringHasher::Option)
namespace App {
inline bool StringID::isBinary() const {
return _flags.testFlag(Flag::Binary);
}
inline bool StringID::isHashed() const {
return _flags.testFlag(Flag::Hashed);
}
inline bool StringID::isPostfixed() const {
return _flags.testFlag(Flag::Postfixed);
}
inline bool StringID::isPostfixEncoded() const {
return _flags.testFlag(Flag::PostfixEncoded);
}
inline bool StringID::isIndexed() const {
return _flags.testFlag(Flag::Indexed);
}
inline bool StringID::isPrefixID() const {
return _flags.testFlag(Flag::PrefixID);
}
inline bool StringID::isPrefixIDIndex() const {
return _flags.testFlag(Flag::PrefixIDIndex);
}
inline bool StringID::isMarked() const {
return _flags.testFlag(Flag::Marked);
}
inline bool StringID::isPersistent() const {
return _flags.testFlag(Flag::Persistent);
}
inline void StringID::setPersistent(bool enable) {
_flags.setFlag(Flag::Persistent, enable);
}
} //namespace App
#endif
+70
View File
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="BaseClassPy"
Name="StringHasherPy"
Twin="StringHasher"
TwinPointer="StringHasher"
Include="App/StringHasher.h"
FatherInclude="Base/BaseClassPy.h"
Namespace="App"
FatherNamespace="Base"
Constructor="true"
Reference="true">
<Documentation>
<Author Licence="LGPL" Name="Zheng, Lei" EMail="realthunder.dev@gmail.com" />
<DeveloperDocu>This is the StringHasher class</DeveloperDocu>
<UserDocu>This is the StringHasher class</UserDocu>
</Documentation>
<Methode Name="getID">
<Documentation>
<UserDocu>
getID(txt|id, base64=False) -> StringID
If the input is text, return a StringID object that is unique within this hasher. This
StringID object is reference counted. The hasher may only save hash ID's that are used.
If the input is an integer, then the hasher will try to find the StringID object stored
with the same integer value.
base64: indicate if the input 'txt' is base64 encoded binary data
</UserDocu>
</Documentation>
</Methode>
<Methode Name="isSame" Const="true">
<Documentation>
<UserDocu>Check if two hasher are the same</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Count" ReadOnly="true">
<Documentation>
<UserDocu>Return count of used hashes</UserDocu>
</Documentation>
<Parameter Name="Count" Type="Int" />
</Attribute>
<Attribute Name="Size" ReadOnly="true">
<Documentation>
<UserDocu>Return the size of the hashes</UserDocu>
</Documentation>
<Parameter Name="Size" Type="Int"/>
</Attribute>
<Attribute Name="SaveAll">
<Documentation>
<UserDocu>Whether to save all string hashes regardless of its use count</UserDocu>
</Documentation>
<Parameter Name="SaveAll" Type="Boolean"/>
</Attribute>
<Attribute Name="Threshold">
<Documentation>
<UserDocu>Data length exceed this threshold will be hashed before storing</UserDocu>
</Documentation>
<Parameter Name="Threshold" Type="Int"/>
</Attribute>
<Attribute Name="Table" ReadOnly="true">
<Documentation>
<UserDocu>Return the entire string table as Int->String dictionary</UserDocu>
</Documentation>
<Parameter Name="Table" Type="Dict"/>
</Attribute>
</PythonExport>
</GenerateModel>
+150
View File
@@ -0,0 +1,150 @@
/****************************************************************************
* Copyright (c) 2018 Zheng Lei (realthunder) <realthunder.dev@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
****************************************************************************/
#include "PreCompiled.h"
#include "StringHasher.h"
#include "StringHasherPy.h"
#include "StringHasherPy.cpp"
using namespace App;
// returns a string which represent the object e.g. when printed in python
std::string StringHasherPy::representation(void) const
{
std::ostringstream str;
str << "<StringHasher at " << getStringHasherPtr() << ">";
return str.str();
}
PyObject *StringHasherPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
return new StringHasherPy(new StringHasher);
}
// constructor method
int StringHasherPy::PyInit(PyObject* , PyObject* )
{
return 0;
}
PyObject* StringHasherPy::isSame(PyObject *args)
{
PyObject *other;
if (!PyArg_ParseTuple(args, "O!", &StringHasherPy::Type, &other)){ // convert args: Python->C
return Py::new_reference_to(Py::False());
}
auto otherHasher = static_cast<StringHasherPy*>(other)->getStringHasherPtr();
return Py::new_reference_to(Py::Boolean(getStringHasherPtr() == otherHasher));
}
PyObject* StringHasherPy::getID(PyObject *args)
{
long id = -1;
int index = 0;
PyObject *value = 0;
PyObject *base64 = Py_False;
if (!PyArg_ParseTuple(args, "l|i",&id,&index)) {
PyErr_Clear();
if (!PyArg_ParseTuple(args, "O|O",&value,&base64))
return NULL; // NULL triggers exception
}
if(id>0) {
PY_TRY {
auto sid = getStringHasherPtr()->getID(id, index);
if(!sid) Py_Return;
return sid.getPyObject();
}PY_CATCH;
}
std::string txt;
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_Check(value)) {
txt = PyUnicode_AsUTF8(value);
}
#else
if (PyUnicode_Check(value)) {
PyObject* unicode = PyUnicode_AsLatin1String(value);
txt = PyString_AsString(unicode);
Py_DECREF(unicode);
}
else if (PyString_Check(value)) {
txt = PyString_AsString(value);
}
#endif
else
throw Py::TypeError("expect argument of type string");
PY_TRY {
QByteArray data;
StringIDRef sid;
if(PyObject_IsTrue(base64)) {
data = QByteArray::fromBase64(QByteArray::fromRawData(txt.c_str(),txt.size()));
sid = getStringHasherPtr()->getID(data,true);
}else
sid = getStringHasherPtr()->getID(txt.c_str(),txt.size());
return sid.getPyObject();
}PY_CATCH;
}
Py::Int StringHasherPy::getCount(void) const {
return Py::Int((long)getStringHasherPtr()->count());
}
Py::Int StringHasherPy::getSize(void) const {
return Py::Int((long)getStringHasherPtr()->size());
}
Py::Boolean StringHasherPy::getSaveAll(void) const {
return Py::Boolean(getStringHasherPtr()->getSaveAll());
}
void StringHasherPy::setSaveAll(Py::Boolean value) {
getStringHasherPtr()->setSaveAll(value);
}
Py::Int StringHasherPy::getThreshold(void) const {
return Py::Int((long)getStringHasherPtr()->getThreshold());
}
void StringHasherPy::setThreshold(Py::Int value) {
getStringHasherPtr()->setThreshold(value);
}
Py::Dict StringHasherPy::getTable() const {
Py::Dict dict;
for(auto &v : getStringHasherPtr()->getIDMap())
dict.setItem(Py::Int(v.first),Py::String(v.second.dataToText()));
return dict;
}
PyObject *StringHasherPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int StringHasherPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}
+64
View File
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="BaseClassPy"
Name="StringIDPy"
Twin="StringID"
TwinPointer="StringID"
Include="App/StringHasher.h"
FatherInclude="Base/BaseClassPy.h"
Namespace="App"
FatherNamespace="Base"
Reference="true">
<Documentation>
<Author Licence="LGPL" Name="Zheng, Lei" EMail="realthunder.dev@gmail.com" />
<DeveloperDocu>This is the StringID class</DeveloperDocu>
<UserDocu>This is the StringID class</UserDocu>
</Documentation>
<Methode Name="isSame" Const="true">
<Documentation>
<UserDocu>Check if two StringIDs are the same</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Value" ReadOnly="true">
<Documentation>
<UserDocu>Return the integer value of this ID</UserDocu>
</Documentation>
<Parameter Name="Value" Type="Int"/>
</Attribute>
<Attribute Name="Related" ReadOnly="true">
<Documentation>
<UserDocu>Return the related string IDs</UserDocu>
</Documentation>
<Parameter Name="Related" Type="List"/>
</Attribute>
<Attribute Name="Data" ReadOnly="true">
<Documentation>
<UserDocu>Return the data associated with this ID</UserDocu>
</Documentation>
<Parameter Name="Data" Type="String"/>
</Attribute>
<Attribute Name="IsBinary" ReadOnly="true">
<Documentation>
<UserDocu>Check if the data is binary, </UserDocu>
</Documentation>
<Parameter Name="IsBinary" Type="Boolean"/>
</Attribute>
<Attribute Name="IsHashed" ReadOnly="true">
<Documentation>
<UserDocu>Check if the data is hash, if so 'Data' returns a base64 encoded string of the raw hash</UserDocu>
</Documentation>
<Parameter Name="IsHashed" Type="Boolean"/>
</Attribute>
<Attribute Name="Index" ReadOnly="false">
<Documentation>
<UserDocu>Geometry index. Only meaningful for geometry element name</UserDocu>
</Documentation>
<Parameter Name="Index" Type="Int"/>
</Attribute>
<ClassDeclarations>private:
friend class StringID;
int _index = 0;
</ClassDeclarations>
</PythonExport>
</GenerateModel>
+91
View File
@@ -0,0 +1,91 @@
/****************************************************************************
* Copyright (c) 2018 Zheng Lei (realthunder) <realthunder.dev@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
****************************************************************************/
#include "PreCompiled.h"
#include "StringHasher.h"
#include "StringIDPy.h"
#include "StringIDPy.cpp"
using namespace App;
// returns a string which represent the object e.g. when printed in python
std::string StringIDPy::representation(void) const
{
return getStringIDPtr()->toString(_index);
}
PyObject* StringIDPy::isSame(PyObject *args)
{
PyObject *other;
if (!PyArg_ParseTuple(args, "O!", &StringIDPy::Type, &other)) { // convert args: Python->C
return Py::new_reference_to(Py::False());
}
auto otherPy = static_cast<StringIDPy*>(other);
return Py::new_reference_to(Py::Boolean(
otherPy->getStringIDPtr() == this->getStringIDPtr()
&& otherPy->_index == this->_index));
}
Py::Int StringIDPy::getValue(void) const {
return Py::Int(getStringIDPtr()->value());
}
Py::List StringIDPy::getRelated(void) const {
Py::List list;
for (auto &id : getStringIDPtr()->relatedIDs())
list.append(Py::Long(id.value()));
return list;
}
Py::String StringIDPy::getData(void) const {
return Py::String(getStringIDPtr()->dataToText(this->_index));
}
Py::Boolean StringIDPy::getIsBinary(void) const {
return Py::Boolean(getStringIDPtr()->isBinary());
}
Py::Boolean StringIDPy::getIsHashed(void) const {
return Py::Boolean(getStringIDPtr()->isHashed());
}
Py::Int StringIDPy::getIndex(void) const {
return Py::Int(this->_index);
}
void StringIDPy::setIndex(Py::Int index) {
this->_index = index;
}
PyObject *StringIDPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int StringIDPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}
+52 -25
View File
@@ -22,11 +22,17 @@
3. This notice may not be removed or altered from any source distribution.
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
*/
Copyright (C) 2019 Zheng Lei (realthunder.dev@gmail.com)
* Added support of in-line transformation using boost iostream for memory
efficiency
*/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <iostream>
# include <string>
#endif
@@ -39,12 +45,31 @@ static const std::string base64_chars =
"0123456789+/";
static inline bool is_base64(unsigned char c) {
return (isalnum(c) || (c == '+') || (c == '/'));
const signed char *Base::base64_decode_table() {
static const signed char _table[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -1, -2, -1, -1, // 0-15
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 16-31
-2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, // 32-47
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, -1, // 48-63
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 64-79
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, // 80-95
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 96-111
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, // 112-127
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 128-143
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 144-159
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 160-175
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 176-191
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 192-207
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 208-223
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 224-239
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // 240-255
};
return _table;
}
std::string Base::base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
std::string ret;
std::size_t Base::base64_encode(char *out, void const* in, std::size_t in_len) {
char *ret = out;
unsigned char const *bytes_to_encode = reinterpret_cast<unsigned char const*>(in);
int i = 0;
int j = 0;
unsigned char char_array_3[3];
@@ -59,7 +84,7 @@ std::string Base::base64_encode(unsigned char const* bytes_to_encode, unsigned i
char_array_4[3] = char_array_3[2] & 0x3f;
for(i = 0; (i <4) ; i++)
ret += base64_chars[char_array_4[i]];
*ret++ = base64_chars[char_array_4[i]];
i = 0;
}
}
@@ -75,37 +100,41 @@ std::string Base::base64_encode(unsigned char const* bytes_to_encode, unsigned i
char_array_4[3] = char_array_3[2] & 0x3f;
for (j = 0; (j < i + 1); j++)
ret += base64_chars[char_array_4[j]];
*ret++ = base64_chars[char_array_4[j]];
while((i++ < 3))
ret += '=';
*ret++ = '=';
}
return ret;
return ret-out;
}
std::string Base::base64_decode(std::string const& encoded_string) {
int in_len = encoded_string.size();
std::pair<std::size_t, std::size_t> Base::base64_decode(
void *_out, char const *in, std::size_t in_len)
{
unsigned char *out = reinterpret_cast<unsigned char*>(_out);
unsigned char *ret = out;
char const *input = in;
int i = 0;
int j = 0;
int in_ = 0;
unsigned char char_array_4[4], char_array_3[3];
std::string ret;
while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
char_array_4[i++] = encoded_string[in_]; in_++;
static const signed char *table = base64_decode_table();
while (in_len-- && *in != '=') {
const signed char v = table[(int)(*in++)];
if(v < 0)
break;
char_array_4[i++] = (unsigned char)v;
if (i ==4) {
for (i = 0; i <4; i++)
char_array_4[i] = base64_chars.find(char_array_4[i]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
for (i = 0; (i < 3); i++)
ret += char_array_3[i];
*ret++ = char_array_3[i];
i = 0;
}
}
@@ -114,15 +143,13 @@ std::string Base::base64_decode(std::string const& encoded_string) {
for (j = i; j <4; j++)
char_array_4[j] = 0;
for (j = 0; j <4; j++)
char_array_4[j] = base64_chars.find(char_array_4[j]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
for (j = 0; (j < i - 1); j++) *ret++ = char_array_3[j];
}
return ret;
return std::make_pair((std::size_t)(ret-out), (std::size_t)(in-input));
}
+366 -5
View File
@@ -23,20 +23,381 @@
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
Copyright (C) 2019 Zheng Lei (realthunder.dev@gmail.com)
* Added support of in-line transformation using boost iostream for memory
efficiency
*/
#ifndef BASE_BASE64_H
#define BASE_BASE64_H
#include <FCGlobal.h>
#include <string>
#include <memory>
#include <vector>
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/operations.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/device/file.hpp>
namespace Base
{
std::string BaseExport base64_encode(unsigned char const* , unsigned int len);
std::string BaseExport base64_decode(std::string const& s);
/// Returns the max bytes of a encoded base64 string
inline std::size_t base64_encode_size(std::size_t len) {
return 4 * ((len + 2) / 3);
}
}
/// Returns the max bytes of a decoded base64 binary string
inline std::size_t base64_decode_size(std::size_t len) {
return len / 4 * 3;
}
/** Encode input binary with base64
* @param out: output buffer with minimum size of base64_encode(len)
* appending new data.
* @param in: input binary data
* @param len: input length
* @return The character count written to output.
*/
BaseExport std::size_t base64_encode(char *out, void const *in , std::size_t len);
/** Return the internal base64 decoding table
*
* The table maps from any 8-bit character to the decoded binary bits.
* Valid base64 characters are mapped to the corresponding 6-bit binary
* data. White space (space, tab, vtab, CR and LF) characters are mapped
* to -2. Other invalid characters are mapped to -1.
*/
BaseExport const signed char *base64_decode_table();
/** Decode the input base64 string into binary data
* @param out: output buffer with minimum size of base64_encode(len)
* appending new data.
* @param in: input binary data
* @param len: input length
* @return Return a pair of output size and input read size. Compare the
* read size to input size to check for error.
*/
BaseExport std::pair<std::size_t, std::size_t> base64_decode(
void *out, char const *, std::size_t len);
/** Encode input binary into base64 string
* @param out: output string. Note that the string is not cleared before
* adding new content.
* @param in: input binary data
* @param len: input length
*/
inline void base64_encode(std::string &out, void const* in , std::size_t len) {
std::size_t size = out.size();
out.resize(size + base64_encode_size(len));
len = base64_encode(&out[size],in,len);
out.resize(size+len);
}
/** Encode input binary into base64 string
* @param in: input binary data
* @param len: input length
* @return Return the base64 string.
*/
inline std::string base64_encode(void const* in , std::size_t len) {
std::string out;
base64_encode(out,in,len);
return out;
}
/** Decode base64 string into binary data
* @param out: output binary data. Note that the data is not cleared before
* adding new content.
* @param in: input base64 string
* @param len: input length
* @return Return the processed input length. Compare this with the
* argument \c len to check for error.
*/
template<typename T>
inline std::size_t base64_decode(T &out, char const *in, std::size_t len) {
std::size_t size = out.size();
out.resize(size + base64_decode_size(len));
std::pair<std::size_t,std::size_t> res = base64_decode(&out[size],in,len);
out.resize(size + res.first);
return res.second;
}
/** Decode base64 string into binary data
* @param out: output binary data. Note that the data is not cleared before
* adding new content.
* @param s: input base64 string
* @return Return the processed input length. Compare this with the
* argument \c len to check for error.
*/
template<typename T>
inline std::size_t base64_decode(T &out, std::string const &s) {
return base64_decode(out,s.c_str(),s.size());
}
/** Decode base64 string into binary data
* @param out adding new content.
* @param s: input base64 string
* @return Return the decoded binary data.
*/
inline std::string base64_decode(std::string const& s) {
std::string out;
base64_decode(out,s.c_str(),s.size());
return out;
}
namespace bio = boost::iostreams;
/** A base64 encoder that can be used as a boost iostream filter
*
* @sa See create_base64_encoder() for example usage
*/
struct base64_encoder {
typedef char char_type;
struct category : bio::multichar_output_filter_tag
, bio::closable_tag
, bio::optimally_buffered_tag
{};
/** Constructor
* @param line_size: line size for the output base64 string, 0 to
* disable segmentation.
*/
base64_encoder(std::size_t line_size)
:line_size(line_size)
{
}
std::streamsize optimal_buffer_size() const {
return base64_decode_size(line_size);
}
template<typename Device>
void close(Device &dev)
{
if(pending_size)
base64_encode(buffer,pending,pending_size);
if(buffer.size()) {
bio::write(dev,buffer.c_str(),buffer.size());
if(line_size)
bio::put(dev,'\n');
buffer.clear();
}else if(pos && line_size)
bio::put(dev,'\n');
}
template<typename Device>
std::streamsize write(Device& dev, const char_type* s, std::streamsize n) {
std::streamsize res = n;
if(pending_size) {
while(n && pending_size < 3) {
pending[pending_size++] = *s++;
--n;
}
if(pending_size!=3)
return res;
base64_encode(buffer,pending,3);
}
pending_size = n%3;
n = n/3*3;
base64_encode(buffer,s,n);
s += n;
for(unsigned i=0;i<pending_size;++i)
pending[i] = s[i];
const char *buf = buffer.c_str();
const char *end = buf + buffer.size();
if(line_size && buffer.size()>=line_size-pos) {
bio::write(dev,buf,line_size-pos);
bio::put(dev,'\n');
buf += line_size-pos;
pos = 0;
for(; end-buf>=(int)line_size; buf+=line_size) {
bio::write(dev,buf,line_size);
bio::put(dev,'\n');
}
}
pos += end-buf;
bio::write(dev,buf,end-buf);
buffer.clear();
return n;
}
std::size_t line_size;
std::size_t pos = 0;
std::size_t pending_size = 0;
unsigned char pending[3];
std::string buffer;
};
/** A base64 decoder that can be used as a boost iostream filter
*
* @sa See create_base64_decoder() for example usage
*/
struct base64_decoder {
typedef char char_type;
struct category : bio::multichar_input_filter_tag
, bio::optimally_buffered_tag
{};
/** Constructor
* @param line_size: line size of the encoded base64 string. This is
* used just as a suggestion for better buffering.
* @param silent: whether to throw on invalid non white space character.
*/
base64_decoder(std::size_t line_size, bool silent)
:line_size(line_size), silent(silent)
{
}
std::streamsize optimal_buffer_size() const {
return base64_encode_size(line_size?line_size:1024);
}
template<typename Device>
std::streamsize read(Device& dev, char_type* s, std::streamsize n) {
static const signed char *table = base64_decode_table();
if(!n)
return 0;
std::streamsize count = 0;
for(;;) {
while(pending_out<out_count) {
*s++ = char_array_3[pending_out++];
++count;
if(--n == 0)
return count;
}
if(eof)
return count?count:-1;
for(;;) {
int d = bio::get(dev);
if(d < 0) {
eof = true;
if(pending_in<=1) {
if(pending_in == 1 && !silent)
throw BOOST_IOSTREAMS_FAILURE("Unexpected ending of base64 string");
return count?count:-1;
}
out_count = pending_in-1;
pending_in = 4;
} else {
signed char c = table[d];
if(c < 0) {
if(c==-2 || silent)
continue;
throw BOOST_IOSTREAMS_FAILURE("Invalid character in base64 string");
}
char_array_4[pending_in++] = (char)c;
}
if(pending_in == 4) {
pending_out = pending_in = 0;
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
break;
}
}
}
}
std::size_t line_size;
std::uint8_t pending_in = 0;
char char_array_4[4];
std::uint8_t pending_out = 3;
std::uint8_t out_count = 3;
char char_array_3[3];
bool silent;
bool eof = false;
};
/** Create an output stream that transforms the input binary data to base64 strings
*
* @param out: the downstream output stream that will be fed with base64 string
* @param line_size: line size of the base64 string. Zero to disable segmenting.
*
* @return A unique pointer to an output stream that can transforms the
* input binary data to base64 strings.
*/
inline std::unique_ptr<std::ostream> create_base64_encoder(
std::ostream &out, std::size_t line_size=80)
{
std::unique_ptr<std::ostream> res(new bio::filtering_ostream);
bio::filtering_ostream *f = static_cast<bio::filtering_ostream*>(res.get());
f->push(base64_encoder(line_size));
f->push(out);
return res;
}
/** Create an output stream that stores the input binary data to file as base64 strings
*
* @param filename: the output file path
* @param line_size: line size of the base64 string. Zero to disable segmenting.
*
* @return A unique pointer to an output stream that can transforms the
* input binary data to base64 strings.
*/
inline std::unique_ptr<std::ostream> create_base64_encoder(
const std::string &filepath, std::size_t line_size=80)
{
std::unique_ptr<std::ostream> res(new bio::filtering_ostream);
bio::filtering_ostream *f = static_cast<bio::filtering_ostream*>(res.get());
f->push(base64_encoder(line_size));
f->push(bio::file_sink(filepath));
return res;
}
/** Create an input stream that can transform base64 into binary
*
* @param in: input upstream.
* @param line_size: line size of the encoded base64 string. This is
* used just as a suggestion for better buffering.
* @param silent: whether to throw on invalid non white space character.
*
* @return A unique pointer to an input stream that read from the given
* upstream and transform the read base64 strings into binary data.
*/
inline std::unique_ptr<std::istream> create_base64_decoder(
std::istream &in, std::size_t line_size=80, bool silent=true)
{
std::unique_ptr<std::istream> res(new bio::filtering_istream);
bio::filtering_istream *f = static_cast<bio::filtering_istream*>(res.get());
f->push(base64_decoder(line_size,silent));
f->push(in);
return res;
}
/** Create an input stream that can transform base64 into binary
*
* @param filepath: input file.
* @param ending: optional ending character. If non zero, the filter
* will signal EOF when encounter this character.
* @param putback: if true and the filter read the ending character
* it will put it back into upstream
* @param line_size: line size of the encoded base64 string. This is
* used just as a suggestion for better buffering.
* @param silent: whether to throw on invalid non white space character.
*
* @return A unique pointer to an input stream that read from the given
* file and transform the read base64 strings into binary data.
*/
inline std::unique_ptr<std::istream> create_base64_decoder(
const std::string &filepath, std::size_t line_size=80, bool silent=true)
{
std::unique_ptr<std::istream> res(new bio::filtering_istream);
bio::filtering_istream *f = static_cast<bio::filtering_istream*>(res.get());
f->push(base64_decoder(line_size,silent));
f->push(bio::file_source(filepath));
return res;
}
} // namespace Base
#endif
+7
View File
@@ -109,6 +109,7 @@ template <typename Enum>
class Flags {
static_assert(std::is_enum<Enum>::value, "Flags is only usable on enumeration types.");
Enum i;
typedef typename std::underlying_type<Enum>::type underlying_type;
public:
constexpr inline Flags(Enum f) : i(f) {}
@@ -123,6 +124,12 @@ public:
using u = typename std::underlying_type<Enum>::type;
return static_cast<u>(i) == static_cast<u>(f.i);
}
Enum getValue() const {
return i;
}
underlying_type toUnderlyingType() const {
return static_cast<underlying_type>(i);
}
};
}
+2
View File
@@ -34,6 +34,7 @@
#include <frameobject.h>
#include "ConsoleObserver.h"
#include "Interpreter.h"
using namespace Base;
@@ -263,6 +264,7 @@ std::stringstream &LogLevel::prefix(std::stringstream &str, const char *src, int
}
if (print_tag) str << '<' << tag << "> ";
if (print_src==2) {
PyGILStateLocker lock;
PyFrameObject* frame = PyEval_GetFrame();
if (frame) {
line = PyFrame_GetLineNumber(frame);
-42
View File
@@ -25,52 +25,10 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <cassert>
# include <iostream>
#endif
#include <QAtomicInt>
#include "Handle.h"
using namespace Base;
//**************************************************************************
// Construction/Destruction
Handled::Handled()
: _lRefCount(new QAtomicInt(0))
{
}
Handled::~Handled()
{
if (static_cast<int>(*_lRefCount) != 0)
std::cerr << "Reference counter of deleted object is not zero!!!!!" << std::endl;
delete _lRefCount;
}
void Handled::ref() const
{
_lRefCount->ref();
}
void Handled::unref() const
{
assert(*_lRefCount > 0);
if (!_lRefCount->deref()) {
delete this;
}
}
int Handled::getRefCount() const
{
return static_cast<int>(*_lRefCount);
}
const Handled& Handled::operator = (const Handled&)
{
// we must not assign _lRefCount
return *this;
}
+51 -22
View File
@@ -29,8 +29,9 @@
#include <FCGlobal.h>
#endif
class QAtomicInt;
#include <assert.h>
#include <atomic>
#include <iostream>
namespace Base
{
@@ -72,6 +73,18 @@ public:
_toHandle->unref();
}
void reset(const Reference<T> &p=Reference<T>()) {
*this = p;
}
void swap(Reference<T> &p) {
if(*this != p) {
auto tmp = p;
p = *this;
*this = tmp;
}
}
//**************************************************************************
// operator implementation
@@ -116,18 +129,18 @@ public:
}
/** Lower operator, needed for sorting in maps and sets */
bool operator<(const Reference<T>& p) const {
return _toHandle < p._toHandle;
}
// bool operator<(const Reference<T>& p) const {
// return _toHandle < p._toHandle;
// }
/** Equal operator */
bool operator==(const Reference<T>& p) const {
return _toHandle == p._toHandle;
}
bool operator!=(const Reference<T>& p) const {
return _toHandle != p._toHandle;
}
// bool operator==(const Reference<T>& p) const {
// return _toHandle == p._toHandle;
// }
//
// bool operator!=(const Reference<T>& p) const {
// return _toHandle != p._toHandle;
// }
//**************************************************************************
@@ -160,20 +173,36 @@ private:
class BaseExport Handled
{
public:
Handled();
virtual ~Handled();
Handled()
:_lRefCount(0)
{}
void ref() const;
void unref() const;
Handled(const Handled&) = delete;
int getRefCount() const;
const Handled& operator = (const Handled&);
virtual ~Handled()
{
if (_lRefCount != 0)
std::cerr << "Reference counter of deleted object is not zero!!!!!" << std::endl;
}
void ref() const {++_lRefCount;}
int unref() const
{
int res = --_lRefCount;
if (res == 0)
delete this;
else
assert(res>0);
return res;
}
int getRefCount(void) const {return _lRefCount;}
const Handled& operator = (const Handled&) {return *this;}
private:
Handled(const Handled&);
private:
QAtomicInt* _lRefCount;
mutable std::atomic<int> _lRefCount;
};
} // namespace Base
+2
View File
@@ -201,6 +201,8 @@ public:
//@{
/// set a string value
void SetASCII(const char* Name, const char *sValue);
/// set a string value
void SetASCII(const char* Name, const std::string &sValue) { SetASCII(Name, sValue.c_str()); }
/// read a string values
std::string GetASCII(const char* Name, const char * pPreset=nullptr) const;
/// remove a string value from this group
+3 -2
View File
@@ -124,13 +124,14 @@ void Persistence::dumpToStream(std::ostream& stream, int compression)
void Persistence::restoreFromStream(std::istream& stream)
{
zipios::ZipInputStream zipstream(stream);
Base::XMLReader reader("", zipstream);
Base::ZipReader zreader(zipstream,std::string("<stream>"));
Base::XMLReader reader(zreader);
if (!reader.isValid())
throw Base::ValueError("Unable to construct reader");
reader.readElement("Content");
Restore(reader);
reader.readFiles(zipstream);
reader.readFiles();
restoreFinished();
}
+4
View File
@@ -141,6 +141,10 @@ public:
* @see Base::Reader,Base::XMLReader
*/
virtual void RestoreDocFile(Reader &/*reader*/);
/// Called by reader to set restoring error
virtual void SetRestoreError(const char *) {}
/// Encodes an attribute upon saving.
static std::string encodeAttribute(const std::string&);
+387 -152
View File
@@ -29,6 +29,10 @@
#include <locale>
#include <boost/ref.hpp>
#include <boost/algorithm/string/predicate.hpp>
/// Here the FreeCAD includes sorted by Base,App,Gui......
#include "Reader.h"
#include "Base64.h"
#include "Console.h"
@@ -44,24 +48,73 @@
#include <zipios++/zipinputstream.h>
FC_LOG_LEVEL_INIT("Base",true,true);
XERCES_CPP_NAMESPACE_USE
using namespace std;
using namespace Base;
namespace bio = boost::iostreams;
static std::string _ReaderContext;
#define _FC_READER_THROW(_excp,_msg) \
FC_THROWM(_excp, _msg << "\nIn context: " << _ReaderContext);
#define FC_READER_THROW(_msg) _FC_READER_THROW(Base::XMLParseException, _msg)
ReaderContext::ReaderContext(const char *name)
{
init(name);
}
ReaderContext::ReaderContext(const std::string &name)
{
init(name.c_str());
}
void ReaderContext::init(const char *name)
{
size = std::string::npos;
if(name && name[0]) {
size = _ReaderContext.size();
_ReaderContext += "|";
_ReaderContext += name;
}
}
ReaderContext::~ReaderContext()
{
if(size != std::string::npos)
_ReaderContext.resize(size);
}
// ---------------------------------------------------------------------------
// Base::XMLReader: Constructors and Destructor
// ---------------------------------------------------------------------------
Base::XMLReader::XMLReader(const char* FileName, std::istream& str)
: DocumentSchema(0), ProgramVersion(""), FileVersion(0), Level(0),
CharacterCount(0), ReadType(None), _File(FileName), _valid(false),
_verbose(true)
Base::XMLReader::XMLReader(Base::Reader &reader, std::size_t bufsize)
: DocumentSchema(0), ProgramVersion(""), FileVersion(reader.getFileVersion()), Level(0),
CharacterOffset(-1), ReadType(None), _File(reader.getFileName()), _valid(false),
_verbose(true), _reader(&reader), _ownReader(false)
{
init(bufsize);
}
Base::XMLReader::XMLReader(const char *name, std::istream &str, std::size_t bufsize)
: DocumentSchema(0), ProgramVersion(""), FileVersion(0), Level(0),
CharacterOffset(-1), ReadType(None), _File(name), _valid(false),
_verbose(true),_reader(new Base::Reader(str,name)), _ownReader(true)
{
init(bufsize);
}
void Base::XMLReader::init(std::size_t bufsize) {
#ifdef _MSC_VER
str.imbue(std::locale::empty());
_reader->imbue(std::locale::empty());
#else
str.imbue(std::locale::classic());
_reader->imbue(std::locale::classic());
#endif
// create the parser
@@ -74,12 +127,16 @@ Base::XMLReader::XMLReader(const char* FileName, std::istream& str)
//parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
//parser->setFeature(XMLUni::fgXercesDynamic, true);
parser->setInputBufferSize(bufsize);
parser->setContentHandler(this);
parser->setLexicalHandler(this);
// We don't seem to need this?
// parser->setLexicalHandler(this);
parser->setErrorHandler(this);
try {
StdInputSource file(str, _File.filePath().c_str());
StdInputSource file(*_reader, _File.filePath().c_str());
_valid = parser->parseFirst(file, token);
}
catch (const XMLException& toCatch) {
@@ -105,6 +162,8 @@ Base::XMLReader::~XMLReader()
{
// Delete the parser itself. Must be done prior to calling Terminate, below.
delete parser;
if(_ownReader)
delete _reader;
}
const char* Base::XMLReader::localName() const
@@ -117,63 +176,32 @@ unsigned int Base::XMLReader::getAttributeCount() const
return static_cast<unsigned int>(AttrMap.size());
}
long Base::XMLReader::getAttributeAsInteger(const char* AttrName) const
long Base::XMLReader::getAttributeAsInteger(const char* AttrName, const char *def) const
{
AttrMapType::const_iterator pos = AttrMap.find(AttrName);
if (pos != AttrMap.end()) {
return atol(pos->second.c_str());
}
else {
// wrong name, use hasAttribute if not sure!
std::ostringstream msg;
msg << "XML Attribute: \"" << AttrName << "\" not found";
throw Base::XMLAttributeError(msg.str());
}
return atol(getAttribute(AttrName,def));
}
unsigned long Base::XMLReader::getAttributeAsUnsigned(const char* AttrName) const
unsigned long Base::XMLReader::getAttributeAsUnsigned(const char* AttrName, const char *def) const
{
AttrMapType::const_iterator pos = AttrMap.find(AttrName);
if (pos != AttrMap.end()) {
return strtoul(pos->second.c_str(),nullptr,10);
}
else {
// wrong name, use hasAttribute if not sure!
std::ostringstream msg;
msg << "XML Attribute: \"" << AttrName << "\" not found";
throw Base::XMLAttributeError(msg.str());
}
return strtoul(getAttribute(AttrName,def),0,10);
}
double Base::XMLReader::getAttributeAsFloat (const char* AttrName) const
double Base::XMLReader::getAttributeAsFloat (const char* AttrName, const char *def) const
{
AttrMapType::const_iterator pos = AttrMap.find(AttrName);
if (pos != AttrMap.end()) {
return atof(pos->second.c_str());
}
else {
// wrong name, use hasAttribute if not sure!
std::ostringstream msg;
msg << "XML Attribute: \"" << AttrName << "\" not found";
throw Base::XMLAttributeError(msg.str());
}
return atof(getAttribute(AttrName,def));
}
const char* Base::XMLReader::getAttribute (const char* AttrName) const
const char* Base::XMLReader::getAttribute (const char* AttrName, const char *def) const
{
AttrMapType::const_iterator pos = AttrMap.find(AttrName);
if (pos != AttrMap.end()) {
return pos->second.c_str();
}
else if(def)
return def;
else {
// wrong name, use hasAttribute if not sure!
std::ostringstream msg;
msg << "XML Attribute: \"" << AttrName << "\" not found";
throw Base::XMLAttributeError(msg.str());
_FC_READER_THROW(Base::XMLAttributeError, "XML Attribute: '" << AttrName << "' not found");
}
}
@@ -184,6 +212,9 @@ bool Base::XMLReader::hasAttribute (const char* AttrName) const
bool Base::XMLReader::read()
{
if(ReadType == EndDocument)
FC_READER_THROW("End of document reached");
ReadType = None;
try {
@@ -200,7 +231,7 @@ bool Base::XMLReader::read()
char* message = XMLString::transcode(toCatch.getMessage());
std::string what = message;
XMLString::release(&message);
throw Base::XMLBaseException(what);
_FC_READER_THROW(Base::XMLBaseException, what);
#endif
}
catch (const SAXParseException& toCatch) {
@@ -214,7 +245,7 @@ bool Base::XMLReader::read()
char* message = XMLString::transcode(toCatch.getMessage());
std::string what = message;
XMLString::release(&message);
throw Base::XMLParseException(what);
FC_READER_THROW(what);
#endif
}
catch (...) {
@@ -222,146 +253,200 @@ bool Base::XMLReader::read()
cerr << "Unexpected Exception \n" ;
return false;
#else
throw Base::XMLBaseException("Unexpected XML exception");
_FC_READER_THROW(Base::XMLBaseException, "Unexpected XML exception");
#endif
}
return true;
}
void Base::XMLReader::readElement(const char* ElementName)
void Base::XMLReader::readElement(const char* ElementName, int *guard)
{
bool ok;
endCharStream();
AttrMap.clear();
int currentLevel = Level;
std::string currentName = LocalName;
do {
ok = read(); if (!ok) break;
read();
if (ReadType == EndElement && currentName == LocalName && currentLevel >= Level) {
// we have reached the end of the element when calling this method
// thus we must stop reading on.
if(ElementName && currentName!=ElementName) {
if (FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG)) {
// Missing element. Consider this as non-fatal
FC_WARN("Document XML element '" << (ElementName?ElementName:"") << "' not found\n"
<< "In context: " << _ReaderContext);
}
}
break;
}
else if (ReadType == EndDocument) {
// the end of the document has been reached but we still try to continue on reading
throw Base::XMLParseException("End of document reached");
FC_READER_THROW("End of document reached");
}
if(Guards.size() && Level < *Guards.back())
FC_READER_THROW("Document parsing error");
} while ((ReadType != StartElement && ReadType != StartEndElement) ||
(ElementName && LocalName != ElementName));
if(guard) {
if(ReadType == StartEndElement)
*guard = Level;
else
*guard = Level-1;
Guards.push_back(guard);
}
}
int Base::XMLReader::level() const {
return Level;
}
void Base::XMLReader::readEndElement(const char* ElementName, int level)
void Base::XMLReader::readEndElement(const char* ElementName, int *guard)
{
endCharStream();
int level = -1;
if(guard) {
level = *guard;
if(Guards.empty() || Guards.back()!=guard || Level < level)
FC_READER_THROW("Parsing error while reading end element '"
<< (ElementName?ElementName:"?") << "'");
}
// if we are already at the end of the current element
if (ReadType == EndElement
if ((ReadType == EndElement || ReadType == StartEndElement)
&& ElementName
&& LocalName == ElementName
&& (level<0 || level==Level))
{
if(guard)
Guards.pop_back();
return;
}
else if (ReadType == EndDocument) {
// the end of the document has been reached but we still try to continue on reading
throw Base::XMLParseException("End of document reached");
FC_READER_THROW("End of document reached while reading end element '"
<< (ElementName?ElementName:"?") << "'");
}
bool ok;
do {
ok = read(); if (!ok) break;
read();
if (ReadType == EndDocument)
break;
} while (ReadType != EndElement
|| (ElementName
&& (LocalName != ElementName
|| (level>=0 && level!=Level))));
if(guard)
Guards.pop_back();
}
void Base::XMLReader::readCharacters()
{
}
std::streamsize Base::XMLReader::read(char_type* s, std::streamsize n) {
void Base::XMLReader::readBinFile(const char* filename)
{
Base::FileInfo fi(filename);
Base::ofstream to(fi, std::ios::out | std::ios::binary);
if (!to)
throw Base::FileException("XMLReader::readBinFile() Could not open file!");
char_type *buf = s;
if(CharacterOffset<0)
return -1;
bool ok;
do {
ok = read(); if (!ok) break;
} while (ReadType != EndCDATA);
for(;;) {
std::streamsize copy_size = Characters.size()-CharacterOffset;
if(n<copy_size)
copy_size = n;
std::memcpy(s,Characters.c_str()+CharacterOffset,copy_size);
n -= copy_size;
s += copy_size;
CharacterOffset += copy_size;
to << Base::base64_decode(Characters);
to.close();
}
if(!n)
break;
void Base::XMLReader::readFiles(zipios::ZipInputStream &zipstream) const
{
// It's possible that not all objects inside the document could be created, e.g. if a module
// is missing that would know these object types. So, there may be data files inside the zip
// file that cannot be read. We simply ignore these files.
// On the other hand, however, it could happen that a file should be read that is not part of
// the zip file. This happens e.g. if a document is written without GUI up but is read with GUI
// up. In this case the associated GUI document asks for its file which is not part of the ZIP
// file, then.
// In either case it's guaranteed that the order of the files is kept.
zipios::ConstEntryPointer entry;
try {
entry = zipstream.getNextEntry();
}
catch (const std::exception&) {
// There is no further file at all. This can happen if the
// project file was created without GUI
return;
}
std::vector<FileEntry>::const_iterator it = FileList.begin();
Base::SequencerLauncher seq("Importing project files...", FileList.size());
while (entry->isValid() && it != FileList.end()) {
std::vector<FileEntry>::const_iterator jt = it;
// Check if the current entry is registered, otherwise check the next registered files as soon as
// both file names match
while (jt != FileList.end() && entry->getName() != jt->FileName)
++jt;
// If this condition is true both file names match and we can read-in the data, otherwise
// no file name for the current entry in the zip was registered.
if (jt != FileList.end()) {
try {
Base::Reader reader(zipstream, jt->FileName, FileVersion);
jt->Object->RestoreDocFile(reader);
if (reader.getLocalReader())
reader.getLocalReader()->readFiles(zipstream);
}
catch(...) {
// For any exception we just continue with the next file.
// It doesn't matter if the last reader has read more or
// less data than the file size would allow.
// All what we need to do is to notify the user about the
// failure.
Base::Console().Error("Reading failed from embedded file: %s\n", entry->toString().c_str());
}
// Go to the next registered file name
it = jt + 1;
}
seq.next();
// In either case we must go to the next entry
try {
entry = zipstream.getNextEntry();
}
catch (const std::exception&) {
// there is no further entry
if(ReadType==Chars)
read();
else {
CharacterOffset = -1;
break;
}
}
return s - buf;
}
void Base::XMLReader::endCharStream() {
CharacterOffset = -1;
CharStream.reset();
}
std::istream &Base::XMLReader::charStream() {
if(!CharStream)
FC_READER_THROW("no current character stream");
return *CharStream;
}
std::istream &Base::XMLReader::beginCharStream(bool base64) {
if(CharStream)
FC_READER_THROW("recursive character stream");
// TODO: An XML element can actually contain a mix of child elements and
// characters. So we should not actually demand 'StartElement' here. But
// with the current implementation of character stream, we cannot track
// child elements and character content at the same time.
if (ReadType == StartElement) {
CharacterOffset = 0;
read();
} else if (ReadType == StartEndElement) {
// If we are current at a self closing element, just leave the offset
// as negative and do not read any characters. This will result in an
// empty input stream for the caller.
CharacterOffset = -1;
} else
FC_READER_THROW("invalid state while reading character stream");
CharStream.reset(new bio::filtering_istream);
auto f = static_cast<bio::filtering_istream*>(CharStream.get());
if(base64)
f->push(base64_decoder(80,false));
f->push(boost::ref(*this));
return *CharStream;
}
void Base::XMLReader::readCharacters(const char* filename, bool base64)
{
Base::FileInfo fi(filename);
Base::ofstream to(fi, std::ios::out | std::ios::binary | std::ios::trunc);
if (!to)
_FC_READER_THROW(Base::FileException, "failed to open binary file " << filename);
beginCharStream(base64) >> to.rdbuf();
to.close();
endCharStream();
}
std::string Base::XMLReader::readCharacters()
{
std::stringstream ss;
beginCharStream(false) >> ss.rdbuf();
endCharStream();
return ss.str();
}
void Base::XMLReader::readFiles()
{
if(FileList.size()) {
assert(!_reader->getParent());
_reader->readFiles(*this);
}
}
const char *Base::XMLReader::addFile(const char* Name, Base::Persistence *Object)
{
if(_reader->getParent())
return _reader->getParent()->addFile(Name,Object);
FileEntry temp;
temp.FileName = Name;
temp.Object = Object;
@@ -374,11 +459,21 @@ const char *Base::XMLReader::addFile(const char* Name, Base::Persistence *Object
const std::vector<std::string>& Base::XMLReader::getFilenames() const
{
if(_reader->getParent())
return _reader->getParent()->getFilenames();
return FileNames;
}
const std::vector<Base::XMLReader::FileEntry> &Base::XMLReader::getFileList() const {
return FileList;
}
bool Base::XMLReader::isRegistered(Base::Persistence *Object) const
{
if(_reader->getParent())
return _reader->getParent()->isRegistered(Object);
if (Object) {
for (std::vector<FileEntry>::const_iterator it = FileList.begin(); it != FileList.end(); ++it) {
if (it->Object == Object)
@@ -389,18 +484,26 @@ bool Base::XMLReader::isRegistered(Base::Persistence *Object) const
return false;
}
void Base::XMLReader::addName(const char*, const char*)
void Base::XMLReader::addName(const char *key, const char *value)
{
if(_reader->getParent())
_reader->getParent()->addName(key,value);
}
const char* Base::XMLReader::getName(const char* name) const
{
return name;
if(_reader->getParent())
return _reader->getParent()->getName(name);
else
return name;
}
bool Base::XMLReader::doNameMapping() const
{
return false;
if(_reader->getParent())
return _reader->getParent()->doNameMapping();
else
return false;
}
// ---------------------------------------------------------------------------
@@ -439,6 +542,9 @@ void Base::XMLReader::endElement (const XMLCh* const /*uri*/, const XMLCh *cons
ReadType = StartEndElement;
else
ReadType = EndElement;
if(Guards.size() && Level<*Guards.back())
*Guards.back() = INT_MAX;
}
void Base::XMLReader::startCDATA ()
@@ -452,14 +558,19 @@ void Base::XMLReader::endCDATA ()
}
#if (XERCES_VERSION_MAJOR == 2)
void Base::XMLReader::characters(const XMLCh* const chars, const unsigned int length)
void Base::XMLReader::characters(const XMLCh* const chars, const unsigned int len)
#else
void Base::XMLReader::characters(const XMLCh* const chars, const XMLSize_t length)
void Base::XMLReader::characters(const XMLCh* const chars, const XMLSize_t len)
#endif
{
Characters = StrX(chars).c_str();
(void)len;
ReadType = Chars;
CharacterCount += length;
// We only capture characters when some one wants it
if(CharacterOffset>=0) {
Characters = StrXUTF8(chars).c_str();
CharacterOffset = 0;
}
}
#if (XERCES_VERSION_MAJOR == 2)
@@ -524,7 +635,11 @@ bool Base::XMLReader::testStatus(ReaderStatus pos) const
void Base::XMLReader::setStatus(ReaderStatus pos, bool on)
{
StatusBits.set(static_cast<size_t>(pos), on);
if(testStatus(pos)!=on) {
if(_reader->getParent() && pos == PartialRestore)
_reader->getParent()->setStatus(pos,on);
StatusBits.set((size_t)pos, on);
}
}
void Base::XMLReader::setPartialRestore(bool on)
@@ -555,32 +670,152 @@ void Base::XMLReader::clearPartialRestoreObject()
// ----------------------------------------------------------
Base::Reader::Reader(std::istream& str, const std::string& name, int version)
: std::istream(str.rdbuf()), _str(str), _name(name), fileVersion(version)
Base::Reader::Reader(std::istream &str, const std::string& name, Base::XMLReader *parent)
: std::istream(str.rdbuf()), _name(name), _parent(parent)
{
}
std::string Base::Reader::getFileName() const
Base::Reader::Reader(const std::string& name, Base::XMLReader *parent)
: std::istream(nullptr), _name(name), _parent(parent)
{
}
const std::string &Base::Reader::getFileName() const
{
return this->_name;
}
int Base::Reader::getFileVersion() const
{
return fileVersion;
return _parent?_parent->FileVersion:0;
}
std::istream& Base::Reader::getStream()
int Base::Reader::getDocumentSchema() const
{
return this->_str;
return _parent?_parent->DocumentSchema:0;
}
void Base::Reader::initLocalReader(std::shared_ptr<Base::XMLReader> reader)
{
this->localreader = reader;
Base::XMLReader *Base::Reader::getParent() const {
return _parent;
}
std::shared_ptr<Base::XMLReader> Base::Reader::getLocalReader() const
// ----------------------------------------------------------
Base::ZipReader::ZipReader(zipios::ZipInputStream &str, const std::string &name, Base::XMLReader *parent)
:Base::Reader(str,name,parent),_stream(str)
{
return(this->localreader);
}
void Base::ZipReader::readFiles(XMLReader &xmlReader)
{
// It's possible that not all objects inside the document could be created, e.g. if a module
// is missing that would know these object types. So, there may be data files inside the zip
// file that cannot be read. We simply ignore these files.
// On the other hand, however, it could happen that a file should be read that is not part of
// the zip file. This happens e.g. if a document is written without GUI up but is read with GUI
// up. In this case the associated GUI document asks for its file which is not part of the ZIP
// file, then.
// In either case it's guaranteed that the order of the files is kept.
zipios::ConstEntryPointer entry;
try {
entry = _stream.getNextEntry();
}
catch (const std::exception&) {
// There is no further file at all. This can happen if the
// project file was created without GUI
return;
}
const auto &FileList = xmlReader.getFileList();
std::size_t it = 0;
Base::SequencerLauncher seq("Importing project files...", FileList.size());
while (entry->isValid() && it < FileList.size()) {
auto jt = it;
// Check if the current entry is registered, otherwise check the next registered files as soon as
// both file names match
while (jt < FileList.size() && entry->getName() != FileList[jt].FileName)
++jt;
// If this condition is true both file names match and we can read-in the data, otherwise
// no file name for the current entry in the zip was registered.
if (jt < FileList.size()) {
try {
Base::ZipReader zipreader(_stream, FileList[jt].FileName, &xmlReader);
FileList[jt].Object->RestoreDocFile(zipreader);
} catch(Base::AbortException &e) {
e.ReportException();
FC_ERR("User abort when reading embedded file: " << FileList[jt].FileName);
throw;
} catch(Base::Exception &e) {
e.ReportException();
FC_ERR("Reading failed from embedded file: " << FileList[jt].FileName);
} catch(...) {
// For any exception we just continue with the next file.
// It doesn't matter if the last reader has read more or
// less data than the file size would allow.
// All what we need to do is to notify the user about the
// failure.
FC_ERR("Reading failed from embedded file: " << FileList[jt].FileName);
}
// Go to the next registered file name
it = jt + 1;
}
seq.next();
// In either case we must go to the next entry
try {
entry = _stream.getNextEntry();
}
catch (const std::exception&) {
// there is no further entry
break;
}
}
}
// ----------------------------------------------------------
Base::FileReader::FileReader(const Base::FileInfo &fi,
const std::string &name, Base::XMLReader *parent)
:Base::Reader(name.size()?name:fi.fileName(),parent)
,_dir(fi.dirPath())
,_stream(fi,std::ios::in|std::ios::binary)
{
this->rdbuf(_stream.rdbuf());
}
void Base::FileReader::readFiles(Base::XMLReader &xmlReader) {
const auto &FileList = xmlReader.getFileList();
Base::SequencerLauncher seq("Importing project files...", FileList.size());
std::string dirname = Base::FileInfo(_dir).fileName();
for(size_t i=0; i<FileList.size(); ++i) {
const auto &entry = FileList[i];
Base::FileInfo fi(_dir+'/'+entry.FileName);
try {
Base::FileReader freader(fi, dirname+'/'+entry.FileName, &xmlReader);
if(!freader._stream.is_open()) {
std::string msg("Failed to open ");
msg += fi.filePath();
FC_ERR(msg);
entry.Object->SetRestoreError(msg.c_str());
} else
entry.Object->RestoreDocFile(freader);
} catch(Base::AbortException &e) {
e.ReportException();
FC_ERR("User abort when reading: " << fi.filePath());
throw;
} catch(Base::Exception &e) {
e.ReportException();
FC_ERR("Reading failed: " << fi.filePath());
}
catch(...) {
// For any exception we just continue with the next file.
// It doesn't matter if the last reader has read more or
// less data than the file size would allow.
// All what we need to do is to notify the user about the
// failure.
FC_ERR("Reading failed: " << fi.filePath());
}
seq.next();
}
}
+154 -40
View File
@@ -33,8 +33,11 @@
#include <xercesc/sax2/Attributes.hpp>
#include <xercesc/sax2/DefaultHandler.hpp>
#include "FileInfo.h"
#include <boost/iostreams/concepts.hpp>
#include "FileInfo.h"
#include "Writer.h"
#include "Stream.h"
namespace zipios {
class ZipInputStream;
@@ -47,7 +50,8 @@ XERCES_CPP_NAMESPACE_END
namespace Base
{
class Persistence;
class Reader;
/** The XML reader class
* This is an important helper class for the store and retrieval system
@@ -124,9 +128,17 @@ public:
PartialRestoreInObject = 3 // Local to the object partially restored itself
};
/// open the file and read the first element
XMLReader(const char* FileName, std::istream&);
XMLReader(Base::Reader &reader, std::size_t bufsize=16*1024);
XMLReader(const char *name, std::istream &, std::size_t bufsize=16*1024);
~XMLReader();
/** @name boost iostream device interface */
//@{
typedef boost::iostreams::source_tag category;
typedef char char_type;
std::streamsize read(char_type* s, std::streamsize n);
//@}
bool isValid() const { return _valid; }
bool isVerbose() const { return _verbose; }
void setVerbose(bool on) { _verbose = on; }
@@ -137,28 +149,68 @@ public:
const char* localName() const;
/// get the current element level
int level() const;
/// read until a start element is found (\<name\>) or start-end element (\<name/\>) (with special name if given)
void readElement (const char* ElementName=nullptr);
/** read until a start element is found (\<name\>) or start-end element (\<name/\>) (with special name if given)
*
* @param ElementName: element name to look for. If NULL, then the
* parser will return when encounter any start element. If not NULL,
* then the parser will only search within the current element for
* any child element start with this name, and throw exception if
* not found.
*
* @param guard: The guard is used to protect against over reading when
* calling readEndElement(). When the guard is not given, it is possible
* for the matching readEndElement() call to acsend above the current level
* (at the time of calling readElement()) and look for end element in
* parent or sibling elements, potentially skipping elements in between
* without caller noticing. If the guard is given, it will be assigned the
* element level immediate above the found start element, and you must pass
* the same pointered integer when calling readEndElement() to disarm the
* guard. Every following call of read(End)Element() will check if the
* current level goes above the current guard, and throw exception if it
* does. The reader internally keeps a stack of guards, so you can setup
* additional guard when calling readElement() at deeper level.
*/
void readElement (const char* ElementName=0, int *guard=0);
/** read until an end element is found
*
* @param ElementName: optional end element name to look for. If given, then
* the parser will read until this name is found.
*
* @param level: optional level to look for. If given, then the parser will
* read until this level. Note that the parse only increase the level when
* finding a start element, not start-end element, and decrease the level
* after finding an end element. So, if you obtain the parser level after
* calling readElement(), you should specify a level minus one when calling
* this function. This \c level parameter is only useful if you know the
* child element may have the same name as its parent, otherwise, using \c
* ElementName is enough.
* @param guard: optional level guard. @sa readElement().
*/
void readEndElement(const char* ElementName=nullptr, int level=-1);
/// read until characters are found
void readCharacters();
/// read binary file
void readBinFile(const char*);
void readEndElement(const char* ElementName=0, int *guard=0);
/** Read element character content and save to a file
*
* @param filename: file name to save into
* @param base64: whether to decode data with base64 before saving
*
* This function assumes you are in the middle of an element, or else
* exception will be thrown.
*/
void readCharacters(const char *filename, bool base64);
/** Read element character content as text string
*
* This function reads the entire character content of the current element
* and return it as a string. This function assumes you are in the middle
* of an element, or else exception will be thrown.
*
* For more memory efficient reading of large amount of characters,
* consider using beginCharStream().
*/
std::string readCharacters();
/** Obtain an input stream for reading characters
*
* @param base64: whether to decode data using base64
*
* @return Return a input stream for reading characters. The stream will be
* auto destroyed when you call with readElement() or readEndElement(), or
* you can end it explicitly with endCharStream().
*/
std::istream &beginCharStream(bool base64);
/// Manually end the current character stream
void endCharStream();
/// Obtain the current character stream
std::istream &charStream();
//@}
/** @name Attribute handling */
@@ -168,20 +220,31 @@ public:
/// check if the read element has a special attribute
bool hasAttribute(const char* AttrName) const;
/// return the named attribute as an interer (does type checking)
long getAttributeAsInteger(const char* AttrName) const;
unsigned long getAttributeAsUnsigned(const char* AttrName) const;
long getAttributeAsInteger(const char* AttrName, const char *def=0) const;
unsigned long getAttributeAsUnsigned(const char* AttrName, const char *def=0) const;
/// return the named attribute as a double floating point (does type checking)
double getAttributeAsFloat(const char* AttrName) const;
double getAttributeAsFloat(const char* AttrName, const char *def=0) const;
/// return the named attribute as a double floating point (does type checking)
const char* getAttribute(const char* AttrName) const;
const char* getAttribute(const char* AttrName, const char *def=0) const;
//@}
/** @name additional file reading */
//@{
/// add a read request of a persistent object
const char *addFile(const char* Name, Base::Persistence *Object);
/// add a read request of a persistent object
const char *addFile(const std::string &Name, Base::Persistence *Object) {
return addFile(Name.c_str(),Object);
}
/// process the requested file writes
void readFiles(zipios::ZipInputStream &zipstream) const;
void readFiles();
struct FileEntry {
std::string FileName;
Base::Persistence *Object;
};
const std::vector<FileEntry> &getFileList() const;
/// get all registered file names
const std::vector<std::string>& getFilenames() const;
bool isRegistered(Base::Persistence *Object) const;
@@ -208,16 +271,14 @@ public:
bool testStatus(ReaderStatus pos) const;
/// set the status bits
void setStatus(ReaderStatus pos, bool on);
struct FileEntry {
std::string FileName;
Base::Persistence *Object;
};
std::vector<FileEntry> FileList;
protected:
/// read the next element
bool read();
protected:
void init(std::size_t bufsize);
// -----------------------------------------------------------------------
// Handlers for the SAX ContentHandler interface
// -----------------------------------------------------------------------
@@ -259,11 +320,10 @@ protected:
void resetErrors();
//@}
int Level;
std::string LocalName;
std::string Characters;
unsigned int CharacterCount;
std::streamsize CharacterOffset;
std::map<std::string,std::string> AttrMap;
typedef std::map<std::string,std::string> AttrMapType;
@@ -287,26 +347,80 @@ protected:
bool _valid;
bool _verbose;
std::vector<FileEntry> FileList;
std::vector<std::string> FileNames;
std::vector<int*> Guards;
std::bitset<32> StatusBits;
std::unique_ptr<std::istream> CharStream;
Base::Reader *_reader;
bool _ownReader;
};
class BaseExport Reader : public std::istream
{
public:
Reader(std::istream&, const std::string&, int version);
std::istream& getStream();
std::string getFileName() const;
Reader(std::istream&, const std::string&, XMLReader *parent=0);
XMLReader *getParent() const;
const std::string &getFileName() const;
int getFileVersion() const;
void initLocalReader(std::shared_ptr<Base::XMLReader>);
std::shared_ptr<Base::XMLReader> getLocalReader() const;
int getDocumentSchema() const;
friend class XMLReader;
protected:
Reader(const std::string&, XMLReader *parent=0);
typedef XMLReader::FileEntry FileEntry;
virtual void readFiles(XMLReader &) {};
private:
std::istream& _str;
std::string _name;
int fileVersion;
std::shared_ptr<Base::XMLReader> localreader;
XMLReader *_parent;
};
class BaseExport ZipReader : public Base::Reader
{
public:
ZipReader(zipios::ZipInputStream &, const std::string&, XMLReader *parent=0);
protected:
virtual void readFiles(XMLReader &reader);
zipios::ZipInputStream &_stream;
};
class BaseExport FileReader : public Base::Reader
{
public:
FileReader(const Base::FileInfo &fi, const std::string &name = std::string(), XMLReader *parent=0);
protected:
virtual void readFiles(XMLReader &reader);
std::string _dir;
Base::ifstream _stream;
};
/// Helper class for providing diagnoistic information in the process if xml parsing
class BaseExport ReaderContext {
private:
/// Private new operator to prevent heap allocation
void* operator new(size_t size);
void init(const char *name);
public:
ReaderContext(const char *name);
ReaderContext(const std::string &name);
~ReaderContext();
private:
std::size_t size;
};
}
+103 -159
View File
@@ -28,13 +28,13 @@
# include <QByteArray>
# include <QIODevice>
# include <cstring>
#ifdef __GNUC__
# include <cstdint>
# ifdef __GNUC__
# include <cstdint>
# endif
# include <climits>
#endif
#endif
#include <iomanip>
#include "Stream.h"
#include "Swap.h"
#include <CXX/Objects.hxx>
@@ -58,170 +58,114 @@ void Stream::setByteOrder(ByteOrder bo)
_swap = (bo == BigEndian);
}
OutputStream::OutputStream(std::ostream &rout) : _out(rout)
OutputStream::OutputStream(std::ostream &rout, bool binary)
: _out(rout), _binary(binary)
{
if(!_binary)
_out << std::setprecision(std::numeric_limits<double>::max_digits10);
}
OutputStream::~OutputStream()
{
}
OutputStream& OutputStream::operator << (const char *s) {
if(_binary) {
uint32_t len = s?std::strlen(s):0;
(*this) << len;
_out.write(s,len);
return *this;
}
OutputStream& OutputStream::operator << (bool b)
{
_out.write((const char*)&b, sizeof(bool));
// for text mode, we count the line so that we can deal with potential eol
// conversion by external software.
uint32_t count=0;
for(const char *c=s;*c;++c) {
if(*c == '\n')
++count;
}
// Stores the line count followed by a colon as the dimilter. We don't use
// whitespace because the input stream may also start with whitespace.
_out << count << ':';
// Stores the text, and normalize the end of line to a single '\n'.
for(char c=*s++; c; c=*s++) {
if(c == '\r') {
c = *s++;
if(!c)
break;
if(c!='\n') {
// We allow '\r' if it is not at the end of a line
_out.put('\r');
}
}
_out.put(c);
}
// Add an extra newline as the delimiter for the following data.
_out.put('\n');
return *this;
}
OutputStream& OutputStream::operator << (int8_t ch)
// --------------------------------------------------------
InputStream::InputStream(std::istream &rin, bool binary)
: _in(rin), _binary(binary)
{
_out.write((const char*)&ch, sizeof(int8_t));
}
InputStream& InputStream::operator >> (std::string &s) {
if(_binary) {
uint32_t len;
(*this) >> len;
s.resize(len);
_in.read(&s[0],len);
return *this;
}
uint32_t count;
char c;
// The count is followed by a colon as the delimiter. The string is allowed
// to start with any character.
_in >> count >> c;
_ss.str("");
for(uint32_t i=0; i<count && _in ;++i) {
for(;;) {
if(!_in.get(c))
break;
// Normalize \r\n to \n
if(c == '\r') {
if(!_in.get(c))
break;
if(c == '\n')
break;
_ss.put('\r');
_ss.put(c);
} else {
_ss.put(c);
if(c == '\n')
break;
}
}
}
// Reading the last line
while(_in.get(c)) {
// Normalize \r\n to \n, but DO NOT insert '\n' into the extracted
// line, because the last '\n' is inserted by us (See OutputStream
// operator>>(const char*) above)
if(c == '\r') {
if(!_in.get(c))
break;
if(c == '\n')
break;
_ss.put('\r');
} else if(c == '\n')
break;
_ss.put(c);
}
s = _ss.str();
return *this;
}
OutputStream& OutputStream::operator << (uint8_t uch)
{
_out.write((const char*)&uch, sizeof(uint8_t));
return *this;
}
OutputStream& OutputStream::operator << (int16_t s)
{
if (_swap) SwapEndian<int16_t>(s);
_out.write((const char*)&s, sizeof(int16_t));
return *this;
}
OutputStream& OutputStream::operator << (uint16_t us)
{
if (_swap) SwapEndian<uint16_t>(us);
_out.write((const char*)&us, sizeof(uint16_t));
return *this;
}
OutputStream& OutputStream::operator << (int32_t i)
{
if (_swap) SwapEndian<int32_t>(i);
_out.write((const char*)&i, sizeof(int32_t));
return *this;
}
OutputStream& OutputStream::operator << (uint32_t ui)
{
if (_swap) SwapEndian<uint32_t>(ui);
_out.write((const char*)&ui, sizeof(uint32_t));
return *this;
}
OutputStream& OutputStream::operator << (int64_t l)
{
if (_swap) SwapEndian<int64_t>(l);
_out.write((const char*)&l, sizeof(int64_t));
return *this;
}
OutputStream& OutputStream::operator << (uint64_t ul)
{
if (_swap) SwapEndian<uint64_t>(ul);
_out.write((const char*)&ul, sizeof(uint64_t));
return *this;
}
OutputStream& OutputStream::operator << (float f)
{
if (_swap) SwapEndian<float>(f);
_out.write((const char*)&f, sizeof(float));
return *this;
}
OutputStream& OutputStream::operator << (double d)
{
if (_swap) SwapEndian<double>(d);
_out.write((const char*)&d, sizeof(double));
return *this;
}
InputStream::InputStream(std::istream &rin) : _in(rin)
{
}
InputStream::~InputStream()
{
}
InputStream& InputStream::operator >> (bool& b)
{
_in.read((char*)&b, sizeof(bool));
return *this;
}
InputStream& InputStream::operator >> (int8_t& ch)
{
_in.read((char*)&ch, sizeof(int8_t));
return *this;
}
InputStream& InputStream::operator >> (uint8_t& uch)
{
_in.read((char*)&uch, sizeof(uint8_t));
return *this;
}
InputStream& InputStream::operator >> (int16_t& s)
{
_in.read((char*)&s, sizeof(int16_t));
if (_swap) SwapEndian<int16_t>(s);
return *this;
}
InputStream& InputStream::operator >> (uint16_t& us)
{
_in.read((char*)&us, sizeof(uint16_t));
if (_swap) SwapEndian<uint16_t>(us);
return *this;
}
InputStream& InputStream::operator >> (int32_t& i)
{
_in.read((char*)&i, sizeof(int32_t));
if (_swap) SwapEndian<int32_t>(i);
return *this;
}
InputStream& InputStream::operator >> (uint32_t& ui)
{
_in.read((char*)&ui, sizeof(uint32_t));
if (_swap) SwapEndian<uint32_t>(ui);
return *this;
}
InputStream& InputStream::operator >> (int64_t& l)
{
_in.read((char*)&l, sizeof(int64_t));
if (_swap) SwapEndian<int64_t>(l);
return *this;
}
InputStream& InputStream::operator >> (uint64_t& ul)
{
_in.read((char*)&ul, sizeof(uint64_t));
if (_swap) SwapEndian<uint64_t>(ul);
return *this;
}
InputStream& InputStream::operator >> (float& f)
{
_in.read((char*)&f, sizeof(float));
if (_swap) SwapEndian<float>(f);
return *this;
}
InputStream& InputStream::operator >> (double& d)
{
_in.read((char*)&d, sizeof(double));
if (_swap) SwapEndian<double>(d);
return *this;
}
// ----------------------------------------------------------------------
ByteArrayOStreambuf::ByteArrayOStreambuf(QByteArray& ba) : _buffer(new QBuffer(&ba))
+262 -26
View File
@@ -29,9 +29,12 @@
#endif
#include <fstream>
#include <ios>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "Swap.h"
#include "FileInfo.h"
@@ -66,20 +69,121 @@ protected:
class BaseExport OutputStream : public Stream
{
public:
OutputStream(std::ostream &rout);
~OutputStream();
/** Constructor
* @param rout: output downstream
* @param binary: whether to output as text or not
*/
OutputStream(std::ostream &rout, bool binary=true);
OutputStream& operator << (bool b);
OutputStream& operator << (int8_t ch);
OutputStream& operator << (uint8_t uch);
OutputStream& operator << (int16_t s);
OutputStream& operator << (uint16_t us);
OutputStream& operator << (int32_t i);
OutputStream& operator << (uint32_t ui);
OutputStream& operator << (int64_t l);
OutputStream& operator << (uint64_t ul);
OutputStream& operator << (float f);
OutputStream& operator << (double d);
OutputStream& operator << (bool b) {
if(_binary)
_out.write((const char*)&b, sizeof(bool));
else
_out << b << '\n';
return *this;
}
OutputStream& operator << (int8_t ch) {
if(_binary)
_out.write((const char*)&ch, sizeof(int8_t));
else
_out << ch << '\n';
return *this;
}
OutputStream& operator << (uint8_t uch) {
if(_binary)
_out.write((const char*)&uch, sizeof(uint8_t));
else
_out << uch << '\n';
return *this;
}
OutputStream& operator << (int16_t s) {
if(_binary) {
if (_swap) SwapEndian<int16_t>(s);
_out.write((const char*)&s, sizeof(int16_t));
}else
_out << s << '\n';
return *this;
}
OutputStream& operator << (uint16_t us) {
if(_binary) {
if (_swap) SwapEndian<uint16_t>(us);
_out.write((const char*)&us, sizeof(uint16_t));
}else
_out << us << '\n';
return *this;
}
OutputStream& operator << (int32_t i) {
if(_binary) {
if (_swap) SwapEndian<int32_t>(i);
_out.write((const char*)&i, sizeof(int32_t));
}else
_out << i << '\n';
return *this;
}
OutputStream& operator << (uint32_t ui) {
if(_binary) {
if (_swap) SwapEndian<uint32_t>(ui);
_out.write((const char*)&ui, sizeof(uint32_t));
}else
_out << ui << '\n';
return *this;
}
OutputStream& operator << (int64_t l) {
if(_binary) {
if (_swap) SwapEndian<int64_t>(l);
_out.write((const char*)&l, sizeof(int64_t));
}else
_out << l << '\n';
return *this;
}
OutputStream& operator << (uint64_t ul) {
if(_binary) {
if (_swap) SwapEndian<uint64_t>(ul);
_out.write((const char*)&ul, sizeof(uint64_t));
}else
_out << ul << '\n';
return *this;
}
OutputStream& operator << (float f) {
if(_binary) {
if (_swap) SwapEndian<float>(f);
_out.write((const char*)&f, sizeof(float));
}else
_out << f << '\n';
return *this;
}
OutputStream& operator << (double d) {
if(_binary) {
if (_swap) SwapEndian<double>(d);
_out.write((const char*)&d, sizeof(double));
}else
_out << d << '\n';
return *this;
}
OutputStream& operator << (const char *s);
OutputStream& operator << (const std::string &s) {
return (*this) << s.c_str();
}
OutputStream& operator << (char c) {
_out.put(c);
return *this;
}
bool isBinary() const {return _binary;}
private:
OutputStream (const OutputStream&);
@@ -87,6 +191,7 @@ private:
private:
std::ostream& _out;
bool _binary;
};
/**
@@ -96,20 +201,120 @@ private:
class BaseExport InputStream : public Stream
{
public:
InputStream(std::istream &rin);
~InputStream();
/** Constructor
* @param rin: upstream input
* @param binary: whether read the stream as text or not
*/
InputStream(std::istream &rin, bool binary=true);
InputStream& operator >> (bool& b);
InputStream& operator >> (int8_t& ch);
InputStream& operator >> (uint8_t& uch);
InputStream& operator >> (int16_t& s);
InputStream& operator >> (uint16_t& us);
InputStream& operator >> (int32_t& i);
InputStream& operator >> (uint32_t& ui);
InputStream& operator >> (int64_t& l);
InputStream& operator >> (uint64_t& ul);
InputStream& operator >> (float& f);
InputStream& operator >> (double& d);
InputStream& operator >> (bool& b) {
if(_binary)
_in.read((char*)&b, sizeof(bool));
else
_in >> b;
return *this;
}
InputStream& operator >> (int8_t& ch) {
if(_binary)
_in.read((char*)&ch, sizeof(int8_t));
else {
int i;
_in >> i;
ch = (int8_t)i;
}
return *this;
}
InputStream& operator >> (uint8_t& uch) {
if(_binary)
_in.read((char*)&uch, sizeof(uint8_t));
else {
unsigned u;
_in >> u;
uch = (uint8_t)u;
}
return *this;
}
InputStream& operator >> (int16_t& s) {
if(_binary) {
_in.read((char*)&s, sizeof(int16_t));
if (_swap) SwapEndian<int16_t>(s);
} else
_in >> s;
return *this;
}
InputStream& operator >> (uint16_t& us) {
if(_binary) {
_in.read((char*)&us, sizeof(uint16_t));
if (_swap) SwapEndian<uint16_t>(us);
} else
_in >> us;
return *this;
}
InputStream& operator >> (int32_t& i) {
if(_binary) {
_in.read((char*)&i, sizeof(int32_t));
if (_swap) SwapEndian<int32_t>(i);
} else
_in >> i;
return *this;
}
InputStream& operator >> (uint32_t& ui) {
if(_binary) {
_in.read((char*)&ui, sizeof(uint32_t));
if (_swap) SwapEndian<uint32_t>(ui);
} else
_in >> ui;
return *this;
}
InputStream& operator >> (int64_t& l) {
if(_binary) {
_in.read((char*)&l, sizeof(int64_t));
if (_swap) SwapEndian<int64_t>(l);
} else
_in >> l;
return *this;
}
InputStream& operator >> (uint64_t& ul) {
if(_binary) {
_in.read((char*)&ul, sizeof(uint64_t));
if (_swap) SwapEndian<uint64_t>(ul);
} else
_in >> ul;
return *this;
}
InputStream& operator >> (float& f) {
if(_binary) {
_in.read((char*)&f, sizeof(float));
if (_swap) SwapEndian<float>(f);
} else
_in >> f;
return *this;
}
InputStream& operator >> (double& d) {
if(_binary) {
_in.read((char*)&d, sizeof(double));
if (_swap) SwapEndian<double>(d);
} else
_in >> d;
return *this;
}
InputStream& operator >> (std::string &s);
InputStream& operator >> (char &c) {
c = (char)_in.get();
return *this;
}
operator bool() const
{
@@ -117,12 +322,16 @@ public:
return !_in.eof();
}
bool isBinary() const {return _binary;}
private:
InputStream (const InputStream&);
void operator = (const InputStream&);
private:
std::istream& _in;
std::ostringstream _ss;
bool _binary;
};
// ----------------------------------------------------------------------------
@@ -339,6 +548,9 @@ class FileInfo;
class ofstream : public std::ofstream
{
public:
ofstream()
{}
ofstream(const FileInfo& fi, ios_base::openmode mode =
std::ios::out | std::ios::trunc)
#ifdef _MSC_VER
@@ -348,6 +560,17 @@ public:
#endif
{
}
void open(const FileInfo &fi, ios_base::openmode mode =
std::ios::out | std::ios::trunc)
{
#ifdef _MSC_VER
std::ofstream::open(fi.toStdWString().c_str(), mode);
#else
std::ofstream::open(fi.filePath().c_str(), mode);
#endif
}
virtual ~ofstream()
{
}
@@ -362,6 +585,8 @@ public:
class ifstream : public std::ifstream
{
public:
ifstream() {}
ifstream(const FileInfo& fi, ios_base::openmode mode =
std::ios::in)
#ifdef _MSC_VER
@@ -371,6 +596,17 @@ public:
#endif
{
}
void open(const FileInfo &fi, ios_base::openmode mode =
std::ios::in)
{
#ifdef _MSC_VER
std::ifstream::open(fi.toStdWString().c_str(), mode);
#else
std::ifstream::open(fi.filePath().c_str(), mode);
#endif
}
virtual ~ifstream()
{
}
+25
View File
@@ -240,6 +240,31 @@ public:
}
};
// ----------------------------------------------------------------------------
/** Temporary shorten a sub-object path for more efficient traversal */
class StringGuard {
public:
StringGuard(char *c)
:c(c)
{
v1 = c[0];
v2 = c[1];
c[0] = '.';
c[1] = 0;
}
~StringGuard()
{
c[0] = v1;
c[1] = v2;
}
char *c;
char v1;
char v2;
};
// ----------------------------------------------------------------------------
struct BaseExport Tools
+181 -76
View File
@@ -23,31 +23,65 @@
#include "PreCompiled.h"
#include <algorithm>
#include <iomanip>
#include <limits>
#include <locale>
#include "Writer.h"
#include "Base64.h"
#include "Exception.h"
#include "FileInfo.h"
#include "Persistence.h"
#include "Stream.h"
#include "Tools.h"
#include "Persistence.h"
using namespace Base;
using namespace std;
using namespace zipios;
// boost iostream filter to escape ']]>' in text file saved into CDATA section.
// It does not check if the character is valid utf8 or not.
struct cdata_filter {
typedef char char_type;
typedef bio::output_filter_tag category;
template<typename Device>
inline bool put(Device& dev, char c) {
switch(state) {
case 0:
case 1:
if(c == ']')
++state;
else
state = 0;
break;
case 2:
if(c == '>') {
static const char escape[] = "]]><![CDATA[";
bio::write(dev,escape,sizeof(escape)-1);
}
state = 0;
break;
}
return bio::put(dev,c);
}
int state = 0;
};
// ---------------------------------------------------------------------------
// Writer: Constructors and Destructor
// ---------------------------------------------------------------------------
Writer::Writer()
Writer::Writer(short indent_size)
: indent(0)
, indBuf{}
, forceXML(false)
, indent_size(indent_size)
, forceXML(0)
, splitXML(false)
, preferBinary(true)
, fileVersion(1)
{
indBuf[0] = '\0';
@@ -57,46 +91,95 @@ Writer::~Writer()
{
}
std::ostream &Writer::beginCharStream(bool base64, unsigned line_size) {
if(CharStream)
throw Base::RuntimeError("Writer::beginCharStream(): invalid state");
CharBase64 = base64;
if(base64) {
CharStream = create_base64_encoder(Stream(),line_size);
} else {
Stream() << "<![CDATA[";
CharStream.reset(new bio::filtering_ostream);
auto f = static_cast<bio::filtering_ostream*>(CharStream.get());
f->push(cdata_filter());
f->push(Stream());
*f << std::setprecision(std::numeric_limits<double>::digits10 + 1);
}
return *CharStream;
}
std::ostream &Writer::endCharStream() {
if(CharStream) {
CharStream.reset();
if(!CharBase64)
Stream() << "]]>";
}
return Stream();
}
std::ostream &Writer::charStream() {
if(!CharStream)
throw Base::RuntimeError("Writer::endCharStream(): no current character stream");
return *CharStream;
}
void Writer::insertText(const std::string &s) {
beginCharStream(false) << s;
endCharStream();
}
void Writer::insertAsciiFile(const char* FileName)
{
Base::FileInfo fi(FileName);
Base::ifstream from(fi);
Base::ifstream from(fi, std::ios::in | std::ios::binary);
if (!from)
throw Base::FileException("Writer::insertAsciiFile() Could not open file!");
Stream() << "<![CDATA[";
char ch;
while (from.get(ch))
Stream().put(ch);
Stream() << "]]>" << endl;
beginCharStream(false) << from.rdbuf();
endCharStream();
}
void Writer::insertBinFile(const char* FileName)
void Writer::insertBinFile(const char* FileName, unsigned line_size)
{
Base::FileInfo fi(FileName);
Base::ifstream from(fi, std::ios::in | std::ios::binary | std::ios::ate);
Base::ifstream from(fi, std::ios::in | std::ios::binary);
if (!from)
throw Base::FileException("Writer::insertAsciiFile() Could not open file!");
throw Base::FileException("Writer::insertBinaryFile() Could not open file!");
Stream() << "<![CDATA[";
std::ifstream::pos_type fileSize = from.tellg();
from.seekg(0, std::ios::beg);
std::vector<unsigned char> bytes(static_cast<size_t>(fileSize));
from.read(reinterpret_cast<char*>(&bytes[0]), fileSize);
Stream() << Base::base64_encode(&bytes[0], static_cast<unsigned int>(fileSize));
Stream() << "]]>" << endl;
beginCharStream(true,line_size) << from.rdbuf();
endCharStream();
}
void Writer::setForceXML(bool on)
void Writer::setForceXML(int on)
{
forceXML = on;
}
bool Writer::isForceXML()
int Writer::isForceXML()
{
return forceXML;
}
void Writer::setSplitXML(bool on)
{
splitXML = on;
}
bool Writer::isSplitXML()
{
return splitXML;
}
void Writer::setPreferBinary(bool on)
{
preferBinary = on;
}
bool Writer::isPreferBinary() const
{
return preferBinary;
}
void Writer::setFileVersion(int v)
{
fileVersion = v;
@@ -160,52 +243,43 @@ std::vector<std::string> Writer::getErrors() const
return Errors;
}
std::string Writer::addFile(const char* Name,const Base::Persistence *Object)
const std::string &Writer::addFile(const char* Name,const Base::Persistence *Object)
{
// always check isForceXML() before requesting a file!
assert(!isForceXML());
assert(Name);
FileEntry temp;
temp.FileName = getUniqueFileName(Name);
temp.Object = Object;
FileList.emplace_back();
FileEntry &entry = FileList.back();
FileList.push_back(temp);
if(!FileNameSet.insert(Name).second) {
entry.FileName = getUniqueFileName(Name);
FileNameSet.insert(entry.FileName);
} else
entry.FileName = Name;
FileNames.push_back( temp.FileName );
FileNames.push_back(entry.FileName);
// return the unique file name
return temp.FileName;
entry.Object = Object;
return entry.FileName;
}
std::string Writer::getUniqueFileName(const char *Name)
{
// name in use?
std::string CleanName = (Name ? Name : "");
std::vector<std::string>::const_iterator pos;
pos = find(FileNames.begin(),FileNames.end(),CleanName);
if (pos == FileNames.end()) {
// if not, name is OK
return CleanName;
}
else {
std::vector<std::string> names;
names.reserve(FileNames.size());
FileInfo fi(CleanName);
CleanName = fi.fileNamePure();
std::string ext = fi.extension();
for (pos = FileNames.begin();pos != FileNames.end();++pos) {
fi.setFile(*pos);
std::string FileName = fi.fileNamePure();
if (fi.extension() == ext)
names.push_back(FileName);
}
std::stringstream str;
str << Base::Tools::getUniqueName(CleanName, names);
if (!ext.empty())
str << "." << ext;
return str.str();
std::vector<std::string> names;
names.reserve(FileNames.size());
FileInfo fi(Name);
std::string CleanName = fi.fileNamePure();
std::string ext = fi.extension();
for (auto pos = FileNames.begin();pos != FileNames.end();++pos) {
fi.setFile(*pos);
std::string FileName = fi.fileNamePure();
if (fi.extension() == ext)
names.push_back(FileName);
}
std::stringstream str;
str << Base::Tools::getUniqueName(CleanName, names);
if (!ext.empty())
str << "." << ext;
return str.str();
}
const std::vector<std::string>& Writer::getFilenames() const
@@ -215,25 +289,29 @@ const std::vector<std::string>& Writer::getFilenames() const
void Writer::incInd()
{
if (indent < 1020) {
indBuf[indent ] = ' ';
indBuf[indent+1] = ' ';
indBuf[indent+2] = ' ';
indBuf[indent+3] = ' ';
indBuf[indent+4] = '\0';
indent += 4;
}
int pos = sizeof(indBuf)-1;
if(indent < pos)
pos = indent;
for(int i=0;i<indent_size && pos-1<(int)sizeof(indBuf);++i)
indBuf[pos++] = ' ';
indBuf[pos] = 0;
indent += indent_size;
}
void Writer::decInd()
{
if (indent >= 4) {
indent -= 4;
if (indent >= indent_size) {
indent -= indent_size;
}
else {
indent = 0;
}
indBuf[indent] = '\0';
if(indent < (int)sizeof(indBuf))
indBuf[indent] = '\0';
}
void Writer::putNextEntry(const char *file, const char *obj) {
ObjectName = obj?obj:file;
}
// ----------------------------------------------------------------------------
@@ -262,14 +340,22 @@ ZipWriter::ZipWriter(std::ostream& os)
ZipStream.setf(ios::fixed,ios::floatfield);
}
void ZipWriter::putNextEntry(const char *file, const char *obj) {
Writer::putNextEntry(file,obj);
ZipStream.putNextEntry(file);
}
void ZipWriter::writeFiles()
{
// use a while loop because it is possible that while
// processing the files new ones can be added
size_t index = 0;
while (index < FileList.size()) {
FileEntry entry = FileList[index];
ZipStream.putNextEntry(entry.FileName);
FileEntry entry = FileList.begin()[index];
putNextEntry(entry.FileName.c_str());
indent = 0;
indBuf[0] = 0;
entry.Object->SaveDocFile(*this);
index++;
}
@@ -282,6 +368,21 @@ ZipWriter::~ZipWriter()
// ----------------------------------------------------------------------------
StringWriter::StringWriter() {
setFileVersion(2);
setForceXML(9999);
setSplitXML(false);
setPreferBinary(false);
this->StrStream << std::setprecision(std::numeric_limits<double>::digits10 + 1);
}
void StringWriter::writeFiles() {
if(FileList.size())
throw Base::FileException("StringWriter does not support saving into multiple files");
}
// ----------------------------------------------------------------------------
FileWriter::FileWriter(const char* DirName) : DirName(DirName)
{
}
@@ -290,10 +391,13 @@ FileWriter::~FileWriter()
{
}
void FileWriter::putNextEntry(const char* file)
void FileWriter::putNextEntry(const char* file, const char *obj)
{
Writer::putNextEntry(file,obj);
std::string fileName = DirName + "/" + file;
this->FileStream.open(fileName.c_str(), std::ios::out | std::ios::binary);
this->FileStream.open(fileName.c_str(), std::ios::out | std::ios::binary | std::ios::trunc);
this->FileStream << std::setprecision(std::numeric_limits<double>::digits10 + 1);
}
bool FileWriter::shouldWrite(const std::string& , const Base::Persistence *) const
@@ -320,8 +424,9 @@ void FileWriter::writeFiles()
fi.createDirectory();
}
std::string fileName = DirName + "/" + entry.FileName;
this->FileStream.open(fileName.c_str(), std::ios::out | std::ios::binary);
putNextEntry(entry.FileName.c_str());
indent = 0;
indBuf[0] = 0;
entry.Object->SaveDocFile(*this);
this->FileStream.close();
}
+69 -14
View File
@@ -25,10 +25,12 @@
#include <set>
#include <unordered_set>
#include <string>
#include <sstream>
#include <vector>
#include <cassert>
#include <memory>
#ifdef _MSC_VER
#include <zipios++/zipios-config.h>
@@ -58,25 +60,44 @@ class BaseExport Writer
{
public:
Writer();
Writer(short indent_size=2);
virtual ~Writer();
/// switch the writer in XML only mode (no files allowed)
void setForceXML(bool on);
void setForceXML(int on);
/// check on state
bool isForceXML();
int isForceXML();
/// split xml among each object
void setSplitXML(bool on);
/// check whether to split xml among each object
bool isSplitXML();
/// set preference of binary output
void setPreferBinary(bool on);
bool isPreferBinary() const;
void setFileVersion(int);
int getFileVersion() const;
/// put the next entry with a give name
virtual void putNextEntry(const char *filename, const char *objName=0);
/// insert a file as CDATA section in the XML file
void insertAsciiFile(const char* FileName);
/// insert a binary file BASE64 coded as CDATA section in the XML file
void insertBinFile(const char* FileName);
void insertBinFile(const char* FileName, unsigned base64_line_size=80);
/// insert text string as CDATA
void insertText(const std::string &s);
/** @name additional file writing */
//@{
/// add a write request of a persistent object
std::string addFile(const char* Name, const Base::Persistence *Object);
const std::string &addFile(const char* Name, const Base::Persistence *Object);
/// add a write request of a persistent object
const std::string &addFile(const std::string &Name, const Base::Persistence *Object) {
return addFile(Name.c_str(),Object);
}
/// process the requested file storing
virtual void writeFiles()=0;
/// get all registered file names
@@ -95,6 +116,11 @@ public:
void clearModes();
//@}
/// Obtain the current file name
const char *getCurrentFileName() const {
return ObjectName.c_str();
}
/** @name Error handling */
//@{
void addError(const std::string&);
@@ -115,8 +141,24 @@ public:
virtual std::ostream &Stream()=0;
/// name for underlying file saves
std::string ObjectName;
/** Create an output stream for storing character content
* @param base64: If true, the input will be base64 encoded before storing.
* If false, the input is assumed to be valid character with
* the current XML encoding, and will be enclosed inside
* CDATA section. The stream will scan the input and
* properly escape any CDATA ending inside.
* @param line_size: specifies the line size of the base64 output
* @return Returns an output stream.
*
* You must call endCharStream() to end the current character stream.
*/
std::ostream &beginCharStream(bool base64, unsigned line_size=80);
/** End the current character output stream
* @return Returns the normal writer stream for convenience
*/
std::ostream &endCharStream();
/// Return the current character output stream
std::ostream &charStream();
protected:
std::string getUniqueFileName(const char *Name);
@@ -126,18 +168,28 @@ protected:
};
std::vector<FileEntry> FileList;
std::vector<std::string> FileNames;
std::unordered_set<std::string> FileNameSet;
std::vector<std::string> Errors;
std::set<std::string> Modes;
short indent;
char indBuf[1024];
int indent;
short indent_size;
char indBuf[65];
int forceXML;
bool splitXML;
bool preferBinary;
bool forceXML;
int fileVersion;
private:
Writer(const Writer&);
Writer& operator=(const Writer&);
private:
std::string ObjectName;
std::unique_ptr<std::ostream> CharStream;
bool CharBase64 = false;
};
@@ -160,7 +212,7 @@ public:
void setComment(const char* str){ZipStream.setComment(str);}
void setLevel(int level){ZipStream.setLevel( level );}
void putNextEntry(const char* str){ZipStream.putNextEntry(str);}
virtual void putNextEntry(const char *filename, const char *objName=0);
private:
zipios::ZipOutputStream ZipStream;
@@ -176,12 +228,15 @@ class BaseExport StringWriter : public Writer
{
public:
StringWriter();
virtual std::ostream &Stream(){return StrStream;}
std::string getString() const {return StrStream.str();}
virtual void writeFiles(){}
virtual void writeFiles();
void clear() { StrStream.str(""); }
private:
std::stringstream StrStream;
std::ostringstream StrStream;
};
/*! The FileWriter class
@@ -195,7 +250,7 @@ public:
FileWriter(const char* DirName);
virtual ~FileWriter();
void putNextEntry(const char* file);
virtual void putNextEntry(const char *filename, const char *objName=nullptr);
virtual void writeFiles();
virtual std::ostream &Stream(){return FileStream;}
+35
View File
@@ -41,6 +41,7 @@
#include <App/Document.h>
#include <App/DocumentObjectPy.h>
#include <App/DocumentParams.h>
#include <Base/Console.h>
#include <Base/Interpreter.h>
#include <Base/Exception.h>
@@ -334,6 +335,40 @@ Application::Application(bool GUIenabled)
App::GetApplication().signalRelabelDocument.connect(std::bind(&Gui::Application::slotRelabelDocument, this, sp::_1));
App::GetApplication().signalShowHidden.connect(std::bind(&Gui::Application::slotShowHidden, this, sp::_1));
App::GetApplication().signalFinishOpenDocument.connect([]() {
std::vector<App::Document*> docs;
for(auto doc : App::GetApplication().getDocuments()) {
if(doc->testStatus(App::Document::RecomputeOnRestore)) {
docs.push_back(doc);
doc->setStatus(App::Document::RecomputeOnRestore, false);
}
}
if(docs.empty() || !App::DocumentParams::getWarnRecomputeOnRestore())
return;
WaitCursor wc;
wc.restoreCursor();
auto res = QMessageBox::warning(getMainWindow(), QObject::tr("Recompution required"),
QObject::tr("Some document(s) require recomputation for migration purpose. "
"It is highly recommended to perform a recomputation before "
"any modification to avoid compatibility problem.\n\n"
"Do you want to recompute now?"),
QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
if(res != QMessageBox::Yes)
return;
bool hasError = false;
for(auto doc : App::Document::getDependentDocuments(docs,true)) {
try {
doc->recompute({},false,&hasError);
} catch (Base::Exception &e) {
e.ReportException();
hasError = true;
}
}
if(hasError)
QMessageBox::critical(getMainWindow(), QObject::tr("Recompute error"),
QObject::tr("Failed to recompute some document(s).\n"
"Please check report view for more details."));
});
// install the last active language
ParameterGrp::handle hPGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp");
+103 -90
View File
@@ -35,94 +35,6 @@
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="Gui::PrefCheckBox" name="prefCheckNewDoc">
<property name="toolTip">
<string>The application will create a new document when started</string>
</property>
<property name="text">
<string>Create new document at start up</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>CreateNewDoc</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Document</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="Line" name="line1">
<property name="frameShape">
<enum>QFrame::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="textLabel1">
<property name="text">
<string>Document save compression level
(0 = none, 9 = highest, 3 = default)</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefSpinBox" name="prefCompression">
<property name="toolTip">
<string>Compression level for FCStd files</string>
</property>
<property name="value">
<number>3</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>CompressionLevel</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Document</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="Line" name="line1_2">
<property name="frameShape">
<enum>QFrame::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="Gui::PrefCheckBox" name="prefUndoRedo">
<property name="toolTip">
@@ -184,13 +96,81 @@
</item>
</layout>
</item>
<item row="6" column="0">
<widget class="Line" name="line">
<item row="1" column="0">
<widget class="Line" name="line1">
<property name="frameShape">
<enum>QFrame::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="Gui::PrefCheckBox" name="prefCheckNewDoc">
<property name="toolTip">
<string>The application will create a new document when started</string>
</property>
<property name="text">
<string>Create new document at start up</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>CreateNewDoc</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Document</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="textLabel1">
<property name="text">
<string>Document save compression level
(0 = none, 9 = highest, 3 = default)</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefSpinBox" name="prefCompression">
<property name="toolTip">
<string>Compression level for FCStd files</string>
</property>
<property name="value">
<number>3</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>CompressionLevel</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Document</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0">
<widget class="Gui::PrefCheckBox" name="prefCanAbortRecompute">
<property name="toolTip">
@@ -208,6 +188,39 @@ This feature may slightly increase recomputation time.</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="Line" name="line1_2">
<property name="frameShape">
<enum>QFrame::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="Gui::PrefCheckBox" name="prefRecomputeOnRestore">
<property name="text">
<string>Prompt recomputation after loading legacy document</string>
</property>
<property name="prefPath" stdset="0">
<cstring>Document</cstring>
</property>
<property name="prefEntry" stdset="0">
<cstring>WarnRecomputeOnRestore</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
+2
View File
@@ -93,6 +93,7 @@ void DlgSettingsDocumentImp::saveSettings()
ui->prefAutoSaveEnabled->onSave();
ui->prefAutoSaveTimeout->onSave();
ui->prefCanAbortRecompute->onSave();
ui->prefRecomputeOnRestore->onSave();
int timeout = ui->prefAutoSaveTimeout->value();
if (!ui->prefAutoSaveEnabled->isChecked())
@@ -127,6 +128,7 @@ void DlgSettingsDocumentImp::loadSettings()
ui->prefAutoSaveEnabled->onRestore();
ui->prefAutoSaveTimeout->onRestore();
ui->prefCanAbortRecompute->onRestore();
ui->prefRecomputeOnRestore->onRestore();
}
/**
+46 -37
View File
@@ -1398,21 +1398,23 @@ void Document::Restore(Base::XMLReader &reader)
*/
void Document::RestoreDocFile(Base::Reader &reader)
{
// We must create an XML parser to read from the input stream
std::shared_ptr<Base::XMLReader> localreader = std::make_shared<Base::XMLReader>("GuiDocument.xml", reader);
localreader->FileVersion = reader.getFileVersion();
Base::XMLReader xmlReader(reader);
xmlReader.readElement("Document");
xmlReader.DocumentSchema = xmlReader.getAttributeAsInteger("SchemaVersion","");
if(!xmlReader.DocumentSchema)
xmlReader.DocumentSchema = reader.getDocumentSchema();
xmlReader.FileVersion = xmlReader.getAttributeAsInteger("FileVersion","");
if(!xmlReader.FileVersion)
xmlReader.FileVersion = reader.getFileVersion();
localreader->readElement("Document");
long scheme = localreader->getAttributeAsInteger("SchemaVersion");
localreader->DocumentSchema = scheme;
bool hasExpansion = localreader->hasAttribute("HasExpansion");
bool hasExpansion = xmlReader.hasAttribute("HasExpansion");
if(hasExpansion) {
auto tree = TreeWidget::instance();
if(tree) {
auto docItem = tree->getDocumentItem(this);
if(docItem)
docItem->Restore(*localreader);
docItem->Restore(xmlReader);
}
}
@@ -1420,34 +1422,36 @@ void Document::RestoreDocFile(Base::Reader &reader)
// Now we must restore the properties of the view providers only.
//
// SchemeVersion "1"
if (scheme == 1) {
if (xmlReader.DocumentSchema == 1) {
// read the viewproviders itself
localreader->readElement("ViewProviderData");
int Cnt = localreader->getAttributeAsInteger("Count");
xmlReader.readElement("ViewProviderData");
int Cnt = xmlReader.getAttributeAsInteger("Count");
for (int i=0; i<Cnt; i++) {
localreader->readElement("ViewProvider");
std::string name = localreader->getAttribute("name");
int guard;
xmlReader.readElement("ViewProvider",&guard);
std::string name = xmlReader.getAttribute("name");
bool expanded = false;
if (!hasExpansion && localreader->hasAttribute("expanded")) {
const char* attr = localreader->getAttribute("expanded");
if (!hasExpansion && xmlReader.hasAttribute("expanded")) {
const char* attr = xmlReader.getAttribute("expanded");
if (strcmp(attr,"1") == 0) {
expanded = true;
}
}
ViewProvider* pObj = getViewProviderByName(name.c_str());
if (pObj) // check if this feature has been registered
pObj->Restore(*localreader);
pObj->Restore(xmlReader);
if (pObj && expanded) {
Gui::ViewProviderDocumentObject* vp = static_cast<Gui::ViewProviderDocumentObject*>(pObj);
this->signalExpandObject(*vp, TreeItemMode::ExpandItem,0,0);
}
localreader->readEndElement("ViewProvider");
xmlReader.readEndElement("ViewProvider",&guard);
}
localreader->readEndElement("ViewProviderData");
xmlReader.readEndElement("ViewProviderData");
// read camera settings
localreader->readElement("Camera");
const char* ppReturn = localreader->getAttribute("settings");
xmlReader.readElement("Camera");
const char* ppReturn = xmlReader.getAttribute("settings");
cameraSettings.clear();
if(ppReturn && ppReturn[0]) {
saveCameraSettings(ppReturn);
@@ -1465,10 +1469,13 @@ void Document::RestoreDocFile(Base::Reader &reader)
}
}
localreader->readEndElement("Document");
xmlReader.readEndElement("Document");
// In the file GuiDocument.xml new data files might be added
if (!xmlReader.getFilenames().empty())
xmlReader.readFiles();
// reset modified flag
reader.initLocalReader(localreader);
setModified(false);
}
@@ -1487,6 +1494,8 @@ void Document::slotFinishRestoreObject(const App::DocumentObject &obj) {
vpd->finishRestoring();
if(!vpd->canAddToSceneGraph())
toggleInSceneGraph(vpd);
else if (vpd->Visibility.getValue())
vpd->setModeSwitch();
}
}
@@ -1639,9 +1648,9 @@ void Document::importObjects(const std::vector<App::DocumentObject*>& obj, Base:
const std::map<std::string, std::string>& nameMapping)
{
// We must create an XML parser to read from the input stream
std::shared_ptr<Base::XMLReader> localreader = std::make_shared<Base::XMLReader>("GuiDocument.xml", reader);
localreader->readElement("Document");
long scheme = localreader->getAttributeAsInteger("SchemaVersion");
Base::XMLReader xmlReader(reader);
xmlReader.readElement("Document");
long scheme = xmlReader.getAttributeAsInteger("SchemaVersion");
// At this stage all the document objects and their associated view providers exist.
// Now we must restore the properties of the view providers only.
@@ -1649,21 +1658,21 @@ void Document::importObjects(const std::vector<App::DocumentObject*>& obj, Base:
// SchemeVersion "1"
if (scheme == 1) {
// read the viewproviders itself
localreader->readElement("ViewProviderData");
int Cnt = localreader->getAttributeAsInteger("Count");
xmlReader.readElement("ViewProviderData");
int Cnt = xmlReader.getAttributeAsInteger("Count");
std::vector<App::DocumentObject*>::const_iterator it = obj.begin();
for (int i=0;i<Cnt&&it!=obj.end();++i,++it) {
// The stored name usually doesn't match with the current name anymore
// thus we try to match by type. This should work because the order of
// objects should not have changed
localreader->readElement("ViewProvider");
std::string name = localreader->getAttribute("name");
xmlReader.readElement("ViewProvider");
std::string name = xmlReader.getAttribute("name");
std::map<std::string, std::string>::const_iterator jt = nameMapping.find(name);
if (jt != nameMapping.end())
name = jt->second;
bool expanded = false;
if (localreader->hasAttribute("expanded")) {
const char* attr = localreader->getAttribute("expanded");
if (xmlReader.hasAttribute("expanded")) {
const char* attr = xmlReader.getAttribute("expanded");
if (strcmp(attr,"1") == 0) {
expanded = true;
}
@@ -1673,22 +1682,22 @@ void Document::importObjects(const std::vector<App::DocumentObject*>& obj, Base:
pObj->setStatus(Gui::isRestoring,true);
auto vpd = Base::freecad_dynamic_cast<ViewProviderDocumentObject>(pObj);
if(vpd) vpd->startRestoring();
pObj->Restore(*localreader);
pObj->Restore(xmlReader);
if (expanded && vpd)
this->signalExpandObject(*vpd, TreeItemMode::ExpandItem,0,0);
}
localreader->readEndElement("ViewProvider");
xmlReader.readEndElement("ViewProvider");
if (it == obj.end())
break;
}
localreader->readEndElement("ViewProviderData");
xmlReader.readEndElement("ViewProviderData");
}
localreader->readEndElement("Document");
xmlReader.readEndElement("Document");
// In the file GuiDocument.xml new data files might be added
if (!localreader->getFilenames().empty())
reader.initLocalReader(localreader);
if (!xmlReader.getFilenames().empty())
xmlReader.readFiles();
}
void Document::slotFinishImportObjects(const std::vector<App::DocumentObject*> &objs) {
+248
View File
@@ -0,0 +1,248 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="svg3140"
height="64px"
width="64px"
sodipodi:docname="freecad_toponaming.svg"
inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)">
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1848"
inkscape:window-height="1016"
id="namedview48"
showgrid="false"
inkscape:zoom="10.429825"
inkscape:cx="39.393288"
inkscape:cy="39.060955"
inkscape:window-x="72"
inkscape:window-y="27"
inkscape:window-maximized="1"
inkscape:current-layer="svg3140" />
<defs
id="defs3142">
<linearGradient
id="linearGradient3864">
<stop
style="stop-color:#71b2f8;stop-opacity:1;"
offset="0"
id="stop3866" />
<stop
style="stop-color:#002795;stop-opacity:1;"
offset="1"
id="stop3868" />
</linearGradient>
<linearGradient
id="linearGradient3682">
<stop
id="stop3684"
offset="0"
style="stop-color:#ff6d0f;stop-opacity:1;" />
<stop
id="stop3686"
offset="1"
style="stop-color:#ff1000;stop-opacity:1;" />
</linearGradient>
<linearGradient
id="linearGradient3864-9">
<stop
id="stop3866-1"
offset="0"
style="stop-color:#204a87;stop-opacity:1" />
<stop
id="stop3868-1"
offset="1"
style="stop-color:#729fcf;stop-opacity:1" />
</linearGradient>
<linearGradient
id="linearGradient3682-0">
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="0"
id="stop3684-0" />
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="1"
id="stop3686-0" />
</linearGradient>
<radialGradient
xlink:href="#linearGradient3682-0-6"
id="radialGradient3817-5-3"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1.2361257,0.30001695,-0.83232803,3.3883821,-499.9452,-167.33108)"
cx="270.58316"
cy="33.899986"
fx="270.58316"
fy="33.899986"
r="19.571428" />
<linearGradient
id="linearGradient3682-0-6">
<stop
style="stop-color:#ff390f;stop-opacity:1"
offset="0"
id="stop3684-0-7" />
<stop
style="stop-color:#ff1000;stop-opacity:1;"
offset="1"
id="stop3686-0-5" />
</linearGradient>
<linearGradient
gradientUnits="userSpaceOnUse"
y2="7.7114096"
x2="-211.40184"
y1="68.841812"
x1="-206.69949"
id="linearGradient3806"
xlink:href="#linearGradient3682-0" />
<linearGradient
gradientTransform="matrix(1.0094494,0,0,1.0094493,-20.307973,3.7260081)"
gradientUnits="userSpaceOnUse"
y2="26.520763"
x2="-157.32494"
y1="58.261547"
x1="-146.74467"
id="linearGradient3808"
xlink:href="#linearGradient3864-9" />
<linearGradient
gradientTransform="matrix(1.0094494,0,0,1.0094493,-20.307973,3.7260081)"
gradientUnits="userSpaceOnUse"
y2="26.520763"
x2="-157.32494"
y1="58.261547"
x1="-146.74467"
id="linearGradient3808-5"
xlink:href="#linearGradient3864-9-6" />
<linearGradient
id="linearGradient3864-9-6">
<stop
id="stop3866-1-2"
offset="0"
style="stop-color:#204a87;stop-opacity:1" />
<stop
id="stop3868-1-9"
offset="1"
style="stop-color:#729fcf;stop-opacity:1" />
</linearGradient>
<linearGradient
gradientTransform="matrix(1.0094494,0,0,1.0094493,-20.307973,3.7260081)"
gradientUnits="userSpaceOnUse"
y2="26.520763"
x2="-157.32494"
y1="58.261547"
x1="-146.74467"
id="linearGradient3808-2"
xlink:href="#linearGradient3864-9-7" />
<linearGradient
id="linearGradient3864-9-7">
<stop
id="stop3866-1-0"
offset="0"
style="stop-color:#204a87;stop-opacity:1" />
<stop
id="stop3868-1-93"
offset="1"
style="stop-color:#729fcf;stop-opacity:1" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient3774"
id="linearGradient4316"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(-0.10685519,0,0,0.09098806,56.982333,0.72568927)"
x1="288.11227"
y1="358.15811"
x2="372.52457"
y2="7.5416322" />
<linearGradient
id="linearGradient3774">
<stop
style="stop-color:#4e9a06;stop-opacity:1"
offset="0"
id="stop3776" />
<stop
style="stop-color:#8ae234;stop-opacity:1"
offset="1"
id="stop3778" />
</linearGradient>
</defs>
<metadata
id="metadata3145">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="g4761"
transform="matrix(0.8506406,0,0,0.8506406,186.2842,1.0896469)">
<path
inkscape:connector-curvature="0"
id="path3659-5"
d="m -159.14682,27.762572 -7.26628,4.168914 -3.20873,-1.113515 -3.06139,-7.823962 -4.81574,0.253068 -2.19659,8.090466 -3.07424,1.472191 -7.66769,-3.354213 -3.23863,3.598875 4.16893,7.266276 -1.13925,3.199324 -7.82397,3.061399 0.27879,4.825129 8.09048,2.196583 1.47219,3.074238 -3.37993,7.658303 3.59887,3.238623 7.26627,-4.168916 3.22506,1.148635 3.03567,7.81457 4.85085,-0.269405 2.17086,-8.099855 3.07425,-1.472193 7.68401,3.389334 3.23863,-3.598876 -4.16892,-7.266274 1.1229,-3.234445 7.81458,-3.035677 -0.24366,-4.841457 -8.09987,-2.170857 -1.4722,-3.074238 3.36361,-7.693423 z m -10.88267,11.915801 1.49161,0.865459 1.29232,1.171703 1.03462,1.398312 0.74426,1.554681 0.43759,1.67593 0.0725,1.71754 -0.24807,1.717095 -0.56614,1.630089 -0.90058,1.507949 -1.13658,1.275982 -1.39832,1.034618 -1.55468,0.744257 -1.67593,0.43758 -1.72693,0.09823 -1.71711,-0.248055 -1.63008,-0.566152 -1.50794,-0.900579 -1.26661,-1.162311 -1.04399,-1.372584 -0.74428,-1.554679 -0.42818,-1.701656 -0.0982,-1.726934 0.24806,-1.717099 0.56616,-1.630085 0.89118,-1.482225 1.14599,-1.301706 1.3983,-1.034618 1.55468,-0.744261 1.70165,-0.428183 1.71754,-0.0725 1.7171,0.248053 1.63009,0.566153 z"
style="display:inline;overflow:visible;visibility:visible;fill:url(#linearGradient3808);fill-opacity:1;fill-rule:evenodd;stroke:#000137;stroke-width:2.35116911;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
<path
inkscape:connector-curvature="0"
id="path3659-5-6"
d="m -159.40722,30.604211 -6.78206,3.885229 -5.11355,-1.83873 -2.97765,-7.211069 -1.43915,0.07782 -2.07148,7.584439 -4.99186,2.2766 -7.06968,-3.072549 -0.94649,1.083504 3.90414,6.857637 -1.95648,5.010571 -7.1355,2.845405 0.0822,1.531739 7.52777,2.062954 2.33329,4.991861 -3.11471,7.061187 1.0457,0.908702 6.7065,-3.828556 5.39281,1.889398 2.65209,7.164787 1.44166,-0.01704 2.09636,-7.536257 4.8974,-2.446633 7.38672,3.161002 0.88982,-0.951258 -3.90413,-6.687603 1.6772,-5.250163 7.33482,-2.916596 -0.0504,-1.508727 -7.44181,-1.907432 -2.46554,-5.048537 3.11884,-7.22521 z"
style="display:inline;overflow:visible;visibility:visible;fill:none;stroke:#729fcf;stroke-width:2.35116911;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
<circle
transform="matrix(1.2975787,0,0,1.2975787,-227.20403,-4.4100648)"
id="path3898"
style="fill:none;stroke:#729fcf;stroke-width:1.81196654;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:6;stroke-opacity:1"
cx="41.15683"
cy="40.103004"
r="8.6941996" />
<path
inkscape:connector-curvature="0"
id="rect3663-8"
d="m -217.27976,4.1846558 1e-5,68.1839092 14.10701,-2e-6 v -28.21403 h 14.10701 V 30.047518 h -14.10701 V 18.291671 h 23.51169 V 4.1846558 Z"
style="display:inline;overflow:visible;visibility:visible;fill:url(#linearGradient3806);fill-opacity:1;fill-rule:evenodd;stroke:#280000;stroke-width:2.35116887;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
<path
inkscape:connector-curvature="0"
id="rect3663-8-3"
d="m -214.92859,6.535825 v 63.481569 h 9.40468 v -28.21403 h 14.10701 v -9.404677 h -14.10701 V 15.940502 h 23.51169 V 6.535825 Z"
style="display:inline;overflow:visible;visibility:visible;fill:none;stroke:#ef2929;stroke-width:2.35116887;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
</g>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:40px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
x="35.254238"
y="-15.050847"
id="text860"><tspan
sodipodi:role="line"
id="tspan858"
x="35.254238"
y="20.339779"
style="font-style:italic;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold Italic'" /></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:39.3972435px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#00ff80;fill-opacity:1;stroke:#002611;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
x="26.978266"
y="29.824902"
id="text864"
transform="scale(1.0552833,0.94761283)"><tspan
sodipodi:role="line"
id="tspan862"
x="26.978266"
y="29.824902"
style="font-style:italic;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold Italic';fill:#00ff80;fill-opacity:1;stroke:#002611;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1">T</tspan></text>
</svg>

After

Width:  |  Height:  |  Size: 11 KiB

+1
View File
@@ -11,6 +11,7 @@
<file>list-remove.svg</file>
<file>list-add.svg</file>
<file>freecad.svg</file>
<file>freecad_toponaming.svg</file>
<file>freecad-doc.png</file>
<file>bulb.svg</file>
<file>TextDocument.svg</file>
+5 -4
View File
@@ -44,8 +44,8 @@ namespace Gui {
class XMLMergeReader : public Base::XMLReader
{
public:
XMLMergeReader(std::map<std::string, std::string>& name, const char* FileName, std::istream& str)
: Base::XMLReader(FileName, str), nameMap(name)
XMLMergeReader(std::map<std::string, std::string>& name, Base::Reader &reader)
: Base::XMLReader(reader), nameMap(name)
{}
void addName(const char* s1, const char* s2)
@@ -146,7 +146,8 @@ MergeDocuments::importObjects(std::istream& input)
{
this->nameMap.clear();
this->stream = new zipios::ZipInputStream(input);
XMLMergeReader reader(this->nameMap,"<memory>", *stream);
Base::ZipReader zreader(*this->stream,std::string("<memory>"));
XMLMergeReader reader(this->nameMap, zreader);
std::vector<App::DocumentObject*> objs = appdoc->importObjects(reader);
delete this->stream;
@@ -164,7 +165,7 @@ void MergeDocuments::importObject(const std::vector<App::DocumentObject*>& o, Ba
}
Restore(r);
r.readFiles(*this->stream);
r.readFiles();
}
void MergeDocuments::exportObject(const std::vector<App::DocumentObject*>& o, Base::Writer & w)
+86 -51
View File
@@ -40,10 +40,9 @@
#include "Document.h"
#include "FileDialog.h"
#include "Selection.h"
#include "SelectionObject.h"
#include "ViewParams.h"
#include "ViewProviderLink.h"
FC_LOG_LEVEL_INIT("Gui", true, true)
using namespace Gui;
@@ -59,7 +58,6 @@ public:
Document *vpDoc;
std::map<std::string,QListWidgetItem*> elements;
std::vector<QListWidgetItem*> items;
std::string hiddenSub;
Connection connectDelDoc;
Connection connectDelObj;
QPixmap px;
@@ -196,31 +194,89 @@ public:
}
void accept() {
if(touched && ui->recompute->isChecked()) {
auto obj = vp->getObject();
obj->touch();
obj->getDocument()->recompute(obj->getInListRecursive());
touched = false;
}
App::GetApplication().closeActiveTransaction();
}
void removeAll() {
if(elements.size()) {
hiddenSub.clear();
ui->elementList->clear();
elements.clear();
apply();
if(elements.empty())
return;
auto itFace = elements.find("Face");
auto itEdge = elements.find("Edge");
auto itVertex = elements.find("Vertex");
bool revert = false;
for (auto & v : elements) {
if (itFace != elements.end() && v.first != "Face" && boost::starts_with(v.first, "Face")) {
revert = true;
v.second->setData(Qt::UserRole, itFace->second->data(Qt::UserRole));
}
if (itEdge != elements.end() && v.first != "Edge" && boost::starts_with(v.first, "Edge")) {
revert = true;
v.second->setData(Qt::UserRole, itEdge->second->data(Qt::UserRole));
}
if (itVertex != elements.end() && v.first != "Vertex" && boost::starts_with(v.first, "Vertex")) {
revert = true;
v.second->setData(Qt::UserRole, itVertex->second->data(Qt::UserRole));
}
}
if (revert)
apply();
ui->elementList->clear();
elements.clear();
apply();
}
void removeItems() {
std::vector<QListWidgetItem*> faces;
std::vector<QListWidgetItem*> edges;
std::vector<QListWidgetItem*> vertexes;
std::vector<std::string> subs;
for(auto item : ui->elementList->selectedItems()) {
std::string sub = qPrintable(item->data(Qt::UserRole+1).value<QString>());
if(sub == hiddenSub)
hiddenSub.clear();
elements.erase(sub);
delete item;
subs.push_back(qPrintable(item->data(Qt::UserRole+1).value<QString>()));
if (subs.back() != "Face" && boost::starts_with(subs.back(), "Face"))
faces.push_back(item);
else if (subs.back() != "Edge" && boost::starts_with(subs.back(), "Edge"))
edges.push_back(item);
else if (subs.back() != "Vertex" && boost::starts_with(subs.back(), "Vertex"))
vertexes.push_back(item);
}
// In order to better support backward compatibility, Part view provider
// still allow user to set color through DiffuseColor. So when doing
// color mapping, it will not touch any element color that are not
// explicitly set through ColoredElements property. Therefore, when the
// user removes colored elements here, we must explicitly revert only
// those element too. Same for the removeAll() above.
if (faces.size()) {
auto it = elements.find("Face");
if (it != elements.end()) {
for (auto item : faces)
item->setData(Qt::UserRole, it->second->data(Qt::UserRole));
}
}
if (edges.size()) {
auto it = elements.find("Edge");
if (it != elements.end()) {
for (auto item : edges)
item->setData(Qt::UserRole, it->second->data(Qt::UserRole));
}
}
if (vertexes.size()) {
auto it = elements.find("Vertex");
if (it != elements.end()) {
for (auto item : vertexes)
item->setData(Qt::UserRole, it->second->data(Qt::UserRole));
}
}
apply();
// now remove the items
for (auto & sub : subs) {
auto it = elements.find(sub);
if (it != elements.end()) {
delete it->second;
elements.erase(it);
}
}
apply();
}
@@ -287,8 +343,6 @@ public:
}
for(auto item : ui->elementList->selectedItems()) {
std::string name(qPrintable(item->data(Qt::UserRole+1).value<QString>()));
if(ViewProvider::hasHiddenMarker(name.c_str()))
continue;
auto &v = sels[name];
if(!v)
Selection().addSelection(editDoc.c_str(),
@@ -317,12 +371,7 @@ ElementColors::ElementColors(ViewProviderDocumentObject* vp, bool noHide)
if(noHide)
d->ui->hideSelection->setVisible(false);
ParameterGrp::handle hPart = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/View");
d->ui->recompute->setChecked(hPart->GetBool("ColorRecompute",true));
d->ui->onTop->setChecked(hPart->GetBool("ColorOnTop",true));
if(d->ui->onTop->isChecked())
d->vpParent->OnTopWhenSelected.setValue(3);
d->ui->onTop->setChecked(ViewParams::instance()->getColorOnTop());
Selection().addSelectionGate(d, ResolveMode::NoResolve);
@@ -341,16 +390,8 @@ ElementColors::~ElementColors()
Selection().rmvSelectionGate();
}
void ElementColors::on_recompute_clicked(bool checked) {
ParameterGrp::handle hPart = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/View");
hPart->SetBool("ColorRecompute",checked);
}
void ElementColors::on_onTop_clicked(bool checked) {
ParameterGrp::handle hPart = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/View");
hPart->SetBool("ColorOnTop",checked);
ViewParams::instance()->setColorOnTop(checked);
d->vpParent->OnTopWhenSelected.setValue(checked?3:d->onTopMode);
}
@@ -414,8 +455,12 @@ void ElementColors::on_addSelection_clicked()
break;
}
for(auto &sub : subs) {
if(boost::starts_with(sub,d->editSub))
d->addItem(-1,sub.c_str()+d->editSub.size(),true);
if(!boost::starts_with(sub,d->editSub))
continue;
std::string s(sub.c_str()+d->editSub.size());
if(s.empty() || s.back() == '.')
s += "Face";
d->addItem(-1,s.c_str(),true);
}
break;
}
@@ -468,23 +513,13 @@ void ElementColors::changeEvent(QEvent *e)
void ElementColors::leaveEvent(QEvent *e) {
QWidget::leaveEvent(e);
Selection().rmvPreselect();
if(d->hiddenSub.size()) {
d->vp->partialRender({d->hiddenSub},false);
d->hiddenSub.clear();
}
}
void ElementColors::on_elementList_itemEntered(QListWidgetItem *item) {
std::string name(qPrintable(item->data(Qt::UserRole+1).value<QString>()));
if(d->hiddenSub.size()) {
d->vp->partialRender({d->hiddenSub},false);
d->hiddenSub.clear();
}
if(ViewProvider::hasHiddenMarker(name.c_str())) {
d->hiddenSub = name;
d->vp->partialRender({name},true);
name.resize(name.size()-ViewProvider::hiddenMarker().size());
}
const char *hidden = ViewProvider::hasHiddenMarker(name.c_str());
if(hidden)
name.resize(name.size()-std::strlen(hidden));
Selection().setPreselect(d->editDoc.c_str(),
d->editObj.c_str(), (d->editSub+name).c_str(),0,0,0,
d->ui->onTop->isChecked() ? Gui::SelectionChanges::MsgSource::TreeView
-1
View File
@@ -51,7 +51,6 @@ private Q_SLOTS:
void on_elementList_itemDoubleClicked(QListWidgetItem *item);
void on_elementList_itemSelectionChanged();
void on_elementList_itemEntered(QListWidgetItem *item);
void on_recompute_clicked(bool checked);
void on_onTop_clicked(bool checked);
void on_hideSelection_clicked();
void on_boxSelect_clicked();
-7
View File
@@ -72,13 +72,6 @@
</layout>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="recompute">
<property name="text">
<string>Recompute after commit</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="onTop">
<property name="text">
<string>On-top when selected</string>
+26 -21
View File
@@ -385,18 +385,18 @@ class DocumentItem::ExpandInfo :
public std::unordered_map<std::string, DocumentItem::ExpandInfoPtr>
{
public:
void restore(Base::XMLReader& reader) {
int level = reader.level();
void restore(Base::XMLReader &reader) {
int count = reader.getAttributeAsInteger("count");
for (int i = 0; i < count; ++i) {
reader.readElement("Expand");
auto& entry = (*this)[reader.getAttribute("name")];
if (!reader.hasAttribute("count"))
continue;
entry.reset(new ExpandInfo);
entry->restore(reader);
for(int i=0;i<count;++i) {
int guard;
reader.readElement("Expand",&guard);
auto &entry = (*this)[reader.getAttribute("name")];
if(reader.hasAttribute("count")) {
entry.reset(new ExpandInfo);
entry->restore(reader);
}
reader.readEndElement("Expand",&guard);
}
reader.readEndElement("Expand", level - 1);
}
};
@@ -3940,17 +3940,22 @@ void DocumentItem::Save(Base::Writer& writer) const {
saveExpandedItem(writer, this);
}
void DocumentItem::Restore(Base::XMLReader& reader) {
reader.readElement("Expand");
if (!reader.hasAttribute("count"))
return;
_ExpandInfo.reset(new ExpandInfo);
_ExpandInfo->restore(reader);
for (auto inst : TreeWidget::Instances) {
if (inst != getTree()) {
auto docItem = inst->getDocumentItem(document());
if (docItem)
docItem->_ExpandInfo = _ExpandInfo;
void DocumentItem::Restore(Base::XMLReader &reader) {
int guard;
_ExpandInfo.reset();
reader.readElement("Expand",&guard);
if(reader.hasAttribute("count")) {
_ExpandInfo.reset(new ExpandInfo);
_ExpandInfo->restore(reader);
}
reader.readEndElement("Expand",&guard);
if(_ExpandInfo) {
for(auto inst : TreeWidget::Instances) {
if(inst!=getTree()) {
auto docItem = inst->getDocumentItem(document());
if(docItem)
docItem->_ExpandInfo = _ExpandInfo;
}
}
}
}
+1
View File
@@ -62,6 +62,7 @@ public:
FC_VIEW_PARAM(EnablePropertyViewForInactiveDocument,bool,Bool,true) \
FC_VIEW_PARAM(ShowSelectionBoundingBox,bool,Bool,false) \
FC_VIEW_PARAM(PropertyViewTimer, unsigned long, Unsigned, 100) \
FC_VIEW_PARAM(ColorOnTop, bool, Bool, true) \
#undef FC_VIEW_PARAM
#define FC_VIEW_PARAM(_name,_ctype,_type,_def) \
+105 -169
View File
@@ -319,28 +319,24 @@ QIcon ViewProvider::getIcon(void) const
QIcon ViewProvider::mergeGreyableOverlayIcons (const QIcon & orig) const
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
QIcon overlayedIcon = orig;
for (Gui::ViewProviderExtension* ext : vector) {
foreachExtension<ViewProviderExtension>([&overlayedIcon](ViewProviderExtension *ext) {
if (!ext->ignoreOverlayIcon())
overlayedIcon = ext->extensionMergeGreyableOverlayIcons(overlayedIcon);
}
return false;
});
return overlayedIcon;
}
QIcon ViewProvider::mergeColorfulOverlayIcons (const QIcon & orig) const
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
QIcon overlayedIcon = orig;
for (Gui::ViewProviderExtension* ext : vector) {
foreachExtension<ViewProviderExtension>([&overlayedIcon](ViewProviderExtension *ext) {
if (!ext->ignoreOverlayIcon())
overlayedIcon = ext->extensionMergeColorfullOverlayIcons(overlayedIcon);
}
return false;
});
return overlayedIcon;
}
@@ -426,9 +422,7 @@ void ViewProvider::setDisplayMode(const char* ModeName)
_sCurrentMode = ModeName;
//infom the exteensions
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector)
ext->extensionSetDisplayMode(ModeName);
callExtension(&ViewProviderExtension::extensionSetDisplayMode,ModeName);
}
const char* ViewProvider::getDefaultDisplayMode() const {
@@ -439,11 +433,7 @@ const char* ViewProvider::getDefaultDisplayMode() const {
vector<std::string> ViewProvider::getDisplayModes(void) const {
std::vector< std::string > modes;
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector) {
auto extModes = ext->extensionGetDisplayModes();
modes.insert( modes.end(), extModes.begin(), extModes.end() );
}
callExtension(&ViewProviderExtension::extensionGetDisplayModes, modes);
return modes;
}
@@ -454,17 +444,16 @@ std::string ViewProvider::getActiveDisplayMode(void) const
void ViewProvider::hide(void)
{
auto exts = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
if(pcModeSwitch->whichChild.getValue() >= 0) {
int which = pcModeSwitch->whichChild.getValue();
if(which >= 0)
pcModeSwitch->whichChild = -1;
for(auto ext : exts)
ext->extensionModeSwitchChange();
}
//tell extensions that we hide
for (Gui::ViewProviderExtension* ext : exts)
foreachExtension<ViewProviderExtension>([&](ViewProviderExtension *ext) {
if(which >= 0)
ext->extensionModeSwitchChange();
ext->extensionHide();
return false;
});
}
void ViewProvider::show(void)
@@ -472,9 +461,7 @@ void ViewProvider::show(void)
setModeSwitch();
//tell extensions that we show
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector)
ext->extensionShow();
callExtension(&ViewProviderExtension::extensionShow);
}
bool ViewProvider::isShow(void) const
@@ -507,10 +494,8 @@ void ViewProvider::setOverrideMode(const std::string &mode)
}
if (pcModeSwitch->whichChild.getValue() != -1)
setModeSwitch();
else {
for(auto ext : getExtensionsDerivedFromType<Gui::ViewProviderExtension>())
ext->extensionModeSwitchChange();
}
else
callExtension(&ViewProviderExtension::extensionModeSwitchChange);
}
const string ViewProvider::getOverrideMode() {
@@ -520,21 +505,26 @@ const string ViewProvider::getOverrideMode() {
void ViewProvider::setModeSwitch()
{
if (isRestoring())
return;
int mode;
if (viewOverrideMode == -1)
pcModeSwitch->whichChild = _iActualMode;
mode = _iActualMode;
else if (viewOverrideMode < pcModeSwitch->getNumChildren())
pcModeSwitch->whichChild = viewOverrideMode;
mode = viewOverrideMode;
else
return;
for(auto ext : getExtensionsDerivedFromType<Gui::ViewProviderExtension>())
ext->extensionModeSwitchChange();
if(mode != pcModeSwitch->whichChild.getValue()) {
pcModeSwitch->whichChild = mode;
callExtension(&ViewProviderExtension::extensionModeSwitchChange);
}
}
void ViewProvider::setDefaultMode(int val)
{
_iActualMode = val;
for(auto ext : getExtensionsDerivedFromType<Gui::ViewProviderExtension>())
ext->extensionModeSwitchChange();
setModeSwitch();
}
int ViewProvider::getDefaultMode() const {
@@ -686,18 +676,19 @@ bool ViewProvider::mouseWheelEvent(int delta, const SbVec2s &cursorPos, const Vi
void ViewProvider::setupContextMenu(QMenu* menu, QObject* receiver, const char* method)
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector)
foreachExtension<ViewProviderExtension>([&](ViewProviderExtension *ext) {
ext->extensionSetupContextMenu(menu, receiver, method);
return false;
});
}
bool ViewProvider::onDelete(const vector< string >& subNames)
{
bool del = true;
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector)
foreachExtension<ViewProviderExtension>([&](ViewProviderExtension *ext) {
del &= ext->extensionOnDelete(subNames);
return false;
});
return del;
}
@@ -708,123 +699,92 @@ bool ViewProvider::canDelete(App::DocumentObject*) const
bool ViewProvider::canDragObject(App::DocumentObject* obj) const
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector) {
if (ext->extensionCanDragObject(obj))
return true;
}
return false;
return queryExtension(&ViewProviderExtension::extensionCanDragObject,obj);
}
bool ViewProvider::canDragObjects() const
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector) {
if (ext->extensionCanDragObjects())
return true;
}
return false;
return queryExtension(&ViewProviderExtension::extensionCanDragObjects);
}
void ViewProvider::dragObject(App::DocumentObject* obj)
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector) {
int res = false;
foreachExtension<ViewProviderExtension>([&res,obj](ViewProviderExtension *ext) {
if (ext->extensionCanDragObject(obj)) {
ext->extensionDragObject(obj);
return;
res = true;
return true;
}
}
throw Base::RuntimeError("ViewProvider::dragObject: no extension for dragging given object available.");
return false;
});
if(!res)
throw Base::RuntimeError("Cannot drag object.");
}
bool ViewProvider::canDropObject(App::DocumentObject* obj) const
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
#if FC_DEBUG
Base::Console().Log("Check extensions for drop\n");
#endif
for (Gui::ViewProviderExtension* ext : vector){
#if FC_DEBUG
Base::Console().Log("Check extensions %s\n", ext->name().c_str());
#endif
if (ext->extensionCanDropObject(obj))
return true;
}
return false;
return queryExtension(&ViewProviderExtension::extensionCanDropObject,obj);
}
bool ViewProvider::canDropObjects() const {
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector)
if(ext->extensionCanDropObjects())
return true;
return false;
return queryExtension(&ViewProviderExtension::extensionCanDropObjects);
}
bool ViewProvider::canDragAndDropObject(App::DocumentObject* obj) const {
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector){
if(!ext->extensionCanDragAndDropObject(obj))
return false;
}
return true;
return queryExtension(&ViewProviderExtension::extensionCanDragAndDropObject,obj);
}
void ViewProvider::dropObject(App::DocumentObject* obj) {
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector) {
int res = false;
foreachExtension<ViewProviderExtension>([&res,obj](ViewProviderExtension *ext) {
if (ext->extensionCanDropObject(obj)) {
ext->extensionDropObject(obj);
return;
res = true;
return true;
}
}
return false;
});
throw Base::RuntimeError("ViewProvider::dropObject: no extension for dropping given object available.");
if(!res)
throw Base::RuntimeError("Cannot drop object.");
}
bool ViewProvider::canDropObjectEx(App::DocumentObject* obj, App::DocumentObject *owner,
const char *subname, const std::vector<std::string> &elements) const
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector){
if(ext->extensionCanDropObjectEx(obj,owner,subname, elements))
return true;
}
if(queryExtension(&ViewProviderExtension::extensionCanDropObjectEx,obj,owner,subname,elements))
return true;
return canDropObject(obj);
}
std::string ViewProvider::dropObjectEx(App::DocumentObject* obj, App::DocumentObject *owner,
const char *subname, const std::vector<std::string> &elements)
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector) {
if(ext->extensionCanDropObjectEx(obj, owner, subname, elements))
return ext->extensionDropObjectEx(obj, owner, subname, elements);
}
dropObject(obj);
return std::string();
std::string name;
bool res = false;
foreachExtension<ViewProviderExtension>([&](ViewProviderExtension *ext) {
if(ext->extensionCanDropObjectEx(obj, owner, subname, elements)) {
res = true;
name = ext->extensionDropObjectEx(obj, owner, subname, elements);
return true;
}
return false;
});
if(!res)
dropObject(obj);
return name;
}
int ViewProvider::replaceObject(App::DocumentObject* oldValue, App::DocumentObject* newValue)
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector) {
if (ext->extensionCanDropObject(newValue)) {
int ret = ext->extensionReplaceObject(oldValue, newValue);
if(ret>=0)
return !!ret;
}
}
return -1;
int res = -1;
foreachExtension<ViewProviderExtension>([&](ViewProviderExtension *ext) {
res = ext->extensionReplaceObject(oldValue, newValue);
return res>=0;
});
return res;
}
void ViewProvider::Restore(Base::XMLReader& reader) {
@@ -841,76 +801,58 @@ void ViewProvider::Restore(Base::XMLReader& reader) {
void ViewProvider::updateData(const App::Property* prop)
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector)
ext->extensionUpdateData(prop);
callExtension(&ViewProviderExtension::extensionUpdateData,prop);
}
SoSeparator* ViewProvider::getBackRoot(void) const
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector) {
auto* node = ext->extensionGetBackRoot();
if (node)
return node;
}
return nullptr;
SoSeparator *node = 0;
foreachExtension<ViewProviderExtension>([&node](ViewProviderExtension *ext) {
node = ext->extensionGetBackRoot();
return node?true:false;
});
return node;
}
SoGroup* ViewProvider::getChildRoot(void) const
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector) {
auto* node = ext->extensionGetChildRoot();
if (node)
return node;
}
return nullptr;
SoGroup *node = 0;
foreachExtension<ViewProviderExtension>([&node](ViewProviderExtension *ext) {
node = ext->extensionGetChildRoot();
return node?true:false;
});
return node;
}
SoSeparator* ViewProvider::getFrontRoot(void) const
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector) {
auto* node = ext->extensionGetFrontRoot();
if (node)
return node;
}
return nullptr;
SoSeparator *node = 0;
foreachExtension<ViewProviderExtension>([&node](ViewProviderExtension *ext) {
node = ext->extensionGetFrontRoot();
return node?true:false;
});
return node;
}
std::vector< App::DocumentObject* > ViewProvider::claimChildren(void) const
{
std::vector< App::DocumentObject* > vec;
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector) {
std::vector< App::DocumentObject* > nvec = ext->extensionClaimChildren();
if (!nvec.empty())
vec.insert(std::end(vec), std::begin(nvec), std::end(nvec));
}
callExtension(&ViewProviderExtension::extensionClaimChildren,vec);
return vec;
}
std::vector< App::DocumentObject* > ViewProvider::claimChildren3D(void) const
{
std::vector< App::DocumentObject* > vec;
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector) {
std::vector< App::DocumentObject* > nvec = ext->extensionClaimChildren3D();
if (!nvec.empty())
vec.insert(std::end(vec), std::begin(nvec), std::end(nvec));
}
callExtension(&ViewProviderExtension::extensionClaimChildren3D,vec);
return vec;
}
bool ViewProvider::getElementPicked(const SoPickedPoint *pp, std::string &subname) const {
if(!isSelectable())
return false;
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector) {
if(ext->extensionGetElementPicked(pp,subname))
return true;
}
subname = getElement(pp?pp->getDetail():nullptr);
if(!queryExtension(&ViewProviderExtension::extensionGetElementPicked,pp,subname))
subname = getElement(pp?pp->getDetail():nullptr);
return true;
}
@@ -926,12 +868,8 @@ bool ViewProvider::getDetailPath(const char *subname, SoFullPath *pPath, bool ap
pPath->append(pcRoot);
pPath->append(pcModeSwitch);
}
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector) {
if(ext->extensionGetDetailPath(subname,pPath,det))
return true;
}
det = getDetail(subname);
if(!queryExtension(&ViewProviderExtension::extensionGetDetailPath,subname,pPath,det))
det = getDetail(subname);
return true;
}
@@ -988,9 +926,7 @@ bool ViewProvider::useNewSelectionModel() const {
}
void ViewProvider::beforeDelete() {
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector)
ext->extensionBeforeDelete();
callExtension(&ViewProviderExtension::extensionBeforeDelete);
}
void ViewProvider::setRenderCacheMode(int mode) {
+4
View File
@@ -411,6 +411,10 @@ public:
virtual void setElementColors(const std::map<std::string, App::Color> &colors) {
(void)colors;
}
virtual void updateColors(App::Document *sourceDoc=0, bool forceColorMap=false) {
(void)sourceDoc;
(void)forceColorMap;
}
static const std::string &hiddenMarker();
static const char *hasHiddenMarker(const char *subname);
//@}
+75 -27
View File
@@ -54,6 +54,58 @@ FC_LOG_LEVEL_INIT("Gui", true, true)
using namespace Gui;
///////////////////////////////////////////////////////////////////////////
//
static int _ColorUpdateCounter;
static std::set<App::DocumentObjectT> _ColorChangedObjects;
ColorUpdater::ColorUpdater()
{
if (_ColorUpdateCounter >= 0)
++_ColorUpdateCounter;
}
ColorUpdater::~ColorUpdater()
{
if (_ColorUpdateCounter <= 0
|| --_ColorUpdateCounter > 0
|| _ColorChangedObjects.empty())
return;
// To prevent infinite recursive update
_ColorUpdateCounter = -1;
try {
std::set<App::DocumentObject*> inset;
for (const auto &objT : _ColorChangedObjects) {
if (auto obj = objT.getObject()) {
if (!obj->isRecomputing() && !obj->isTouched())
obj->getInListEx(inset, true);
}
}
std::vector<App::DocumentObject*> objs(inset.begin(), inset.end());
for (auto obj : App::Document::getDependencyList(objs, App::Document::DepSort)) {
if (obj->isRecomputing() || obj->isTouched() || !inset.count(obj))
continue;
if (auto vp = Base::freecad_dynamic_cast<ViewProviderDocumentObject>(
Gui::Application::Instance->getViewProvider(obj))) {
vp->checkColorUpdate();
}
}
} catch (Base::Exception &e) {
e.ReportException();
} catch (...)
{}
_ColorChangedObjects.clear();
_ColorUpdateCounter = 0;
}
void ColorUpdater::addObject(App::DocumentObject *obj)
{
if (_ColorUpdateCounter && obj && !obj->isRecomputing() && !obj->isTouched())
_ColorChangedObjects.emplace(obj);
}
///////////////////////////////////////////////////////////////////////////////////
PROPERTY_SOURCE(Gui::ViewProviderDocumentObject, Gui::ViewProvider)
@@ -97,16 +149,12 @@ void ViewProviderDocumentObject::getTaskViewContent(std::vector<Gui::TaskView::T
void ViewProviderDocumentObject::startRestoring()
{
hide();
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector)
ext->extensionStartRestoring();
callExtension(&ViewProviderExtension::extensionStartRestoring);
}
void ViewProviderDocumentObject::finishRestoring()
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector)
ext->extensionFinishRestoring();
callExtension(&ViewProviderExtension::extensionFinishRestoring);
}
bool ViewProviderDocumentObject::isAttachedToDocument() const
@@ -139,9 +187,9 @@ bool ViewProviderDocumentObject::removeDynamicProperty(const char* name)
App::Property* ViewProviderDocumentObject::addDynamicProperty(
const char* type, const char* name, const char* group, const char* doc,
short attr, bool ro, bool hidden)
short attr, bool readonly, bool hidden)
{
auto prop = ViewProvider::addDynamicProperty(type,name,group,doc,attr,ro,hidden);
auto prop = ViewProvider::addDynamicProperty(type,name,group,doc,attr,readonly,hidden);
if(prop) {
// transactions of view providers are also managed in App::Document.
App::DocumentObject* docobject = getObject();
@@ -278,6 +326,8 @@ void ViewProviderDocumentObject::addDefaultAction(QMenu* menu, const QString& te
void ViewProviderDocumentObject::setModeSwitch() {
if(isShowable())
ViewProvider::setModeSwitch();
else
callExtension(&ViewProviderExtension::extensionModeSwitchChange);
}
void ViewProviderDocumentObject::show(void)
@@ -357,15 +407,12 @@ void ViewProviderDocumentObject::attach(App::DocumentObject *pcObj)
}
//attach the extensions
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector)
ext->extensionAttach(pcObj);
callExtension(&ViewProviderExtension::extensionAttach,pcObj);
}
void ViewProviderDocumentObject::reattach(App::DocumentObject *pcObj) {
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for (Gui::ViewProviderExtension* ext : vector)
ext->extensionReattach(pcObj);
setStatus(Detach, false);
callExtension(&ViewProviderExtension::extensionReattach,pcObj);
}
void ViewProviderDocumentObject::update(const App::Property* prop)
@@ -505,11 +552,8 @@ PyObject* ViewProviderDocumentObject::getPyObject()
bool ViewProviderDocumentObject::canDropObjectEx(App::DocumentObject* obj, App::DocumentObject *owner,
const char *subname, const std::vector<std::string> &elements) const
{
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector){
if(ext->extensionCanDropObjectEx(obj,owner,subname,elements))
return true;
}
if(queryExtension(&ViewProviderExtension::extensionCanDropObjectEx,obj,owner,subname,elements))
return true;
if(obj && obj->getDocument()!=getObject()->getDocument())
return false;
return canDropObject(obj);
@@ -583,10 +627,8 @@ bool ViewProviderDocumentObject::getElementPicked(const SoPickedPoint *pp, std::
{
if(!isSelectable())
return false;
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector)
if(ext->extensionGetElementPicked(pp,subname))
return true;
if(queryExtension(&ViewProviderExtension::extensionGetElementPicked,pp,subname))
return true;
auto childRoot = getChildRoot();
int idx;
@@ -687,8 +729,14 @@ ViewProviderDocumentObject *ViewProviderDocumentObject::getLinkedViewProvider(
return res;
}
std::string ViewProviderDocumentObject::getFullName() const {
if(pcObject)
return pcObject->getFullName() + ".ViewObject";
return std::string("?");
std::string ViewProviderDocumentObject::getFullName(bool python) const {
if (!isAttachedToDocument())
return "?";
if (pcObject)
return pcObject->getFullName(python) + ".ViewObject";
return std::string(python?"None":"?");
}
App::Document *ViewProviderDocumentObject::getOwnerDocument() const {
return pcObject?pcObject->getDocument():0;
}
+20 -2
View File
@@ -126,7 +126,7 @@ public:
virtual App::Property* addDynamicProperty(
const char* type, const char* name=nullptr,
const char* group=nullptr, const char* doc=nullptr,
short attr=0, bool ro=false, bool hidden=false) override;
short attr=0, bool readonly=false, bool hidden=false) override;
/** Return the linked view object
*
@@ -142,7 +142,9 @@ public:
virtual ViewProviderDocumentObject *getLinkedViewProvider(
std::string *subname=nullptr, bool recursive=false) const;
virtual std::string getFullName() const override;
virtual std::string getFullName(bool python=false) const override;
virtual App::Document *getOwnerDocument() const override;
/** Allow this class to be used as an override for the original view provider of the given object
*
@@ -158,6 +160,8 @@ public:
/** Start the edit mode with ViewProvider::Default */
void startDefaultEditMode();
virtual void checkColorUpdate() {}
protected:
/*! Get the active mdi view of the document this view provider is part of.
@note The returned mdi view doesn't need to be a 3d view but can be e.g.
@@ -223,6 +227,20 @@ private:
};
/** Convenient class to auto update colors for all affect objects
*/
class GuiExport ColorUpdater
{
public:
ColorUpdater();
~ColorUpdater();
static void addObject(App::DocumentObject *obj);
private:
/// Private new operator to prevent heap allocation
void* operator new(size_t size);
};
} // namespace Gui
#endif // GUI_VIEWPROVIDER_DOCUMENTOBJECT_H
+4 -7
View File
@@ -61,15 +61,12 @@ public:
Gui::ViewProviderDocumentObject* getExtendedViewProvider();
const Gui::ViewProviderDocumentObject* getExtendedViewProvider() const;
virtual std::vector<App::DocumentObject*> extensionClaimChildren3D(void) const {
return std::vector<App::DocumentObject*>(); }
virtual void extensionClaimChildren3D(std::vector<App::DocumentObject*> &) const { }
virtual void extensionClaimChildren(std::vector<App::DocumentObject*> &) const { }
virtual bool extensionOnDelete(const std::vector<std::string> &){ return true;}
virtual void extensionBeforeDelete(){}
virtual std::vector<App::DocumentObject*> extensionClaimChildren(void) const {
return std::vector<App::DocumentObject*>(); }
virtual bool extensionCanDragObjects() const { return false; }
virtual bool extensionCanDragObject(App::DocumentObject*) const { return true; }
virtual void extensionDragObject(App::DocumentObject*) { }
@@ -100,10 +97,10 @@ public:
virtual void extensionAttach(App::DocumentObject* ) { }
virtual void extensionReattach(App::DocumentObject* ) { }
virtual void extensionSetDisplayMode(const char* ) { }
virtual std::vector<std::string> extensionGetDisplayModes(void) const {return std::vector<std::string>();}
virtual void extensionGetDisplayModes(std::vector<std::string> &) const {}
virtual void extensionSetupContextMenu(QMenu*, QObject*, const char*) {}
//update data of extended opject
//update data of extended object
virtual void extensionUpdateData(const App::Property*);
virtual PyObject* getExtensionPyObject();
@@ -63,19 +63,21 @@ ViewProviderGeoFeatureGroupExtension::~ViewProviderGeoFeatureGroupExtension()
pcGroupBack = nullptr;
}
std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroupExtension::extensionClaimChildren3D(void) const {
void ViewProviderGeoFeatureGroupExtension::extensionClaimChildren3D(
std::vector<App::DocumentObject*> &children) const
{
//all object in the group must be claimed in 3D, as we are a coordinate system for all of them
auto* ext = getExtendedViewProvider()->getObject()->getExtensionByType<App::GeoFeatureGroupExtension>();
if (ext) {
auto objs = ext->Group.getValues();
return objs;
const auto &objs = ext->Group.getValues();
children.insert(children.end(),objs.begin(),objs.end());
}
return std::vector<App::DocumentObject*>();
}
std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroupExtension::extensionClaimChildren(void) const {
void ViewProviderGeoFeatureGroupExtension::extensionClaimChildren(
std::vector<App::DocumentObject *> &children) const
{
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GeoFeatureGroupExtension>();
const std::vector<App::DocumentObject*> &model = group->Group.getValues ();
@@ -89,8 +91,8 @@ std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroupExtension::extensio
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider ( obj );
if (!vp || vp == getExtendedViewProvider()) { continue; }
auto children = vp->claimChildren();
std::remove_copy ( children.begin (), children.end (), std::inserter (outSet, outSet.begin () ), nullptr);
auto objs = vp->claimChildren();
std::remove_copy ( objs.begin (), objs.end (), std::inserter (outSet, outSet.begin () ), nullptr);
}
// remove the otherwise handled objects, preserving their order so the order in the TreeWidget is correct
@@ -102,16 +104,16 @@ std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroupExtension::extensio
obj->setStatus(App::ObjectStatus::GeoExcluded,true);
else {
obj->setStatus(App::ObjectStatus::GeoExcluded,false);
Result.push_back(obj);
children.push_back(obj);
}
}
return Result;
}
void ViewProviderGeoFeatureGroupExtension::extensionFinishRestoring()
{
// setup GeoExlcuded flag for children
extensionClaimChildren();
std::vector<App::DocumentObject*> children;
extensionClaimChildren(children);
ViewProviderGroupExtension::extensionFinishRestoring();
}
@@ -129,15 +131,14 @@ void ViewProviderGeoFeatureGroupExtension::extensionSetDisplayMode(const char* M
ViewProviderGroupExtension::extensionSetDisplayMode( ModeName );
}
std::vector<std::string> ViewProviderGeoFeatureGroupExtension::extensionGetDisplayModes(void) const
void ViewProviderGeoFeatureGroupExtension::extensionGetDisplayModes(std::vector<std::string> &StrList) const
{
// get the modes of the father
std::vector<std::string> StrList = ViewProviderGroupExtension::extensionGetDisplayModes();
ViewProviderGroupExtension::extensionGetDisplayModes(StrList);
// add your own modes
StrList.push_back("Group");
return StrList;
}
void ViewProviderGeoFeatureGroupExtension::extensionUpdateData(const App::Property* prop)
@@ -40,14 +40,14 @@ public:
ViewProviderGeoFeatureGroupExtension(void);
virtual ~ViewProviderGeoFeatureGroupExtension();
virtual std::vector<App::DocumentObject*> extensionClaimChildren3D(void)const override;
virtual std::vector< App::DocumentObject* > extensionClaimChildren(void) const override;
virtual void extensionClaimChildren3D(std::vector< App::DocumentObject* > &) const override;
virtual void extensionClaimChildren(std::vector< App::DocumentObject* > &) const override;
virtual SoGroup* extensionGetChildRoot(void) const override {return pcGroupChildren;};
virtual SoSeparator* extensionGetFrontRoot() const override {return pcGroupFront;}
virtual SoSeparator* extensionGetBackRoot() const override {return pcGroupBack;}
virtual SoGroup* extensionGetChildRoot(void) const override {return pcGroupChildren;}
virtual void extensionAttach(App::DocumentObject* pcObject) override;
virtual void extensionSetDisplayMode(const char* ModeName) override;
virtual std::vector<std::string> extensionGetDisplayModes(void) const override;
virtual void extensionGetDisplayModes(std::vector<std::string> &) const override;
virtual void extensionFinishRestoring() override;
/// Show the object in the view: suppresses behavior of DocumentObjectGroup
+8 -7
View File
@@ -114,14 +114,16 @@ ViewProviderGeometryObject::~ViewProviderGeometryObject()
void ViewProviderGeometryObject::onChanged(const App::Property* prop)
{
// Actually, the properties 'ShapeColor' and 'Transparency' are part of the property 'ShapeMaterial'.
// Both redundant properties are kept due to more convenience for the user. But we must keep the values
// consistent of all these properties.
Gui::ColorUpdater colorUpdater;
if (prop == &Selectable) {
bool Sel = Selectable.getValue();
setSelectable(Sel);
}
else if (prop == &ShapeColor) {
// Actually, the properties 'ShapeColor' and 'Transparency' are part of the property 'ShapeMaterial'.
// Both redundant properties are kept due to more convenience for the user. But we must keep the values
// consistent of all these properties.
const App::Color& c = ShapeColor.getValue();
pcShapeMaterial->diffuseColor.setValue(c.r,c.g,c.b);
if (c != ShapeMaterial.getValue().diffuseColor)
@@ -137,21 +139,20 @@ void ViewProviderGeometryObject::onChanged(const App::Property* prop)
}
}
else if (prop == &ShapeMaterial) {
if (getObject() && getObject()->testStatus(App::ObjectStatus::TouchOnColorChange))
getObject()->touch(true);
const App::Material& Mat = ShapeMaterial.getValue();
long value = (long)(100*Mat.transparency);
if (value != Transparency.getValue())
Transparency.setValue(value);
const App::Color& color = Mat.diffuseColor;
if (color != ShapeColor.getValue())
ShapeColor.setValue(Mat.diffuseColor);
pcShapeMaterial->ambientColor.setValue(Mat.ambientColor.r,Mat.ambientColor.g,Mat.ambientColor.b);
pcShapeMaterial->diffuseColor.setValue(Mat.diffuseColor.r,Mat.diffuseColor.g,Mat.diffuseColor.b);
pcShapeMaterial->specularColor.setValue(Mat.specularColor.r,Mat.specularColor.g,Mat.specularColor.b);
pcShapeMaterial->emissiveColor.setValue(Mat.emissiveColor.r,Mat.emissiveColor.g,Mat.emissiveColor.b);
pcShapeMaterial->shininess.setValue(Mat.shininess);
pcShapeMaterial->transparency.setValue(Mat.transparency);
if (color != ShapeColor.getValue())
ShapeColor.setValue(Mat.diffuseColor);
Gui::ColorUpdater::addObject(getObject());
}
else if (prop == &BoundingBox) {
showBoundingBox(BoundingBox.getValue());
+3 -3
View File
@@ -108,10 +108,10 @@ void ViewProviderGroupExtension::extensionDropObject(App::DocumentObject* obj) {
Gui::Command::doCommand(Gui::Command::App, cmd.toUtf8());
}
std::vector< App::DocumentObject* > ViewProviderGroupExtension::extensionClaimChildren(void) const {
void ViewProviderGroupExtension::extensionClaimChildren(std::vector<App::DocumentObject*> &children) const {
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
return std::vector<App::DocumentObject*>(group->Group.getValues());
const auto &objs = group->Group.getValues();
children.insert(children.end(),objs.begin(),objs.end());
}
void ViewProviderGroupExtension::extensionShow(void) {
+1 -1
View File
@@ -38,7 +38,7 @@ public:
ViewProviderGroupExtension(void);
virtual ~ViewProviderGroupExtension();
virtual std::vector<App::DocumentObject*> extensionClaimChildren(void)const override;
virtual void extensionClaimChildren(std::vector<App::DocumentObject*> &)const override;
virtual bool extensionCanDragObjects() const override;
virtual bool extensionCanDragObject(App::DocumentObject*) const override;
virtual void extensionDragObject(App::DocumentObject*) override;
+12 -14
View File
@@ -59,33 +59,29 @@ ViewProviderOriginGroupExtension::~ViewProviderOriginGroupExtension()
connectChangedObjectGui.disconnect();
}
std::vector<App::DocumentObject*> ViewProviderOriginGroupExtension::constructChildren (
const std::vector<App::DocumentObject*> &children ) const
void ViewProviderOriginGroupExtension::constructChildren (
std::vector<App::DocumentObject*> &children ) const
{
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::OriginGroupExtension>();
if(!group)
return children;
return;
App::DocumentObject *originObj = group->Origin.getValue();
// Origin must be first
if (originObj) {
std::vector<App::DocumentObject*> rv;
rv.push_back (originObj);
std::copy (children.begin(), children.end(), std::back_inserter (rv));
return rv;
} else { // Generally shouldn't happen but must be handled in case origin is lost
return children;
children.insert(children.begin(),originObj);
}
}
std::vector<App::DocumentObject*> ViewProviderOriginGroupExtension::extensionClaimChildren () const {
return constructChildren ( ViewProviderGeoFeatureGroupExtension::extensionClaimChildren () );
void ViewProviderOriginGroupExtension::extensionClaimChildren (std::vector<App::DocumentObject *> &children) const {
ViewProviderGeoFeatureGroupExtension::extensionClaimChildren (children);
constructChildren ( children );
}
std::vector<App::DocumentObject*> ViewProviderOriginGroupExtension::extensionClaimChildren3D () const {
return constructChildren ( ViewProviderGeoFeatureGroupExtension::extensionClaimChildren3D () );
void ViewProviderOriginGroupExtension::extensionClaimChildren3D (std::vector<App::DocumentObject *> &children) const {
ViewProviderGeoFeatureGroupExtension::extensionClaimChildren3D (children);
constructChildren ( children );
}
void ViewProviderOriginGroupExtension::extensionAttach(App::DocumentObject *pcObject) {
@@ -152,6 +148,8 @@ void ViewProviderOriginGroupExtension::updateOriginSize () {
try {
origin = group->getOrigin ();
assert (origin);
if (origin->OriginFeatures.getSize() == 0)
return;
Gui::ViewProvider *vp = Gui::Application::Instance->getViewProvider(origin);
if (!vp) {
+3 -4
View File
@@ -39,8 +39,8 @@ public:
ViewProviderOriginGroupExtension(void);
virtual ~ViewProviderOriginGroupExtension();
virtual std::vector<App::DocumentObject*> extensionClaimChildren(void)const override;
virtual std::vector<App::DocumentObject*> extensionClaimChildren3D(void)const override;
virtual void extensionClaimChildren(std::vector<App::DocumentObject*> &)const override;
virtual void extensionClaimChildren3D(std::vector<App::DocumentObject*> &)const override;
virtual void extensionAttach(App::DocumentObject *pcObject) override;
virtual void extensionUpdateData(const App::Property* prop) override;
@@ -52,8 +52,7 @@ protected:
void slotChangedObjectGui ( const Gui::ViewProviderDocumentObject& obj );
private:
std::vector<App::DocumentObject*> constructChildren (
const std::vector<App::DocumentObject*> &children ) const;
void constructChildren ( std::vector<App::DocumentObject*> &children ) const;
boost::signals2::connection connectChangedObjectApp;
boost::signals2::connection connectChangedObjectGui;
+10 -1
View File
@@ -1,9 +1,18 @@
#add_defintions(-D_FC_GUI_ENABLED_)
#add_defintions(-DFREECADMAINPY)
if(FREECAD_TOPONAMING_BRANDING)
set(PACKAGE_VERSION_SUFFIX "toponaming")
configure_file(icon_toponaming.ico ${CMAKE_CURRENT_BINARY_DIR}/icon.ico COPYONLY)
configure_file(res/branding_toponaming.xml ${CMAKE_BINARY_DIR}/bin/branding_toponaming.xml COPYONLY)
INSTALL(FILES res/branding_toponaming.xml DESTINATION ${CMAKE_INSTALL_BINDIR})
else(FREECAD_TOPONAMING_BRANDING)
configure_file(icon.ico ${CMAKE_CURRENT_BINARY_DIR}/icon.ico COPYONLY)
file(REMOVE ${CMAKE_BINARY_DIR}/bin/branding_toponaming.xml)
endif(FREECAD_TOPONAMING_BRANDING)
configure_file(freecad.rc.cmake ${CMAKE_CURRENT_BINARY_DIR}/freecad.rc)
configure_file(freecadCmd.rc.cmake ${CMAKE_CURRENT_BINARY_DIR}/freecadCmd.rc)
file(COPY icon.ico DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
if(BUILD_GUI)
include_directories(

Some files were not shown because too many files have changed in this diff Show More