if (needNewObjects) {
// Create list of objects composing a fillet
// copy aFeatureA
- aNewFeatureA = sketch()->addFeature(aFeatureA->getKind());
- aFeatureA->data()->copyTo(aNewFeatureA->data());
+ aNewFeatureA = SketchPlugin_Sketch::addUniqueNamedCopiedFeature(aFeatureA, sketch());
// copy aFeatureB
- aNewFeatureB = sketch()->addFeature(aFeatureB->getKind());
- aFeatureB->data()->copyTo(aNewFeatureB->data());
+ aNewFeatureB = SketchPlugin_Sketch::addUniqueNamedCopiedFeature(aFeatureB, sketch());
// create filleting arc (it will be attached to the list later)
aNewArc = sketch()->addFeature(SketchPlugin_Arc::ID());
} else {
if (aMirrorIter != aMirroredList.end())
break; // the lists are inconsistent
// There is no mirrored object yet, create it
- FeaturePtr aNewFeature = sketch()->addFeature(aFeatureIn->getKind());
- aFeatureIn->data()->copyTo(aNewFeature->data());
+ FeaturePtr aNewFeature = SketchPlugin_Sketch::addUniqueNamedCopiedFeature(aFeatureIn, sketch());
aNewFeature->execute();
ModelAPI_EventCreator::get()->sendUpdated(aNewFeature, aRedisplayEvent);
if (!aFeature || !aResult)
return ObjectPtr();
- FeaturePtr aNewFeature = sketch()->addFeature(aFeature->getKind());
- aFeature->data()->copyTo(aNewFeature->data());
+ FeaturePtr aNewFeature = SketchPlugin_Sketch::addUniqueNamedCopiedFeature(aFeature, sketch());
aNewFeature->execute();
static Events_ID aRedisplayEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
void SketchPlugin_MultiTranslation::execute()
{
+ if (!sketch()) {
+ // it is possible, that
+ return;
+ }
+
AttributeSelectionListPtr aTranslationObjectRefs = selectionList(TRANSLATION_LIST_ID());
int aNbCopies = integer(NUMBER_OF_COPIES_ID())->value();
if (!aFeature || !aResult)
return ObjectPtr();
- FeaturePtr aNewFeature = sketch()->addFeature(aFeature->getKind());
- aFeature->data()->copyTo(aNewFeature->data());
- aNewFeature->execute();
+ FeaturePtr aNewFeature = SketchPlugin_Sketch::addUniqueNamedCopiedFeature(aFeature, sketch());
+ aNewFeature->execute();
static Events_ID aRedisplayEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
ModelAPI_EventCreator::get()->sendUpdated(aNewFeature, aRedisplayEvent);
theFeature->setResult(aResult, theIndex);
}
+
+FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeature,
+ SketchPlugin_Sketch* theSketch)
+{
+ FeaturePtr aNewFeature = theSketch->addFeature(theFeature->getKind());
+ // addFeature generates a unique name for the feature, it caches the name
+ std::string aUniqueFeatureName = aNewFeature->data()->name();
+ // all attribute values are copied\pasted to the new feature, name is not an exception
+ theFeature->data()->copyTo(aNewFeature->data());
+ // as a name for the feature, the generated unique name is set
+ aNewFeature->data()->setName(aUniqueFeatureName);
+
+ return aNewFeature;
+}
static void createPoint2DResult(ModelAPI_Feature* theFeature,
SketchPlugin_Sketch* theSketch,
const std::string& theAttributeID, const int theIndex);
+
+ /// Add new feature and fill the data of the feature by the data of the parameter feature.
+ /// The name of the created feature stays unique.
+ /// \param theFeature a source feature
+ /// \return a created feature
+ static FeaturePtr addUniqueNamedCopiedFeature(FeaturePtr aFeature,
+ SketchPlugin_Sketch* theSketch);
+
/// Customize presentation of the feature
virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
<validator id="GeomValidators_ShapeType" parameters="line"/>
</sketch_shape_selector>
<sketch_multi_selector id="ConstraintMirrorList"
- label="List of objects"
+ label="Segments"
tooltip="Select list of mirroring objects"
type_choice="Edges"
use_external="true">
title="Translation" icon=":icons/translate.png"
tooltip="Make a number of shifted copies of a group of objects">
<sketch_multi_selector id="MultiTranslationList"
- label="List of objects"
+ label="Segments"
tooltip="Select list of translating objects"
type_choice="Edges"
use_external="true">
title="Rotation" icon=":icons/rotate.png"
tooltip="Make a number of rotated copies of a group of objects">
<sketch_multi_selector id="MultiRotationList"
- label="List of objects"
+ label="Segments"
tooltip="Select list of rotating objects"
type_choice="Edges"
use_external="true">