#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);
}
bool GeomValidators_Face::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const
+ const std::list<std::string>& theArguments) const
{
bool aValid = false;
}
}
}
+ else
+ aValid = true; // an empty face selected is valid.
return aValid;
}
TDF_Label aSelLab = selectionLabel();
aSelLab.ForgetAttribute(kSIMPLE_REF_ID);
aSelLab.ForgetAttribute(kCONSTUCTION_SIMPLE_REF_ID);
+ if (!theContext.get()) {
+ // to keep the reference attribute label
+ TDF_Label aRefLab = myRef.myRef->Label();
+ aSelLab.ForgetAllAttributes(true);
+ myRef.myRef = TDF_Reference::Set(aSelLab, aSelLab);
+ return;
+ }
if (theContext->groupName() == ModelAPI_ResultBody::group()) {
// do not select the whole shape for body:it is already must be in the data framework
if (theContext->shape().get() && theContext->shape()->isEqual(theSubShape)) {
//********************************************************************
bool ModuleBase_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject,
- GeomShapePtr theShape) const
+ GeomShapePtr theShape)
{
bool isChanged = false;
FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theSelectedObject);
myIsObject = aRefAttr->isObject();
myRefAttribute = aRefAttr->attr();
}
+ myExternalObject = NULL;
}
else {
storeAttributeValues(myObject, myShape);
if (!myIsObject)
aRefAttr->setAttr(myRefAttribute);
}
+ if (myExternalObject.get()) {
+ /*DocumentPtr aDoc = myExternalObject->document();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject);
+ if (aFeature.get() != NULL) {
+ aDoc->removeFeature(aFeature);
+ }*/
+ }
}
}
/// the specific type and set the given values
/// \param theSelectedObject an object
/// \param theShape a selected shape, which is used in the selection attribute
- virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const;
+ virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
//----------- Class members -------------
protected:
AttributePtr myRefAttribute;
/// A boolean value whether refAttr uses reference of object
bool myIsObject;
+ /// An external object
+ ObjectPtr myExternalObject;
};
#endif
{
}
+//********************************************************************
bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue)
{
bool isDone = false;
return isDone;
}
+//********************************************************************
bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& theOwner)
{
+ // stores the current values of the widget attribute
backupAttributeValue(true);
+ // saves the owner value to the widget attribute
setSelection(theOwner);
+
+ // checks the attribute validity
bool aValid = isValidAttribute();
+ // restores the current values of the widget attribute
backupAttributeValue(false);
return aValid;
/// Set the given wrapped value to the current widget
/// This value should be processed in the widget according to the needs
+ /// The method is called by the current operation to process the operation preselection.
+ /// It is redefined to check the value validity and if it is, fill the attribute with by value
/// \param theValue the wrapped widget value
virtual bool setSelection(ModuleBase_ViewerPrs theValue);
#include <PartSet_Tools.h>
#include <SketchPlugin_Feature.h>
-bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const
+bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape)
{
ObjectPtr aSelectedObject = theSelectedObject;
aSelectedObject, mySketch);
if (aObj) {
aSelectedObject = aObj;
+ myExternalObject = aObj;
} else
return false;
}
/// the specific type and set the given values
/// \param theSelectedObject an object
/// \param theShape a selected shape, which is used in the selection attribute
- virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const;
+ virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
private:
/// Pointer to a sketch
#include <PartSet_Tools.h>
#include <SketchPlugin_Feature.h>
-bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const
+bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape)
{
ObjectPtr aSelectedObject = theSelectedObject;
GeomShapePtr aShape = theShape;
if (aObj) {
PartSet_WidgetShapeSelector* that = (PartSet_WidgetShapeSelector*) this;
aSelectedObject = aObj;
+ myExternalObject = aObj;
} else
return false;
} else {
/// the specific type and set the given values
/// \param theSelectedObject an object
/// \param theShape a selected shape, which is used in the selection attribute
- virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const;
+ virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
private:
/// Pointer to a sketch
#include <ModuleBase_Operation.h>
#include <ModuleBase_ViewerPrs.h>
#include <ModuleBase_Tools.h>
+#include <ModuleBase_IModule.h>
#include <GeomAlgoAPI_FaceBuilder.h>
#include <GeomDataAPI_Point.h>
PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
const Config_WidgetAPI* theData,
const std::string& theParentId)
- : ModuleBase_ModelWidget(theParent, theData, theParentId),
+ : ModuleBase_WidgetValidated(theParent, theData, theParentId),
myPreviewDisplayed(false),
myWorkshop(NULL)
{
void PartSet_WidgetSketchLabel::onPlaneSelected()
{
+
XGUI_Selection* aSelection = myWorkshop->selector()->selection();
QList<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
if (!aSelected.empty()) {
ModuleBase_ViewerPrs aPrs = aSelected.first();
- TopoDS_Shape aShape = aPrs.shape();
- if (!aShape.IsNull()) {
- std::shared_ptr<GeomAPI_Dir> aDir = setSketchPlane(aShape);
- if (aDir) {
- erasePreviewPlanes();
+ Handle(SelectMgr_EntityOwner) anOwner = aSelected.first().owner();
+ if (isValid(anOwner)) {
+ setSelection(anOwner);
- if (aPrs.object() && (feature() != aPrs.object())) {
- DataPtr aData = feature()->data();
- AttributeSelectionPtr aSelAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
- (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
- if (aSelAttr) {
- ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs.object());
- if (aRes) {
- GeomShapePtr aShapePtr(new GeomAPI_Shape());
- aShapePtr->setImpl(new TopoDS_Shape(aShape));
- aSelAttr->setValue(aRes, aShapePtr);
- }
+ TopoDS_Shape aShape = aPrs.shape();
+ if (!aShape.IsNull()) {
+ erasePreviewPlanes();
+ DataPtr aData = feature()->data();
+ AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+ if (aSelAttr) {
+ GeomShapePtr aShapePtr = aSelAttr->value();
+ if (aShapePtr.get() == NULL || aShapePtr->isNull()) {
+ std::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
+ aGShape->setImpl(new TopoDS_Shape(aShape));
+ // get plane parameters
+ std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
+ std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+
+ myWorkshop->viewer()->setViewProjection(aDir->x(), aDir->y(), aDir->z());
}
- } else
- myWorkshop->viewer()->setViewProjection(aDir->x(), aDir->y(), aDir->z());
+ }
// Clear text in the label
myLabel->setText("");
myLabel->setToolTip("");
disconnect(myWorkshop->selector(), SIGNAL(selectionChanged()),
this, SLOT(onPlaneSelected()));
+ activateFilters(myWorkshop->module()->workshop(), false);
// Clear selection mode and define sketching mode
- XGUI_Displayer* aDisp = myWorkshop->displayer();
- aDisp->removeSelectionFilter(myFaceFilter);
+ //XGUI_Displayer* aDisp = myWorkshop->displayer();
//aDisp->closeLocalContexts();
emit planeSelected(plane());
setSketchingMode();
myLabel->installEventFilter(this);
}
+void PartSet_WidgetSketchLabel::backupAttributeValue(const bool isBackup)
+{
+ // it is not necessary to save the previous plane value because the plane is chosen once
+ if (!isBackup) {
+ DataPtr aData = feature()->data();
+ AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+ if (aSelAttr) {
+ ResultPtr anEmptyResult;
+ GeomShapePtr anEmptyShape;
+ aSelAttr->setValue(anEmptyResult, anEmptyShape);
+ }
+ }
+}
+
+bool PartSet_WidgetSketchLabel::setSelection(const Handle_SelectMgr_EntityOwner& theOwner)
+{
+ bool isOwnerSet = false;
+
+ ModuleBase_ViewerPrs aPrs;
+ myWorkshop->selector()->selection()->fillPresentation(aPrs, theOwner);
+
+ const TopoDS_Shape& aShape = aPrs.shape();
+ std::shared_ptr<GeomAPI_Dir> aDir;
+
+ if (aPrs.object() && (feature() != aPrs.object())) {
+ DataPtr aData = feature()->data();
+ AttributeSelectionPtr aSelAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+ if (aSelAttr) {
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs.object());
+ if (aRes) {
+ GeomShapePtr aShapePtr(new GeomAPI_Shape());
+ aShapePtr->setImpl(new TopoDS_Shape(aShape));
+ aSelAttr->setValue(aRes, aShapePtr);
+ isOwnerSet = true;
+ }
+ }
+ }
+ else if (!aShape.IsNull()) {
+ aDir = setSketchPlane(aShape);
+ isOwnerSet = aDir;
+ }
+ return isOwnerSet;
+}
+
void PartSet_WidgetSketchLabel::activateCustom()
{
std::shared_ptr<GeomAPI_Pln> aPlane = plane();
if (aPlane) {
//setSketchingMode();
// In order to avoid Opening/Closing of context too often
+ // it can be useful for a delay on the property panel filling
+ // it is possible that it is not necessary anymore, but it requires a check
mySelectionTimer->start(20);
} else {
// We have to select a plane before any operation
XGUI_Displayer* aDisp = myWorkshop->displayer();
//aDisp->openLocalContext();
//aDisp->activateObjects(QIntList());
- if (myFaceFilter.IsNull())
- myFaceFilter = new StdSelect_FaceFilter(StdSelect_Plane);
- aDisp->addSelectionFilter(myFaceFilter);
QIntList aModes;
aModes << TopAbs_FACE;
aDisp->activateObjects(aModes);
myLabel->setToolTip(myTooltip);
connect(myWorkshop->selector(), SIGNAL(selectionChanged()), this, SLOT(onPlaneSelected()));
+ activateFilters(myWorkshop->module()->workshop(), true);
+
aDisp->updateViewer();
}
}
{
// Do not set selection mode if the widget was activated for a small moment
mySelectionTimer->stop();
- XGUI_Displayer* aDisp = myWorkshop->displayer();
- aDisp->removeSelectionFilter(myFaceFilter);
- //aDisp->removeSelectionFilter(mySketchFilter);
+ //XGUI_Displayer* aDisp = myWorkshop->displayer();
//aDisp->closeLocalContexts();
erasePreviewPlanes();
}
#include "PartSet.h"
-#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_WidgetValidated.h>
#include <ModuleBase_ViewerFilters.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Dir.h>
#include <GeomAPI_AISObject.h>
-#include <StdSelect_FaceFilter.hxx>
#include <TopoDS_Shape.hxx>
class QLabel;
* A model widget implementation for a label which provides specific behaviour
* for sketcher starting and launching operations
*/
-class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_ModelWidget
+class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
{
Q_OBJECT
public:
void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
protected:
+ /// Creates a backup of the current values of the attribute
+ /// It should be realized in the specific widget because of different
+ /// parameters of the current attribute
+ /// \param isBackup a boolean flag, if true, store values from the attribute
+ /// to backup, otherwise set the backed up values to the attribute
+ virtual void backupAttributeValue(const bool isBackup);
+
+ /// Fills the attribute with the value of the selected owner
+ /// \param theOwner a selected owner
+ virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner);
+
/// Saves the internal parameters to the given feature
/// \return True in success
virtual bool storeValueCustom() const
AISObjectPtr myXYPlane;
bool myPreviewDisplayed;
- Handle(StdSelect_FaceFilter) myFaceFilter;
-
QTimer* mySelectionTimer;
};
title="Sketch"
tooltip="Create a new sketch"
icon=":icons/sketch.png">
- <sketch-start-label title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/>
+ <sketch-start-label id="External" title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch">
+ <validator id="GeomValidators_Face" parameters="plane"/>
+ </sketch-start-label>
<!--icon=":pictures/x_point.png"-->
</feature>
<feature id="SketchPoint" title="Point" tooltip="Create a new point" icon=":icons/point.png">