X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_Tools.cpp;h=3ef5b735f9fd6124b25fce78ca250a7aff826e6d;hb=f421ab3932a5e09ae8082215c3eaaa8cc4944e02;hp=d7c4812d02a6325b3b57d505225b89c74c6647bb;hpb=08f1aef6629e6a63cc4671d271ded4de6e826948;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp old mode 100755 new mode 100644 index d7c4812d0..3ef5b735f --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.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 @@ -71,6 +70,7 @@ #include #include #include +#include #include #include @@ -90,6 +90,7 @@ #include #include #include +#include #include @@ -310,6 +311,17 @@ std::shared_ptr PartSet_Tools::sketchPlane(CompositeFeaturePtr theS return aPlane; } +void PartSet_Tools::nullifySketchPlane(CompositeFeaturePtr theSketch) +{ + std::shared_ptr anOrigin = std::dynamic_pointer_cast( + theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + std::shared_ptr aNormal = std::dynamic_pointer_cast( + theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); + + aNormal->reset(); + anOrigin->reset(); +} + std::shared_ptr PartSet_Tools::point3D(std::shared_ptr thePoint2D, CompositeFeaturePtr theSketch) { @@ -373,7 +385,13 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal( AttributeRefAttrPtr aRefAttr = aProjectionFeature->data()->refattr( SketchPlugin_Projection::PROJECTED_FEATURE_ID()); if (!aRefAttr || !aRefAttr->isInitialized()) + { + // remove external feature if the attribute is not filled + std::set aFeatures; + aFeatures.insert(aProjectionFeature); + ModelAPI_Tools::removeFeaturesAndReferences(aFeatures); return ResultPtr(); + } FeaturePtr aProjection = ModelAPI_Feature::feature(aRefAttr->object()); if (aProjection.get() && aProjection->lastResult().get()) @@ -504,7 +522,7 @@ FeaturePtr PartSet_Tools::findFirstCoincidence(const FeaturePtr& theFeature, for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) { std::shared_ptr aAttr = (*aIt); FeaturePtr aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); - if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { + if (aConstrFeature && aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { std::shared_ptr a2dPnt = PartSet_Tools::getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A()); if (a2dPnt.get() && thePoint->isEqual(a2dPnt)) { @@ -656,7 +674,8 @@ void PartSet_Tools::sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite return; static Events_Loop* aLoop = Events_Loop::loop(); - for (int i = 0; i < theComposite->numberOfSubs(); i++) { + int aNumberOfSubs = theComposite->numberOfSubs(); + for (int i = 0; i < aNumberOfSubs; i++) { FeaturePtr aSubFeature = theComposite->subFeature(i); static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); aECreator->sendUpdated(aSubFeature, theEventId); @@ -679,19 +698,50 @@ bool PartSet_Tools::isAuxiliarySketchEntity(const ObjectPtr& theObject) return isAuxiliaryFeature; } +bool PartSet_Tools::isIncludeIntoSketchResult(const ObjectPtr& theObject) +{ + // check the feature is neither Projection nor IntersectionPoint feature + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + if (aFeature->getKind() == SketchPlugin_Projection::ID() || + aFeature->getKind() == SketchPlugin_IntersectionPoint::ID()) + return false; + + // go through the references to the feature to check + // if it was created by Projection or Intersection + const std::set& aRefs = theObject->data()->refsToMe(); + for (std::set::const_iterator aRefIt = aRefs.begin(); + aRefIt != aRefs.end(); ++aRefIt) { + AttributePtr anAttr = *aRefIt; + std::string anIncludeToResultAttrName; + if (anAttr->id() == SketchPlugin_Projection::PROJECTED_FEATURE_ID()) + anIncludeToResultAttrName = SketchPlugin_Projection::INCLUDE_INTO_RESULT(); + else if (anAttr->id() == SketchPlugin_IntersectionPoint::INTERSECTION_POINTS_ID()) + anIncludeToResultAttrName = SketchPlugin_IntersectionPoint::INCLUDE_INTO_RESULT(); + + if (!anIncludeToResultAttrName.empty()) { + // check "include into result" flag + FeaturePtr aParent = ModelAPI_Feature::feature(anAttr->owner()); + return aParent->boolean(anIncludeToResultAttrName)->value(); + } + } + return true; +} + ResultPtr PartSet_Tools::createFixedByExternalCenter( const ObjectPtr& theObject, const std::shared_ptr& theEdge, ModelAPI_AttributeSelection::CenterType theType, const CompositeFeaturePtr& theSketch, - bool theTemporary) + bool theTemporary, + FeaturePtr& theCreatedFeature) { ResultPtr aResult = std::dynamic_pointer_cast(theObject); if (!aResult.get()) return ResultPtr(); FeaturePtr aProjectionFeature = theSketch->addFeature(SketchPlugin_Projection::ID()); + theCreatedFeature = aProjectionFeature; AttributeSelectionPtr anExternalAttr = std::dynamic_pointer_cast( aProjectionFeature->attribute(SketchPlugin_Projection::EXTERNAL_FEATURE_ID())); anExternalAttr->setValueCenter(aResult, theEdge, theType, theTemporary); @@ -713,3 +763,30 @@ ResultPtr PartSet_Tools::createFixedByExternalCenter( return ResultPtr(); } + +void PartSet_Tools::getFirstAndLastIndexInFolder(const ObjectPtr& theFolder, + int& theFirst, int& theLast) +{ + theFirst = -1; + theLast = -1; + + DocumentPtr aDoc = theFolder->document(); + FolderPtr aFolder = std::dynamic_pointer_cast(theFolder); + if (!aFolder.get()) + return; + + AttributeReferencePtr aFirstFeatAttr = + aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID()); + if (!aFirstFeatAttr.get()) + return; + FeaturePtr aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value()); + if (!aFirstFeatureInFolder.get()) + return; + + FeaturePtr aLastFeatureInFolder = aFolder->lastVisibleFeature(); + if (!aLastFeatureInFolder.get()) + return; + + theFirst = aDoc->index(aFirstFeatureInFolder); + theLast = aDoc->index(aLastFeatureInFolder); +}