Files
create/src/App/GeoFeatureGroupExtension.h
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

148 lines
7.8 KiB
C++

/***************************************************************************
* Copyright (c) Juergen Riegel (juergen.riegel@web.de) 2014 *
* Copyright (c) Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> 2015 *
* *
* 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_GeoFeatureGroup_H
#define APP_GeoFeatureGroup_H
#include <App/FeaturePython.h>
#include "DocumentObjectGroup.h"
#include "PropertyGeo.h"
namespace App
{
/**
* @brief The base class for placeable group of DocumentObjects. It represents a local coordnate system
*
* This class is the FreeCAD way of representing local coordinate systems. It groups its children beneath
* it and transforms them all with the GeoFeatureGroup placement. A few important properties:
* - Every child that belongs to the CS must be in the Group property. Even if a sketch is part of a pad,
* it must be in the Group property of the same GeoFeatureGroup as pad. This also holds for normal
* GroupExtensions. They can be added to a GeoFeatureGroup, but all objects that the group holds must
* also be added to the GeoFeatureGroup
* - Objects can be only in a single GeoFeatureGroup. It is not allowed to have a document object in
* multiple GeoFeatureGroups
* - PropertyLinks between different GeoFeatureGroups are forbidden. There are special link properties
* that allow such cross-CS links.
* - Expressions can cross GeoFeatureGroup borders
*/
class AppExport GeoFeatureGroupExtension : public App::GroupExtension
{
typedef App::GroupExtension inherited;
EXTENSION_PROPERTY_HEADER_WITH_OVERRIDE(App::GeoFeatureGroupExtension);
public:
PropertyPlacement& placement();
virtual void initExtension(ExtensionContainer* obj) override;
/**
* @brief transformPlacement applies transform to placement of this shape.
* Override this function to propagate the change of placement to base
* features.
* @param transform (input).
*/
virtual void transformPlacement(const Base::Placement &transform);
/// Constructor
GeoFeatureGroupExtension(void);
virtual ~GeoFeatureGroupExtension();
virtual void extensionOnChanged(const Property* p) override;
/** Returns the geo feature group which contains this object.
* In case this object is not part of any geoFeatureGroup 0 is returned.
* Unlike DocumentObjectGroup::getGroupOfObject serches only for GeoFeatureGroups
* @param obj the object to search for
*/
static DocumentObject* getGroupOfObject(const DocumentObject* obj);
/**
* @brief Calculates the global placement of this group
*
* The returned placement describes the transformation from the global reference coordinate
* system to the local coordinate system of this geo feature group. If this group has a no parent
* GeoFeatureGroup the returned placement is the one of this group. For multiple stacked
* GeoFeatureGroups the returned Placement is the combination of all parent placements including
* the one of this group.
* @return Base::Placement The transformation from global reference system to the groups local system
*/
Base::Placement globalGroupPlacement();
/// Returns true if the given DocumentObject is DocumentObjectGroup but not GeoFeatureGroup
static bool isNonGeoGroup(const DocumentObject* obj) {
return obj->hasExtension(GroupExtension::getExtensionClassTypeId()) &&
!obj->hasExtension(GeoFeatureGroupExtension::getExtensionClassTypeId());
}
virtual bool extensionGetSubObject(DocumentObject *&ret, const char *subname, PyObject **pyObj,
Base::Matrix4D *mat, bool transform, int depth) const override;
virtual bool extensionGetSubObjects(std::vector<std::string> &ret, int reason) const override;
virtual std::vector< DocumentObject* > addObjects(std::vector< DocumentObject* > obj) override;
virtual std::vector< DocumentObject* > removeObjects(std::vector< DocumentObject* > obj) override;
/// Collects all links that are relevant for the coordinate system, meaning all recursive links to
/// obj and from obj excluding expressions and stopping the recursion at other geofeaturegroups.
/// The result is the combination of CSOutList and CSInList.
static std::vector<App::DocumentObject*> getCSRelevantLinks(const App::DocumentObject* obj);
/// Checks if the links of the given object comply with all GeoFeatureGroup requirements, that means
/// if normal links are only within the parent GeoFeatureGroup.
static bool areLinksValid(const App::DocumentObject* obj);
/// Checks if the given link complies with all GeoFeatureGroup requirements, that means
/// if normal links are only within the parent GeoFeatureGroup.
static bool isLinkValid(App::Property* link);
//Returns all objects that are wrongly linked from this object, meaning which are out of scope of the
//links of obj
static void getInvalidLinkObjects(const App::DocumentObject* obj, std::vector<App::DocumentObject*>& vec);
private:
Base::Placement recursiveGroupPlacement(GeoFeatureGroupExtension* group);
static std::vector<App::DocumentObject*> getScopedObjectsFromLinks(const App::DocumentObject*, LinkScope scope = LinkScope::Local);
static std::vector<App::DocumentObject*> getScopedObjectsFromLink(App::Property*, LinkScope scope = LinkScope::Local);
/// Collects GeoFeatureGroup relevant objects that are linked from the given one. That means all linked objects
/// except GeoFeatureGroups. Expressions links are ignored. Only local scope links are considered. There is no
/// recursion. An exception is thrown when there are dependency loops.
static void getCSOutList(const App::DocumentObject* obj, std::vector<App::DocumentObject*>& vec);
/// Collects GeoFeatureGroup relevant objects that link to the given one. That means all objects
/// except GeoFeatureGroups. Expression links are ignored. Only local scope links are relevant, and
/// there is no recursion. An exception is thrown when there are dependency loops.
static void getCSInList(const App::DocumentObject* obj, std::vector<App::DocumentObject*>& vec);
static void recursiveCSRelevantLinks(const App::DocumentObject* obj,
std::vector<App::DocumentObject*>& vec);
};
typedef ExtensionPythonT<GroupExtensionPythonT<GeoFeatureGroupExtension>> GeoFeatureGroupExtensionPython;
} //namespace App
#endif // APP_GeoFeatureGroup_H