Salome HOME
External edges for mirror
authornds <natalia.donis@opencascade.com>
Fri, 17 Apr 2015 11:52:58 +0000 (14:52 +0300)
committernds <natalia.donis@opencascade.com>
Fri, 17 Apr 2015 11:52:58 +0000 (14:52 +0300)
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/PartSet/PartSet_ExternalObjectsMgr.cpp
src/PartSet/PartSet_ExternalObjectsMgr.h
src/PartSet/PartSet_WidgetMultiSelector.cpp
src/PartSet/PartSet_WidgetMultiSelector.h
src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp

index 9fc28310e116507ba863a82bd8c77c8383c43972..cc702f6a129f0da3763c4e498e26bb4c6e84eeab 100644 (file)
@@ -81,7 +81,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge
   void onSelectionTypeChanged();
 
   /// Slot is called on selection changed
-  void onSelectionChanged();
+  virtual void onSelectionChanged();
 
 protected slots:
   /// Slot for copy command in a list pop-up menu
index 2ba5b86688e4d2373476f4977238243678234862..b12f92b5f05e11978614f49697962480d3637b15 100644 (file)
@@ -37,6 +37,24 @@ ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelecte
   return aSelectedObject;
 }
 
+//********************************************************************
+ObjectPtr PartSet_ExternalObjectsMgr::externalObjectValidated(const ObjectPtr& theSelectedObject,
+                                                     const GeomShapePtr& theShape,
+                                                     const CompositeFeaturePtr& theSketch)
+{
+  // TODO(nds): unite with externalObject()
+  ObjectPtr aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
+                                                             theSelectedObject, theSketch);
+  if (!aSelectedObject.get()) {
+    // Processing of external (non-sketch) object
+    aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
+                                                                 theSelectedObject, theSketch);
+    if (aSelectedObject.get())
+      myExternalObjectValidated = aSelectedObject;
+  }
+  return aSelectedObject;
+}
+
 //********************************************************************
 void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch,
                                                 const FeaturePtr& theFeature)
@@ -61,6 +79,61 @@ void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSk
         XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);
       }
     }
+    //removeExternalObject(anObject, theSketch, theFeature);
   }
   myExternalObjects.clear();
 }
+
+//********************************************************************
+void PartSet_ExternalObjectsMgr::removeUnusedExternalObjects(const QObjectPtrList& theIgnoreObjects,
+                                                             const CompositeFeaturePtr& theSketch,
+                                                             const FeaturePtr& theFeature)
+{
+  /*
+  // TODO(nds): unite with removeExternal(), remove parameters
+  QObjectPtrList aUsedExternalObjects;
+
+  QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end();
+  for (; anIt != aLast; anIt++) {
+    ObjectPtr anObject = *anIt;
+    if (theIgnoreObjects.contains(anObject))
+      aUsedExternalObjects.append(anObject);
+    else
+      removeExternalObject(anObject, theSketch, theFeature);
+  }*/
+  myExternalObjects.clear();
+  //if (!aUsedExternalObjects.empty())
+  //  myExternalObjects = aUsedExternalObjects;
+}
+
+//********************************************************************
+void PartSet_ExternalObjectsMgr::removeExternalValidated(const CompositeFeaturePtr& theSketch,
+                                                         const FeaturePtr& theFeature)
+{
+  // TODO(nds): unite with removeExternal(), remove parameters
+  removeExternalObject(myExternalObjectValidated, theSketch, theFeature);
+  myExternalObjectValidated = NULL;
+}
+
+void PartSet_ExternalObjectsMgr::removeExternalObject(const ObjectPtr& theObject,
+                                                      const CompositeFeaturePtr& theSketch,
+                                                      const FeaturePtr& theFeature)
+{
+  if (theObject.get()) {
+    DocumentPtr aDoc = theObject->document();
+    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+    if (aFeature.get() != NULL) {
+      QObjectPtrList anObjects;
+      anObjects.append(aFeature);
+      // the external feature should be removed with all references, sketch feature should be ignored
+      std::set<FeaturePtr> anIgnoredFeatures;
+      anIgnoredFeatures.insert(theSketch);
+      // the current feature should be ignored, because it can use the external feature in the
+      // attributes and, therefore have a references to it. So, the delete functionality tries
+      // to delete this feature. Test case is creation of a constraint on external point,
+      // use in this control after an external point, the point of the sketch.
+      anIgnoredFeatures.insert(theFeature);
+      XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);
+    }
+  }
+}
index 6451751dee3dda3e01d0e659f079de9f3583d918..45f89a84c90eaab6b444b03a124948ab44c498a5 100644 (file)
@@ -44,16 +44,35 @@ class PARTSET_EXPORT PartSet_ExternalObjectsMgr
   ObjectPtr externalObject(const ObjectPtr& theSelectedObject, const GeomShapePtr& theShape,
                            const CompositeFeaturePtr& theSketch);
 
+  ObjectPtr externalObjectValidated(const ObjectPtr& theSelectedObject, const GeomShapePtr& theShape,
+                           const CompositeFeaturePtr& theSketch);
+
+
   // Removes the external presentation from the model
   /// \param theSketch a current sketch
   /// \param theFeature a current feature
   void removeExternal(const CompositeFeaturePtr& theSketch,
                       const FeaturePtr& theFeature);
 
+  void removeExternalValidated(const CompositeFeaturePtr& theSketch,
+                               const FeaturePtr& theFeature);
+
+  void removeUnusedExternalObjects(const QObjectPtrList& theIgnoreObjects,
+                            const CompositeFeaturePtr& theSketch,
+                            const FeaturePtr& theFeature);
+
+protected:
+  void removeExternalObject(const ObjectPtr& theObject,
+                            const CompositeFeaturePtr& theSketch,
+                            const FeaturePtr& theFeature);
+
 protected:
   /// An external object
   QObjectPtrList myExternalObjects;
 
+  /// An external object
+  ObjectPtr myExternalObjectValidated;
+
   /// Boolean value about the neccessity of the external object use
   bool myUseExternal;
 };
index 1c046be78d49a083c419f68ec88af9b030b9e1e6..43f066ea2337b8e935f502013489d968d4328e9f 100644 (file)
@@ -41,11 +41,41 @@ PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector()
   delete myExternalObjectMgr;
 }
 
+//********************************************************************
+void PartSet_WidgetMultiSelector::onSelectionChanged()
+{
+  ModuleBase_WidgetMultiSelector::onSelectionChanged();
+  // TODO(nds): unite with externalObject(), remove parameters
+  //myFeature->execute();
+
+  DataPtr aData = myFeature->data();
+  AttributeSelectionListPtr aSelectionListAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+  QObjectPtrList aListOfAttributeObjects;
+  for (int i = 0; i < aSelectionListAttr->size(); i++) {
+    AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
+    aListOfAttributeObjects.append(anAttr->context());
+  }
+
+  myExternalObjectMgr->removeUnusedExternalObjects(aListOfAttributeObjects, sketch(), myFeature);
+}
+
+//********************************************************************
+void PartSet_WidgetMultiSelector::storeAttributeValue()
+{
+  myIsInVaildate = true;
+  ModuleBase_WidgetMultiSelector::storeAttributeValue();
+
+}
+
 //********************************************************************
 void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid)
 {
+  myIsInVaildate = false;
   ModuleBase_WidgetMultiSelector::restoreAttributeValue(theValid);
-  myExternalObjectMgr->removeExternal(sketch(), myFeature);
+
+  myExternalObjectMgr->removeExternalValidated(sketch(), myFeature);
 }
 
 //********************************************************************
@@ -126,7 +156,10 @@ bool PartSet_WidgetMultiSelector::setObject(const ObjectPtr& theSelectedObject,
     return false;
 
   if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull() && myExternalObjectMgr->useExternal()) {
-    aSelectedObject = myExternalObjectMgr->externalObject(theSelectedObject, theShape, sketch());
+    if (myIsInVaildate)
+      aSelectedObject = myExternalObjectMgr->externalObjectValidated(theSelectedObject, theShape, sketch());
+    else
+      aSelectedObject = myExternalObjectMgr->externalObject(theSelectedObject, theShape, sketch());
   }
 
 
index 0bb999f082cc898c886a3b5c49a069adb761838a..ba7ffea5497942228d1df1a2d90b3fffd4f4a5c0 100644 (file)
@@ -47,7 +47,16 @@ Q_OBJECT
   /// \param theOwner a selected owner
   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
 
+public slots:
+  /// Slot is called on selection changed
+  virtual void onSelectionChanged();
+
 protected:
+  /// Creates a backup of the current values of the attribute
+  /// It should be realized in the specific widget because of different
+  /// parameters of the current attribute
+  virtual void storeAttributeValue();
+
   /// Creates a backup of the current values of the attribute
   /// It should be realized in the specific widget because of different
   /// parameters of the current attribute
@@ -65,6 +74,8 @@ protected:
   PartSet_ExternalObjectsMgr* myExternalObjectMgr;
   /// Pointer to a sketch 
   CompositeFeaturePtr mySketch;
+
+  bool myIsInVaildate;
 };
 
 #endif
\ No newline at end of file
index f28a09516757ff59a05cbe8966e34693cfeb4fd4..d3ba226f6205b57c555ca4f8d7c084c484d100fe 100644 (file)
@@ -43,8 +43,6 @@ void SketchPlugin_ConstraintMirror::execute()
 {
   AttributeSelectionListPtr aMirrorObjectRefs =
       selectionList(SketchPlugin_ConstraintMirror::MIRROR_LIST_ID());
-  if (!aMirrorObjectRefs->isInitialized())
-    return;
 
   std::shared_ptr<ModelAPI_Data> aData = data();
   AttributeRefListPtr aRefListOfShapes = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(