]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
addUniqueNamedCopiedFeature to use unique names for copies features.
authornds <natalia.donis@opencascade.com>
Thu, 28 May 2015 16:41:46 +0000 (19:41 +0300)
committernds <natalia.donis@opencascade.com>
Thu, 28 May 2015 16:41:46 +0000 (19:41 +0300)
src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp
src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp
src/SketchPlugin/SketchPlugin_MultiRotation.cpp
src/SketchPlugin/SketchPlugin_MultiTranslation.cpp
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h
src/SketchPlugin/plugin-Sketch.xml

index 8c6f918a47c91fe09f9c9a4954af754373df671d..450621fa9f2d3cb2ad0a26b6b0889ffdafa3f22d 100644 (file)
@@ -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 {
index 029200ff814e2205be9f937e75a154383067a6e9..03a3a90058b6d64fb63c7d64ed2961ef713d1c07 100644 (file)
@@ -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);
 
index f0ad011d0d2f2aba2ae53a143c68dfe672db8439..d4cf1ec716bc09175e5644225b62e131756af982 100644 (file)
@@ -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);
index 71eca57ca89f10927d685525d7996c18a3e12c82..715f166507b28da2b627029d519782d01363beaf 100644 (file)
@@ -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);
 
index 7b7fb78d0e1608a9afbbf4ab8c677feccadb3508..f7d09acbba8c470885577364080549c77b94cb5d 100644 (file)
@@ -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;
+}
index 9f5f4a4580113b7c147890da43f3499099f075c2..2043f33f59eb640429dc48c6621bb59bf0c07e13 100644 (file)
@@ -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<GeomAPI_ICustomPrs> theDefaultPrs)
index e246821a9ee7f2eedf93dc666728c2124bcac064..9d77cde4eb1fb8239cee2a9815a223080dc20502 100644 (file)
             <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">