Commit Graph

67 Commits

Author SHA1 Message Date
wmayer
6f5259af26 App: Apply clang format (part 1) 2024-11-21 07:54:24 +01:00
wmayer
2390690330 Core: Extend DocumentObjectPy
* expose isAttachedToDocument to Python
* change DocumentObjectPy::getName() to return None instead of throwing an exception if object is not part of a document
2024-10-28 14:06:51 +01:00
bgbsww
19e450a667 Refactor all element name pairs into clearer struct names - renames 2024-07-20 16:32:12 -04:00
wmayer
58988a7482 Core: Fix memory leaks with PySequence_GetItem 2024-05-08 23:40:27 +02:00
Zheng, Lei
6acf5a00e6 Toponaming/Part: Transfer in python ElementMapVersion 2024-04-14 07:10:27 -04:00
Ajinkya Dahale
d83ba67b82 [Core] Use keyword arguments in DocumentObjectPy addProperty 2023-10-16 17:49:12 +02:00
Chris Hennes
393c1020f5 App: Wrap PyArg_ParseTupleAndKeywords 2023-08-25 15:34:20 -05:00
wmayer
1cf1a90a17 App: modernize C++: use default member init 2023-08-23 19:51:44 +02:00
wmayer
af8c05c507 App: modernize C++: return braced init list 2023-08-18 00:36:24 +02:00
wmayer
4991475341 App: modernize C++: use range-based for loop 2023-08-14 16:40:25 +02:00
wmayer
ec23d2ce66 App: expose function getParent() to Python 2023-05-15 23:40:25 +02:00
marioalexis
7aa200b965 App: Check Python types using Base::PyTypeCheck 2022-09-24 05:10:34 +02:00
marioalexis
209c78d43e App: Replace C cast 2022-09-18 11:06:51 -05:00
wmayer
8328264690 App: [skip ci] whitespace improvements 2022-08-24 10:43:56 +02:00
berniev
d2babf0eb5 App: Single arg ctors must be explicit 2022-08-24 07:20:57 +02:00
berniev
ac81a8380f App: use emplace_back 2022-08-05 10:31:51 +02:00
berniev
85170b2879 remove redundant void 2022-07-31 10:27:44 +02:00
wmayer
25483b78be Fix several clazy issue:
* Missing reference in range-for with non trivial type [-Wclazy-range-loop-reference]
2022-07-24 22:29:06 +02:00
andrea
187772de7c fix warning :unused variables 2022-07-23 14:27:50 +02:00
andrea
61a5551940 Remove unused code into App 2022-07-23 14:27:50 +02:00
wmayer
ab6c75fad9 Core: replace PyObject_IsTrue with Base::asBoolean 2022-07-16 14:04:05 +02:00
marioalexis
1bc43b8606 App: Use PyObject_IsTrue in combination with conditional ternary operator 2022-06-22 19:50:03 -04:00
wmayer
8353338db5 App: fix DocumentObjectPy::getSubObject:
* do not set pyMat to Py_None by default but nullptr and do type check in PyArg_ParseTupleAndKeywords
* if refType is out of range raise a ValueError instead of TypeError
* replace (undocumented) magic numbers with an enum class
* implement a lambda function to avoid code duplication
* fix bug for retType=3 or retType=4 if subname is a list of strings
2022-05-14 15:54:27 +02:00
wmayer
1a20b7f119 App: modernize C++11
* use nullptr
2022-03-23 17:29:23 +01:00
wmayer
b34a00fe14 App: add convenience method DocumentObject::clearExpression() 2022-03-10 12:09:57 +01:00
wmayer
08b77bff08 Core/Mod: modernize C++11
* use nullptr
2022-03-09 21:55:31 +01:00
Uwe
09ce5ce137 [App] Document: remove unused includes 2022-02-23 01:56:26 +01:00
wmayer
2a3991d799 App: do not hide actual exception type in DocumentObjectPy::addProperty/DocumentObjectPy::removeProperty
and throw TypeError in DynamicProperty::addDynamicProperty() if the based type id is invalid
2022-01-19 10:48:00 +01:00
wmayer
1eed1f16b7 App: add comment for clarification 2021-09-23 18:51:41 +02:00
wmayer
5381c9447d App: make evalExpression() a class method of DocumentObject 2021-09-23 15:31:15 +02:00
luz paz
a1fc733ddf App: remove Py2 code from several src/App .cpp files 2021-04-19 15:27:06 +02:00
Benjamin Nauck
079ffa5b0f [App] Use std::shared_ptr instead of boost::shared_ptr
There's no need to use boost version when stl has support for shared_ptr
2021-03-06 19:32:03 +01:00
wmayer
85c1fa1739 App: [skip ci] expose functions to Python to get status string of a feature and whether it's valid 2020-11-12 15:46:40 +01:00
wmayer
4807fd3b33 PVS: V730 Not all members of a class are initialized inside the constructor 2020-07-18 10:59:27 +02:00
luz.paz
019f73852c src/App: [skip ci] fix header uniformity
This PR fixes header uniformity across all `src/App` files
2019-12-25 11:38:43 +01:00
Zheng, Lei
8426ebe2ba Fix various Py::Object leak 2019-10-08 17:53:20 +02:00
Zheng, Lei
4bf4444d81 App: add DocumentObjectPy.evalExpression()
Allow easy evlauation of expression.
2019-10-07 17:24:31 +02:00
Zheng, Lei
38c47d6e95 Expression: split Expression.h to ExpressionParser.h
Split Expression details into a separate header to reduce recompilation
time on changes.
2019-09-28 15:30:41 +02:00
luz.paz
3a1a6eb7d8 Fix typos in src/App 2019-08-17 15:32:48 +02:00
Zheng, Lei
b057952a7e App: API changes for document recompute/save/restore/import/export
This patch adds support of recomputation with external linked object,
as well as external document auto loading and partial loading.

Application:

* Modified new/openDocument()/signalNewDocument to choose whether to
  signal GUI for creating a view for the document. This makes it possible
  to suppress view creation when opening external documents.

* New API openDocuments() which does the actual job of loading the
  document together with any external dependencies. There are afew
  extra arguments to allow setting FileName property differently from
  the actual file path, which are required when auto loading
  dependencies during document recovery (with future patch to
  Gui::DocumentRecovery)

* openDocumentPrivate() is an internal helper for opening individual
  document.

* New signalStart/FinishOpenDocument to be signaled before and after
  opening a document. There may be multiple depending documents actually
  opened in between these two signals.

* New signalBeforeRecomputeDocument signaled before recompute a
  document.

* New API addPendingDocument() for use by external capable link
  properties' to queue up external documents.

* isRestoring/isClosingAll(), for convenience status reporting.

Document:

* signalFinishImport/RestoreObjects, new signal triggered after imported
  or restored all input objects

* signalBeforeRecompute, signaled before start recomputing this document

* Modified signalRecomputed with additional recomputed objects, this is
  to make it more efficient for Gui::TreeWidget to check recomputation
  result.

* signalSkipRecompute, signal to inform which objects are skipped
  during recomputation because of their owner document SkipRecompute
  setting.

* restore/save/read/writeObjects() modified to suport partial
  loading. See [here](https://git.io/fj6PY) for more information.

* afterRestore(), internal function called to finish restore. The
  function is separated from restore() because there is quite a few
  critical steps needed to fully restore a document with external
  linking. See [here](https://git.io/fj6P4) for more information.

* DocumentP::_RecomputeLog is modified to store more accurate object
  recomputation error, including those happened during restore/import.

* isExporting(), new API for checking if an object is exporting.
  External linking properties will use this function to decide how to
  export.

* copyObject(), modified to support external linking objects, and
  accepts multiple input objects.

* moveObject(), modified to support arbitary object moves. The original
  implementation may cause crash if undo/redo is enabled. Furthermore,
  because the original information fakes the object's deletion to break
  its dependency, it does not work for objects that may auto delete their
  children when being deleted. The new implementation copy the object,
  and than paste it to the other document. It then deletes the input
  objects from the original document. In case of recursive move, it only
  deletes the depending object if it has an empty in list.

* importLinks(), new API to import any external object linked by the
  input objects into this document. It will auto correct all link
  references after importing.

* getDependencyList/_rebuildDependencyList(), these two APIs are unified
  and implemented by an internal function _buildDependencyList() with a
  new algorithm to handle external objects. The returned dependency list
  will now include objects from external documents. In case of cyclic
  dependencies, getDpendencyList() will report the actual objects
  involved in dependency loops.

* mustExecute(), new API to check if there are any object requires
  recomputation. This function will call _buildDependencyList() and
  check for external objects as well.

* addRecomputeObject(), new API for marking changes during document
  restore. It only marks the object but does not actually recompute
  them for performance reason. One use case is for geo feature to
  request for recomputation to generate geometry topological names.

* recompute(), support partial, external, and inverse dependency
  recomputation. Improve error handling during recomputation.
  See [here](https://git.io/fj6PO) for more information.

* _recomputeFeature(), suppoert user abort.

* getDependentDocuments/getInList(), new API to obtain an optional
  dependency sorted list of depending documents.

DocumentObject:

* Add various ObjectStatus flags

* isExporting/getExportName(), return a safe name for exporting, in the
  form of <ObjName>@<DocName>, which is guarrenteed to be unique.
  Various link property will save linked object using this name if the
  the linked object is exported together with the owner object, see
  [PropertyLinkBase::restoreLabelReference()](https://git.io/fj6XO)
  for more information.

* recomputeFeature(), add option to recompute this object together with
  all its dependent objects.

* canLoadPartial(), new API for [partial document loading](https://git.io/fj6PY).

MergeDocuments:

* Move object name mapping logic to various link properties. See

Base::Sequencer:

* Add new API checkAbort() for checking user abort.
2019-08-17 14:52:10 +02:00
Zheng, Lei
00166c2346 DocumentObject: add allowDuplicateLabel/onBeforeChangeLabel()
These two APIs allow an object to control its own labeling rules.
The previous auto re-labeling for uniqueness logic is moved from
ObjectLabelObserver (resides in Application.cpp) to PropertyString.

DocumentObject::allowDuplicateLabel() is used to inform PropertyString
that the object allows duplicate label regardless of application
setting. onBeforeChangeLabel() is called before actual label change to
give object a chance to override the new label.
2019-08-17 14:52:09 +02:00
Zheng, Lei
ced27a69c6 PropertyExpressionEngine: convert to link type property
PropertyExpressionEngine is changed to derived from a new class
PropertyExpressionContainer, which is in turn derives from
PropertyXLinkContainer. This makes PropertyExpressionEngine a link type
property that is capable of external linking. It now uses the unified
link property APIs for dependency management and tracking of object
life time, re-labeling, etc.

ObjectIdentifier is modified to support sub-object reference, but is
not exposed to end-user, because expression syntax is kept mostly
unchanged, which will be submitted in future PR. There is, however,
one small change in expression syntax (ExpressionParser.y) to introduce
local property reference to avoid ambiguity mentioned in
FreeCAD/FreeCAD#1619

Modified Expression/ExpressionModifier interface to support various link
property API for link modification.
2019-08-17 14:52:09 +02:00
Zheng, Lei
29bc24a5cf PropertyLinks: refactor property link API
* Create new class PropertyLinkBase as the common parent class for all
  type of links. See the class document for details of its API.

* Added new link scope 'Hidden' that is ignored during normal object
  dependency calculation, but still keep tracks of object remove,
  relabel, etc.

* There is a new concept called 'Shadow subname' introduced in this
  patch, which will only be meaningful in future topological naming
  feature. See [here](https://git.io/fjXKR) for more details.

* DocumentObject added a new API adjustRelativeLink() and a helper
  resolveRelativeLink() function.
2019-08-17 14:52:09 +02:00
Zheng, Lei
be6ec3fdfc App: Property related API changes
Property:

* Extended property status bitset. Mirror most of PropertyType and
  allow dynamic change property type.

* Cache property name and type to improve performance

* Centralize property status change signalling

* Change aboutToSetValue()/hasSetValue() to virtual

* Add new API getFullName() to obtain full quanlified name of the property

AtomicPropertyChangeInterface:

* Allow calling aboutToSetValue()/hasSetValue() when actually changed

PropertyLists:

* Refactor implementation by an abstract class PropertyListBase and a
  template class PropertyListsT, to allow better code reuse.
  PropertyListT is derived from AtomicPropertyChangeInterface to allow
  more efficient change on individual elements.

* All list type property now accept setting python value as a dictionary
  with index as key to set individual element of a list.

* Add touch list for more efficient handling of value changes. The list
  contains the index of changed value. And empty touch list should be
  treated as the entire list is changed. PropertyContainerPy expose this
  functionality with getPropertyTouchList().

PropertyPersistentObject:

* New property to allow dynamic creation of any FreeCAD object derived
  from Base::Persistence, and use it as a property.

DynamicProperty:

* Use boost multi_index_container for efficient property lookup while
  keeping order.

* Modify to be allowed to use in PropertyContainer directly

PropertyContainer:

* Use boost multi_index_container for efficient property lookup while
  keeping order.

* Allow adding/removing dynamic property on all property container

* Modify Save/Restore() to persist property status, and better handle
  transient property which can now be dynamically enabled/disabled per
  object.

* Add new API getFullName() to obtain full quanlified name of the property.
  Implemented by Document, DocumentObject, and also
  ViewProviderDocumentObject if future patch

DocumentObject and FeaturePython are modified to accommondate the
dynamic property changes.

Removed get/setCustomAttribute() implementation from DocumentObjectPy,
and rely on PropertyContainerPy for the implementation, because of the
additional dynamic property support in property container.

Gui::ViewProviderDocumentObject, which is derived from
PropertyContainer, is also modified accordingly
2019-08-17 14:52:09 +02:00
Zheng, Lei
6731e83bf5 App: add New APIs for future Link function
DocumentObject:

* getSubObject(): the most important API for Link to work with
  hierarchies. The function is a inspired from and replaces the
  getPySubObjects(). It returns a child object following a dot separated
  subname reference, and can optionally return accumulated
  transformation, and/or a python object of the refered
  sub-object/element. The default implementation here is to look for
  link type property, and search for the referenced object. This patch also
  include other specialized implementation of this API, such as
  (GeoFeature)GroupExtension (through extensionGetSubObject()),
  PartDesign::Body, and so on. A link type object is expected to
  call the linked object's getSubObject() for resolving.

* getSubObjectList(): helper function to return a list of object
  referenced in the given subname.

* getSubObjects(): return a list of subname references of all children
  objects. The purpose of this function is similar to
  ViewProvider::claimChildren().  Container type object is expected to
  implement this function.  The reason it returns subname references
  instead of just object is to allow the container to skip hierarchies.
  For example, the Assembly3 container uses this to skip the constraint
  and element group.

* getLinkedObject(), obtain the linked object, and optionally with the
  accumulated transformation. It is expected to return a linked object
  or the object itself if it is not a link. In case there are multiple
  levels of linking involved, this function allows the caller to retrieve
  the linked object recursively.

* hasChildElement(), set/isElementVisible(), controls the children
  visibility for a group type object. Because the child object may be
  claimed by other objects, it is essential to have independent control
  of children visibilities. These APIs are designed to abstract how
  group manages the child visibility. For performance reason, these
  function are meant to control only the immediate child object.

* resolve(), helper function to parse subname reference and resolve the
  final object, and optionally the immediate parent of the final object,
  the final object reference name (for calling `set/isElementVisible()`),
  and the subname reference if there is one.

* touch(), add optional argument 'noRecompute' for better backward
  compatibility with the NoRecompute flag. By default, touch() causes
  recompute unless noRecompute is true

* signalChanged/signalBeforeChange, two new signal for tracking changes
  of a specific object.

* getViewProviderNameOverride(), return a string of the view provider
  type of this object. This allows Python class to override the view
  provider of an object. This feature will be used by ViewProviderLink
  which is designed to work with any object that has LinkBaseExtension.

* canLinkProperties(), will be used by Gui::PropertyView to display
  linked object properties together with the object's own properties.

* redirectSubname(), will be used by Gui::Tree to allow an object to
  redirect selection to some other object when (pre)selected in the tree
  view.

* Visibility, new property serve as the same purpose as view provider
  property of the same name. It is added here so that App namespace
  code can check for visibility without Gui module. This is useful,
  for example, when constructing a compound shape of a container that
  respects the children visibility.

* (has)hasHiddenMarker(), return or check for a special sub-element
  name used as marker for overriding sub-object visibility. Will be
  used by Gui::ViewProvider, it is put here for the same reason as
  adding Visibility property.

* getID(), return object internal identifier. Each object is now
  assigned an integer identifier that is unique within its containing
  document.

Document:

* ShowHidden, new property to tell tree view whether to show hidden
  object items.

* signalTouchedObject, new signal triggered when manually touch an
  object when calling its touch() function

* getObjectByID(), get object by its identifier

* addObject() is modified to allow overriding view provider

* has/getLinksTo(), helper function to obtain links to a given object.

Application:

* checkLinkDepth(), helper function to check recursive depth for link
  traversal. The depth is checked against the total object count of
  all opened documents. The count (_objCount) is internally updated
  whenever object is added or removed.

* has/getLinksTo(), same as Document::has/getLinksTo() but return links
  from all opened documents.

GroupExtension/OriginGroupExtension/DatumFeature/DatumCS/Part::Feature:
implement sepcialized getSubObject/getSubObjects().
2019-08-17 14:52:08 +02:00
wmayer
9660b1fb1e when trying to access ViewObject attribute check that FreeCADGui is already loaded 2019-06-03 11:30:29 +02:00
wmayer
7bf4c9d96f fixes 0003410: 0.17 Regression: recompute will make parts lose color and take a longer delay compared to FC0.16 2018-10-02 19:04:44 +02:00
luzpaz
8200c97ed2 Fix Techdraw UI typo found via crowdin + misc. typos
Ref: https://crowdin.com/translate/freecad/27911/en-eu#6503377
2017-11-26 15:48:20 +01:00
wmayer
bed779a530 method to get paths between two objects 2017-10-20 18:26:18 +02:00
wmayer
f59db97ac2 when accessing view provider of object make sure the object hasn't been removed from the document, raise an exception otherwise 2017-09-12 16:28:31 +02:00