X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConstructionPlugin%2FConstructionPlugin_Point.cpp;h=08ff70a3a7a2ed8a7f5cdba439c975df2f0fe4ef;hb=f49e611d444c66d735a381bb9541717b4115b8b1;hp=7fde6c6676ceaf1c01d141d9ece927f37d6af339;hpb=2532fb2df83ee1ddd9ff3e8b381d3788eaa15b69;p=modules%2Fshaper.git diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index 7fde6c667..08ff70a3a 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -14,7 +14,8 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com // #include "ConstructionPlugin_Point.h" @@ -26,10 +27,12 @@ #include #include +#include #include #include #include +#include //================================================================================================== ConstructionPlugin_Point::ConstructionPlugin_Point() @@ -46,12 +49,12 @@ const std::string& ConstructionPlugin_Point::getKind() //================================================================================================== void ConstructionPlugin_Point::initAttributes() { - //data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId()); - data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId()); + /*data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId()); data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId()); @@ -62,35 +65,55 @@ void ConstructionPlugin_Point::initAttributes() data()->addAttribute(FIRST_LINE(), ModelAPI_AttributeSelection::typeId()); data()->addAttribute(SECOND_LINE(), ModelAPI_AttributeSelection::typeId()); - +*/ data()->addAttribute(INTERSECTION_LINE(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(INTERSECTION_PLANE(), ModelAPI_AttributeSelection::typeId());*/ + data()->addAttribute(INTERSECTION_PLANE(), ModelAPI_AttributeSelection::typeId()); + + data()->addAttribute(USE_OFFSET(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(OFFSET(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(REVERSE_OFFSET(), ModelAPI_AttributeBoolean::typeId()); } //================================================================================================== void ConstructionPlugin_Point::execute() { - GeomShapePtr aShape = createByXYZ(); - - /*GeomShapePtr aShape; + GeomShapePtr aShape; - std::string aCreationMethod = string(CREATION_METHOD())->value(); + // to support compatibility with old documents where aCreationMethod did not exist + std::string aCreationMethod = + string(CREATION_METHOD()).get() && !string(CREATION_METHOD())->value().empty() ? + string(CREATION_METHOD())->value() : CREATION_METHOD_BY_XYZ(); if(aCreationMethod == CREATION_METHOD_BY_XYZ()) { aShape = createByXYZ(); - } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) { + }/* else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) { aShape = createByDistanceOnEdge(); } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) { aShape = createByProjection(); } else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) { aShape = createByLinesIntersection(); - } else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) { - aShape = createByLineAndPlaneIntersection(); - }*/ + }*/ else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) { + // this may produce several points + std::list > aPoints = createByLineAndPlaneIntersection(); + if (!aPoints.empty()) { // if no points found produce the standard error later + int anIndex = 0; + std::list >::iterator aPIter = aPoints.begin(); + for(; aPIter != aPoints.end(); aPIter++, anIndex++) { + std::shared_ptr aConstr = + document()->createConstruction(data(), anIndex); + aConstr->setShape(*aPIter); + setResult(aConstr, anIndex); + } + removeResults(anIndex); + return; + } + } if(!aShape.get()) { + setError("Error: intersection not found."); return; } + removeResults(1); // for case the point type was switched from multi-results type std::shared_ptr aConstr = document()->createConstruction(data()); aConstr->setShape(aShape); setResult(aConstr); @@ -179,12 +202,14 @@ std::shared_ptr ConstructionPlugin_Point::createByLinesIntersect return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge); } +*/ //================================================================================================== -std::shared_ptr ConstructionPlugin_Point::createByLineAndPlaneIntersection() +std::list > + ConstructionPlugin_Point::createByLineAndPlaneIntersection() { // Get line. - AttributeSelectionPtr aLineSelection= selection(INTERSECTION_LINE()); + AttributeSelectionPtr aLineSelection = selection(INTERSECTION_LINE()); GeomShapePtr aLineShape = aLineSelection->value(); if(!aLineShape.get()) { aLineShape = aLineSelection->context()->shape(); @@ -199,5 +224,15 @@ std::shared_ptr ConstructionPlugin_Point::createByLineAndPlaneIn } std::shared_ptr aFace(new GeomAPI_Face(aPlaneShape)); - return GeomAlgoAPI_PointBuilder::vertexByIntersection(anEdge, aFace); -}*/ + if (!string(USE_OFFSET())->value().empty()) { + double anOffset = real(OFFSET())->value(); + if (boolean(REVERSE_OFFSET())->value()) + anOffset = -anOffset; + if (fabs(anOffset) > 1.e-9) { // move face + aFace->translate(aFace->getPlane()->direction(), anOffset); + } + } + + return GeomAlgoAPI_ShapeTools::intersect(anEdge, aFace, + aPlaneSelection->context()->groupName() == ModelAPI_ResultConstruction::group()); +}