+
+void PartSet_Tools::sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite,
+ const Events_ID theEventId)
+{
+ if (!theComposite.get())
+ return;
+
+ static Events_Loop* aLoop = Events_Loop::loop();
+ 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);
+ }
+ Events_Loop::loop()->flush(theEventId);
+}
+
+bool PartSet_Tools::isAuxiliarySketchEntity(const ObjectPtr& theObject)
+{
+ bool isAuxiliaryFeature = false;
+
+ FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
+ std::string anAuxiliaryAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID();
+ AttributeBooleanPtr anAuxiliaryAttr = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
+ anObjectFeature->data()->attribute(anAuxiliaryAttribute));
+ if (anAuxiliaryAttr.get())
+ isAuxiliaryFeature = anAuxiliaryAttr->value();
+
+
+ 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<AttributePtr>& aRefs = theObject->data()->refsToMe();
+ for (std::set<AttributePtr>::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<GeomAPI_Edge>& theEdge,
+ ModelAPI_AttributeSelection::CenterType theType,
+ const CompositeFeaturePtr& theSketch,
+ bool theTemporary,
+ FeaturePtr& theCreatedFeature)
+{
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (!aResult.get())
+ return ResultPtr();
+
+ FeaturePtr aProjectionFeature = theSketch->addFeature(SketchPlugin_Projection::ID());
+ theCreatedFeature = aProjectionFeature;
+ AttributeSelectionPtr anExternalAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(
+ aProjectionFeature->attribute(SketchPlugin_Projection::EXTERNAL_FEATURE_ID()));
+ anExternalAttr->setValueCenter(aResult, theEdge, theType, theTemporary);
+
+ AttributeBooleanPtr anIntoResult = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>
+ (aProjectionFeature->data()->attribute(SketchPlugin_Projection::INCLUDE_INTO_RESULT()));
+ anIntoResult->setValue(SKETCH_PROJECTION_INCLUDE_INTO_RESULT);
+ aProjectionFeature->execute();
+
+ // if projection feature has not been created, exit
+ AttributeRefAttrPtr aRefAttr = aProjectionFeature->data()->refattr(
+ SketchPlugin_Projection::PROJECTED_FEATURE_ID());
+ if (!aRefAttr || !aRefAttr->isInitialized())
+ return ResultPtr();
+
+ FeaturePtr aProjection = ModelAPI_Feature::feature(aRefAttr->object());
+ if (aProjection.get() && aProjection->lastResult().get())
+ return aProjection->lastResult();
+
+ 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<ModelAPI_Folder>(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;
+
+ AttributeReferencePtr aLastFeatAttr =
+ aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
+ if (!aLastFeatAttr.get())
+ return;
+ FeaturePtr aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
+ if (!aLastFeatureInFolder.get())
+ return;
+
+ theFirst = aDoc->index(aFirstFeatureInFolder);
+ theLast = aDoc->index(aLastFeatureInFolder);
+}
\ No newline at end of file