X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_Fillet.cpp;h=2e55f8c0c2ae6e4b4975098b8a7af3c6bb5005f2;hb=4cb749258f33b7de231da5bb50140407c0599d30;hp=3916cfb35e1a343b4171f63302a320a779c7d957;hpb=faaea2f382805c9a5eb6d1e98a9e10354f62be5d;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Fillet.cpp b/src/SketchPlugin/SketchPlugin_Fillet.cpp index 3916cfb35..2e55f8c0c 100644 --- a/src/SketchPlugin/SketchPlugin_Fillet.cpp +++ b/src/SketchPlugin/SketchPlugin_Fillet.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 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,10 +12,9 @@ // // 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_Fillet.h" @@ -82,8 +81,9 @@ static std::set findFeaturesToRemove(const FeaturePtr theFeature, const AttributePtr theAttribute); SketchPlugin_Fillet::SketchPlugin_Fillet() -: myFilletCreated(false) +: myFilletCreated(false), myIsReversed(false) { + myIsNotInversed[0] = myIsNotInversed[1] = true; } void SketchPlugin_Fillet::initAttributes() @@ -104,6 +104,10 @@ void SketchPlugin_Fillet::execute() // create feature for fillet arc FeaturePtr aFilletArc = createFilletArc(); + if (!aFilletArc) { + setError("Error: unable to create a fillet arc."); + return; + } // collect features referred to the edges participating in fillet AttributePoint2DPtr aFilletPoints[2]; @@ -133,12 +137,12 @@ void SketchPlugin_Fillet::execute() FeaturePtr aConstraint; // Create coincidence features. - aConstraint = SketchPlugin_Tools::createConstraint(sketch(), + aConstraint = SketchPlugin_Tools::createConstraintAttrAttr(sketch(), SketchPlugin_ConstraintCoincidence::ID(), aFilletArc->attribute(SketchPlugin_Arc::START_ID()), myBaseFeatures[aFeatInd[0]]->attribute(myFeatAttributes[anAttrInd[0]])); ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent); - aConstraint = SketchPlugin_Tools::createConstraint(sketch(), + aConstraint = SketchPlugin_Tools::createConstraintAttrAttr(sketch(), SketchPlugin_ConstraintCoincidence::ID(), aFilletArc->attribute(SketchPlugin_Arc::END_ID()), myBaseFeatures[aFeatInd[1]]->attribute(myFeatAttributes[anAttrInd[1]])); @@ -146,7 +150,7 @@ void SketchPlugin_Fillet::execute() // Create tangent features. for (int i = 0; i < 2; i++) { - aConstraint = SketchPlugin_Tools::createConstraint(sketch(), + aConstraint = SketchPlugin_Tools::createConstraintObjectObject(sketch(), SketchPlugin_ConstraintTangent::ID(), aFilletArc->lastResult(), myBaseFeatures[i]->lastResult()); @@ -189,6 +193,11 @@ AISObjectPtr SketchPlugin_Fillet::getAISObject(AISObjectPtr thePrevious) anAISObject = AISObjectPtr(new GeomAPI_AISObject); } anAISObject->createShape(anArcShape); + bool isAxiliary = false; + AttributeBooleanPtr aAttr = boolean(AUXILIARY_ID()); + if (aAttr.get()) + isAxiliary = aAttr->value(); + SketchPlugin_Tools::customizeFeaturePrs(anAISObject, isAxiliary); return anAISObject; } @@ -203,8 +212,29 @@ bool SketchPlugin_Fillet::calculateFilletParameters() if (!aFilletPoint2D.get()) return false; - std::set aFilletFeatures = - SketchPlugin_Tools::findFeaturesCoincidentToPoint(aFilletPoint2D); + std::set aCoincidentPoints = + SketchPlugin_Tools::findPointsCoincidentToPoint(aFilletPoint2D); + std::set aFilletFeatures; + for (std::set::iterator aCPIt = aCoincidentPoints.begin(); + aCPIt != aCoincidentPoints.end(); ++aCPIt) { + std::shared_ptr anOwner = + std::dynamic_pointer_cast( + ModelAPI_Feature::feature((*aCPIt)->owner())); + if (anOwner && !anOwner->isExternal()) + aFilletFeatures.insert(anOwner); + } + // remove auxilary entities from set of coincident features + if (aFilletFeatures.size() > 2) { + std::set::iterator anIt = aFilletFeatures.begin(); + while (anIt != aFilletFeatures.end()) { + if ((*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) { + std::set::iterator aRemoveIt = anIt++; + aFilletFeatures.erase(aRemoveIt); + } + else + ++anIt; + } + } if (aFilletFeatures.size() != 2) { setError("Error: Selected point does not have two suitable edges for fillet."); return false; @@ -299,6 +329,10 @@ FeaturePtr SketchPlugin_Fillet::createFilletArc() if (!myBaseFeatures[0] || !myBaseFeatures[1]) calculateFilletParameters(); + // fix for issue #2810 (sometimes, myCenterXY is NULL, fillet should report an error) + if (!myCenterXY) + return FeaturePtr(); + // Create arc feature. FeaturePtr aFilletArc = sketch()->addFeature(SketchPlugin_Arc::ID()); @@ -332,12 +366,13 @@ FeaturePtr SketchPlugin_Fillet::createFilletApex(const GeomPnt2dPtr& theCoordina AttributePoint2DPtr aCoord = std::dynamic_pointer_cast( anApex->attribute(SketchPlugin_Point::COORD_ID())); aCoord->setValue(theCoordinates); + anApex->boolean(SketchPlugin_Point::AUXILIARY_ID())->setValue(true); // additional coincidence constraints static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); FeaturePtr aConstraint; for (int i = 0; i < 2; i++) { - aConstraint = SketchPlugin_Tools::createConstraint(sketch(), + aConstraint = SketchPlugin_Tools::createConstraintAttrObject(sketch(), SketchPlugin_ConstraintCoincidence::ID(), aCoord, myBaseFeatures[i]->lastResult()); @@ -348,18 +383,19 @@ FeaturePtr SketchPlugin_Fillet::createFilletApex(const GeomPnt2dPtr& theCoordina return anApex; } +struct Length { + AttributePtr myPoints[2]; + std::string myValueText; + double myValueDouble; + GeomPnt2dPtr myFlyoutPoint; + int myLocationType; +}; + void SketchPlugin_Fillet::removeReferencesButKeepDistances( std::set& theFeaturesToRemove, const AttributePoint2DPtr theFilletPoints[2]) { FeaturePtr aFilletApex; - struct Length { - AttributePtr myPoints[2]; - std::string myValueText; - double myValueDouble; - GeomPnt2dPtr myFlyoutPoint; - int myLocationType; - }; std::list aLengthToDistance; std::set::iterator aFeat = theFeaturesToRemove.begin(); @@ -415,7 +451,7 @@ void SketchPlugin_Fillet::removeReferencesButKeepDistances( AttributePoint2DPtr aFlyoutAttr = std::dynamic_pointer_cast( aLength->attribute(SketchPlugin_ConstraintLength::FLYOUT_VALUE_PNT())); if (aFlyoutAttr && aFlyoutAttr->isInitialized()) - aNewLength.myFlyoutPoint = aFlyoutAttr->pnt(); + aNewLength.myFlyoutPoint = SketchPlugin_Tools::flyoutPointCoordinates(aLength); AttributeIntegerPtr aLocationAttr = aLength->integer(SketchPlugin_ConstraintLength::LOCATION_TYPE_ID()); if (aLocationAttr && aLocationAttr->isInitialized()) @@ -437,7 +473,7 @@ void SketchPlugin_Fillet::removeReferencesButKeepDistances( FeaturePtr aConstraint; std::list::iterator anIt = aLengthToDistance.begin(); for (; anIt != aLengthToDistance.end(); ++anIt) { - aConstraint = SketchPlugin_Tools::createConstraint(sketch(), + aConstraint = SketchPlugin_Tools::createConstraintAttrAttr(sketch(), SketchPlugin_ConstraintDistance::ID(), anIt->myPoints[0], anIt->myPoints[1]); // set value AttributeDoublePtr aValue = aConstraint->real(SketchPlugin_Constraint::VALUE()); @@ -554,7 +590,7 @@ double calculateFilletRadius(FeaturePtr theFilletFeatures[2]) if (anEdge) aLengths[i] = anEdge->length(); } - return std::min(aLengths[0], aLengths[1]) / 6.0; + return (aLengths[0] < aLengths[1] ? aLengths[0] : aLengths[1]) / 6.0; } std::set findFeaturesToRemove(const FeaturePtr theFeature,