]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
COPY attribute in SketchEntity now persistent
authordbv <dbv@opencascade.com>
Thu, 24 Dec 2015 14:04:49 +0000 (17:04 +0300)
committerdbv <dbv@opencascade.com>
Thu, 24 Dec 2015 14:05:01 +0000 (17:05 +0300)
15 files changed:
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_Arc.h
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Circle.h
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Line.h
src/SketchPlugin/SketchPlugin_MultiRotation.cpp
src/SketchPlugin/SketchPlugin_MultiRotation.h
src/SketchPlugin/SketchPlugin_MultiTranslation.cpp
src/SketchPlugin/SketchPlugin_MultiTranslation.h
src/SketchPlugin/SketchPlugin_Point.cpp
src/SketchPlugin/SketchPlugin_Point.h
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_SketchEntity.cpp
src/SketchPlugin/SketchPlugin_SketchEntity.h

index 7d285d079dd1cfa00f5c3494330be7ef428054cf..261e70b9526613c849954c5af876529c1c585dfb 100644 (file)
@@ -41,10 +41,8 @@ SketchPlugin_Arc::SketchPlugin_Arc()
   myParamBefore = 0;
 }
 
-void SketchPlugin_Arc::initAttributes()
+void SketchPlugin_Arc::initDerivedClassAttributes()
 {
-  SketchPlugin_SketchEntity::initAttributes();
-
   data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId());
   data()->addAttribute(START_ID(), GeomDataAPI_Point2D::typeId());
   std::shared_ptr<GeomDataAPI_Point2D> anEndAttr = std::dynamic_pointer_cast<
index 0464ebeadb30d60da9aa89f6937af6657f29508c..296b849bc0bebb6204d094c1aec97b784095c37a 100644 (file)
@@ -77,9 +77,6 @@ class SketchPlugin_Arc : public SketchPlugin_SketchEntity, public GeomAPI_IPrese
   /// Creates an arc-shape
   SKETCHPLUGIN_EXPORT virtual void execute();
 
-  /// Request for initialization of data model of the feature: adding all attributes
-  SKETCHPLUGIN_EXPORT virtual void initAttributes();
-
   /// Called on change of any argument-attribute of this object
   /// \param theID identifier of changed attribute
   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
@@ -101,6 +98,10 @@ class SketchPlugin_Arc : public SketchPlugin_SketchEntity, public GeomAPI_IPrese
   /// Use plugin manager for features creation
   SketchPlugin_Arc();
 
+protected:
+  /// \brief Initializes attributes of derived class.
+  virtual void initDerivedClassAttributes();
+
 private:
   /// Returns true if all obligatory attributes are initialized
   bool isFeatureValid();
index bf8a7d8d07b41186c1d6e62c7932970b7b7ce461..5dd78c10c01638afcd6f38ac2fe859a804c5ee8c 100644 (file)
@@ -26,10 +26,8 @@ SketchPlugin_Circle::SketchPlugin_Circle()
 {
 }
 
-void SketchPlugin_Circle::initAttributes()
+void SketchPlugin_Circle::initDerivedClassAttributes()
 {
-  SketchPlugin_SketchEntity::initAttributes();
-
   data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId());
   data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
index 2edff8e39e43655b0fadac8627a1a52e64c48ed6..941d90f229b3ccd6faa0b9fb8ad636e30dadb99d 100644 (file)
@@ -53,9 +53,6 @@ class SketchPlugin_Circle : public SketchPlugin_SketchEntity
   /// Creates a new part document if needed
   SKETCHPLUGIN_EXPORT virtual void execute();
 
-  /// Request for initialization of data model of the feature: adding all attributes
-  SKETCHPLUGIN_EXPORT virtual void initAttributes();
-
   /// Adds sub-feature of the higher level feature (sub-element of the sketch)
   /// \param theFeature sub-feature
   SKETCHPLUGIN_EXPORT virtual const void addSub(const FeaturePtr& theFeature)
@@ -73,6 +70,10 @@ class SketchPlugin_Circle : public SketchPlugin_SketchEntity
 
   /// Use plugin manager for features creation
   SketchPlugin_Circle();
+
+protected:
+  /// \brief Initializes attributes of derived class.
+  virtual void initDerivedClassAttributes();
 };
 
 #endif
index f4382e4314af3983bc7a57310c8228aa4a2128f2..33d087d2c6d5aff70cd11cd44c739062cd2ecff3 100644 (file)
@@ -26,10 +26,8 @@ SketchPlugin_Line::SketchPlugin_Line()
     : SketchPlugin_SketchEntity()
 {}
 
-void SketchPlugin_Line::initAttributes()
+void SketchPlugin_Line::initDerivedClassAttributes()
 {
-  SketchPlugin_SketchEntity::initAttributes();
-
   data()->addAttribute(START_ID(), GeomDataAPI_Point2D::typeId());
   data()->addAttribute(END_ID(), GeomDataAPI_Point2D::typeId());
   data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
index eaa3330f3737ee5dbfdb63ee257a74c4e94b063d..57363add5491597a8bf19d1e81d8cd87cab18cef 100644 (file)
@@ -49,9 +49,6 @@ class SketchPlugin_Line : public SketchPlugin_SketchEntity
   /// Creates a new part document if needed
   SKETCHPLUGIN_EXPORT virtual void execute();
 
-  /// Request for initialization of data model of the feature: adding all attributes
-  SKETCHPLUGIN_EXPORT virtual void initAttributes();
-
   /// Moves the feature
   /// \param theDeltaX the delta for X coordinate is moved
   /// \param theDeltaY the delta for Y coordinate is moved
@@ -66,6 +63,10 @@ class SketchPlugin_Line : public SketchPlugin_SketchEntity
 
   /// Use plugin manager for features creation
   SketchPlugin_Line();
+
+protected:
+  /// \brief Initializes attributes of derived class.
+  virtual void initDerivedClassAttributes();
 };
 
 #endif
index e878ea50d612b3a9db9d9899f0ec7bb2879f4853..68e0eab6da41e116d6f308bfa5d4b13bb2c79a06 100755 (executable)
@@ -19,6 +19,8 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 
+#include <SketchPlugin_SketchEntity.h>
+
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_XY.h>
 
@@ -209,6 +211,37 @@ AISObjectPtr SketchPlugin_MultiRotation::getAISObject(AISObjectPtr thePrevious)
   return anAIS;
 }
 
+void SketchPlugin_MultiRotation::erase()
+{
+  // Set copy attribute to false on all copied features.
+  AttributeRefListPtr aRefListOfRotated = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+      data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
+
+  if(aRefListOfRotated.get()) {
+    static Events_Loop* aLoop = Events_Loop::loop();
+    static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+
+    std::list<ObjectPtr> aTargetList = aRefListOfRotated->list();
+    for(std::list<ObjectPtr>::const_iterator aTargetIt = aTargetList.cbegin(); aTargetIt != aTargetList.cend(); aTargetIt++) {
+      if((*aTargetIt).get()) {
+        ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*aTargetIt);
+        if(aRes.get()) {
+          FeaturePtr aFeature = aRes->document()->feature(aRes);
+          if(aFeature.get()) {
+            AttributeBooleanPtr aBooleanAttr = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
+            if(aBooleanAttr.get()) {
+              aBooleanAttr->setValue(false);
+              // Redisplay object as it is not copy anymore.
+              ModelAPI_EventCreator::get()->sendUpdated(aRes, aRedispEvent);
+            }
+          }
+        }
+      }
+    }
+  }
+
+  SketchPlugin_ConstraintBase::erase();
+}
 
 ObjectPtr SketchPlugin_MultiRotation::copyFeature(ObjectPtr theObject)
 {
index 97528ebc0aaa6c5d42582d0e0cb7656956442bc7..3a1be2088bd46f66a413418e9f465c38c0c055c2 100644 (file)
@@ -86,6 +86,9 @@ class SketchPlugin_MultiRotation : public SketchPlugin_ConstraintBase
   /// Returns the AIS preview
   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
 
+  /// removes all fields from this feature: results, data, etc
+  SKETCHPLUGIN_EXPORT virtual void erase();
+
   /// \brief Use plugin manager for features creation
   SketchPlugin_MultiRotation();
 
index df1643454b5ebf784154cdcf37d0778a82b17be5..df58c765db0a0f62a52f68ed0a069d5d60f06766 100755 (executable)
@@ -20,6 +20,7 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 
+#include <SketchPlugin_SketchEntity.h>
 #include <SketcherPrs_Factory.h>
 
 SketchPlugin_MultiTranslation::SketchPlugin_MultiTranslation()
@@ -197,6 +198,38 @@ AISObjectPtr SketchPlugin_MultiTranslation::getAISObject(AISObjectPtr thePreviou
   return anAIS;
 }
 
+void SketchPlugin_MultiTranslation::erase()
+{
+  // Set copy attribute to false on all copied features.
+  AttributeRefListPtr aRefListOfTranslated = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+      data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
+
+  if(aRefListOfTranslated.get()) {
+    static Events_Loop* aLoop = Events_Loop::loop();
+    static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+
+    std::list<ObjectPtr> aTargetList = aRefListOfTranslated->list();
+    for(std::list<ObjectPtr>::const_iterator aTargetIt = aTargetList.cbegin(); aTargetIt != aTargetList.cend(); aTargetIt++) {
+      if((*aTargetIt).get()) {
+        ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*aTargetIt);
+        if(aRes.get()) {
+          FeaturePtr aFeature = aRes->document()->feature(aRes);
+          if(aFeature.get()) {
+            AttributeBooleanPtr aBooleanAttr = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
+            if(aBooleanAttr.get()) {
+              aBooleanAttr->setValue(false);
+              // Redisplay object as it is not copy anymore.
+              ModelAPI_EventCreator::get()->sendUpdated(aRes, aRedispEvent);
+            }
+          }
+        }
+      }
+    }
+  }
+
+  SketchPlugin_ConstraintBase::erase();
+}
+
 ObjectPtr SketchPlugin_MultiTranslation::copyFeature(ObjectPtr theObject)
 {
   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theObject);
index 7a3a78bc8b13ce7f94fe6e865c4c6c1822fd1150..cdf08a5a5b5eaee2631521c3469647299d73c468 100644 (file)
@@ -87,6 +87,9 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase
   /// Returns the AIS preview
   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
 
+  /// removes all fields from this feature: results, data, etc
+  SKETCHPLUGIN_EXPORT virtual void erase();
+
   /// \brief Use plugin manager for features creation
   SketchPlugin_MultiTranslation();
 
index cf718db760dd812324db95cf16a10a297494b29b..17dbb0a3fe63e4ac097c687e09664a554938b684 100644 (file)
@@ -25,10 +25,8 @@ SketchPlugin_Point::SketchPlugin_Point()
 {
 }
 
-void SketchPlugin_Point::initAttributes()
+void SketchPlugin_Point::initDerivedClassAttributes()
 {
-  SketchPlugin_SketchEntity::initAttributes();
-
   data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::typeId());
   data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
index 59995ff4310aeb44edc72c2f950f4d3e09c0c119..142d0915a4e008fd1cbc43f69452553172f70cce 100644 (file)
@@ -44,9 +44,6 @@ class SketchPlugin_Point : public SketchPlugin_SketchEntity
   /// Creates a new part document if needed
   SKETCHPLUGIN_EXPORT virtual void execute();
 
-  /// Request for initialization of data model of the feature: adding all attributes
-  SKETCHPLUGIN_EXPORT virtual void initAttributes();
-
   /// Moves the feature
   /// \param theDeltaX the delta for X coordinate is moved
   /// \param theDeltaY the delta for Y coordinate is moved
@@ -57,6 +54,10 @@ class SketchPlugin_Point : public SketchPlugin_SketchEntity
 
   /// Use plugin manager for features creation
   SketchPlugin_Point();
+
+protected:
+  /// \brief Initializes attributes of derived class.
+  virtual void initDerivedClassAttributes();
 };
 
 #endif
index bc71a6445737f3515aeba053bd25d96a157b3ff8..739f347bfd3b0077ec7b43fb087591c8c70632ba 100644 (file)
@@ -310,12 +310,10 @@ FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeatur
   // text expressions could block setValue of some attributes
   SketchPlugin_Tools::clearExpressions(aNewFeature);
   // Set copy attribute
-  std::shared_ptr<ModelAPI_AttributeBoolean> anAttr = aNewFeature->data()->boolean(SketchPlugin_SketchEntity::COPY_ID());
-  if(!anAttr.get()) {
-    aNewFeature->data()->addAttribute(SketchPlugin_SketchEntity::COPY_ID(), ModelAPI_AttributeBoolean::typeId());
-    ModelAPI_Session::get()->validators()->registerNotObligatory(aNewFeature->getKind(), SketchPlugin_SketchEntity::COPY_ID());
+  AttributeBooleanPtr anAttr = aNewFeature->data()->boolean(SketchPlugin_SketchEntity::COPY_ID());
+  if(anAttr.get()) {
+    anAttr->setValue(theIsCopy);
   }
-  aNewFeature->data()->boolean(SketchPlugin_SketchEntity::COPY_ID())->setValue(theIsCopy);
 
   return aNewFeature;
 }
index 9e95496ef455fa95572ba3c4f53c1a0c82b3ac47..f29dfc1391dfe661ce98ec2f780e2107b77a71ed 100644 (file)
@@ -15,4 +15,14 @@ void SketchPlugin_SketchEntity::initAttributes()
 {
   data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), AUXILIARY_ID());
+
+  initDerivedClassAttributes();
+
+  AttributePtr anAttr = data()->addAttribute(SketchPlugin_SketchEntity::COPY_ID(), ModelAPI_AttributeBoolean::typeId());
+  anAttr->setIsArgument(false);
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SketchPlugin_SketchEntity::COPY_ID());
+  AttributeBooleanPtr anAttrBool = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(anAttr);
+  if(anAttr.get()) {
+    anAttrBool->setValue(false);
+  }
 }
index 3148b0c57705a1d18a89f2ab8d1c168c442dfe30..16101d1866aaac9b4c70b587adf8e23782152e7e 100644 (file)
@@ -123,7 +123,7 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
     }
     if(isCopy()) {
       double aWidth = thePrs->width();
-      thePrs->setWidth(aWidth / 2.5);
+      isCustomized = thePrs->setWidth(aWidth / 2.5) || isCustomized;
     }
     return isCustomized;
   }
@@ -131,6 +131,10 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
 protected:
   /// initializes mySketch
   SketchPlugin_SketchEntity();
+
+  /// \brief Initializes attributes of derived class.
+  virtual void initDerivedClassAttributes(){};
+
 };
 
 #endif