Files
create/src/Mod/Part/App/PartFeature.h
Zheng, Lei ff1d1cd341 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

157 lines
5.5 KiB
C++

/***************************************************************************
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
* *
* 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 PART_FEATURE_H
#define PART_FEATURE_H
#include "TopoShape.h"
#include "PropertyTopoShape.h"
#include <App/GeoFeature.h>
#include <App/FeaturePython.h>
#include <App/PropertyGeo.h>
// includes for findAllFacesCutBy()
#include <TopoDS_Face.hxx>
#include <BRep_Builder.hxx>
#include <TopoDS_Compound.hxx>
class gp_Dir;
class BRepBuilderAPI_MakeShape;
namespace Part
{
class PartFeaturePy;
/** Base class of all shape feature classes in FreeCAD
*/
class PartExport Feature : public App::GeoFeature
{
PROPERTY_HEADER(Part::Feature);
public:
/// Constructor
Feature(void);
virtual ~Feature();
PropertyPartShape Shape;
/** @name methods override feature */
//@{
virtual short mustExecute(void) const;
//@}
/// returns the type name of the ViewProvider
virtual const char* getViewProviderName(void) const;
virtual const App::PropertyComplexGeoData* getPropertyOfGeometry() const;
virtual PyObject* getPyObject(void);
TopLoc_Location getLocation() const;
virtual DocumentObject *getSubObject(const char *subname, PyObject **pyObj,
Base::Matrix4D *mat, bool transform, int depth) const override;
protected:
/// recompute only this object
virtual App::DocumentObjectExecReturn *recompute(void);
/// recalculate the feature
virtual App::DocumentObjectExecReturn *execute(void);
virtual void onChanged(const App::Property* prop);
/**
* Build a history of changes
* MakeShape: The operation that created the changes, e.g. BRepAlgoAPI_Common
* type: The type of object we are interested in, e.g. TopAbs_FACE
* newS: The new shape that was created by the operation
* oldS: The original shape prior to the operation
*/
ShapeHistory buildHistory(BRepBuilderAPI_MakeShape&, TopAbs_ShapeEnum type,
const TopoDS_Shape& newS, const TopoDS_Shape& oldS);
ShapeHistory joinHistory(const ShapeHistory&, const ShapeHistory&);
};
class FilletBase : public Part::Feature
{
PROPERTY_HEADER(Part::FilletBase);
public:
FilletBase();
App::PropertyLink Base;
PropertyFilletEdges Edges;
short mustExecute() const;
};
typedef App::FeaturePythonT<Feature> FeaturePython;
/** Base class of all shape feature classes in FreeCAD
*/
class PartExport FeatureExt : public Feature
{
PROPERTY_HEADER(Part::FeatureExt);
public:
const char* getViewProviderName(void) const {
return "PartGui::ViewProviderPartExt";
}
};
// Utility methods
/**
* Find all faces cut by a line through the centre of gravity of a given face
* Useful for the "up to face" options to pocket or pad
*/
struct cutFaces {
TopoDS_Face face;
double distsq;
};
PartExport
std::vector<cutFaces> findAllFacesCutBy(const TopoDS_Shape& shape,
const TopoDS_Shape& face, const gp_Dir& dir);
/**
* Check for intersection between the two shapes. Only solids are guaranteed to work properly
* There are two modes:
* 1. Bounding box check only - quick but inaccurate
* 2. Bounding box check plus (if necessary) boolean operation - costly but accurate
* Return true if the shapes intersect, false if they don't
* The flag touch_is_intersection decides whether shapes touching at distance zero are regarded
* as intersecting or not
* 1. If set to true, a true check result means that a boolean fuse operation between the two shapes
* will return a single solid
* 2. If set to false, a true check result means that a boolean common operation will return a
* valid solid
* If there is any error in the boolean operations, the check always returns false
*/
PartExport
bool checkIntersection(const TopoDS_Shape& first, const TopoDS_Shape& second,
const bool quick, const bool touch_is_intersection);
} //namespace Part
#endif // PART_FEATURE_H