From: nds Date: Thu, 28 May 2015 16:41:46 +0000 (+0300) Subject: addUniqueNamedCopiedFeature to use unique names for copies features. X-Git-Tag: V_1.2.0~22 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=23d55c9a069dc7bde8c49f67edd900992aea2dcc;p=modules%2Fshaper.git addUniqueNamedCopiedFeature to use unique names for copies features. --- diff --git a/src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp b/src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp index 8c6f918a4..450621fa9 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp @@ -102,11 +102,9 @@ void SketchPlugin_ConstraintFillet::execute() 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 { diff --git a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp index 029200ff8..03a3a9005 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp @@ -135,8 +135,7 @@ void SketchPlugin_ConstraintMirror::execute() 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); diff --git a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp index f0ad011d0..d4cf1ec71 100644 --- a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp @@ -209,8 +209,7 @@ ObjectPtr SketchPlugin_MultiRotation::copyFeature(ObjectPtr theObject) 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); diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp index 71eca57ca..715f16650 100644 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp @@ -41,6 +41,11 @@ void SketchPlugin_MultiTranslation::initAttributes() 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(); @@ -192,10 +197,9 @@ ObjectPtr SketchPlugin_MultiTranslation::copyFeature(ObjectPtr theObject) 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); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 7b7fb78d0..f7d09acbb 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -280,3 +280,17 @@ void SketchPlugin_Sketch::createPoint2DResult(ModelAPI_Feature* theFeature, 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; +} diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 9f5f4a458..2043f33f5 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -203,6 +203,14 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_ICu 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 theDefaultPrs) diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index e246821a9..9d77cde4e 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -249,7 +249,7 @@ @@ -262,7 +262,7 @@ title="Translation" icon=":icons/translate.png" tooltip="Make a number of shifted copies of a group of objects"> @@ -291,7 +291,7 @@ title="Rotation" icon=":icons/rotate.png" tooltip="Make a number of rotated copies of a group of objects">