myFeatureId = std::string(); // Feature unique id
myIsObligatory = true;
myIsConcealment = false;
+ myIsGeometricalSelection = false;
}
Config_AttributeMessage::~Config_AttributeMessage()
{
myIsMainArgument = isMainArg;
}
+
+bool Config_AttributeMessage::isGeometricalSelection() const
+{
+ return myIsGeometricalSelection;
+}
+
+void Config_AttributeMessage::setGeometricalSelection(bool isGeometricalSelection)
+{
+ myIsGeometricalSelection = isGeometricalSelection;
+}
bool myIsObligatory; ///< Required to be set by user, else it's feature is invalid.
bool myIsConcealment; ///< If true, conceals features used as input
bool myIsMainArgument; ///< Mark attribute as a main argument of the feature
+ bool myIsGeometricalSelection; ///< If true selects geometry instead of shape;
///< a list of pairs, if the attribute is placed inside paged containers: (case, switch)
std::list<std::pair<std::string, std::string> > myCases;
CONFIG_EXPORT bool isConcealment() const;
/// Returns true if attribute is a main argument of the feature
CONFIG_EXPORT bool isMainArgument() const;
+ /// Returns true if attribute selects geometry instead of shape;
+ CONFIG_EXPORT bool isGeometricalSelection() const;
/// Returns container of ids of pair of a case and switches
CONFIG_EXPORT const std::list<std::pair<std::string, std::string> >& getCases() const;
/// Sets ids of pair of a case and switches
CONFIG_EXPORT void setObligatory(bool isObligatory);
/// Set a state that the attribute is a main argument of the feature
CONFIG_EXPORT void setMainArgument(bool isMainArg);
+ /// Set attribute's geometrical selection state
+ CONFIG_EXPORT void setGeometricalSelection(bool isGeometricalSelection);
};
#endif // ATTRIBUTE_MESSAGE_H
aMessage->setConcealment(isConcealment);
bool isMainArg = isConcealment && getBooleanAttribute(theNode, ATTR_MAIN_ARG, false);
aMessage->setMainArgument(isMainArg);
+ aMessage->setGeometricalSelection(getBooleanAttribute(theNode,
+ ATTR_GEOMETRICAL_SELECTION,
+ false));
std::list<std::pair<std::string, std::string> > aCases;
xmlNodePtr aCaseNode = hasParentRecursive(theNode,
const static char* ATTR_GREED = "greed";
const static char* ATTR_MODIFIED_IN_EDIT = "modified_in_edit";
const static char* ATTR_MAIN_ARG = "main_argument";
+const static char* ATTR_GEOMETRICAL_SELECTION = "geometrical_selection";
+
// WDG_INFO properties
const static char* INFO_WDG_TEXT = FEATURE_TEXT;
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
#include <GeomAPI_Pln.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAPI_Vertex.h>
#include <GeomAlgoAPI_EdgeBuilder.h>
#include <GeomAlgoAPI_PointBuilder.h>
void ConstructionPlugin_Axis::createAxisByCylindricalFace()
{
- std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(CYLINDRICAL_FACE())->value();
- // update arguments due to the selection value
- if (aSelection && !aSelection->isNull() && aSelection->isFace()) {
- std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::cylinderAxis(aSelection);
-
- ResultConstructionPtr aConstr = document()->createConstruction(data());
- aConstr->setInfinite(true);
- aConstr->setShape(anEdge);
- setResult(aConstr);
- }
+ std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(CYLINDRICAL_FACE())->value();
+ // update arguments due to the selection value
+
+ if (!aSelection.get() || aSelection->isNull()) {
+ return;
+ }
+
+ if (aSelection->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aSelection);
+ aSelection = anIt.current();
+ }
+
+ if (aSelection->isFace()) {
+ std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::cylinderAxis(aSelection);
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+ }
}
void ConstructionPlugin_Axis::createAxisByDimensions()
if(!aLineShape.get()) {
aLineShape = anEdgeSelection->context()->shape();
}
- std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
+ GeomEdgePtr anEdge;
+ if (aLineShape->isEdge()) {
+ anEdge = aLineShape->edge();
+ }
+ else if (aLineShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aLineShape);
+ anEdge = anIt.current()->edge();
+ }
ResultConstructionPtr aConstr = document()->createConstruction(data());
aConstr->setInfinite(true);
if(!aFaceShape.get()) {
aFaceShape = aFaceSelection->context()->shape();
}
- std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aFaceShape));
+ GeomFacePtr aFace;
+ if (aFaceShape->isFace()) {
+ aFace = aFaceShape->face();
+ }
+ else if (aFaceShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFaceShape);
+ aFace = anIt.current()->face();
+ }
std::shared_ptr<GeomAPI_Pln> aPln = aFace->getPlane();
// Get point.
if(!aFaceShape1.get()) {
aFaceShape1 = aFaceSelection1->context()->shape();
}
- std::shared_ptr<GeomAPI_Face> aFace1(new GeomAPI_Face(aFaceShape1));
+ std::shared_ptr<GeomAPI_Face> aFace1;
+ if (aFaceShape1->isFace()) {
+ aFace1 = aFaceShape1->face();
+ }
+ else if (aFaceShape1->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFaceShape1);
+ aFace1 = anIt.current()->face();
+ }
std::shared_ptr<GeomAPI_Pln> aPln1 = aFace1->getPlane();
std::string useOffset1 = string(USE_OFFSET1())->value();
if(!aFaceShape2.get()) {
aFaceShape2 = aFaceSelection2->context()->shape();
}
- std::shared_ptr<GeomAPI_Face> aFace2(new GeomAPI_Face(aFaceShape2));
+ std::shared_ptr<GeomAPI_Face> aFace2;
+ if (aFaceShape2->isFace()) {
+ aFace2 = aFaceShape2->face();
+ }
+ else if (aFaceShape2->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFaceShape2);
+ aFace2 = anIt.current()->face();
+ }
std::shared_ptr<GeomAPI_Pln> aPln2 = aFace2->getPlane();
std::string useOffset2 = string(USE_OFFSET2())->value();
#include <GeomAPI_Pln.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAPI_Vertex.h>
#include <GeomAPI_XYZ.h>
if(!aLineShape.get()) {
aLineShape = anEdgeSelection->context()->shape();
}
- std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
+ std::shared_ptr<GeomAPI_Edge> anEdge;
+ if (aLineShape->isEdge()) {
+ anEdge = aLineShape->edge();
+ }
+ else if (aLineShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aLineShape);
+ anEdge = anIt.current()->edge();
+ }
// Get point.
AttributeSelectionPtr aPointSelection = selection(POINT());
return aPlane;
}
- std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aShape));
+ std::shared_ptr<GeomAPI_Face> aFace;
+ if (aShape->isFace()) {
+ aFace = aShape->face();
+ }
+ else if (aShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aShape);
+ aFace = anIt.current()->face();
+ }
std::shared_ptr<GeomAPI_Pln> aPln = aFace->getPlane();
std::shared_ptr<GeomAPI_Pnt> aOrig = aPln->location();
if(!aFaceShape.get()) {
aFaceShape = aFaceSelection->context()->shape();
}
- std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aFaceShape));
+ std::shared_ptr<GeomAPI_Face> aFace;
+ if (aFaceShape->isFace()) {
+ aFace = aFaceShape->face();
+ }
+ else if (aFaceShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFaceShape);
+ aFace = anIt.current()->face();
+ }
// Get point.
AttributeSelectionPtr aPointSelection = selection(COINCIDENT_POINT());
if(!aFaceShape.get()) {
aFaceShape = aFaceSelection->context()->shape();
}
- std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aFaceShape));
+ std::shared_ptr<GeomAPI_Face> aFace;
+ if (aFaceShape->isFace()) {
+ aFace = aFaceShape->face();
+ }
+ else if (aFaceShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFaceShape);
+ aFace = anIt.current()->face();
+ }
aFace = makeRectangularFace(aFace, aFace->getPlane());
// Get axis.
if(!anAxisShape.get()) {
anAxisShape = anAxisSelection->context()->shape();
}
- std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(anAxisShape));
+ std::shared_ptr<GeomAPI_Edge> anEdge;
+ if (anAxisShape->isEdge()) {
+ anEdge = anAxisShape->edge();
+ }
+ else if (anAxisShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(anAxisShape);
+ anEdge = anIt.current()->edge();
+ }
std::shared_ptr<GeomAPI_Ax1> anAxis =
std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
if(!aFaceShape1.get()) {
aFaceShape1 = aFaceSelection1->context()->shape();
}
- std::shared_ptr<GeomAPI_Face> aFace1(new GeomAPI_Face(aFaceShape1));
+ std::shared_ptr<GeomAPI_Face> aFace1;
+ if (aFaceShape1->isFace()) {
+ aFace1 = aFaceShape1->face();
+ }
+ else if (aFaceShape1->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFaceShape1);
+ aFace1 = anIt.current()->face();
+ }
std::shared_ptr<GeomAPI_Pln> aPln1 = aFace1->getPlane();
// Get plane 2.
if(!aFaceShape2.get()) {
aFaceShape2 = aFaceSelection2->context()->shape();
}
- std::shared_ptr<GeomAPI_Face> aFace2(new GeomAPI_Face(aFaceShape2));
+ std::shared_ptr<GeomAPI_Face> aFace2;
+ if (aFaceShape2->isFace()) {
+ aFace2 = aFaceShape2->face();
+ }
+ else if (aFaceShape2->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFaceShape2);
+ aFace2 = anIt.current()->face();
+ }
std::shared_ptr<GeomAPI_Pln> aPln2 = aFace2->getPlane();
std::shared_ptr<GeomAPI_Pnt> anOrig1 = aPln1->location();
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Vertex.h>
#include <GeomAPI_Pln.h>
+#include <GeomAPI_ShapeIterator.h>
//==================================================================================================
ConstructionPlugin_Point::ConstructionPlugin_Point()
if(!aLineShape.get()) {
aLineShape = aLineSelection->context()->shape();
}
- std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
+ GeomEdgePtr anEdge;
+ if (aLineShape->isEdge()) {
+ anEdge = aLineShape->edge();
+ }
+ else if (aLineShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aLineShape);
+ anEdge = anIt.current()->edge();
+ }
// Get plane.
AttributeSelectionPtr aPlaneSelection= selection(INTERSECTION_PLANE());
if(!aPlaneShape.get()) {
aPlaneShape = aPlaneSelection->context()->shape();
}
- std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
+ GeomFacePtr aFace;
+ if (aPlaneShape->isFace()) {
+ aFace = aPlaneShape->face();
+ }
+ else if (aPlaneShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aPlaneShape);
+ aFace = anIt.current()->face();
+ }
if (!string(USE_OFFSET())->value().empty()) {
double anOffset = real(OFFSET())->value();
#include <GeomAPI_Pln.h>
#include <GeomAPI_Vertex.h>
#include <GeomAPI_Pnt.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAlgoAPI_ShapeTools.h>
#include <ModelAPI_AttributeSelection.h>
#include <Events_InfoMessage.h>
static std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape);
+static std::shared_ptr<GeomAPI_Face> getFace(const GeomShapePtr theShape);
static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
static std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape);
AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
std::shared_ptr<GeomAPI_Edge> anEdge;
- std::shared_ptr<GeomAPI_Pln> aPln;
+ std::shared_ptr<GeomAPI_Face> aFace;
GeomShapePtr aShape1 = anAttribute1->value();
ResultPtr aContext1 = anAttribute1->context();
bool isPlaneFirst = false;
anEdge = getEdge(aShape1);
- aPln = getPln(aShape2);
- if(!anEdge.get() || !aPln.get()) {
+
+ aFace = getFace(aShape2);
+ if(!anEdge.get() || !aFace.get()) {
anEdge = getEdge(aShape2);
- aPln = getPln(aShape1);
+ aFace = getFace(aShape1);
isPlaneFirst = true;
}
- if(!anEdge.get() || !aPln.get()) {
+ if(!anEdge.get() || !aFace.get()) {
theError = "Wrong shape types selected.";
return false;
}
- std::shared_ptr<GeomAPI_Face> aPlaneFace(new GeomAPI_Face(isPlaneFirst ? aShape1 : aShape2));
- if(GeomAlgoAPI_ShapeTools::isParallel(anEdge, aPlaneFace)) {
+ if(GeomAlgoAPI_ShapeTools::isParallel(anEdge, aFace)) {
theError = "Plane and edge are parallel.";
return false;
}
std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape)
{
- if(!theShape->isEdge()) {
- return std::shared_ptr<GeomAPI_Edge>();
- }
+ GeomEdgePtr anEdge;
- std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
+ if(theShape->isEdge()) {
+ anEdge = theShape->edge();
+ }
+ else if (theShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(theShape);
+ anEdge = anIt.current()->edge();
+ }
return anEdge;
}
+GeomFacePtr getFace(const GeomShapePtr theShape)
+{
+ GeomFacePtr aFace;
+
+ if (theShape->isFace()) {
+ aFace = theShape->face();
+ }
+ else if (theShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(theShape);
+ aFace = anIt.current()->face();
+ }
+
+ return aFace;
+}
+
std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
{
std::shared_ptr<GeomAPI_Lin> aLin;
- if(!theShape->isEdge()) {
+ GeomEdgePtr anEdge;
+
+ if (theShape->isEdge()) {
+ anEdge = theShape->edge();
+ }
+ else if (theShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(theShape);
+ anEdge = anIt.current()->edge();
+ }
+ else {
return aLin;
}
- std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
-
if(!anEdge->isLine()) {
return aLin;
}
{
std::shared_ptr<GeomAPI_Pln> aPln;
- if(!theShape->isFace()) {
+ GeomFacePtr aFace;
+
+ if(theShape->isFace()) {
+ aFace = theShape->face();
+ }
+ else if (theShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(theShape);
+ aFace = anIt.current()->face();
+ }
+ else {
return aPln;
}
- std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(theShape));
-
if(!aFace->isPlanar()) {
return aPln;
}
label="Line"
tooltip="Select line."
icon="icons/Construction/edge.png"
- shape_types="edge">
+ shape_types="edge"
+ geometrical_selection="true">
<validator id="GeomValidators_ShapeType" parameters="line"/>
</shape_selector>
</box>
label="Main object"
icon="icons/Construction/circle.png"
tooltip="Select a cylindrical object"
- shape_types="face">
+ shape_types="face"
+ geometrical_selection="true">
<validator id="GeomValidators_Face" parameters="cylinder"/>
</shape_selector>
</box>
label="Plane"
tooltip="Select a planar face."
icon="icons/Construction/face.png"
- shape_types="face">
+ shape_types="face"
+ geometrical_selection="true">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
<shape_selector id="point"
label="1st plane"
tooltip="Select a planar face."
icon="icons/Construction/face.png"
- shape_types="face">
+ shape_types="face"
+ geometrical_selection="true">
<validator id="GeomValidators_Face" parameters="plane"/>
<validator id="ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes" parameters="plane2"/>
</shape_selector>
label="2nd plane"
tooltip="Select a planar face."
icon="icons/Construction/face.png"
- shape_types="face">
+ shape_types="face"
+ geometrical_selection="true">
<validator id="GeomValidators_Face" parameters="plane"/>
<validator id="ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes" parameters="plane1"/>
</shape_selector>
label="Line"
tooltip="Select line."
icon="icons/Construction/edge.png"
- shape_types="edge">
+ shape_types="edge"
+ geometrical_selection="true">
<validator id="GeomValidators_ShapeType" parameters="line"/>
<validator id="ConstructionPlugin_ValidatorPlaneLinePoint" parameters="point,perpendicular"/>
</shape_selector>
label="Plane"
tooltip="Select a planar face."
icon="icons/Construction/face.png"
- shape_types="face">
+ shape_types="face"
+ geometrical_selection="true">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
<toolbox id="by_other_plane_option">
label="Axis"
tooltip="Select line for axis."
icon="icons/Construction/axis.png"
- shape_types="edge">
+ shape_types="edge"
+ geometrical_selection="true">
<validator id="GeomValidators_ShapeType" parameters="line"/>
</shape_selector>
<doublevalue id="angle"
label="1st plane"
tooltip="Select a planar face."
icon="icons/Construction/face.png"
- shape_types="face">
+ shape_types="face"
+ geometrical_selection="true">
<validator id="GeomValidators_Face" parameters="plane"/>
<validator id="ConstructionPlugin_ValidatorPlaneTwoParallelPlanes" parameters="plane2"/>
</shape_selector>
label="2nd plane"
tooltip="Select a planar face."
icon="icons/Construction/face.png"
- shape_types="face">
+ shape_types="face"
+ geometrical_selection="true">
<validator id="GeomValidators_Face" parameters="plane"/>
<validator id="ConstructionPlugin_ValidatorPlaneTwoParallelPlanes" parameters="plane1"/>
</shape_selector>
label="Line"
tooltip="Line for intersection."
icon="icons/Construction/edge.png"
- shape_types="edge">
+ shape_types="edge"
+ geometrical_selection="true">
<validator id="ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel"
parameters="intersection_plane"/>
</shape_selector>
label="Plane"
tooltip="Plane for intersection."
icon="icons/Construction/face.png"
- shape_types="face">
+ shape_types="face"
+ geometrical_selection="true">
<validator id="GeomValidators_Face" parameters="plane"/>
<validator id="ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel"
parameters="intersection_line"/>
#include <GeomAPI_Dir.h>
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
+#include <GeomAPI_ShapeIterator.h>
//=================================================================================================
FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
getBaseShapes(theBaseShapes);
//Getting direction.
- std::shared_ptr<GeomAPI_Dir> aDir;
- std::shared_ptr<GeomAPI_Edge> anEdge;
+ static const std::string aSelectionError = "Error: The direction shape selection is bad.";
AttributeSelectionPtr aSelection = selection(DIRECTION_OBJECT_ID());
- if(aSelection.get() && aSelection->value().get() && aSelection->value()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->value()));
- } else if(aSelection->context().get() &&
- aSelection->context()->shape().get() &&
- aSelection->context()->shape()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->context()->shape()));
+ GeomShapePtr aShape = aSelection->value();
+ if (!aShape.get()) {
+ if (aSelection->context().get()) {
+ aShape = aSelection->context()->shape();
+ }
+ }
+
+ GeomEdgePtr anEdge;
+ if (aShape.get()) {
+ if (aShape->isEdge())
+ {
+ anEdge = aShape->edge();
+ }
+ else if (aShape->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aShape);
+ anEdge = anIt.current()->edge();
+ }
}
+
+ std::shared_ptr<GeomAPI_Dir> aDir;
if(anEdge.get()) {
if(anEdge->isLine()) {
aDir = anEdge->line()->direction();
if(!aToShape.get() && aSelection->context().get()) {
aToShape = aSelection->context()->shape();
}
+ if (aToShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aToShape);
+ aToShape = anIt.current();
+ }
}
aSelection = selection(FROM_OBJECT_ID());
if(aSelection.get()) {
if(!aFromShape.get() && aSelection->context().get()) {
aFromShape = aSelection->context()->shape();
}
+ if (aFromShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFromShape);
+ aFromShape = anIt.current();
+ }
}
}
#include <GeomAPI_Ax1.h>
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAPI_Trsf.h>
#include <ModelAPI_AttributeDouble.h>
}
//Getting axis.
- std::shared_ptr<GeomAPI_Ax1> anAxis;
- std::shared_ptr<GeomAPI_Edge> anEdge;
- std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
- selection(FeaturesPlugin_MultiRotation::AXIS_ANGULAR_ID());
- if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
- } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
- anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
+ static const std::string aSelectionError = "Error: The axis shape selection is bad.";
+ AttributeSelectionPtr anObjRef = selection(AXIS_ANGULAR_ID());
+ GeomShapePtr aShape = anObjRef->value();
+ if (!aShape.get()) {
+ if (anObjRef->context().get()) {
+ aShape = anObjRef->context()->shape();
+ }
}
- if(anEdge) {
- anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
- anEdge->line()->direction()));
+ if (!aShape.get()) {
+ setError(aSelectionError);
+ return;
+ }
+
+ GeomEdgePtr anEdge;
+ if (aShape->isEdge())
+ {
+ anEdge = aShape->edge();
+ }
+ else if (aShape->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aShape);
+ anEdge = anIt.current()->edge();
}
+ else
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ if (!anEdge.get())
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ std::shared_ptr<GeomAPI_Ax1> anAxis(new GeomAPI_Ax1(anEdge->line()->location(),
+ anEdge->line()->direction()));
// Getting number of copies.
int nbCopies =
#include <GeomAPI_Ax1.h>
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAPI_Trsf.h>
#include <ModelAPI_AttributeDouble.h>
}
//Getting axis.
- std::shared_ptr<GeomAPI_Ax1> anAxis;
- std::shared_ptr<GeomAPI_Edge> anEdge;
- std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
- selection(FeaturesPlugin_MultiTranslation::AXIS_FIRST_DIR_ID());
- if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
- } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
- anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
+ static const std::string aSelectionError = "Error: The axis shape selection is bad.";
+ AttributeSelectionPtr anObjRef = selection(AXIS_FIRST_DIR_ID());
+ GeomShapePtr aShape = anObjRef->value();
+ if (!aShape.get()) {
+ if (anObjRef->context().get()) {
+ aShape = anObjRef->context()->shape();
+ }
}
- if(anEdge) {
- anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
- anEdge->line()->direction()));
+ if (!aShape.get()) {
+ setError(aSelectionError);
+ return;
+ }
+
+ GeomEdgePtr anEdge;
+ if (aShape->isEdge())
+ {
+ anEdge = aShape->edge();
+ }
+ else if (aShape->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aShape);
+ anEdge = anIt.current()->edge();
+ }
+ else
+ {
+ setError(aSelectionError);
+ return;
}
+ if (!anEdge.get())
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ std::shared_ptr<GeomAPI_Ax1> anAxis (new GeomAPI_Ax1(anEdge->line()->location(),
+ anEdge->line()->direction()));
+
// Getting step.
double aStep = real(FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID())->value();
}
//Getting axis.
- std::shared_ptr<GeomAPI_Ax1> aFirstAxis;
- std::shared_ptr<GeomAPI_Edge> anEdge;
- std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
- selection(FeaturesPlugin_MultiTranslation::AXIS_FIRST_DIR_ID());
- if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
- } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
- anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
+ static const std::string aSelectionError = "Error: The axis shape selection is bad.";
+ AttributeSelectionPtr anObjRef = selection(AXIS_FIRST_DIR_ID());
+ GeomShapePtr aShape = anObjRef->value();
+ if (!aShape.get()) {
+ if (anObjRef->context().get()) {
+ aShape = anObjRef->context()->shape();
+ }
}
- if(anEdge) {
- aFirstAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
- anEdge->line()->direction()));
+ if (!aShape.get()) {
+ setError(aSelectionError);
+ return;
}
- std::shared_ptr<GeomAPI_Ax1> aSecondAxis;
- anObjRef = selection(FeaturesPlugin_MultiTranslation::AXIS_SECOND_DIR_ID());
- if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
- } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
- anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
+
+ GeomEdgePtr anEdge;
+ if (aShape->isEdge())
+ {
+ anEdge = aShape->edge();
}
- if(anEdge) {
- aSecondAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
- anEdge->line()->direction()));
+ else if (aShape->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aShape);
+ anEdge = anIt.current()->edge();
}
+ else
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ if (!anEdge.get())
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ std::shared_ptr<GeomAPI_Ax1> aFirstAxis(new GeomAPI_Ax1(anEdge->line()->location(),
+ anEdge->line()->direction()));
+
+ //Getting axis.
+ anObjRef = selection(AXIS_SECOND_DIR_ID());
+ aShape = anObjRef->value();
+ if (!aShape.get()) {
+ if (anObjRef->context().get()) {
+ aShape = anObjRef->context()->shape();
+ }
+ }
+ if (!aShape.get()) {
+ setError(aSelectionError);
+ return;
+ }
+
+ if (aShape->isEdge())
+ {
+ anEdge = aShape->edge();
+ }
+ else if (aShape->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aShape);
+ anEdge = anIt.current()->edge();
+ }
+ else
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ if (!anEdge.get())
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ std::shared_ptr<GeomAPI_Ax1> aSecondAxis(new GeomAPI_Ax1(anEdge->line()->location(),
+ anEdge->line()->direction()));
// Getting step.
double aFirstStep = real(FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID())->value();
#include <GeomAPI_Edge.h>
#include <GeomAPI_Face.h>
#include <GeomAPI_Pln.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAlgoAPI_Placement.h>
#include <GeomAlgoAPI_Transform.h>
// Verify planarity of faces and linearity of edges
std::shared_ptr<GeomAPI_Shape> aShapes[2] = {aStartShape, anEndShape};
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 = "Error: 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 = "Error: One of selected endges is not linear.";
- setError(aLinearityError);
- return;
- }
+ if (!isShapeValid(aShapes[i])) {
+ return;
}
}
removeResults(aResultIndex);
}
+//==================================================================================================
+bool FeaturesPlugin_Placement::isShapeValid(GeomShapePtr theShape)
+{
+ if (theShape->isCompound()) {
+ GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
+ for (GeomAPI_ShapeIterator anIt(theShape); anIt.more(); anIt.next()) {
+ GeomShapePtr aCurrentShape = anIt.current();
+ if (aShapeType == GeomAPI_Shape::SHAPE) {
+ aShapeType = aCurrentShape->shapeType();
+ }
+ else if (aShapeType != aCurrentShape->shapeType()) {
+ static const std::string aLinearityError =
+ "Error: Selected compound contains shapes with different types.";
+ setError(aLinearityError);
+ return false;
+ }
+
+ if (!isShapeValid(aCurrentShape)) {
+ return false;
+ }
+ }
+ }
+ else if (theShape->isFace()) {
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(theShape));
+ if (!aFace->isPlanar()) {
+ static const std::string aPlanarityError = "Error: One of selected faces is not planar.";
+ setError(aPlanarityError);
+ return false;
+ }
+ }
+ else if (theShape->isEdge()) {
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
+ if (!anEdge->isLine()) {
+ static const std::string aLinearityError = "Error: One of selected edges is not linear.";
+ setError(aLinearityError);
+ return false;
+ }
+ }
+
+ return true;
+}
+
//============================================================================
void FeaturesPlugin_Placement::loadNamingDS(GeomAlgoAPI_Transform& theTransformAlgo,
std::shared_ptr<ModelAPI_ResultBody> theResultBody,
/// Use plugin manager for features creation
FeaturesPlugin_Placement();
private:
+ /// Checks validity of passed shape.
+ bool isShapeValid(GeomShapePtr theShape);
+
/// Load Naming data structure of the feature to the document
void loadNamingDS(GeomAlgoAPI_Transform& theTransformAlgo,
std::shared_ptr<ModelAPI_ResultBody> theResultBody,
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
+#include <GeomAPI_ShapeIterator.h>
//=================================================================================================
FeaturesPlugin_Revolution::FeaturesPlugin_Revolution()
// Getting base shapes.
getBaseShapes(theBaseShapes);
- //Getting axis.
- std::shared_ptr<GeomAPI_Ax1> anAxis;
- std::shared_ptr<GeomAPI_Edge> anEdge;
+ // Getting axis.
+ static const std::string aSelectionError = "Error: The axis shape selection is bad.";
AttributeSelectionPtr aSelection = selection(AXIS_OBJECT_ID());
- if(aSelection.get() && aSelection->value().get() && aSelection->value()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->value()));
- } else if(aSelection->context().get() &&
- aSelection->context()->shape().get() &&
- aSelection->context()->shape()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->context()->shape()));
+ GeomShapePtr aShape = aSelection->value();
+ if (!aShape.get()) {
+ if (aSelection->context().get()) {
+ aShape = aSelection->context()->shape();
+ }
+ }
+ if (!aShape.get()) {
+ setError(aSelectionError);
+ return false;
+ }
+
+ GeomEdgePtr anEdge;
+ if (aShape->isEdge())
+ {
+ anEdge = aShape->edge();
+ }
+ else if (aShape->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aShape);
+ anEdge = anIt.current()->edge();
}
+ else
+ {
+ setError(aSelectionError);
+ return false;
+ }
+
+ std::shared_ptr<GeomAPI_Ax1> anAxis;
if(anEdge.get()) {
if(anEdge->isLine()) {
anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
if(!aToShape.get() && aSelection->context().get()) {
aToShape = aSelection->context()->shape();
}
+ if (aToShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aToShape);
+ aToShape = anIt.current();
+ }
}
aSelection = selection(FROM_OBJECT_ID());
if(aSelection.get()) {
if(!aFromShape.get() && aSelection->context().get()) {
aFromShape = aSelection->context()->shape();
}
+ if (aFromShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFromShape);
+ aFromShape = anIt.current();
+ }
}
}
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAPI_Trsf.h>
#include <FeaturesPlugin_Tools.h>
}
//Getting axis.
- std::shared_ptr<GeomAPI_Ax1> anAxis;
- std::shared_ptr<GeomAPI_Edge> anEdge;
- std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
- selection(FeaturesPlugin_Rotation::AXIS_OBJECT_ID());
- if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
- } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
- anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
+ static const std::string aSelectionError = "Error: The axis shape selection is bad.";
+ AttributeSelectionPtr anObjRef = selection(AXIS_OBJECT_ID());
+ GeomShapePtr aShape = anObjRef->value();
+ if (!aShape.get()) {
+ if (anObjRef->context().get()) {
+ aShape = anObjRef->context()->shape();
+ }
+ }
+ if (!aShape.get()) {
+ setError(aSelectionError);
+ return;
}
- if(anEdge) {
- anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
- anEdge->line()->direction()));
+
+ GeomEdgePtr anEdge;
+ if (aShape->isEdge())
+ {
+ anEdge = aShape->edge();
+ }
+ else if (aShape->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aShape);
+ anEdge = anIt.current()->edge();
}
+ else
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ if (!anEdge.get())
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ std::shared_ptr<GeomAPI_Ax1> anAxis (new GeomAPI_Ax1(anEdge->line()->location(),
+ anEdge->line()->direction()));
// Getting angle.
double anAngle = real(FeaturesPlugin_Rotation::ANGLE_ID())->value();
#include <GeomAPI_Face.h>
#include <GeomAPI_Lin.h>
#include <GeomAPI_Pln.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAPI_Trsf.h>
#include <ModelAPI_AttributeBoolean.h>
return;
//Getting axis.
- std::shared_ptr<GeomAPI_Ax1> anAxis;
- std::shared_ptr<GeomAPI_Edge> anEdge;
- std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
- selection(FeaturesPlugin_Symmetry::AXIS_OBJECT_ID());
- if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
- } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
- anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
+ static const std::string aSelectionError = "Error: The axis shape selection is bad.";
+ AttributeSelectionPtr anObjRef = selection(AXIS_OBJECT_ID());
+ GeomShapePtr aShape = anObjRef->value();
+ if (!aShape.get()) {
+ if (anObjRef->context().get()) {
+ aShape = anObjRef->context()->shape();
+ }
}
- if(anEdge) {
- anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
- anEdge->line()->direction()));
+ if (!aShape.get()) {
+ setError(aSelectionError);
+ return;
}
+ GeomEdgePtr anEdge;
+ if (aShape->isEdge())
+ {
+ anEdge = aShape->edge();
+ }
+ else if (aShape->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aShape);
+ anEdge = anIt.current()->edge();
+ }
+ else
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ if (!anEdge.get())
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ std::shared_ptr<GeomAPI_Ax1> anAxis (new GeomAPI_Ax1(anEdge->line()->location(),
+ anEdge->line()->direction()));
+
+
// Moving each object.
int aResultIndex = 0;
std::list<ResultPtr>::iterator aContext = aContextes.begin();
if (!collectSourceObjects(anObjects, aContextes))
return;
- //Getting axis.
- std::shared_ptr<GeomAPI_Ax2> aPlane;
- std::shared_ptr<GeomAPI_Pln> aPln;
- std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
- selection(FeaturesPlugin_Symmetry::PLANE_OBJECT_ID());
- if (anObjRef && anObjRef->value() && anObjRef->value()->isFace()) {
- aPln = std::shared_ptr<GeomAPI_Face>(new GeomAPI_Face(anObjRef->value()))->getPlane();
+ //Getting plane.
+ static const std::string aSelectionError = "Error: The plane shape selection is bad.";
+ AttributeSelectionPtr anObjRef = selection(PLANE_OBJECT_ID());
+ GeomShapePtr aShape = anObjRef->value();
+ if (!aShape.get()) {
+ if (anObjRef->context().get()) {
+ aShape = anObjRef->context()->shape();
+ }
}
- else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
- anObjRef->context()->shape() && anObjRef->context()->shape()->isFace()) {
- aPln =
- std::shared_ptr<GeomAPI_Face>(new GeomAPI_Face(anObjRef->context()->shape()))->getPlane();
+ if (!aShape.get()) {
+ setError(aSelectionError);
+ return;
}
- if (aPln) {
- aPlane = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aPln->location(),
- aPln->direction()));
+
+ GeomFacePtr aFace;
+ if (aShape->isFace())
+ {
+ aFace = aShape->face();
+ }
+ else if (aShape->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aShape);
+ aFace = anIt.current()->face();
}
+ else
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ if (!aFace.get())
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ std::shared_ptr<GeomAPI_Ax2> aPlane(new GeomAPI_Ax2(aFace->getPlane()->location(),
+ aFace->getPlane()->direction()));
+
// Moving each object.
int aResultIndex = 0;
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAPI_Trsf.h>
#include <GeomAlgoAPI_PointBuilder.h>
}
//Getting axis.
- std::shared_ptr<GeomAPI_Ax1> anAxis;
- std::shared_ptr<GeomAPI_Edge> anEdge;
- std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
- selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID());
- if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
- } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
- anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
+ static const std::string aSelectionError = "Error: The axis shape selection is bad.";
+ AttributeSelectionPtr anObjRef = selection(AXIS_OBJECT_ID());
+ GeomShapePtr aShape = anObjRef->value();
+ if (!aShape.get()) {
+ if (anObjRef->context().get()) {
+ aShape = anObjRef->context()->shape();
+ }
+ }
+ if (!aShape.get()) {
+ setError(aSelectionError);
+ return;
+ }
+
+ GeomEdgePtr anEdge;
+ if (aShape->isEdge())
+ {
+ anEdge = aShape->edge();
+ }
+ else if (aShape->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aShape);
+ anEdge = anIt.current()->edge();
}
- if(anEdge) {
- anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
- anEdge->line()->direction()));
+ else
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ if (!anEdge.get())
+ {
+ setError(aSelectionError);
+ return;
}
+ std::shared_ptr<GeomAPI_Ax1> anAxis(new GeomAPI_Ax1(anEdge->line()->location(),
+ anEdge->line()->direction()));
+
+
// Getting distance.
double aDistance = real(FeaturesPlugin_Translation::DISTANCE_ID())->value();
if(aContext.get()) {
aDirShape = aContext->shape();
}
+
+ if (aDirShape.get() && aDirShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aDirShape);
+ aDirShape = anIt.current();
+ }
}
}
label="Direction"
tooltip="Select an edge for direction"
shape_types="edge"
+ geometrical_selection="true"
default="<base normal>">
<validator id="GeomValidators_ShapeType" parameters="empty,line"/>
</shape_selector>
label="Plane face"
tooltip="Bounding plane (select a planar face)"
shape_types="face"
+ geometrical_selection="true"
default="<base sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
label="Plane face"
tooltip="Bounding plane (select a planar face)"
shape_types="face"
+ geometrical_selection="true"
default="<base sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
label="Direction"
tooltip="Select an edge for direction"
shape_types="edge"
+ geometrical_selection="true"
default="<base normal>">
<validator id="GeomValidators_ShapeType" parameters="empty,line"/>
</shape_selector>
label="Plane face"
tooltip="Bounding plane (select a planar face)"
shape_types="face"
+ geometrical_selection="true"
default="<base sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
label="Plane face"
tooltip="Bounding plane (select a planar face)"
shape_types="face"
+ geometrical_selection="true"
default="<base sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
label="Direction"
tooltip="Select an edge for direction"
shape_types="edge"
+ geometrical_selection="true"
default="<base normal>">
<validator id="GeomValidators_ShapeType" parameters="empty,line"/>
</shape_selector>
label="Plane face"
tooltip="Bounding plane (select a planar face)"
shape_types="face"
+ geometrical_selection="true"
default="<base sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
label="Plane face"
tooltip="Bounding plane (select a planar face)"
shape_types="face"
+ geometrical_selection="true"
default="<base sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
label="Axis"
tooltip="Select an edge for the angular direction"
shape_types="edge"
- default="">
+ default=""
+ geometrical_selection="true">
<validator id="GeomValidators_ShapeType" parameters="line"/>
</shape_selector>
<optionalbox id="use_step_angular" title="Angular step">
label="Axis"
tooltip="Select an edge for the first direction"
shape_types="edge"
- default="">
+ default=""
+ geometrical_selection="true">
<validator id="GeomValidators_ShapeType" parameters="line"/>
</shape_selector>
<doublevalue id="step_first_dir"
label="Axis"
tooltip="Select an edge for the second direction"
shape_types="edge"
- default="">
+ default=""
+ geometrical_selection="true">
<validator id="GeomValidators_ShapeType" parameters="line"/>
</shape_selector>
<doublevalue id="step_second_dir"
label="Select an object"
icon="icons/Features/placement_from.png"
tooltip="Select a start face, edge or vertex"
- shape_types="face edge vertex">
+ shape_types="face edge vertex"
+ geometrical_selection="true">
<validator id="GeomValidators_BodyShapes"/>
</shape_selector>
<shape_selector id="placement_end_shape"
label="Select an object"
icon="icons/Features/placement_to.png"
tooltip="Select an end face, edge or vertex"
- shape_types="face edge vertex">
+ shape_types="face edge vertex"
+ geometrical_selection="true">
<validator id="PartSet_DifferentObjects"/>
<validator id="GeomValidators_BodyShapes"/>
</shape_selector>
label="Axis"
tooltip="Select an edge for axis"
shape_types="edge"
+ geometrical_selection="true"
default="">
<validator id="GeomValidators_ShapeType" parameters="line"/>
</shape_selector>
label="Plane face"
tooltip="Bounding plane (select a planar face)"
shape_types="face"
+ geometrical_selection="true"
default="<base sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
label="Plane face"
tooltip="Bounding plane (select a planar face)"
shape_types="face"
+ geometrical_selection="true"
default="<base sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
label="Axis"
tooltip="Select an edge for axis"
shape_types="edge"
+ geometrical_selection="true"
default="">
<validator id="GeomValidators_ShapeType" parameters="line"/>
</shape_selector>
label="Plane face"
tooltip="Bounding plane (select a planar face)"
shape_types="face"
+ geometrical_selection="true"
default="<sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
label="Plane face"
tooltip="Bounding plane (select a planar face)"
shape_types="face"
+ geometrical_selection="true"
default="<sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
label="Axis"
tooltip="Select an edge for axis"
shape_types="edge"
+ geometrical_selection="true"
default="">
<validator id="GeomValidators_ShapeType" parameters="line"/>
</shape_selector>
label="Plane face"
tooltip="Bounding plane (select a planar face)"
shape_types="face"
+ geometrical_selection="true"
default="<sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
label="Plane face"
tooltip="Bounding plane (select a planar face)"
shape_types="face"
+ geometrical_selection="true"
default="<sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
label="Axis"
tooltip="Select an edge for axis"
shape_types="edge"
- default="">
+ default=""
+ geometrical_selection="true">
<validator id="GeomValidators_ShapeType" parameters="line"/>
</shape_selector>
<doublevalue id="angle"
label="Axis"
tooltip="Select an axis"
shape_types="edge"
- default="">
+ default=""
+ geometrical_selection="true">
<validator id="GeomValidators_ShapeType" parameters="line"/>
</shape_selector>
</box>
label="Axis"
tooltip="Select an edge for axis"
shape_types="edge"
- default="">
+ default=""
+ geometrical_selection="true">
<validator id="GeomValidators_ShapeType" parameters="line"/>
</shape_selector>
<doublevalue id="distance"
#include "GeomAlgoAPI_Placement.h"
#include <GeomAlgoAPI_DFLoader.h>
+#include <GeomAlgoAPI_ShapeTools.h>
#include <GeomAPI_Dir.h>
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Pln.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAPI_Vertex.h>
#include <GeomAPI_XYZ.h>
GProp_GProps aProps;
static const double aPropEps = 1.e-4;
+ GeomShapePtr aShape;
+ bool isCompound = false;
for (int i = 0; i < aNbObjects; i++) {
- if (aShapes[i]->isFace()) {
- std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aShapes[i]));
+ aShape = aShapes[i];
+ isCompound = false;
+ if (aShapes[i]->isCompound()) {
+ isCompound = true;
+ GeomAPI_ShapeIterator anIt(aShapes[i]);
+ aShape = anIt.current();
+
+ GeomPointPtr aPnt = GeomAlgoAPI_ShapeTools::centreOfMass(aShapes[i]);
+ aSrcDstPoints[i].SetCoord(aPnt->x(), aPnt->y(), aPnt->z());
+ }
+
+ if (aShape->isFace()) {
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aShape));
std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
aSrcDstNormals[i].SetCoord(aDir->x(), aDir->y(), aDir->z());
- BRepGProp::SurfaceProperties(aFace->impl<TopoDS_Face>(), aProps, aPropEps);
- gp_Pnt aLoc = aProps.CentreOfMass();
- aSrcDstPoints[i].SetCoord(aLoc.X(), aLoc.Y(), aLoc.Z());
+ if (!isCompound) {
+ BRepGProp::SurfaceProperties(aFace->impl<TopoDS_Face>(), aProps, aPropEps);
+ gp_Pnt aLoc = aProps.CentreOfMass();
+ aSrcDstPoints[i].SetCoord(aLoc.X(), aLoc.Y(), aLoc.Z());
+ }
}
- else if (aShapes[i]->isEdge()) {
- std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShapes[i]));
+ else if (aShape->isEdge()) {
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
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());
+
+ if (!isCompound) {
+ 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());
+ }
}
- else if (aShapes[i]->isVertex()) {
- std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aShapes[i]));
+ else if (aShape->isVertex()) {
+ std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aShape));
std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
aSrcDstPoints[i].SetCoord(aPnt->x(), aPnt->y(), aPnt->z());
} else // something goes wrong
#include "ModelAPI_AttributeSelection.h"
#include <GeomAPI_Face.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAbs_SurfaceType.hxx>
return GeomAbs_Plane;
}
+bool isValidFace(const GeomShapePtr theShape,
+ const GeomAbs_SurfaceType theFaceType,
+ Events_InfoMessage& theError)
+{
+ GeomFacePtr aGeomFace = theShape->face();
+
+ if (!aGeomFace.get()) {
+ theError = "The shape is not a face.";
+ return false;
+ }
+
+ bool aValid = true;
+
+ switch (theFaceType) {
+ case GeomAbs_Plane: {
+ aValid = aGeomFace->isPlanar();
+ if (!aValid) theError = "The shape is not a plane.";
+ break;
+ }
+ case GeomAbs_Cylinder: {
+ aValid = aGeomFace->isCylindrical();
+ if (!aValid) theError = "The shape is not a cylinder.";
+ break;
+ }
+ default: {
+ aValid = false;
+ theError = "The shape is not an available face.";
+ break;
+ }
+ }
+
+ return aValid;
+}
+
bool GeomValidators_Face::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments,
Events_InfoMessage& theError) const
theError = "The shape is not a face.";
}
else {
- std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
- if (!aGeomFace.get()) {
- aValid = false;
- theError = "The shape is not a face.";
+ GeomAbs_SurfaceType aFaceType = GeomAbs_Plane;
+ if (theArguments.size() == 1) aFaceType = faceType(theArguments.front());
+ if (aGeomShape->isFace()) {
+ isValidFace(aGeomShape, aFaceType, theError);
}
- else {
- GeomAbs_SurfaceType aFaceType = GeomAbs_Plane;
- if (theArguments.size() == 1)
- aFaceType = faceType(theArguments.front());
-
- switch (aFaceType) {
- case GeomAbs_Plane: {
- aValid = aGeomFace->isPlanar();
- if (!aValid)
- theError = "The shape is not a plane.";
- }
- break;
- case GeomAbs_Cylinder:{
- aValid = aGeomFace->isCylindrical();
- if (!aValid)
- theError = "The shape is not a cylinder.";
- }
- break;
- default: {
- aValid = false;
- theError = "The shape is not an available face.";
+ else if (aSelectionAttr->isGeometricalSelection() && aGeomShape->isCompound()) {
+ for (GeomAPI_ShapeIterator anIt(aGeomShape); anIt.more(); anIt.next()) {
+ if (!isValidFace(anIt.current(), aFaceType, theError)) {
break;
}
}
}
+ else {
+ aValid = false;
+ theError = "The shape is not a face.";
+ }
}
}
return aValid;
#include "GeomValidators_Tools.h"
#include <GeomAPI_Curve.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomDataAPI_Point2D.h>
#include <ModelAPI_Result.h>
std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
GeomShapePtr aShape = anAttr->value();
if (aShape.get())
- aValid = isValidShape(aShape, theShapeType, theError);
+ aValid = isValidShape(aShape, theShapeType, anAttr->isGeometricalSelection(), theError);
else {
if (anAttr->context().get())
- aValid = isValidObject(anAttr->context(), theShapeType, theError);
+ aValid = isValidObject(anAttr->context(),
+ theShapeType,
+ anAttr->isGeometricalSelection(),
+ theError);
else
- aValid = isValidObject(anAttr->contextFeature(), theShapeType, theError);
+ aValid = isValidObject(anAttr->contextFeature(),
+ theShapeType,
+ anAttr->isGeometricalSelection(),
+ theError);
}
}
else if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) {
AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
if (anAttr->isObject()) {
- aValid = isValidObject(anAttr->object(), theShapeType, theError);
+ aValid = isValidObject(anAttr->object(),
+ theShapeType,
+ false,
+ theError);
}
else if (theShapeType == Vertex) {
AttributePtr aRefAttr = anAttr->attr();
else if (anAttributeType == ModelAPI_AttributeReference::typeId()) {
AttributeReferencePtr anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
- aValid = isValidObject(anAttr->value(), theShapeType, theError);
+ aValid = isValidObject(anAttr->value(), theShapeType, false, theError);
}
else if (anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
AttributeSelectionListPtr aListAttr =
bool GeomValidators_ShapeType::isValidObject(const ObjectPtr& theObject,
const TypeOfShape theShapeType,
+ const bool theIsGeometricalSelection,
Events_InfoMessage& theError) const
{
bool aValid = true;
aValid = false;
theError = "The result is empty";
} else {
- aValid = isValidShape(aResult->shape(), theShapeType, theError);
+ aValid = isValidShape(aResult->shape(), theShapeType, theIsGeometricalSelection, theError);
}
} else {
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape,
const TypeOfShape theShapeType,
+ const bool theIsGeometricalSelection,
Events_InfoMessage& theError) const
{
bool aValid = true;
case Edge:
aValid = theShape->isEdge();
break;
- case Line:
- aValid = theShape->isEdge() && GeomAPI_Curve(theShape).isLine();
+ case Line: {
+ if (theIsGeometricalSelection && theShape->isCompound()) {
+ aValid = true;
+ for (GeomAPI_ShapeIterator anIt(theShape); anIt.more(); anIt.next()) {
+ if (!anIt.current()->isEdge() || !GeomAPI_Curve(anIt.current()).isLine()) {
+ aValid = false;
+ break;
+ }
+ }
+ }
+ else {
+ aValid = theShape->isEdge() && GeomAPI_Curve(theShape).isLine();
+ }
break;
+ }
case Circle:
aValid = theShape->isEdge() && GeomAPI_Curve(theShape).isCircle();
break;
/// \param[out] theError error message.
bool isValidObject(const ObjectPtr& theObject,
const TypeOfShape theShapeType,
+ const bool theIsGeometricalSelection,
Events_InfoMessage& theError) const;
/// Returns true if the attibute's object type satisfies the argument value
/// \param[out] theError error message.
bool isValidShape(const GeomShapePtr theShape,
const TypeOfShape theShapeType,
+ const bool theIsGeometricalSelection,
Events_InfoMessage& theError) const;
};
#include <GeomAPI_Dir.h>
#include <GeomAPI_Face.h>
#include <GeomAPI_Shape.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAPI_Pln.h>
#include <GeomAPI_Pnt.h>
if(aToShape.get() == NULL && anAttrSel->context().get() != NULL) {
aToShape = anAttrSel->context()->shape();
}
+ if (aToShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aToShape);
+ aToShape = anIt.current();
+ }
}
anIt++;
if(aFromShape.get() == NULL && anAttrSel->context().get() != NULL) {
aFromShape = anAttrSel->context()->shape();
}
+ if (aFromShape->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aFromShape);
+ aFromShape = anIt.current();
+ }
}
anIt++;
#include <Events_InfoMessage.h>
#include <GeomAPI_Edge.h>
#include <GeomAPI_Pnt.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAPI_Vertex.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
#include <GeomAlgoAPI_NExplode.h>
{
myRef.setID(theID);
ModelAPI_AttributeSelection::setID(theID);
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
+ // TODO: check if parent list have geometrical selection flag.
+ myIsGeometricalSelection =
+ ModelAPI_Session::get()->validators()->isGeometricalSelection(aFeature->getKind(), id());
}
ResultPtr Model_AttributeSelection::context()
if (aEraseResults) // erase results without flash deleted and redisplay: do it after Select
aFeatureOwner->removeResults(0, false, false);
}
- aSel.Select(aNewSub, aNewContext);
+ aSel.Select(aNewSub, aNewContext, myIsGeometricalSelection);
// face may become divided after the model update, so, new labels may be added to the scope
myScope.Clear();
return "";
}
+ if (myIsGeometricalSelection
+ && aSubSh.get()
+ && aSubSh->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aSubSh);
+ aSubSh = anIt.current();
+ }
+
Model_SelectionNaming aSelNaming(selectionLabel());
std::string aResult = aSelNaming.namingName(
aCont, aSubSh, theDefaultName, owner()->document() != aCont->document());
CenterType myTmpCenterType;
/// Reference to the partent attribute, if any (to split selection compounds in issue 1799)
Model_AttributeSelectionList* myParent;
+ /// If true attribute selects geometry instead of shape.
+ bool myIsGeometricalSelection;
+
public:
/// Defines the result and its selected sub-shape
/// \param theContext object where the sub-shape was selected
void computeValues(ResultPtr theOldContext, ResultPtr theNewContext, TopoDS_Shape theValShape,
TopTools_ListOfShape& theShapes);
+ /// Returns true if is geometrical selection.
+ virtual bool isGeometricalSelection() const {
+ return myIsGeometricalSelection;
+ };
+
friend class Model_Data;
friend class Model_AttributeSelectionList;
};
// (if attribute is deleted and created, the abort updates attriute and makes the Attr invalid)
std::shared_ptr<Model_AttributeSelection> aNewAttr =
std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aLabel));
- aNewAttr->setID(id());
if (owner()) {
aNewAttr->setObject(owner());
aNewAttr->setParent(this);
}
+ aNewAttr->setID(id());
return aNewAttr;
}
if (!aCases.empty()) {
validators()->registerCase(aMsgAttr->featureId(), aMsgAttr->attributeId(), aCases);
}
+ if (aMsgAttr->isGeometricalSelection()) {
+ validators()->registerGeometricalSelection(aMsgAttr->featureId(),
+ aMsgAttr->attributeId());
+ }
}
}
// plugins information was started to load, so, it will be loaded
std::map<std::string, std::string>::iterator aFound = myMainArgument.find(theFeature);
return aFound != myMainArgument.end() && aFound->second == theAttribute;
}
+
+void Model_ValidatorsFactory::registerGeometricalSelection(std::string theFeature,
+ std::string theAttribute)
+{
+ std::map<std::string, std::set<std::string> >::iterator aFind =
+ myGeometricalSelection.find(theFeature);
+ if (aFind == myGeometricalSelection.end()) {
+ std::set<std::string> aNewSet;
+ aNewSet.insert(theAttribute);
+ myGeometricalSelection[theFeature] = aNewSet;
+ }
+ else {
+ aFind->second.insert(theAttribute);
+ }
+}
+
+bool Model_ValidatorsFactory::isGeometricalSelection(std::string theFeature,
+ std::string theAttribute)
+{
+ std::map<std::string, std::set<std::string> >::iterator aFind =
+ myGeometricalSelection.find(theFeature);
+ return aFind != myGeometricalSelection.end()
+ && aFind->second.find(theAttribute) != aFind->second.end();
+}
std::map<std::string, std::set<std::string> > > > myCases;
/// Stores main attribute for each feature
std::map<std::string, std::string> myMainArgument;
+ std::map<std::string, std::set<std::string> > myGeometricalSelection;
public:
/// Registers the instance of the validator by the ID
/// Returns true is the attribute is a main argument of the feature
virtual bool isMainArgument(std::string theFeature, std::string theAttribute);
+ /// Register the selection attribute as geometrical selection
+ virtual void registerGeometricalSelection(std::string theFeature, std::string theAttribute);
+
+ /// Returns true if the attribute is a geometrical selection
+ virtual bool isGeometricalSelection(std::string theFeature, std::string theAttribute);
+
protected:
/// Adds the defualt validators that are usefull for all features.
/// Returns true if recompute of selection become impossible
virtual bool isInvalid() = 0;
+ /// Returns true if is geometrical selection.
+ virtual bool isGeometricalSelection() const = 0;
+
/// To virtually destroy the fields of successors
MODELAPI_EXPORT virtual ~ModelAPI_AttributeSelection();
/// Returns true if the attribute must be checked (the case is selected)
virtual bool isCase(FeaturePtr theFeature, std::string theAttribute) = 0;
+ /// Register the selection attribute as geometrical selection
+ virtual void registerGeometricalSelection(std::string theFeature, std::string theAttribute) = 0;
+
+ /// Returns true if the attribute is a geometrical selection
+ virtual bool isGeometricalSelection(std::string theFeature, std::string theAttribute) = 0;
+
protected:
/// Get instance from Session
ModelAPI_ValidatorsFactory()
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Dir.h>
#include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAlgoAPI_NExplode.h>
#include <GeomDataAPI_Dir.h>
isDumpByGeom = aSelectedFeature && aSelectedFeature->isInHistory();
}
+ if (theAttrSelect->isGeometricalSelection() && aShape->shapeType() == GeomAPI_Shape::COMPOUND) {
+ GeomAPI_ShapeIterator anIt(aShape);
+ aShape = anIt.current();
+ }
+
myDumpBuffer << "\"" << aShape->shapeTypeStr();
bool aStandardDump = true;
if (isDumpByGeom) {
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
#include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAlgoAPI_PointBuilder.h>
}
// Getting axis.
- std::shared_ptr<GeomAPI_Ax2> anAxis;
+ static const std::string aSelectionError = "Error: The axis shape selection is bad.";
+ std::shared_ptr<ModelAPI_AttributeSelection> anEdgeRef = selection(AXIS_ID());
+ GeomShapePtr aShape = anEdgeRef->value();
+ if (!aShape.get()) {
+ if (anEdgeRef->context().get()) {
+ aShape = anEdgeRef->context()->shape();
+ }
+ }
+ if (!aShape.get()) {
+ setError(aSelectionError);
+ return;
+ }
std::shared_ptr<GeomAPI_Edge> anEdge;
- std::shared_ptr<ModelAPI_AttributeSelection> anEdgeRef =
- selection(PrimitivesPlugin_Cone::AXIS_ID());
- if(anEdgeRef && anEdgeRef->value() && anEdgeRef->value()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anEdgeRef->value()));
- } else if (anEdgeRef && !anEdgeRef->value() && anEdgeRef->context() &&
- anEdgeRef->context()->shape() && anEdgeRef->context()->shape()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anEdgeRef->context()->shape()));
+ if (aShape->isEdge())
+ {
+ anEdge = aShape->edge();
+ }
+ else if (aShape->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aShape);
+ anEdge = anIt.current()->edge();
}
- if(anEdge) {
- anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
- anEdge->line()->direction()));
+ else
+ {
+ setError(aSelectionError);
+ return;
}
+ if (!anEdge.get())
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ std::shared_ptr<GeomAPI_Ax2> anAxis(new GeomAPI_Ax2(aBasePoint,
+ anEdge->line()->direction()));
+
// Getting base radius, top radius and height
double aBaseRadius = real(PrimitivesPlugin_Cone::BASE_RADIUS_ID())->value();
double aTopRadius = real(PrimitivesPlugin_Cone::TOP_RADIUS_ID())->value();
#include <GeomAPI_Dir.h>
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAlgoAPI_PointBuilder.h>
}
// Getting axis.
- std::shared_ptr<GeomAPI_Ax2> anAxis;
+ static const std::string aSelectionError = "Error: The axis shape selection is bad.";
+ std::shared_ptr<ModelAPI_AttributeSelection> anEdgeRef = selection(AXIS_ID());
+ GeomShapePtr aShape = anEdgeRef->value();
+ if (!aShape.get()) {
+ if (anEdgeRef->context().get()) {
+ aShape = anEdgeRef->context()->shape();
+ }
+ }
+ if (!aShape.get()) {
+ setError(aSelectionError);
+ return;
+ }
std::shared_ptr<GeomAPI_Edge> anEdge;
- std::shared_ptr<ModelAPI_AttributeSelection> anEdgeRef =
- selection(PrimitivesPlugin_Cylinder::AXIS_ID());
- if(anEdgeRef && anEdgeRef->value() && anEdgeRef->value()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anEdgeRef->value()));
- } else if (anEdgeRef && !anEdgeRef->value() && anEdgeRef->context() &&
- anEdgeRef->context()->shape() && anEdgeRef->context()->shape()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anEdgeRef->context()->shape()));
- }
- if(anEdge) {
- anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
- anEdge->line()->direction()));
+ if (aShape->isEdge())
+ {
+ anEdge = aShape->edge();
+ }
+ else if (aShape->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aShape);
+ anEdge = anIt.current()->edge();
+ }
+ else
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ if (!anEdge.get())
+ {
+ setError(aSelectionError);
+ return;
}
+ std::shared_ptr<GeomAPI_Ax2> anAxis(new GeomAPI_Ax2(aBasePoint,
+ anEdge->line()->direction()));
+
+
// Getting radius and height
double aRadius = real(PrimitivesPlugin_Cylinder::RADIUS_ID())->value();
double aHeight = real(PrimitivesPlugin_Cylinder::HEIGHT_ID())->value();
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
#include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAlgoAPI_PointBuilder.h>
}
// Getting axis.
- std::shared_ptr<GeomAPI_Ax2> anAxis;
+ static const std::string aSelectionError = "Error: The axis shape selection is bad.";
+ std::shared_ptr<ModelAPI_AttributeSelection> anEdgeRef = selection(AXIS_ID());
+ GeomShapePtr aShape = anEdgeRef->value();
+ if (!aShape.get()) {
+ if (anEdgeRef->context().get()) {
+ aShape = anEdgeRef->context()->shape();
+ }
+ }
+ if (!aShape.get()) {
+ setError(aSelectionError);
+ return;
+ }
std::shared_ptr<GeomAPI_Edge> anEdge;
- std::shared_ptr<ModelAPI_AttributeSelection> anEdgeRef =
- selection(PrimitivesPlugin_Torus::AXIS_ID());
- if(anEdgeRef && anEdgeRef->value() && anEdgeRef->value()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anEdgeRef->value()));
- } else if (anEdgeRef && !anEdgeRef->value() && anEdgeRef->context() &&
- anEdgeRef->context()->shape() && anEdgeRef->context()->shape()->isEdge()) {
- anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anEdgeRef->context()->shape()));
+ if (aShape->isEdge())
+ {
+ anEdge = aShape->edge();
+ }
+ else if (aShape->isCompound())
+ {
+ GeomAPI_ShapeIterator anIt(aShape);
+ anEdge = anIt.current()->edge();
}
- if(anEdge) {
- anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
- anEdge->line()->direction()));
+ else
+ {
+ setError(aSelectionError);
+ return;
}
+ if (!anEdge.get())
+ {
+ setError(aSelectionError);
+ return;
+ }
+
+ std::shared_ptr<GeomAPI_Ax2> anAxis(new GeomAPI_Ax2(aBasePoint,
+ anEdge->line()->direction()));
+
// Getting radius and ring radius
double aRadius = real(PrimitivesPlugin_Torus::RADIUS_ID())->value();
double aRingRadius = real(PrimitivesPlugin_Torus::RING_RADIUS_ID())->value();
label="axis"
default=""
shape_types="edge"
+ geometrical_selection="true"
icon="icons/Primitives/axis.png"
tooltip="Select the axis of the cone">
<validator id="GeomValidators_ConstructionComposite"/>
label="axis"
default=""
shape_types="edge"
+ geometrical_selection="true"
icon="icons/Primitives/axis.png"
tooltip="Select the axis of the cylinder">
<validator id="GeomValidators_ConstructionComposite"/>
label="axis"
default=""
shape_types="edge"
+ geometrical_selection="true"
icon="icons/Primitives/axis.png"
tooltip="Select the axis of the cylinder">
<validator id="GeomValidators_ConstructionComposite"/>
label="axis"
default=""
shape_types="edge"
+ geometrical_selection="true"
icon="icons/Primitives/axis.png"
tooltip="Select the axis of the torus">
<validator id="GeomValidators_ConstructionComposite"/>
#include <GeomAPI_Dir.h>
#include <GeomAPI_PlanarEdges.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAPI_Vertex.h>
#include <GeomDataAPI_Point2D.h>
std::shared_ptr<GeomAPI_Shape> aSelection = aSelAttr->value();
if (!aSelection.get()) aSelection = aSelAttr->context()->shape();
// update the sketch plane
- std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aSelection));
+ std::shared_ptr<GeomAPI_Face> aFace;
+ if (aSelection->isFace()) {
+ aFace = aSelection->face();
+ } else if (aSelection->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aSelection);
+ aFace = anIt.current()->face();
+ }
+
std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
if (aPlane) {
double anA, aB, aC, aD;