#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeBoolean.h>
+#include <GeomAPI_Edge.h>
#include <GeomAPI_Face.h>
#include <GeomAPI_Pln.h>
#include <GeomAlgoAPI_Placement.h>
void FeaturesPlugin_Placement::initAttributes()
{
- data()->addAttribute(FeaturesPlugin_Placement::BASE_FACE_ID(), ModelAPI_AttributeSelection::type());
- data()->addAttribute(FeaturesPlugin_Placement::ATTRACT_FACE_ID(), ModelAPI_AttributeSelection::type());
+ data()->addAttribute(FeaturesPlugin_Placement::BASE_OBJECT_ID(), ModelAPI_AttributeSelection::type());
+ data()->addAttribute(FeaturesPlugin_Placement::ATTRACT_OBJECT_ID(), ModelAPI_AttributeSelection::type());
data()->addAttribute(FeaturesPlugin_Placement::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
data()->addAttribute(FeaturesPlugin_Placement::CENTERING_ID(), ModelAPI_AttributeBoolean::type());
}
void FeaturesPlugin_Placement::execute()
{
// Verify the base face
- std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = std::dynamic_pointer_cast<
- ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Placement::BASE_FACE_ID()));
- if (!aFaceRef)
+ std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = std::dynamic_pointer_cast<
+ ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Placement::BASE_OBJECT_ID()));
+ if (!anObjRef)
return;
- std::shared_ptr<GeomAPI_Shape> aBaseFace =
- std::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
- if (!aBaseFace)
+ std::shared_ptr<GeomAPI_Shape> aBaseShape =
+ std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+ if (!aBaseShape)
return;
- std::shared_ptr<GeomAPI_Shape> aBaseFaceContext;
- ResultPtr aContextRes = aFaceRef->context();
+ std::shared_ptr<GeomAPI_Shape> aBaseObject;
+ ResultPtr aContextRes = anObjRef->context();
if (aContextRes) {
if (aContextRes->groupName() == ModelAPI_ResultBody::group())
- aBaseFaceContext = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
+ aBaseObject = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group())
- aBaseFaceContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
+ aBaseObject = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
}
- if (!aBaseFaceContext) {
+ if (!aBaseObject) {
static const std::string aContextError = "The selection context is bad";
setError(aContextError);
return;
}
// Verify the attractive face
- aFaceRef = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(
- data()->attribute(FeaturesPlugin_Placement::ATTRACT_FACE_ID()));
+ anObjRef = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(
+ data()->attribute(FeaturesPlugin_Placement::ATTRACT_OBJECT_ID()));
- std::shared_ptr<GeomAPI_Shape> aSlaveObjectFace =
- std::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
- if (!aSlaveObjectFace)
+ std::shared_ptr<GeomAPI_Shape> aSlaveShape =
+ std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+ if (!aSlaveShape)
return;
std::shared_ptr<GeomAPI_Shape> aSlaveObject;
- aContextRes = aFaceRef->context();
+ aContextRes = anObjRef->context();
if (aContextRes) {
if (aContextRes->groupName() == ModelAPI_ResultBody::group())
aSlaveObject = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
return;
}
- // Verify faces planarity
- std::shared_ptr<GeomAPI_Face> aBaseFace1(new GeomAPI_Face(aBaseFace));
- std::shared_ptr<GeomAPI_Face> aSlaveFace1(new GeomAPI_Face(aSlaveObjectFace));
- if (!aBaseFace1->isPlanar() || !aSlaveFace1->isPlanar()) {
- static const std::string aPlanarityError = "One of selected face is not planar";
- setError(aPlanarityError);
- return;
+ // Verify planarity of faces and linearity of edges
+ std::shared_ptr<GeomAPI_Shape> aShapes[2] = {aBaseShape, aSlaveShape};
+ for (int i = 0; i < 2; i++) {
+ if (aShapes[i]->isFace()) {
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aShapes[i]));
+ if (!aFace->isPlanar()) {
+ static const std::string aPlanarityError = "One of selected faces is not planar";
+ setError(aPlanarityError);
+ return;
+ }
+ }
+ else if (aShapes[i]->isEdge()) {
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShapes[i]));
+ if (!anEdge->isLine()) {
+ static const std::string aLinearityError = "One of selected endges is not linear";
+ setError(aLinearityError);
+ return;
+ }
+ }
}
// Flags of the Placement
bool isCentering = aBoolAttr->value();
std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
- GeomAlgoAPI_Placement aFeature(aSlaveObject, aBaseFaceContext, aSlaveFace1, aBaseFace1, isReverse, isCentering);
+ GeomAlgoAPI_Placement aFeature(aSlaveObject, aBaseObject, aSlaveShape, aBaseShape, isReverse, isCentering);
if(!aFeature.isDone()) {
static const std::string aFeatureError = "Placement algorithm failed";
setError(aFeatureError);
* \ingroup Plugins
* \brief Feature for applying of placement operation: relative movement of Solid.
*
- * Locates the selected attractable_face of the solid in the middle of the selected
- * placement_base face. Faces must be planar. Orientation of the placed solid is
- * depended on the underlied planes of both faces.
+ * Locates the selected placement_attractable_object (face, edge, vertex) of the solid into
+ * the selected placement_base_object. Faces must be planar, edges must be linear.
+ * Orientation of the placed solid depends on the underlied planes of both faces.
*/
class FeaturesPlugin_Placement : public ModelAPI_Feature
{
static const std::string MY_PLACEMENT_ID("Placement");
return MY_PLACEMENT_ID;
}
- /// attribute name of referenced face
- inline static const std::string& BASE_FACE_ID()
+ /// attribute name of referenced object
+ inline static const std::string& BASE_OBJECT_ID()
{
- static const std::string MY_BASE_FACE_ID("placement_base_face");
- return MY_BASE_FACE_ID;
+ static const std::string MY_BASE_OBJECT_ID("placement_base_object");
+ return MY_BASE_OBJECT_ID;
}
/// attribute name of attractable face
- inline static const std::string& ATTRACT_FACE_ID()
+ inline static const std::string& ATTRACT_OBJECT_ID()
{
- static const std::string MY_ATTRACT_FACE_ID("placement_attractable_face");
- return MY_ATTRACT_FACE_ID;
+ static const std::string MY_ATTRACT_OBJECT_ID("placement_attractable_object");
+ return MY_ATTRACT_OBJECT_ID;
}
/// attribute name of flag of reverse direction
inline static const std::string& REVERSE_ID()
<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
<source>
- <shape_selector id="placement_base_face"
- label="Select a face"
+ <shape_selector id="placement_base_object"
+ label="Select an object"
icon=":icons/cut_shape.png"
- tooltip="Select a destination face"
- shape_types="face"
+ tooltip="Select a destination element"
+ shape_types="face edge vertex"
/>
- <shape_selector id="placement_attractable_face"
- label="Select a face"
+ <shape_selector id="placement_attractable_object"
+ label="Select an object"
icon=":icons/cut_shape.png"
- tooltip="Select a face of moved object"
- shape_types="face"
+ tooltip="Select an element of moved object"
+ shape_types="face edge vertex"
concealment="true" >
<validator id="PartSet_DifferentObjects"/>
</shape_selector>
#include<GeomAPI_Pnt.h>
#include<GeomAPI_Circ.h>
#include<GeomAPI_Dir.h>
+#include<GeomAPI_Lin.h>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Edge.hxx>
return std::shared_ptr<GeomAPI_Circ>(); // not circle
}
+std::shared_ptr<GeomAPI_Lin> GeomAPI_Edge::line()
+{
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+ double aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
+ if (aCurve) {
+ Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCurve);
+ if (aLine) {
+ gp_Pnt aStartPnt = aLine->Value(aFirst);
+ std::shared_ptr<GeomAPI_Pnt> aStart(
+ new GeomAPI_Pnt(aStartPnt.X(), aStartPnt.Y(), aStartPnt.Z()));
+ gp_Pnt aEndPnt = aLine->Value(aLast);
+ std::shared_ptr<GeomAPI_Pnt> aEnd(
+ new GeomAPI_Pnt(aEndPnt.X(), aEndPnt.Y(), aEndPnt.Z()));
+ return std::shared_ptr<GeomAPI_Lin>(new GeomAPI_Lin(aStart, aEnd));
+ }
+ }
+ return std::shared_ptr<GeomAPI_Lin>(); // not circle
+}
+
bool GeomAPI_Edge::isEqual(const std::shared_ptr<GeomAPI_Shape> theEdge) const
{
class GeomAPI_Pnt;
class GeomAPI_Circ;
+class GeomAPI_Lin;
/**\class GeomAPI_Edge
* \ingroup DataModel
/// Returns the Last vertex coordinates of the edge
std::shared_ptr<GeomAPI_Pnt> lastPoint();
- /// Returns a circle if edge is based on the cirsle curve
+ /// Returns a circle if edge is based on the circle curve
std::shared_ptr<GeomAPI_Circ> circle();
+ /// Returns a line if edge is based on the linear curve
+ std::shared_ptr<GeomAPI_Lin> line();
+
/// Returns true if the current edge is geometrically equal to the given edge
bool isEqual(const std::shared_ptr<GeomAPI_Shape> theEdge) const;
};
#include <GeomAPI_Lin.h>
#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Dir.h>
#include <gp_Dir.hxx>
#include <gp_Lin.hxx>
{
}
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Lin::location()
+{
+ gp_Pnt aLoc = impl<gp_Lin>().Location();
+ return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
+}
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_Lin::direction()
+{
+ const gp_Dir& aDir = impl<gp_Lin>().Direction();
+ return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
+}
+
double GeomAPI_Lin::distance(const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
{
return MY_LIN->Distance(thePoint->impl<gp_Pnt>());
#include <GeomAPI_Interface.h>
#include <memory>
+class GeomAPI_Dir;
class GeomAPI_Pnt;
/**\class GeomAPI_Lin
GeomAPI_Lin(const std::shared_ptr<GeomAPI_Pnt>& theStart,
const std::shared_ptr<GeomAPI_Pnt>& theEnd);
+ /// Returns point on the line (first point)
+ std::shared_ptr<GeomAPI_Pnt> location();
+
+ /// Returns a line direction
+ std::shared_ptr<GeomAPI_Dir> direction();
+
/// Distance between two points
double distance(const std::shared_ptr<GeomAPI_Pnt>& thePoint) const;
/// Intersection of two lines
#include <GeomAPI_Lin2d.h>
#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Dir2d.h>
#include <gp_Dir2d.hxx>
#include <gp_Lin2d.hxx>
{
}
+std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Lin2d::location()
+{
+ gp_Pnt2d aLoc = impl<gp_Lin2d>().Location();
+ return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aLoc.X(), aLoc.Y()));
+}
+
+std::shared_ptr<GeomAPI_Dir2d> GeomAPI_Lin2d::direction()
+{
+ const gp_Dir2d& aDir = impl<gp_Lin2d>().Direction();
+ return std::shared_ptr<GeomAPI_Dir2d>(new GeomAPI_Dir2d(aDir.X(), aDir.Y()));
+}
+
double GeomAPI_Lin2d::distance(const std::shared_ptr<GeomAPI_Pnt2d>& theOther) const
{
return MY_LIN2D->Distance(theOther->impl<gp_Pnt2d>());
#include <GeomAPI_Interface.h>
#include <memory>
+class GeomAPI_Dir2d;
class GeomAPI_Pnt2d;
/**\class GeomAPI_Lin2d
GeomAPI_Lin2d(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
const std::shared_ptr<GeomAPI_Pnt2d>& theEnd);
+ /// Returns point on the line (first point)
+ std::shared_ptr<GeomAPI_Pnt2d> location();
+
+ /// Returns a line direction
+ std::shared_ptr<GeomAPI_Dir2d> direction();
+
/// Distance between two points
double distance(const std::shared_ptr<GeomAPI_Pnt2d>& theOther) const;
/// Intersection of two lines
#include <GeomAlgoAPI_Placement.h>
#include <GeomAlgoAPI_DFLoader.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Pln.h>
+#include <GeomAPI_Vertex.h>
+#include <GeomAPI_XYZ.h>
#include <BRepBuilderAPI_Transform.hxx>
#include <gp_Trsf.hxx>
#define DEB_PLACEMENT 1
GeomAlgoAPI_Placement::GeomAlgoAPI_Placement(
+ std::shared_ptr<GeomAPI_Shape> theSourceSolid,
+ std::shared_ptr<GeomAPI_Shape> theDestSolid,
std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Shape> theDestShape,
- std::shared_ptr<GeomAPI_Face> theSourcePlane,
- std::shared_ptr<GeomAPI_Face> theDestPlane,
bool theIsReverse,
bool theIsCentering)
: myDone(false),
myShape(new GeomAPI_Shape())
{
- build(theSourceShape, theDestShape, theSourcePlane, theDestPlane, theIsReverse, theIsCentering);
+ build(theSourceSolid, theDestSolid, theSourceShape, theDestShape, theIsReverse, theIsCentering);
}
void GeomAlgoAPI_Placement::build(
+ const std::shared_ptr<GeomAPI_Shape>& theSourceSolid,
+ const std::shared_ptr<GeomAPI_Shape>& theDestSolid,
const std::shared_ptr<GeomAPI_Shape>& theSourceShape,
const std::shared_ptr<GeomAPI_Shape>& theDestShape,
- const std::shared_ptr<GeomAPI_Face>& theSourcePlane,
- const std::shared_ptr<GeomAPI_Face>& theDestPlane,
bool theIsReverse,
bool theIsCentering)
{
- std::shared_ptr<GeomAPI_Pln> aSourcePlane = theSourcePlane->getPlane();
- std::shared_ptr<GeomAPI_Pln> aDestPlane = theDestPlane->getPlane();
- std::shared_ptr<GeomAPI_Dir> aSourceDir = aSourcePlane->direction();
- std::shared_ptr<GeomAPI_Pnt> aSourceLoc = aSourcePlane->location();
- std::shared_ptr<GeomAPI_Dir> aDestDir = aDestPlane->direction();
- std::shared_ptr<GeomAPI_Pnt> aDestLoc = aDestPlane->location();
+ // Filling the parameters of the objects
+ static const int aNbObjects = 2;
+ gp_Pnt aSrcDstPoints[aNbObjects]; // points on the selected objects (0 - source, 1 - destination)
+ gp_Vec aSrcDstNormals[aNbObjects]; // normal vectors, if planar faces are selected
+ gp_Vec aSrcDstDirections[aNbObjects]; // directions of linear edges
+ bool hasNormal[aNbObjects];
+ bool hasDirection[aNbObjects];
+ std::shared_ptr<GeomAPI_Shape> aShapes[aNbObjects] = {theSourceShape, theDestShape};
+
+ for (int i = 0; i < aNbObjects; i++) {
+ if (aShapes[i]->isFace()) {
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aShapes[i]));
+ std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
+ std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+ std::shared_ptr<GeomAPI_Pnt> aLoc = aPlane->location();
+ aSrcDstPoints[i].SetCoord(aLoc->x(), aLoc->y(), aLoc->z());
+ aSrcDstNormals[i].SetCoord(aDir->x(), aDir->y(), aDir->z());
+ } else if (aShapes[i]->isEdge()) {
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShapes[i]));
+ std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
+ std::shared_ptr<GeomAPI_Dir> aDir = aLine->direction();
+ std::shared_ptr<GeomAPI_Pnt> aFirstPnt = anEdge->firstPoint();
+ std::shared_ptr<GeomAPI_Pnt> aLastPnt = anEdge->lastPoint();
+ std::shared_ptr<GeomAPI_XYZ> aLoc = aFirstPnt->xyz()->added(aLastPnt->xyz())->multiplied(0.5);
+ aSrcDstPoints[i].SetCoord(aLoc->x(), aLoc->y(), aLoc->z());
+ aSrcDstDirections[i].SetCoord(aDir->x(), aDir->y(), aDir->z());
+ } else if (aShapes[i]->isVertex()) {
+ std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aShapes[i]));
+ std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+ aSrcDstPoints[i].SetCoord(aPnt->x(), aPnt->y(), aPnt->z());
+ } else // something goes wrong
+ return;
+ hasNormal[i] = aSrcDstNormals[i].SquareMagnitude() >= Precision::SquareConfusion();
+ hasDirection[i] = aSrcDstDirections[i].SquareMagnitude() >= Precision::SquareConfusion();
+ }
+
+ // Calculate directions, which comply the normal, for vertices and edges
+ if (!hasNormal[0] || !hasNormal[1]) {
+ if (hasNormal[0] || hasNormal[1]) { // plane with line or vertex
+ if (hasDirection[0] || hasDirection[1]) { // plane - line
+ int anInd = hasDirection[0] ? 0 : 1;
+ gp_Vec aVec = aSrcDstNormals[1 - anInd].Crossed(aSrcDstDirections[anInd]);
+ if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // normal and direction are collinear
+ aVec = aSrcDstNormals[1 - anInd].Crossed(
+ gp_Vec(aSrcDstPoints[1 - anInd], aSrcDstPoints[anInd]));
+ if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // normal and points direction are collinear
+ if (Abs(aSrcDstNormals[1 - anInd].Y()) >= Precision::Confusion() ||
+ Abs(aSrcDstNormals[1 - anInd].Z()) >= Precision::Confusion())
+ aVec = gp::DX();
+ else
+ aVec = gp::DY();
+ }
+ }
+ aSrcDstNormals[anInd] = aSrcDstDirections[anInd].Crossed(aVec).Normalized();
+ } else { // plane - point
+ int anInd = hasNormal[0] ? 1 : 0;
+ aSrcDstNormals[anInd] = aSrcDstNormals[1 - anInd];
+ }
+ } else {
+ if (hasDirection[0] && hasDirection[1]) { // line - line
+ gp_Vec aVec = aSrcDstDirections[0].Crossed(aSrcDstDirections[1]);
+ if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // lines are parallel
+ aVec = aSrcDstDirections[0].Crossed(gp_Vec(aSrcDstPoints[0], aSrcDstPoints[1]));
+ if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // lines are equal
+ if (Abs(aSrcDstDirections[0].Y()) >= Precision::Confusion() ||
+ Abs(aSrcDstDirections[0].Z()) >= Precision::Confusion())
+ aVec = gp::DX();
+ else
+ aVec = gp::DY();
+ }
+ }
+ aSrcDstNormals[0] = aSrcDstDirections[0].Crossed(aVec);
+ aSrcDstNormals[0].Normalize();
+ aSrcDstNormals[1] = aSrcDstDirections[1].Crossed(aVec).Reversed();
+ aSrcDstNormals[1].Normalize();
+ } else if (!hasDirection[0] && !hasDirection[1]) { // point - point
+ aSrcDstNormals[0] = gp_Vec(aSrcDstPoints[0], aSrcDstPoints[1]);
+ aSrcDstNormals[0].Normalize();
+ aSrcDstNormals[1] = -aSrcDstNormals[0];
+ } else { // line - point
+ int anInd = hasDirection[0] ? 0 : 1;
+ gp_Vec aVec(aSrcDstPoints[anInd], aSrcDstPoints[1 - anInd]);
+ aVec.Cross(aSrcDstDirections[anInd]);
+ if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // point is on line
+ if (Abs(aSrcDstDirections[1 - anInd].Y()) >= Precision::Confusion() ||
+ Abs(aSrcDstDirections[1 - anInd].Z()) >= Precision::Confusion())
+ aVec = gp::DX();
+ else
+ aVec = gp::DY();
+ }
+ aSrcDstNormals[anInd] = aSrcDstDirections[anInd].Crossed(aVec).Normalized();
+ aSrcDstNormals[1 - anInd] = aSrcDstNormals[anInd];
+ }
+ }
+ }
// Initial shapes
- const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
- const TopoDS_Shape& aDestShape = theDestShape->impl<TopoDS_Shape>();
+ const TopoDS_Shape& aSourceShape = theSourceSolid->impl<TopoDS_Shape>();
+ const TopoDS_Shape& aDestShape = theDestSolid->impl<TopoDS_Shape>();
// Calculate transformation
gp_Trsf aTrsf;
- gp_Vec aSrcDir(aSourceDir->x(), aSourceDir->y(), aSourceDir->z());
- gp_Vec aDstDir(aDestDir->x(), aDestDir->y(), aDestDir->z());
+ gp_Vec aSrcDir = aSrcDstNormals[0];
+ gp_Vec aDstDir = aSrcDstNormals[1];
// Check the material of the solids to be on the correct side
BRepClass3d_SolidClassifier aClassifier;
- aClassifier.Load(aSourceShape);
static const double aTransStep = 10. * Precision::Confusion();
- gp_Pnt aPoint(aSourceLoc->x(), aSourceLoc->y(), aSourceLoc->z());
- aPoint.Translate(aSrcDir * aTransStep);
- aClassifier.Perform(aPoint, Precision::Confusion());
- if ((aClassifier.State() == TopAbs_OUT && !theIsReverse) ||
- (aClassifier.State() == TopAbs_IN && theIsReverse))
+ if (hasNormal[0]) {
+ aClassifier.Load(aSourceShape);
+ gp_Pnt aPoint = aSrcDstPoints[0];
+ aPoint.Translate(aSrcDir * aTransStep);
+ aClassifier.Perform(aPoint, Precision::Confusion());
+ if ((aClassifier.State() == TopAbs_OUT && !theIsReverse) ||
+ (aClassifier.State() == TopAbs_IN && theIsReverse))
+ aSrcDir.Reverse();
+ } else if (theIsReverse)
aSrcDir.Reverse();
- aClassifier.Load(aDestShape);
- aPoint.SetCoord(aDestLoc->x(), aDestLoc->y(), aDestLoc->z());
- aPoint.Translate(aDstDir * aTransStep);
- aClassifier.Perform(aPoint, Precision::Confusion());
- if (aClassifier.State() == TopAbs_IN)
- aDstDir.Reverse();
+ if (hasNormal[1]) {
+ aClassifier.Load(aDestShape);
+ gp_Pnt aPoint = aSrcDstPoints[1];
+ aPoint.Translate(aDstDir * aTransStep);
+ aClassifier.Perform(aPoint, Precision::Confusion());
+ if (aClassifier.State() == TopAbs_IN)
+ aDstDir.Reverse();
+ }
// Calculate rotation
gp_Quaternion aRot(aSrcDir, aDstDir);
aTrsf.SetRotation(aRot);
// Calculate translation
- gp_Vec aSrcLoc(aSourceLoc->x(), aSourceLoc->y(), aSourceLoc->z());
- gp_Vec aDstLoc(aDestLoc->x(), aDestLoc->y(), aDestLoc->z());
+ gp_Vec aSrcLoc(aSrcDstPoints[0].XYZ());
+ gp_Vec aDstLoc(aSrcDstPoints[1].XYZ());
if (!theIsCentering)
aDstLoc = aSrcLoc + gp_Vec(aDstDir) * (aDstLoc-aSrcLoc).Dot(aDstDir);
aSrcLoc.Transform(aTrsf);
/**\class GeomAlgoAPI_Placement
* \ingroup DataAlgo
- * \brief Creates the copied object which face is placed on the given plane
+ * \brief Creates the copied object which sub-element is placed on the given element
*/
class GeomAlgoAPI_Placement : public GeomAPI_Interface
{
public:
/** \brief Creates an object which is obtained from current object by transformation calculated
- * as a movement of the source plane to be coincident with the destination plane
- * \param[in] theSourceShape shape to be moved
- * \param[in] theDestShape invariabt shape
- * \param[in] theSourcePlane plane on the shape to be made coincident with destination plane
- * \param[in] theDestPlane destination plane
+ * as a movement of the source object to be coincident with the destination object
+ * \param[in] theSourceSolid a shape to be moved
+ * \param[in] theDestSolid invariant shape
+ * \param[in] theSourceShape a shape on the solid to be made coincident with destination object
+ * \param[in] theDestShape destination object
* \param[in] theIsReverse indicates that the solid materials should be on the same side against the destination plane
* \param[in] theIsCentering indicates the planes should be centered
*/
- GEOMALGOAPI_EXPORT GeomAlgoAPI_Placement(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_Placement(std::shared_ptr<GeomAPI_Shape> theSourceSolid,
+ std::shared_ptr<GeomAPI_Shape> theDestSolid,
+ std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Shape> theDestShape,
- std::shared_ptr<GeomAPI_Face> theSourcePlane,
- std::shared_ptr<GeomAPI_Face> theDestPlane,
bool theIsReverse = false,
bool theIsCentering = false);
private:
/// builds resulting shape
- void build(const std::shared_ptr<GeomAPI_Shape>& theSourceShape,
+ void build(const std::shared_ptr<GeomAPI_Shape>& theSourceSolid,
+ const std::shared_ptr<GeomAPI_Shape>& theDestSolid,
+ const std::shared_ptr<GeomAPI_Shape>& theSourceShape,
const std::shared_ptr<GeomAPI_Shape>& theDestShape,
- const std::shared_ptr<GeomAPI_Face>& theSourcePlane,
- const std::shared_ptr<GeomAPI_Face>& theDestPlane,
bool theIsReverse,
bool theIsCentering);