]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
External object manager to be used in the multi selector widget
authornds <natalia.donis@opencascade.com>
Thu, 16 Apr 2015 17:25:17 +0000 (20:25 +0300)
committernds <natalia.donis@opencascade.com>
Thu, 16 Apr 2015 17:25:17 +0000 (20:25 +0300)
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_ExternalObjectsMgr.cpp [new file with mode: 0644]
src/PartSet/PartSet_ExternalObjectsMgr.h [new file with mode: 0644]
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_WidgetMultiSelector.cpp [new file with mode: 0644]
src/PartSet/PartSet_WidgetMultiSelector.h [new file with mode: 0644]
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h

index 58d1a210c8c328a23fef83ab645fcb621957682e..d254192961fc430f65667c8edfb12bfd195298cd 100644 (file)
@@ -7,12 +7,14 @@ SET(CMAKE_AUTOMOC ON)
 SET(PROJECT_HEADERS
        PartSet.h
        PartSet_Constants.h
+       PartSet_ExternalObjectsMgr.h
        PartSet_Module.h
        PartSet_Tools.h
        PartSet_WidgetSketchLabel.h
        PartSet_Validators.h
        PartSet_WidgetPoint2d.h
-    PartSet_WidgetEditor.h
+       PartSet_WidgetEditor.h
+       PartSet_WidgetMultiSelector.h
        PartSet_WidgetPoint2dDistance.h
        PartSet_WidgetShapeSelector.h
        PartSet_Filters.h
@@ -21,11 +23,13 @@ SET(PROJECT_HEADERS
 )
 
 SET(PROJECT_SOURCES
+       PartSet_ExternalObjectsMgr.cpp
        PartSet_Module.cpp
        PartSet_Tools.cpp
        PartSet_WidgetSketchLabel.cpp
        PartSet_Validators.cpp
-    PartSet_WidgetEditor.cpp
+       PartSet_WidgetEditor.cpp
+       PartSet_WidgetMultiSelector.cpp
        PartSet_WidgetPoint2d.cpp
        PartSet_WidgetPoint2dDistance.cpp
        PartSet_WidgetShapeSelector.cpp
diff --git a/src/PartSet/PartSet_ExternalObjectsMgr.cpp b/src/PartSet/PartSet_ExternalObjectsMgr.cpp
new file mode 100644 (file)
index 0000000..2ba5b86
--- /dev/null
@@ -0,0 +1,66 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        PartSet_ExternalObjectsMgr.cpp
+// Created:     15 Apr 2015
+// Author:      Natalia Ermolaeva
+
+#include "PartSet_ExternalObjectsMgr.h"
+#include "PartSet_Tools.h"
+
+#include <XGUI_Workshop.h>
+
+#include <QString>
+
+PartSet_ExternalObjectsMgr::PartSet_ExternalObjectsMgr(const std::string& theExternal, const bool theDefaultValue)
+: myUseExternal(theDefaultValue)
+{
+  QString aIsExternal(theExternal.c_str());
+  if (!aIsExternal.isEmpty()) {
+    QString aStr = aIsExternal.toUpper();
+    myUseExternal = (aStr == "TRUE") || (aStr == "YES"); 
+  }
+}
+
+ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelectedObject,
+                                                     const GeomShapePtr& theShape,
+                                                     const CompositeFeaturePtr& theSketch)
+{
+  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())
+      myExternalObjects.append(aSelectedObject);
+  }
+  return aSelectedObject;
+}
+
+//********************************************************************
+void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch,
+                                                const FeaturePtr& theFeature)
+{
+  QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end();
+  for (; anIt != aLast; anIt++) {
+    ObjectPtr anObject = *anIt;
+    if (anObject.get()) {
+      DocumentPtr aDoc = anObject->document();
+      FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+      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);
+      }
+    }
+  }
+  myExternalObjects.clear();
+}
diff --git a/src/PartSet/PartSet_ExternalObjectsMgr.h b/src/PartSet/PartSet_ExternalObjectsMgr.h
new file mode 100644 (file)
index 0000000..6451751
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        PartSet_ExternalObjectsMgr.h
+// Created:     15 Apr 2015
+// Author:      Natalia Ermolaeva
+
+
+#ifndef PartSet_ExternalObjectsMgr_H
+#define PartSet_ExternalObjectsMgr_H
+
+#include "PartSet.h"
+
+#include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Object.h>
+#include <GeomAPI_Shape.h>
+
+#include <ModuleBase_Definitions.h>
+
+#include <string>
+
+/**
+* \ingroup Modules
+* Customosation of ModuleBase_WidgetShapeSelector in order to provide 
+* working with sketch specific objects.
+*/
+class PARTSET_EXPORT PartSet_ExternalObjectsMgr
+{
+ public:
+  /// Constructor
+  /// \param theExternal the external state
+  /// \param theDefaultValue the default value for the external object using
+  PartSet_ExternalObjectsMgr(const std::string& theExternal, const bool theDefaultValue);
+
+  virtual ~PartSet_ExternalObjectsMgr() {}
+
+  /// Returns the state whether the external object is used
+  bool useExternal() const { return myUseExternal; }
+
+  /// Finds or create and external object
+  /// \param theSelectedObject an object
+  /// \param theShape a selected shape, which is used in the selection attribute
+  /// \param theSketch a current sketch
+  /// \return the object
+  ObjectPtr externalObject(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);
+
+protected:
+  /// An external object
+  QObjectPtrList myExternalObjects;
+
+  /// Boolean value about the neccessity of the external object use
+  bool myUseExternal;
+};
+
+#endif
\ No newline at end of file
index 33df2709188e2539bde7f5c56ee649016530ce51..09b8ef5d58c71373cb2e8b60fdbcd7e0b8e8c851 100644 (file)
@@ -7,6 +7,7 @@
 #include <PartSet_WidgetPoint2d.h>
 #include <PartSet_WidgetPoint2dDistance.h>
 #include <PartSet_WidgetShapeSelector.h>
+#include <PartSet_WidgetMultiSelector.h>
 #include <PartSet_WidgetEditor.h>
 #include "PartSet_SketcherMgr.h"
 #include "PartSet_MenuMgr.h"
@@ -456,7 +457,13 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
       new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
     aWgt = aShapeSelectorWgt;
-  } if (theType == WDG_DOUBLEVALUE_EDITOR) {
+  } if (theType == "sketch_multi_selector") {
+    PartSet_WidgetMultiSelector* aShapeSelectorWgt =
+      new PartSet_WidgetMultiSelector(theParent, workshop(), theWidgetApi, theParentId);
+    aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
+    aWgt = aShapeSelectorWgt;
+  }
+  if (theType == WDG_DOUBLEVALUE_EDITOR) {
     aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId);
   } 
   return aWgt;
index e46d1a60c83d0695a8d2e2d86f8743a2994a3eb6..3a9487469f07de79def7b3e2e62f6b474d7a7c5a 100644 (file)
@@ -328,7 +328,7 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
       FeaturePtr aFeature = myCurrentSelection.begin().key();
       std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
                 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
-      if (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
+      if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
         DataPtr aData = aSPFeature->data();
         AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
         std::shared_ptr<GeomDataAPI_Point2D> aFPAttr = 
diff --git a/src/PartSet/PartSet_WidgetMultiSelector.cpp b/src/PartSet/PartSet_WidgetMultiSelector.cpp
new file mode 100644 (file)
index 0000000..c59c691
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        PartSet_WidgetMultiSelector.cpp
+// Created:     15 Apr 2015
+// Author:      Natalia Ermolaeva
+
+#include "PartSet_WidgetMultiSelector.h"
+
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+#include <ModuleBase_Definitions.h>
+#include <Config_WidgetAPI.h>
+
+#include <PartSet_Tools.h>
+#include <PartSet_ExternalObjectsMgr.h>
+#include <SketchPlugin_Feature.h>
+
+#include <SketchPlugin_ConstraintRigid.h>
+
+#include <XGUI_Workshop.h>
+
+PartSet_WidgetMultiSelector::PartSet_WidgetMultiSelector(QWidget* theParent,
+                                                         ModuleBase_IWorkshop* theWorkshop,
+                                                         const Config_WidgetAPI* theData,
+                                                         const std::string& theParentId)
+: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId)
+{
+  myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), false);
+}
+
+PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector()
+{
+  delete myExternalObjectMgr;
+}
+
+//********************************************************************
+void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid)
+{
+  ModuleBase_WidgetShapeSelector::restoreAttributeValue(theValid);
+  myExternalObjectMgr->removeExternal(sketch(), myFeature);
+}
diff --git a/src/PartSet/PartSet_WidgetMultiSelector.h b/src/PartSet/PartSet_WidgetMultiSelector.h
new file mode 100644 (file)
index 0000000..db5d408
--- /dev/null
@@ -0,0 +1,58 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        PartSet_WidgetMultiSelector.h
+// Created:     15 Apr 2015
+// Author:      Natalia Ermolaeva
+
+
+#ifndef PartSet_WidgetMultiSelector_H
+#define PartSet_WidgetMultiSelector_H
+
+#include "PartSet.h"
+
+#include <ModuleBase_WidgetShapeSelector.h>
+
+#include <ModelAPI_CompositeFeature.h>
+
+class PartSet_ExternalObjectsMgr;
+
+/**
+* \ingroup Modules
+* Customosation of ModuleBase_WidgetShapeSelector in order to provide 
+* working with sketch specific objects.
+*/
+class PARTSET_EXPORT PartSet_WidgetMultiSelector: public ModuleBase_WidgetShapeSelector
+{
+Q_OBJECT
+ public:
+  /// Constructor
+  /// \param theParent the parent object
+  /// \param theWorkshop instance of workshop interface
+  /// \param theData the widget configuation. The attribute of the model widget is obtained from
+  /// \param theParentId is Id of a parent of the current attribute
+  PartSet_WidgetMultiSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
+    const Config_WidgetAPI* theData, const std::string& theParentId);
+
+  virtual ~PartSet_WidgetMultiSelector();
+
+  /// Set sketcher
+  /// \param theSketch a sketcher object
+  void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
+
+  /// Retrurns installed sketcher
+  CompositeFeaturePtr sketch() const { return mySketch; }
+
+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
+  /// \param theValid a boolean flag, if restore happens for valid parameters
+  void restoreAttributeValue(const bool theValid);
+
+protected:
+  PartSet_ExternalObjectsMgr* myExternalObjectMgr;
+  /// Pointer to a sketch 
+  CompositeFeaturePtr mySketch;
+};
+
+#endif
\ No newline at end of file
index 5174050ff8fd50f5998a7ebf7dd840df7ede06f5..275a65d17197c6db7749c82ab78b8e0fb44f24f4 100644 (file)
@@ -14,6 +14,7 @@
 #include <Config_WidgetAPI.h>
 
 #include <PartSet_Tools.h>
+#include <PartSet_ExternalObjectsMgr.h>
 #include <SketchPlugin_Feature.h>
 
 #include <SketchPlugin_ConstraintRigid.h>
@@ -24,13 +25,14 @@ PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
                                                          ModuleBase_IWorkshop* theWorkshop,
                                                          const Config_WidgetAPI* theData,
                                                          const std::string& theParentId)
-: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId), myUseExternal(true)
+: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId)
 {
-  QString aIsExternal(theData->getProperty("use_external").c_str());
-  if (!aIsExternal.isEmpty()) {
-    QString aStr = aIsExternal.toUpper();
-    myUseExternal = (aStr == "TRUE") || (aStr == "YES"); 
-  }
+  myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), true);
+}
+
+PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
+{
+  delete myExternalObjectMgr;
 }
 
 bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape)
@@ -46,19 +48,11 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
 
   // Do check that we can use external feature
-  if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myUseExternal))
+  if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myExternalObjectMgr->useExternal()))
     return false;
 
-  if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull() && myUseExternal) {
-    aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
-                                                  theSelectedObject, mySketch);
-    if (!aSelectedObject.get()) {
-      // Processing of external (non-sketch) object
-      aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
-                                                  theSelectedObject, mySketch);
-      if (aSelectedObject.get())
-        myExternalObject = aSelectedObject;
-    }
+  if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull() && myExternalObjectMgr->useExternal()) {
+    aSelectedObject = myExternalObjectMgr->externalObject(theSelectedObject, theShape, sketch());
   } else {
     // Processing of sketch object
     DataPtr aData = myFeature->data();
@@ -104,28 +98,5 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha
 void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid)
 {
   ModuleBase_WidgetShapeSelector::restoreAttributeValue(theValid);
-  removeExternal();
-}
-
-//********************************************************************
-void PartSet_WidgetShapeSelector::removeExternal()
-{
-  if (myExternalObject.get()) {
-    DocumentPtr aDoc = myExternalObject->document();
-    FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject);
-    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(sketch());
-      // 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(myFeature);
-      XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);
-    }
-    myExternalObject = ObjectPtr();
-  }
+  myExternalObjectMgr->removeExternal(sketch(), myFeature);
 }
index b10c8a06fff2bf1e060e266e4e01d57faf4eceea..5aa7ca28314e227b957e45fce3f085e549f448f9 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <ModelAPI_CompositeFeature.h>
 
+class PartSet_ExternalObjectsMgr;
 
 /**
 * \ingroup Modules
@@ -32,7 +33,7 @@ Q_OBJECT
   PartSet_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
     const Config_WidgetAPI* theData, const std::string& theParentId);
 
-  virtual ~PartSet_WidgetShapeSelector() {}
+  virtual ~PartSet_WidgetShapeSelector();
 
   /// Set sketcher
   /// \param theSketch a sketcher object
@@ -54,17 +55,10 @@ protected:
   /// \param theValid a boolean flag, if restore happens for valid parameters
   void restoreAttributeValue(const bool theValid);
 
-  // Removes the external presentation from the model
-  void removeExternal();
-
 protected:
+  PartSet_ExternalObjectsMgr* myExternalObjectMgr;
   /// Pointer to a sketch 
   CompositeFeaturePtr mySketch;
-
-  /// An external object
-  ObjectPtr myExternalObject;
-
-  bool myUseExternal;
 };
 
 #endif
\ No newline at end of file