Salome HOME
Preselection using in operations: using of external objects correction.
authornds <natalia.donis@opencascade.com>
Thu, 18 Jun 2015 07:53:38 +0000 (10:53 +0300)
committernds <natalia.donis@opencascade.com>
Thu, 18 Jun 2015 07:53:38 +0000 (10:53 +0300)
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/PartSet/PartSet_ExternalObjectsMgr.cpp
src/PartSet/PartSet_ExternalObjectsMgr.h
src/PartSet/PartSet_WidgetMultiSelector.cpp
src/PartSet/PartSet_WidgetMultiSelector.h
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h

index be3ce6ec69b7f43a689da95bc2fa7ea851a63c64..a74c2758c8bc2804efc520d745a300041a0cca63 100644 (file)
@@ -195,6 +195,18 @@ void ModuleBase_WidgetMultiSelector::storeAttributeValue()
   }
 }
 
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
+                                               GeomShapePtr theShape)
+{
+  DataPtr aData = myFeature->data();
+  AttributeSelectionListPtr aSelectionListAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aResult);
+  aSelectionListAttr->append(aResult, theShape);
+}
+
 //********************************************************************
 void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/)
 {
@@ -211,7 +223,7 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/)
   // Store selection in the attribute
   int aSize = mySelection.size();
   foreach (GeomSelection aSelec, mySelection) {
-    aSelectionListAttr->append(aSelec.first, aSelec.second);
+    setObject(aSelec.first, aSelec.second);
   }
 }
 
@@ -316,50 +328,12 @@ bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_Vie
 //********************************************************************
 bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
 {
-  //TopoDS_Shape aShape = thePrs.shape();
-  //if (!acceptSubShape(aShape))
-  //  return false;
-
-  ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
-  /*
-  if (myFeature) {
-    // We can not select a result of our feature
-    const std::list<ResultPtr>& aResList = myFeature->results();
-    std::list<ResultPtr>::const_iterator aIt;
-    bool isSkipSelf = false;
-    for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
-      if ((*aIt) == aResult) {
-        isSkipSelf = true;
-        break;
-      }
-    }
-    if(isSkipSelf)
-      return false;
-  }*/
+  // DEBUG_THE_SAME_AS_SHAPE
+  ObjectPtr anObject;
+  GeomShapePtr aShape;
+  getGeomSelection(thePrs, anObject, aShape);
 
-  // if the result has the similar shap as the parameter shape, just the context is set to the
-  // selection list attribute.
-  DataPtr aData = myFeature->data();
-  AttributeSelectionListPtr aSelectionListAttr = 
-    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
-
-  /*const TopoDS_Shape& aTDSShape = thePrs.shape();
-  // if only result is selected, an empty shape is set to the model
-  if (aTDSShape.IsNull()) {
-    aSelectionListAttr->append(aResult, GeomShapePtr());
-  }
-  else {
-    GeomShapePtr aShape(new GeomAPI_Shape());
-    aShape->setImpl(new TopoDS_Shape(aTDSShape));
-    // We can not select a result of our feature
-    if (aShape->isEqual(aResult->shape()))
-      aSelectionListAttr->append(aResult, GeomShapePtr());
-    else
-      aSelectionListAttr->append(aResult, aShape);
-  }*/
-  GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
-  aSelectionListAttr->append(aResult, aShape);
-  
+  setObject(anObject, aShape);
   return true;
 }
 
@@ -475,6 +449,16 @@ QList<ModuleBase_ViewerPrs> ModuleBase_WidgetMultiSelector::getAttributeSelectio
   return aSelected;
 }
 
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+                                                      ObjectPtr& theObject,
+                                                      GeomShapePtr& theShape)
+{
+  // DEBUG_THE_SAME_AS_SHAPE
+  theObject = myWorkshop->selection()->getResult(thePrs);
+  theShape = myWorkshop->selection()->getShape(thePrs);
+}
+
 //********************************************************************
 void ModuleBase_WidgetMultiSelector::updateSelectionList(AttributeSelectionListPtr theList)
 {
index a9f7c461cb168ae930f3e984acefb15b345d87bd..83e37216a716e9c80234b1898ab0871020f0b554 100644 (file)
@@ -103,7 +103,7 @@ protected slots:
   /// Slot is called on selection of list of selected items
   void onListSelection();
 
- protected:
+protected:
   /// The methiod called when widget is activated
   virtual void activateCustom();
 
@@ -116,6 +116,13 @@ protected slots:
   /// parameters of the current attribute
   virtual void storeAttributeValue();
 
+  /// Append the values to the model attribute of the widget. It casts this attribute to
+  /// the specific type and set the given values
+  /// \param theSelectedObject an object
+  /// \param theShape a selected shape, which is used in the selection attribute
+  /// \return true if it is succeed
+  void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+
   /// 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
@@ -138,10 +145,17 @@ protected slots:
   /// a shape. If the attribute do not uses the shape, it is empty
   QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
 
- protected:
   /// Update selection list
   void updateSelectionList(AttributeSelectionListPtr);
 
+  /// Return an object and geom shape by the viewer presentation
+  /// \param thePrs a selection
+  /// \param theObject an output object
+  /// \param theShape a shape of the selection
+  virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+                                ObjectPtr& theObject,
+                                GeomShapePtr& theShape);
+
   /// Converts the XML defined type choice to the validator type
   /// For example, the "Edges" is converted to "edge"
   std::string validatorType(const QString& theType) const;
index 2fe1ab684075b5f43af9fd37a8a852c8c0f896e4..d24d2b65d25db798c58aedd7bd44c25e7054e68c 100644 (file)
@@ -67,8 +67,6 @@
 #include <list>
 #include <string>
 
-//#define DEBUG_SHAPE_VALIDATION_PREVIOUS
-
 ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent,
                                                      ModuleBase_IWorkshop* theWorkshop,
                                                      const Config_WidgetAPI* theData,
@@ -114,21 +112,15 @@ bool ModuleBase_WidgetShapeSelector::storeValueCustom() const
 }
 
 //********************************************************************
-bool ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject,
+void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject,
                                                GeomShapePtr theShape)
 {
-  bool isChanged = false;
-  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theSelectedObject);
-  if (aSelectedFeature == myFeature)  // In order to avoid selection of the same object
-    return isChanged;
-
   DataPtr aData = myFeature->data();
   AttributeReferencePtr aRef = aData->reference(attributeID());
   if (aRef) {
     ObjectPtr aObject = aRef->value();
     if (!(aObject && aObject->isSame(theSelectedObject))) {
       aRef->setValue(theSelectedObject);
-      isChanged = true;
     }
   } else {
     AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
@@ -136,18 +128,15 @@ bool ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject,
       ObjectPtr aObject = aRefAttr->object();
       if (!(aObject && aObject->isSame(theSelectedObject))) {
         aRefAttr->setObject(theSelectedObject);
-        isChanged = true;
       }
     } else {
       AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
       if (aSelectAttr.get() != NULL) {
         aSelectAttr->setValue(aResult, theShape);
-        isChanged = true;
       }
     }
   }
-  return isChanged;
 }
 
 //********************************************************************
@@ -170,6 +159,15 @@ QList<ModuleBase_ViewerPrs> ModuleBase_WidgetShapeSelector::getAttributeSelectio
   return aSelected;
 }
 
+//********************************************************************
+void ModuleBase_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+                                                      ObjectPtr& theObject,
+                                                      GeomShapePtr& theShape)
+{
+  theObject = myWorkshop->selection()->getResult(thePrs);
+  theShape = myWorkshop->selection()->getShape(thePrs);
+}
+
 //********************************************************************
 void ModuleBase_WidgetShapeSelector::clearAttribute()
 {
@@ -366,10 +364,6 @@ void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid)
 //********************************************************************
 bool ModuleBase_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
 {
-#ifdef DEBUG_SHAPE_VALIDATION_PREVIOUS
-  return true;
-#endif
-
   GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
   bool aValid;
   // if there is no selected shape, the method returns true
@@ -380,70 +374,23 @@ bool ModuleBase_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_Vie
     TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
     aValid = acceptSubShape(aTopoShape);
   }
+  if (aValid) {
+    // In order to avoid selection of the same object
+    ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
+    FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aResult);
+    aValid = aSelectedFeature != myFeature;
+  }
   return aValid;
 }
 
 //********************************************************************
 bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
 {
-  bool isDone = false;
-
-  ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
-
-  // It should be checked by corresponded validator
-  //ObjectPtr aObject = thePrs.object();
-  //ObjectPtr aCurrentObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID()));
-  /*
-  if ((!aCurrentObject) && (!aObject))
-    return false;*/
-
-  // It should be checked by corresponded validator
-  // Check that the selected object is result (others can not be accepted)
-  //ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
-  //if (!aRes)
-  //  return false;
-  /*if (myFeature) {
-    // We can not select a result of our feature
-    const std::list<std::shared_ptr<ModelAPI_Result>>& aResList = myFeature->results();
-    std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
-    for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
-      if ((*aIt) == aRes)
-        return false;
-    }
-  }
-  */
-  // It should be checked by corresponded validator
-  /*
-  // Check that object belongs to active document or PartSet
-  DocumentPtr aDoc = aRes->document();
-  SessionPtr aMgr = ModelAPI_Session::get();
-  if (!(aDoc == aMgr->activeDocument()) && !(aDoc == aMgr->moduleDocument()))
-    return false;*/
-
-#ifdef DEBUG_SHAPE_VALIDATION_PREVIOUS
-  // It should be checked by corresponded validator
-  // Check that the result has a shape
-  GeomShapePtr aShape = ModelAPI_Tools::shape(aRes);
-  if (!aShape)
-    return false;
-
-  // Get sub-shapes from local selection
-  if (!thePrs.shape().IsNull()) {
-    aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
-    aShape->setImpl(new TopoDS_Shape(thePrs.shape()));
-  }
-
-  // Check that the selection corresponds to selection type
-  TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
-  if (!acceptSubShape(aTopoShape))
-    return false;
-#else
-  // the difference is that the next method returns an empty shape if the result has the same shape
-  // to be checked for all cases and uncommented
-  GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
-#endif
+  ObjectPtr anObject;
+  GeomShapePtr aShape;
+  getGeomSelection(thePrs, anObject, aShape);
 
-  setObject(aResult, aShape);
+  setObject(anObject, aShape);
   return true;
 }
 
index 86494eb5d3672dc36b7eec86c10f7b353c0e7bad..b015a0bf3f2ad1ca572c70b18508b57d6d10dd12 100644 (file)
@@ -136,7 +136,7 @@ protected:
   /// \param theSelectedObject an object
   /// \param theShape a selected shape, which is used in the selection attribute
   /// \return true if it is succeed
-  virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+  virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
 
   /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute
   /// \return a shape
@@ -147,6 +147,14 @@ protected:
   /// a shape. If the attribute do not uses the shape, it is empty
   QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
 
+  /// Return an object and geom shape by the viewer presentation
+  /// \param thePrs a selection
+  /// \param theObject an output object
+  /// \param theShape a shape of the selection
+  virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+                                ObjectPtr& theObject,
+                                GeomShapePtr& theShape);
+
   //----------- Class members -------------
   protected:
   /// Label of the widget
index bf1eeb9b2b1180a5e3b099518b3c9a6fc5fb38c6..9c3e4105d942d5a35b2e153c57763e75881b8aa5 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <XGUI_Workshop.h>
 
+#include <SketchPlugin_Feature.h>
+
 #include <QString>
 
 PartSet_ExternalObjectsMgr::PartSet_ExternalObjectsMgr(const std::string& theExternal, const bool theDefaultValue)
@@ -21,6 +23,22 @@ PartSet_ExternalObjectsMgr::PartSet_ExternalObjectsMgr(const std::string& theExt
   }
 }
 
+bool PartSet_ExternalObjectsMgr::isValidObject(const ObjectPtr& theObject)
+{
+  bool aValid = true;
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+  // Do check using of external feature
+  std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
+          std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+
+  // Do check that we can use external feature
+  if (aSPFeature.get() != NULL && aSPFeature->isExternal() && !useExternal()) {
+    aValid = false;
+  }
+
+  return aValid;
+}
+
 ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelectedObject,
                                                      const GeomShapePtr& theShape,
                                                      const CompositeFeaturePtr& theSketch)
index 45f89a84c90eaab6b444b03a124948ab44c498a5..03b8097301c22bb44a5697b1288adb47623d50be 100644 (file)
@@ -36,6 +36,8 @@ class PARTSET_EXPORT PartSet_ExternalObjectsMgr
   /// Returns the state whether the external object is used
   bool useExternal() const { return myUseExternal; }
 
+  bool isValidObject(const ObjectPtr& theObject);
+
   /// Finds or create and external object
   /// \param theSelectedObject an object
   /// \param theShape a selected shape, which is used in the selection attribute
@@ -47,7 +49,6 @@ class PARTSET_EXPORT PartSet_ExternalObjectsMgr
   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
index 139be4ee3e8273a1b089195052cb0c587eca51e7..19e6cc379f0a0463d6a9f79167b65f0f63622b28 100644 (file)
@@ -61,6 +61,17 @@ void PartSet_WidgetMultiSelector::onSelectionChanged()
   myExternalObjectMgr->removeUnusedExternalObjects(aListOfAttributeObjects, sketch(), myFeature);
 }
 
+//********************************************************************
+bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
+{
+  bool aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs);
+  if (aValid) {
+    ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
+    aValid = myExternalObjectMgr->isValidObject(anObject);
+  }
+  return aValid;
+}
+
 //********************************************************************
 void PartSet_WidgetMultiSelector::storeAttributeValue()
 {
@@ -78,88 +89,21 @@ void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid)
   myExternalObjectMgr->removeExternalValidated(sketch(), myFeature);
 }
 
-//********************************************************************
-bool PartSet_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
-{
-  //TopoDS_Shape aShape = thePrs.shape();
-  //if (!acceptSubShape(aShape))
-  //  return false;
-
-  ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
-  /*if (myFeature) {
-    // We can not select a result of our feature
-    const std::list<ResultPtr>& aResList = myFeature->results();
-    std::list<ResultPtr>::const_iterator aIt;
-    bool isSkipSelf = false;
-    for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
-      if ((*aIt) == aResult) {
-        isSkipSelf = true;
-        break;
-      }
-    }
-    if(isSkipSelf)
-      return false;
-  }*/
-
-  /*GeomShapePtr aGShape = GeomShapePtr();
-  const TopoDS_Shape& aTDSShape = thePrs.shape();
-  // if only result is selected, an empty shape is set to the model
-  if (aTDSShape.IsNull()) {
-    //aSelectionListAttr->append(aResult, GeomShapePtr());
-  }
-  else {
-    aGShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
-    //GeomShapePtr aShape(new GeomAPI_Shape());
-    aGShape->setImpl(new TopoDS_Shape(aTDSShape));
-    // We can not select a result of our feature
-    if (aGShape->isEqual(aResult->shape())) {
-      //aSelectionListAttr->append(aResult, GeomShapePtr());
-      aGShape = GeomShapePtr();
-    }
-    else {
-      //aSelectionListAttr->append(aResult, aShape);
-    }
-  }*/
-
-  GeomShapePtr aGShape = myWorkshop->selection()->getShape(thePrs);
-  setObject(aResult, aGShape);
-  return true;
-}
-
-//********************************************************************
-bool PartSet_WidgetMultiSelector::setObject(const ObjectPtr& theSelectedObject,
-                                            const GeomShapePtr& theShape)
+void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+                                                   ObjectPtr& theObject,
+                                                   GeomShapePtr& theShape)
 {
-  ObjectPtr aSelectedObject = theSelectedObject;
-  GeomShapePtr aShape = theShape;
+  ModuleBase_WidgetMultiSelector::getGeomSelection(thePrs, theObject, theShape);
 
-  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aSelectedObject);
-  //if (aSelectedFeature == myFeature)  // In order to avoid selection of the same object
-  //  return false;
-
-  // Do check using of external feature
+  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
-
-  // Do check that we can use external feature
-  if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myExternalObjectMgr->useExternal()))
-    return false;
-
-  if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull() && myExternalObjectMgr->useExternal()) {
+  // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
+  if (aSPFeature.get() == NULL && theShape.get() != NULL && !theShape->isNull() &&
+      myExternalObjectMgr->useExternal()) {
     if (myIsInVaildate)
-      aSelectedObject = myExternalObjectMgr->externalObjectValidated(theSelectedObject, theShape, sketch());
+      theObject = myExternalObjectMgr->externalObjectValidated(theObject, theShape, sketch());
     else
-      aSelectedObject = myExternalObjectMgr->externalObject(theSelectedObject, theShape, sketch());
+      theObject = myExternalObjectMgr->externalObject(theObject, theShape, sketch());
   }
-
-
-  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aSelectedObject);
-
-  DataPtr aData = myFeature->data();
-  AttributeSelectionListPtr aSelectionListAttr = 
-    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
-
-  aSelectionListAttr->append(aResult, aShape);
-
-  return true;
 }
index 8b71001e8c147cb98fe5213b77feb2834ade8bea..5e1b4a766b868f659e772b33f6cd70a1769a47b6 100644 (file)
@@ -46,15 +46,16 @@ Q_OBJECT
   /// Retrurns installed sketcher
   CompositeFeaturePtr sketch() const { return mySketch; }
 
-  /// Fills the attribute with the value of the selected owner
-  /// \param theOwner a selected owner
-  virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
-
 public slots:
   /// Slot is called on selection changed
   virtual void onSelectionChanged();
 
 protected:
+  /// Checks the widget validity. By default, it returns true.
+  /// \param theValue a selected presentation in the view
+  /// \return a boolean value
+  virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
+
   /// 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
@@ -66,12 +67,13 @@ protected:
   /// \param theValid a boolean flag, if restore happens for valid parameters
   void restoreAttributeValue(const bool theValid);
 
-  /// Store the values to the model attribute of the widget. It casts this attribute to
-  /// the specific type and set the given values
-  /// \param theSelectedObject an object
-  /// \param theShape a selected shape, which is used in the selection attribute
-  /// \return true if it is succeed
-  bool setObject(const ObjectPtr& theSelectedObject, const GeomShapePtr& theShape);
+  /// Return an object and geom shape by the viewer presentation
+  /// \param thePrs a selection
+  /// \param theObject an output object
+  /// \param theShape a shape of the selection
+  virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+                                ObjectPtr& theObject,
+                                GeomShapePtr& theShape);
 
 protected:
   PartSet_ExternalObjectsMgr* myExternalObjectMgr;
index a4dbf44f6f70884839b7e4e019812914989f153b..7fca13598405600bfe582cdbd24d256429bbcc71 100644 (file)
@@ -42,32 +42,44 @@ PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
   delete myExternalObjectMgr;
 }
 
-bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape)
+//********************************************************************
+bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
 {
-  ObjectPtr aSelectedObject = theSelectedObject;
-  //GeomShapePtr aShape = theShape;
+  bool aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
+  if (aValid) {
+    ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
+    aValid = myExternalObjectMgr->isValidObject(anObject);
+  }
+  return aValid;
+}
 
-  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aSelectedObject);
-  if (aSelectedFeature == myFeature)  // In order to avoid selection of the same object
-    return false;
+//********************************************************************
+void PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape)
+{
+  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theSelectedObject);
   // Do check using of external feature
   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
+  // Processing of sketch object
+  if (aSPFeature.get() != NULL && theShape.get())
+    setPointAttribute(theSelectedObject, theShape);
+  else
+    ModuleBase_WidgetShapeSelector::setObject(theSelectedObject, theShape);
+}
 
-  // Do check that we can use external feature
-  if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myExternalObjectMgr->useExternal()))
-    return false;
-
-  if (aSPFeature.get() == NULL && theShape.get() != NULL && !theShape->isNull() && myExternalObjectMgr->useExternal()) {
-    aSelectedObject = myExternalObjectMgr->externalObject(theSelectedObject, theShape, sketch());
-  } else {
-    // Processing of sketch object
-    if (theShape.get()) {
-      setPointAttribute(theSelectedObject, theShape);
-      return true;
-    }
-  }
-  return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape);
+void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+                                                   ObjectPtr& theObject,
+                                                   GeomShapePtr& theShape)
+{
+  ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
+
+  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
+  std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
+          std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
+  // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
+  if (aSPFeature.get() == NULL && theShape.get() != NULL && !theShape->isNull() &&
+      myExternalObjectMgr->useExternal())
+    theObject = myExternalObjectMgr->externalObject(theObject, theShape, sketch());
 }
 
 //********************************************************************
index 050b64e271b479860c10a54c7952c24125d1482d..a2ba2d2bd5310a1033f25f3cb53f2ab9a1966387 100644 (file)
@@ -43,11 +43,25 @@ Q_OBJECT
   CompositeFeaturePtr sketch() const { return mySketch; }
 
 protected:
+  /// Checks the widget validity. By default, it returns true.
+  /// \param theValue a selected presentation in the view
+  /// \return a boolean value
+  virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
+
   /// Store the values to the model attribute of the widget. It casts this attribute to
   /// the specific type and set the given values
   /// \param theSelectedObject an object
   /// \param theShape a selected shape, which is used in the selection attribute
-  virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+  /// \return true if it is succeed
+  virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+
+  /// Return an object and geom shape by the viewer presentation
+  /// \param thePrs a selection
+  /// \param theObject an output object
+  /// \param theShape a shape of the selection
+  virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+                                ObjectPtr& theObject,
+                                GeomShapePtr& theShape);
 
   /// Get the shape from the attribute if the attribute contain a shape
   /// It processes the ref attr type of attributes. It obtains the referenced attribute,