#include <ModelAPI_ResultBody.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeSelectionList.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::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
- data()->addAttribute(FeaturesPlugin_Placement::CENTERING_ID(), ModelAPI_AttributeBoolean::type());
+ /* Modification for specification of 1.3.0
+ AttributeSelectionListPtr aSelection =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
+ FeaturesPlugin_Placement::LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
+ // extrusion works with faces always
+ aSelection->setSelectionType("SOLID");
+ */
+ data()->addAttribute(FeaturesPlugin_Placement::BASE_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(FeaturesPlugin_Placement::ATTRACT_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(FeaturesPlugin_Placement::REVERSE_ID(), ModelAPI_AttributeBoolean::typeId());
+ data()->addAttribute(FeaturesPlugin_Placement::CENTERING_ID(), ModelAPI_AttributeBoolean::typeId());
}
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);