X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_IntersectionPoint.cpp;h=ee6a610ced92c4619c3d6e4a07c1c4b1d2f14a3a;hb=05e2e4a31fa248d71445c40e35eeafa44f5d3b1b;hp=a7ff0b68e92136d1148de98f62cb457aadb869e8;hpb=7074394f8f08413d885f63be01df6bd5007b868c;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp b/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp index a7ff0b68e..ee6a610ce 100644 --- a/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp +++ b/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2022 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,81 +12,153 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// 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 "SketchPlugin_IntersectionPoint.h" +#include "SketchPlugin_Point.h" #include +#include +#include #include +#include #include #include #include +#include #include SketchPlugin_IntersectionPoint::SketchPlugin_IntersectionPoint() - : SketchPlugin_Point() + : SketchPlugin_SketchEntity(), + myIsComputing(false) { } void SketchPlugin_IntersectionPoint::initDerivedClassAttributes() { - data()->addAttribute(EXTERNAL_LINE_ID(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(EXTERNAL_FEATURE_ID(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(INTERSECTION_POINTS_ID(), ModelAPI_AttributeRefList::typeId()); + data()->attribute(INTERSECTION_POINTS_ID())->setIsArgument(false); - SketchPlugin_Point::initDerivedClassAttributes(); -} + data()->addAttribute(INCLUDE_INTO_RESULT(), ModelAPI_AttributeBoolean::typeId()); -void SketchPlugin_IntersectionPoint::execute() -{ - SketchPlugin_Sketch* aSketch = sketch(); - if (aSketch) { - computePoint(); - SketchPlugin_Point::execute(); + data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID()); - // set this feature as external - data()->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape()); - } + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), AUXILIARY_ID()); } -void SketchPlugin_IntersectionPoint::move(double theDeltaX, double theDeltaY) +void SketchPlugin_IntersectionPoint::execute() { + AttributeRefListPtr anIntersectionsList = reflist(INTERSECTION_POINTS_ID()); + if (!anIntersectionsList || !anIntersectionsList->isInitialized()) + return; // no intersections + + computePoint(EXTERNAL_FEATURE_ID()); } void SketchPlugin_IntersectionPoint::attributeChanged(const std::string& theID) { - if (theID == EXTERNAL_LINE_ID()) { - // compute intersection between line and sketch plane - computePoint(); - } + // compute intersection between line and sketch plane + computePoint(theID); } -void SketchPlugin_IntersectionPoint::computePoint() +void SketchPlugin_IntersectionPoint::computePoint(const std::string& theID) { - AttributeSelectionPtr aLineAttr = - std::dynamic_pointer_cast(attribute(EXTERNAL_LINE_ID())); - - std::shared_ptr anEdge; - if(aLineAttr && aLineAttr->value() && aLineAttr->value()->isEdge()) { - anEdge = std::shared_ptr(new GeomAPI_Edge(aLineAttr->value())); - } else if(aLineAttr->context() && aLineAttr->context()->shape() && - aLineAttr->context()->shape()->isEdge()) { - anEdge = std::shared_ptr(new GeomAPI_Edge(aLineAttr->context()->shape())); - } - if(!anEdge.get()) + if (theID != EXTERNAL_FEATURE_ID() && theID != EXTERNAL_ID()) return; - std::shared_ptr aLine = anEdge->line(); - std::shared_ptr aSketchPlane = sketch()->plane(); - - std::shared_ptr anIntersection = aSketchPlane->intersect(aLine); - if (!anIntersection) + if (myIsComputing) return; + myIsComputing = true; + + AttributeSelectionPtr anExternalFeature = selection(EXTERNAL_FEATURE_ID()); + + GeomShapePtr aShape; + GeomEdgePtr anEdge; + if (anExternalFeature) + aShape = anExternalFeature->value(); + if (!aShape && anExternalFeature->context()) + aShape = anExternalFeature->context()->shape(); + if (aShape && aShape->isEdge()) + anEdge = GeomEdgePtr(new GeomAPI_Edge(aShape)); + + if (anEdge) { + std::shared_ptr aSketchPlane = sketch()->plane(); - std::shared_ptr aCoordAttr = - std::dynamic_pointer_cast(attribute(COORD_ID())); - aCoordAttr->setValue(sketch()->to2D(anIntersection)); + std::list anIntersectionsPoints; + anEdge->intersectWithPlane(aSketchPlane, anIntersectionsPoints); + + AttributeRefListPtr anIntersectionsList = reflist(INTERSECTION_POINTS_ID()); + std::list anExistentIntersections = anIntersectionsList->list(); + std::list::const_iterator aExistInterIt = anExistentIntersections.begin(); + + const std::list& aResults = results(); + std::list::const_iterator aResIt = aResults.begin(); + + int aResultIndex = 0; + for (std::list::iterator aPntIt = anIntersectionsPoints.begin(); + aPntIt != anIntersectionsPoints.end(); ++aPntIt, ++aResultIndex) { + std::shared_ptr aCurSketchPoint; + if (aExistInterIt == anExistentIntersections.end()) { + keepCurrentFeature(); + + // create new point + aCurSketchPoint = std::dynamic_pointer_cast( + sketch()->addFeature(SketchPlugin_Point::ID())); + aCurSketchPoint->boolean(COPY_ID())->setValue(true); + anIntersectionsList->append(aCurSketchPoint); + + restoreCurrentFeature(); + } else { + // update existent point + aCurSketchPoint = std::dynamic_pointer_cast(*aExistInterIt); + ++aExistInterIt; + } + + ResultConstructionPtr aCurResult; + if (aResIt == aResults.end()) { + // create new result + aCurResult = document()->createConstruction(data(), aResultIndex); + aCurResult->setIsInHistory(false); + aCurResult->setDisplayed(false); + } else { + // update existent result + aCurResult = std::dynamic_pointer_cast(*aResIt); + aCurResult->setShape(std::shared_ptr()); + ++aResIt; + } + + // update coordinates of intersection + GeomPnt2dPtr aPointInSketch = sketch()->to2D(*aPntIt); + std::dynamic_pointer_cast( + aCurSketchPoint->attribute(SketchPlugin_Point::COORD_ID()))->setValue(aPointInSketch); + aCurSketchPoint->execute(); + + // update result + aCurResult->setShape(aCurSketchPoint->lastResult()->shape()); + setResult(aCurResult, aResultIndex); + + // make intersection point external + GeomShapePtr anEmptyVal; + aCurSketchPoint->selection(EXTERNAL_ID())->setValue(aCurResult, anEmptyVal); + } + + // remove rest results from previous pass + removeResults(aResultIndex); + std::set aFeaturesToBeRemoved; + for (; aExistInterIt != anExistentIntersections.end(); ++aExistInterIt) { + aFeaturesToBeRemoved.insert(ModelAPI_Feature::feature(*aExistInterIt)); + anIntersectionsList->removeLast(); + } + ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToBeRemoved); + + if (theID != EXTERNAL_ID()) + selection(EXTERNAL_ID())->selectValue(anExternalFeature); + } + myIsComputing = false; }