X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_IntersectionPoint.cpp;h=ead725a47e71ed49e01e25895ac1b9822b36bff6;hb=745c72679f6346375d5e886b25cc3865f3c4daae;hp=8310bccf6e6b5465a99755a4d6fe35725ad7e0a6;hpb=06ce9f88a4ba875f2e22ca1a4ecad79fdea2ac18;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp b/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp index 8310bccf6..ead725a47 100644 --- a/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp +++ b/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp @@ -1,71 +1,164 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -// File: SketchPlugin_IntersectionPoint.cpp -// Created: 07 May 2014 -// Author: Artem ZHIDKOV +// Copyright (C) 2014-2021 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// 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 +// +// 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())); - ResultPtr aLineResult = std::dynamic_pointer_cast(aLineAttr->context()); - if (!aLineResult) + if (theID != EXTERNAL_FEATURE_ID() && theID != EXTERNAL_ID()) return; - std::shared_ptr aLinearEdge = - std::dynamic_pointer_cast(aLineResult->shape()); - std::shared_ptr aLine = aLinearEdge->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; }