X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Placement.cpp;h=ad4975878166096d757179600cf59e98928e6321;hb=65fb6fac9731831e7197d0841e4444e69eb7d7ce;hp=96b9d01fcecd6a7ac42e801ab21d23d3e610b5ee;hpb=87b6a30a3afb8fb32e7e43ade8d9c947d9eb1684;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp index 96b9d01fc..ad4975878 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -121,21 +122,8 @@ void FeaturesPlugin_Placement::execute() // Verify planarity of faces and linearity of edges std::shared_ptr aShapes[2] = {aStartShape, anEndShape}; for (int i = 0; i < 2; i++) { - if (aShapes[i]->isFace()) { - std::shared_ptr 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 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; } } @@ -160,36 +148,37 @@ void FeaturesPlugin_Placement::execute() anObjectsIt++, aContext++) { // for part results just set transformation - if ((*aContext)->groupName() == ModelAPI_ResultPart::group()) { + if (aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group()) { ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); aResultPart->setTrsf(aContextRes, aTrsf); setResult(aResultPart, aResultIndex); } else { std::shared_ptr aBaseShape = *anObjectsIt; - GeomAlgoAPI_Transform aTransformAlgo(aBaseShape, aTrsf); + std::shared_ptr 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 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++; @@ -199,18 +188,44 @@ void FeaturesPlugin_Placement::execute() removeResults(aResultIndex); } -//============================================================================ -void FeaturesPlugin_Placement::loadNamingDS(GeomAlgoAPI_Transform& theTransformAlgo, - std::shared_ptr theResultBody, - std::shared_ptr 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 aSubShapes = theTransformAlgo.mapOfSubShapes(); + if (!isShapeValid(aCurrentShape)) { + return false; + } + } + } + else if (theShape->isFace()) { + std::shared_ptr 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 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; }