X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Symmetry.cpp;h=93707eeb088c68f9c4e1bad04537aec6afd77921;hb=5cac7d767796b7593729165c1114d2cfcdf0b0df;hp=d3d058ed3a9f35e61b8ead2df25535d601968ed6;hpb=e65bf14e2ff3cf853884bf8998fadcece6e3b34c;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp b/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp index d3d058ed3..93707eeb0 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp @@ -23,11 +23,14 @@ #include #include #include +#include +#include #include #include #include #include +#include #include #include @@ -99,7 +102,6 @@ bool FeaturesPlugin_Symmetry::collectSourceObjects(ListOfShape& theSourceShapes, anObjectsSelList->value(anObjectsIndex); std::shared_ptr anObject = anObjectAttr->value(); if (!anObject.get()) { // may be for not-activated parts - eraseResults(); return false; } theSourceShapes.push_back(anObject); @@ -137,7 +139,7 @@ void FeaturesPlugin_Symmetry::performSymmetryByPoint() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { @@ -147,27 +149,28 @@ void FeaturesPlugin_Symmetry::performSymmetryByPoint() buildResult(anOrigin, aTrsf, aResultIndex); } else { - GeomAlgoAPI_Symmetry aSymmetryAlgo(aBaseShape, aPoint); + std::shared_ptr aSymmetryAlgo( + new GeomAlgoAPI_Symmetry(aBaseShape, aPoint)); - if (!aSymmetryAlgo.check()) { - setError(aSymmetryAlgo.getError()); + if (!aSymmetryAlgo->check()) { + setError(aSymmetryAlgo->getError()); return; } - aSymmetryAlgo.build(); + aSymmetryAlgo->build(); // Checking that the algorithm worked properly. - if(!aSymmetryAlgo.isDone()) { + if(!aSymmetryAlgo->isDone()) { static const std::string aFeatureError = "Error: Symmetry algorithm failed."; setError(aFeatureError); break; } - if(aSymmetryAlgo.shape()->isNull()) { + if(aSymmetryAlgo->shape()->isNull()) { static const std::string aShapeError = "Error: Resulting shape is Null."; setError(aShapeError); break; } - if(!aSymmetryAlgo.isValid()) { + if(!aSymmetryAlgo->isValid()) { std::string aFeatureError = "Error: Resulting shape is not valid."; setError(aFeatureError); break; @@ -192,28 +195,47 @@ void FeaturesPlugin_Symmetry::performSymmetryByAxis() return; //Getting axis. - std::shared_ptr anAxis; - std::shared_ptr anEdge; - std::shared_ptr anObjRef = - selection(FeaturesPlugin_Symmetry::AXIS_OBJECT_ID()); - if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) { - anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->value())); - } else if (anObjRef && !anObjRef->value() && anObjRef->context() && - anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) { - anEdge = std::shared_ptr(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(new GeomAPI_Ax1(anEdge->line()->location(), - anEdge->line()->direction())); + + if (!anEdge.get()) + { + setError(aSelectionError); + return; } + std::shared_ptr anAxis (new GeomAPI_Ax1(anEdge->line()->location(), + anEdge->line()->direction())); + + // Moving each object. int aResultIndex = 0; std::list::iterator aContext = aContextes.begin(); for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { @@ -223,27 +245,28 @@ void FeaturesPlugin_Symmetry::performSymmetryByAxis() buildResult(anOrigin, aTrsf, aResultIndex); } else { - GeomAlgoAPI_Symmetry aSymmetryAlgo(aBaseShape, anAxis); + std::shared_ptr aSymmetryAlgo( + new GeomAlgoAPI_Symmetry(aBaseShape, anAxis)); - if (!aSymmetryAlgo.check()) { - setError(aSymmetryAlgo.getError()); + if (!aSymmetryAlgo->check()) { + setError(aSymmetryAlgo->getError()); return; } - aSymmetryAlgo.build(); + aSymmetryAlgo->build(); // Checking that the algorithm worked properly. - if(!aSymmetryAlgo.isDone()) { + if(!aSymmetryAlgo->isDone()) { static const std::string aFeatureError = "Error: Symmetry algorithm failed."; setError(aFeatureError); break; } - if(aSymmetryAlgo.shape()->isNull()) { + if(aSymmetryAlgo->shape()->isNull()) { static const std::string aShapeError = "Error: Resulting shape is Null."; setError(aShapeError); break; } - if(!aSymmetryAlgo.isValid()) { + if(!aSymmetryAlgo->isValid()) { std::string aFeatureError = "Error: Resulting shape is not valid."; setError(aFeatureError); break; @@ -267,31 +290,48 @@ void FeaturesPlugin_Symmetry::performSymmetryByPlane() if (!collectSourceObjects(anObjects, aContextes)) return; - //Getting axis. - std::shared_ptr aPlane; - std::shared_ptr aPln; - std::shared_ptr anObjRef = - selection(FeaturesPlugin_Symmetry::PLANE_OBJECT_ID()); - if (anObjRef && anObjRef->value() && anObjRef->value()->isFace()) { - aPln = std::shared_ptr(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(new GeomAPI_Face(anObjRef->context()->shape()))->getPlane(); + if (!aShape.get()) { + setError(aSelectionError); + return; + } + + GeomFacePtr aFace; + if (aShape->isFace()) + { + aFace = aShape->face(); } - if (aPln) { - aPlane = std::shared_ptr(new GeomAPI_Ax2(aPln->location(), - aPln->direction())); + else if (aShape->isCompound()) + { + GeomAPI_ShapeIterator anIt(aShape); + aFace = anIt.current()->face(); } + if (!aFace.get()) + { + setError(aSelectionError); + return; + } + + std::shared_ptr aPlane(new GeomAPI_Ax2(aFace->getPlane()->location(), + aFace->getPlane()->direction())); + + // Moving each object. int aResultIndex = 0; std::list::iterator aContext = aContextes.begin(); for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { @@ -300,27 +340,28 @@ void FeaturesPlugin_Symmetry::performSymmetryByPlane() ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); buildResult(anOrigin, aTrsf, aResultIndex); } else { - GeomAlgoAPI_Symmetry aSymmetryAlgo(aBaseShape, aPlane); + std::shared_ptr aSymmetryAlgo( + new GeomAlgoAPI_Symmetry(aBaseShape, aPlane)); - if (!aSymmetryAlgo.check()) { - setError(aSymmetryAlgo.getError()); + if (!aSymmetryAlgo->check()) { + setError(aSymmetryAlgo->getError()); return; } - aSymmetryAlgo.build(); + aSymmetryAlgo->build(); // Checking that the algorithm worked properly. - if(!aSymmetryAlgo.isDone()) { + if(!aSymmetryAlgo->isDone()) { static const std::string aFeatureError = "Error: Symmetry algorithm failed."; setError(aFeatureError); break; } - if(aSymmetryAlgo.shape()->isNull()) { + if(aSymmetryAlgo->shape()->isNull()) { static const std::string aShapeError = "Error: Resulting shape is Null."; setError(aShapeError); break; } - if(!aSymmetryAlgo.isValid()) { + if(!aSymmetryAlgo->isValid()) { std::string aFeatureError = "Error: Resulting shape is not valid."; setError(aFeatureError); break; @@ -336,24 +377,30 @@ void FeaturesPlugin_Symmetry::performSymmetryByPlane() } //================================================================================================= -void FeaturesPlugin_Symmetry::buildResult(GeomAlgoAPI_Symmetry& theSymmetryAlgo, - std::shared_ptr theBaseShape, - int theResultIndex) +void FeaturesPlugin_Symmetry::buildResult( + std::shared_ptr& theSymmetryAlgo, + std::shared_ptr theBaseShape, int theResultIndex) { + std::shared_ptr anAlgoList(new GeomAlgoAPI_MakeShapeList()); + anAlgoList->appendAlgo(theSymmetryAlgo); // Compose source shape and the result of symmetry. GeomShapePtr aCompound; if (boolean(KEEP_ORIGINAL_RESULT())->value()) { ListOfShape aShapes; - aShapes.push_back(theBaseShape); - aShapes.push_back(theSymmetryAlgo.shape()); + // add a copy of a base shape otherwise selection of this base shape is bad (2592) + std::shared_ptr aCopyAlgo(new GeomAlgoAPI_Copy(theBaseShape)); + aShapes.push_back(aCopyAlgo->shape()); + anAlgoList->appendAlgo(aCopyAlgo); + + aShapes.push_back(theSymmetryAlgo->shape()); aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes); } else - aCompound = theSymmetryAlgo.shape(); + aCompound = theSymmetryAlgo->shape(); // Store and name the result. ResultBodyPtr aResultBody = document()->createBody(data(), theResultIndex); aResultBody->storeModified(theBaseShape, aCompound); - loadNamingDS(theSymmetryAlgo, aResultBody, theBaseShape); + FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, theBaseShape, anAlgoList, "Symmetried"); setResult(aResultBody, theResultIndex); } @@ -374,16 +421,3 @@ void FeaturesPlugin_Symmetry::buildResult(ResultPartPtr theOriginal, aResultPart->setTrsf(theOriginal, theTrsf); setResult(aResultPart, theResultIndex); } - -//================================================================================================= -void FeaturesPlugin_Symmetry::loadNamingDS(GeomAlgoAPI_Symmetry& theSymmetryAlgo, - std::shared_ptr theResultBody, - std::shared_ptr theBaseShape) -{ - // Name the faces - std::shared_ptr aSubShapes = theSymmetryAlgo.mapOfSubShapes(); - std::string aReflectedName = "Symmetried"; - FeaturesPlugin_Tools::storeModifiedShapes(theSymmetryAlgo, theResultBody, - theBaseShape, 1, 2, 3, aReflectedName, - *aSubShapes.get()); -}