FreeCAD/src/Mod/Part/App/PartFeature.h

161 lines
5.6 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>
class gp_Dir;
class BRepBuilderAPI_MakeShape;
// includes for findAllFacesCutBy()
#include <TopoDS_Face.hxx>
class gp_Dir;
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 */
//@{
/// recalculate the feature
/// recompute only this object
virtual App::DocumentObjectExecReturn *recompute(void);
virtual App::DocumentObjectExecReturn *execute(void);
virtual short mustExecute(void) const;
//@}
/// returns the type name of the ViewProvider
virtual const char* getViewProviderName(void) const;
virtual PyObject* getPyObject(void);
virtual std::vector<PyObject *> getPySubObjects(const std::vector<std::string>&) const;
/**
* Find the origin of a reference, e.g. the vertex or edge in a sketch that
* produced a face
*/
const TopoDS_Shape findOriginOf(const TopoDS_Shape& reference);
protected:
void onChanged(const App::Property* prop);
TopLoc_Location getLocation() const;
/**
* 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
const bool checkIntersection(const TopoDS_Shape& first, const TopoDS_Shape& second,
const bool quick, const bool touch_is_intersection);
} //namespace Part
#endif // PART_FEATURE_H