#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;
}
}
setResult(aResultPart, aResultIndex);
} else {
std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
- GeomAlgoAPI_Transform aTransformAlgo(aBaseShape, aTrsf);
+ std::shared_ptr<GeomAlgoAPI_Transform> aTransformAlgo(new GeomAlgoAPI_Transform(aBaseShape,
+ aTrsf));
// Checking that the algorithm worked properly.
- if(!aTransformAlgo.isDone()) {
+ if(!aTransformAlgo->isDone()) {
static const std::string aFeatureError = "Error: Transform algorithm failed.";
setError(aFeatureError);
break;
}
- if(aTransformAlgo.shape()->isNull()) {
+ if(aTransformAlgo->shape()->isNull()) {
static const std::string aShapeError = "Error: Resulting shape is Null.";
setError(aShapeError);
break;
}
- if(!aTransformAlgo.isValid()) {
+ if(!aTransformAlgo->isValid()) {
std::string aFeatureError = "Error: Resulting shape is not valid.";
setError(aFeatureError);
break;
}
//LoadNamingDS
- std::shared_ptr<ModelAPI_ResultBody> aResultBody =
- document()->createBody(data(), aResultIndex);
- loadNamingDS(aTransformAlgo, aResultBody, aBaseShape);
+ ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
+ aResultBody->storeModified(aBaseShape, aTransformAlgo->shape());
+ FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, aBaseShape, aTransformAlgo, "Placed");
setResult(aResultBody, aResultIndex);
}
aResultIndex++;
removeResults(aResultIndex);
}
-//============================================================================
-void FeaturesPlugin_Placement::loadNamingDS(GeomAlgoAPI_Transform& theTransformAlgo,
- std::shared_ptr<ModelAPI_ResultBody> theResultBody,
- std::shared_ptr<GeomAPI_Shape> theBaseShape)
+//==================================================================================================
+bool FeaturesPlugin_Placement::isShapeValid(GeomShapePtr theShape)
{
- //load result
- theResultBody->storeModified(theBaseShape, theTransformAlgo.shape());
+ 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;
+ }
- std::string aPlacedName = "Placed";
- std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theTransformAlgo.mapOfSubShapes();
+ 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;
+ }
+ }
- FeaturesPlugin_Tools::storeModifiedShapes(theTransformAlgo, theResultBody,
- theBaseShape, 1, 2, 3, aPlacedName,
- *aSubShapes.get());
+ return true;
}