]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
authorsbh <sergey.belash@opencascade.com>
Wed, 25 Mar 2015 16:16:15 +0000 (19:16 +0300)
committersbh <sergey.belash@opencascade.com>
Wed, 25 Mar 2015 16:16:15 +0000 (19:16 +0300)
20 files changed:
.gitignore
src/GeomAPI/GeomAPI_Edge.cpp
src/GeomAPI/GeomAPI_Vertex.cpp
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelectionList.cpp
src/Model/Model_ResultConstruction.cpp
src/Model/Model_Update.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/ModuleBase/ModuleBase_WidgetValidated.cpp
src/ModuleBase/ModuleBase_WidgetValidated.h
src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp
src/PartSet/PartSet_WidgetConstraintShapeSelector.h
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h
src/SketchPlugin/plugin-Sketch.xml

index f55ecf287870a46e890ed9032633c95acc3311ab..b3e5bb13fb16b3cafc9c15e28bdc11ef91562fb4 100644 (file)
@@ -28,3 +28,5 @@ start.bat
 *.orig
 *~
 /.project
+*DFBrowser*
+
index f9572daa79949e4da668fc374466dc078f598de2..b5736f4b618d70b52ad2e8c786c8db1ba4d20ff6 100644 (file)
@@ -131,6 +131,8 @@ std::shared_ptr<GeomAPI_Lin> GeomAPI_Edge::line()
 
 bool GeomAPI_Edge::isEqual(const std::shared_ptr<GeomAPI_Shape> theEdge) const
 {
+  if (!theEdge.get() || ! theEdge->isEdge())
+    return false;
   const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
   const TopoDS_Shape& aInShape = theEdge->impl<TopoDS_Shape>();
 
index d881d79b5bf0ea0cbbb7106bc0d3507f9aa05384..b917837a09cfcaa4e9589598625f7a4d4f63765e 100644 (file)
@@ -37,6 +37,8 @@ std::shared_ptr<GeomAPI_Pnt> GeomAPI_Vertex::point()
 
 bool GeomAPI_Vertex::isEqual(const std::shared_ptr<GeomAPI_Shape> theVert) const
 {
+  if (!theVert.get() || ! theVert->isVertex())
+    return false;
   const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Vertex*>(this)->impl<TopoDS_Shape>();
   const TopoDS_Shape& aInShape = theVert->impl<TopoDS_Shape>();
 
index f1cf7fa5b42f4b8266c9cfac080b76ed11ed2e57..9133794ae94460375cf53c75b966de982345e221 100644 (file)
@@ -85,7 +85,15 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext,
   TDF_Label aSelLab = selectionLabel();
   aSelLab.ForgetAttribute(kSIMPLE_REF_ID);
   aSelLab.ForgetAttribute(kCONSTUCTION_SIMPLE_REF_ID);
-  if (!theContext.get()) {
+
+  bool isDegeneratedEdge = false;
+  // do not use the degenerated edge as a shape, a null context and shape is used in the case
+  if (theSubShape.get() && !theSubShape->isNull() && theSubShape->isEdge()) {
+    const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
+    if (aSubShape.ShapeType() == TopAbs_EDGE)
+      isDegeneratedEdge = BRep_Tool::Degenerated(TopoDS::Edge(aSubShape));
+  }
+  if (!theContext.get() || isDegeneratedEdge) {
     // to keep the reference attribute label
     TDF_Label aRefLab = myRef.myRef->Label();
     aSelLab.ForgetAllAttributes(true);
@@ -218,9 +226,10 @@ bool Model_AttributeSelection::update()
     // take the face that more close by the indexes
     ResultConstructionPtr aConstructionContext = 
       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    FeaturePtr aContextFeature = aContext->document()->feature(aContext);
     // sketch sub-element
     if (aConstructionContext && 
-        std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContext).get())
+        std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature).get())
     {
       TDF_Label aLab = myRef.myRef->Label();
       // getting a type of selected shape
@@ -235,10 +244,9 @@ bool Model_AttributeSelection::update()
       bool aNoIndexes = 
         !aLab.FindAttribute(TDataStd_IntPackedMap::GetID(), aSubIds) || aSubIds->Extent() == 0;
       // for now working only with composite features
-      FeaturePtr aContextFeature = aContext->document()->feature(aContext);
       CompositeFeaturePtr aComposite = 
         std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
-      if (!aComposite || aComposite->numberOfSubs() == 0) {
+      if (!aComposite.get() || aComposite->numberOfSubs() == 0) {
         return false;
       }
 
index 000ba2b0d5565b4a9e11c06097c124e26a7f6529..24a9efca5308d5684d3030a0b55c6ac5d4fd8f54 100644 (file)
 #include <TDF_ChildIterator.hxx>
 #include <TopAbs_ShapeEnum.hxx>
 
+#include <TopoDS.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Edge.hxx>
+#include <BRep_Tool.hxx>
+
 using namespace std;
 
 void Model_AttributeSelectionList::append(
     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape)
 {
+  // do not use the degenerated edge as a shape, a list is not incremented in this case
+  if (theSubShape.get() && !theSubShape->isNull() && theSubShape->isEdge()) {
+    const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
+    if (aSubShape.ShapeType() == TopAbs_EDGE && BRep_Tool::Degenerated(TopoDS::Edge(aSubShape))) {
+      return;
+    }
+  }
+
   int aNewTag = mySize->Get() + 1;
   TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
 
index 17b20df98dc4eff497b1eb03ed3bfbbbbaf72e09..2998e9f2db8a4879186ed9cbb458051d027100d1 100644 (file)
@@ -28,9 +28,9 @@ void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::str
 
 void Model_ResultConstruction::setShape(std::shared_ptr<GeomAPI_Shape> theShape)
 {
-  if (myShape != theShape) {
+  if (myShape != theShape && (!theShape.get() || !theShape->isEqual(myShape))) {
     myShape = theShape;
-    if (theShape.get() && (!myShape.get() || !theShape->isEqual(myShape))) {
+    if (theShape.get()) {
       myFacesUpToDate = false;
       myFaces.clear();
     }
index 51eba966c182977e5787340582512cc134b426e3..1b1a3d626820cb2aa587b421d0e357f76c80d930 100644 (file)
@@ -105,11 +105,14 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
       {
         FeaturePtr aF = std::dynamic_pointer_cast<ModelAPI_Feature>(*aFIter);
         if (aF && aF->getKind() == "Extrusion") {
-          if (aF->selection("extrusion_face")) {
-            ResultPtr aSketchRes = aF->selection("extrusion_face")->context();
-            if (aSketchRes) {
-              static Events_ID HIDE_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE);
-              ModelAPI_EventCreator::get()->sendUpdated(aSketchRes, HIDE_DISP);
+          AttributeSelectionListPtr aBase = aF->selectionList("base");
+          if (aBase.get()) {
+            for(int a = aBase->size() - 1; a >= 0; a--) {
+              ResultPtr aSketchRes = aBase->value(a)->context();
+              if (aSketchRes) {
+                static Events_ID HIDE_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE);
+                ModelAPI_EventCreator::get()->sendUpdated(aSketchRes, HIDE_DISP);
+              }
             }
           }
         }
index ff8bafdea6a8746a9ca85a9063af9e2cc62cbe73..8b53074f961a4755a1cd02fc478c41e85979d420 100644 (file)
@@ -9,7 +9,6 @@
 
 #include <ModuleBase_WidgetMultiSelector.h>
 #include <ModuleBase_WidgetShapeSelector.h>
-#include <ModuleBase_FilterNoDegeneratedEdge.h>
 #include <ModuleBase_ISelection.h>
 #include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_IViewer.h>
@@ -159,7 +158,7 @@ bool ModuleBase_WidgetMultiSelector::restoreValue()
 }
 
 //********************************************************************
-void ModuleBase_WidgetMultiSelector::backupAttributeValue(const bool isBackup)
+void ModuleBase_WidgetMultiSelector::storeAttributeValue()
 {
   DataPtr aData = myFeature->data();
   AttributeSelectionListPtr aSelectionListAttr = 
@@ -167,23 +166,32 @@ void ModuleBase_WidgetMultiSelector::backupAttributeValue(const bool isBackup)
   if (aSelectionListAttr.get() == NULL)
     return;
 
-  if (isBackup) {
-    mySelectionType = aSelectionListAttr->selectionType();
-    mySelection.clear();
-    for (int i = 0; i < aSelectionListAttr->size(); i++) {
-      AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
-      mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
-    }
+  mySelectionType = aSelectionListAttr->selectionType();
+  mySelection.clear();
+  int aSize = aSelectionListAttr->size();
+  for (int i = 0; i < aSelectionListAttr->size(); i++) {
+    AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+    mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
   }
-  else {
-    aSelectionListAttr->clear();
-    // Store shapes type
-    aSelectionListAttr->setSelectionType(mySelectionType);
+}
 
-    // Store selection in the attribute
-    foreach (GeomSelection aSelec, mySelection) {
-      aSelectionListAttr->append(aSelec.first, aSelec.second);
-    }
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/)
+{
+  DataPtr aData = myFeature->data();
+  AttributeSelectionListPtr aSelectionListAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+  if (aSelectionListAttr.get() == NULL)
+    return;
+  aSelectionListAttr->clear();
+
+  // Store shapes type
+  aSelectionListAttr->setSelectionType(mySelectionType);
+
+  // Store selection in the attribute
+  int aSize = mySelection.size();
+  foreach (GeomSelection aSelec, mySelection) {
+    aSelectionListAttr->append(aSelec.first, aSelec.second);
   }
 }
 
@@ -311,20 +319,8 @@ void ModuleBase_WidgetMultiSelector::activateShapeSelection()
     QIntList aList;
     aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType));
     myWorkshop->activateSubShapesSelection(aList);
-
-    // it is necessary to filter the selected edges to be non-degenerated
-    // it is not possible to build naming name for such edges
-    if (aNewType == "Edges") {
-      myEdgesTypeFilter = new ModuleBase_FilterNoDegeneratedEdge();
-      aViewer->addSelectionFilter(myEdgesTypeFilter);
-    }
-    else {
-      aViewer->removeSelectionFilter(myEdgesTypeFilter);
-    }
-
   } else {
     myWorkshop->deactivateSubShapesSelection();
-    aViewer->removeSelectionFilter(myEdgesTypeFilter);
   }
 
   activateFilters(myWorkshop, myIsActive);
index ce904a981c9443e92d6d56f9834905dd56679da2..49ae66b6b85f47e9a333df3dc701ae8c954a0785 100644 (file)
@@ -12,7 +12,6 @@
 
 #include <ModuleBase.h>
 #include <ModuleBase_WidgetValidated.h>
-#include <ModuleBase_FilterNoDegeneratedEdge.h>
 
 #include <GeomAPI_Shape.h>
 #include <ModelAPI_Result.h>
@@ -102,9 +101,13 @@ protected slots:
   /// 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 isBackup a boolean flag, if true, store values from the attribute
-  /// to backup, otherwise set the backed up values to the attribute
-  virtual void backupAttributeValue(const bool isBackup);
+  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
+  /// \param theValid a boolean flag, if restore happens for valid parameters
+  virtual void restoreAttributeValue(const bool theValid);
 
   /// Set current shape type for selection
   void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
@@ -134,9 +137,6 @@ protected slots:
   /// An action for pop-up menu in a list control
   QAction* myCopyAction;
 
-  /// A filter for the Edges type, which avoid the generated edges selection
-  Handle(ModuleBase_FilterNoDegeneratedEdge) myEdgesTypeFilter;
-
   /// backup parameters of the model attribute. The class processes three types of attribute:
   /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
   /// values are reserved in the backup
index 7fc40261487056aa53dd9085efdb0b54e9cc8d69..b981a9064f1c92dd6544abec6ab6582be780e4e0 100644 (file)
@@ -370,37 +370,33 @@ void ModuleBase_WidgetShapeSelector::activateCustom()
 }
 
 //********************************************************************
-void ModuleBase_WidgetShapeSelector::backupAttributeValue(const bool isBackup)
+void ModuleBase_WidgetShapeSelector::storeAttributeValue()
 {
   DataPtr aData = myFeature->data();
   AttributePtr anAttribute = myFeature->attribute(attributeID());
 
-  if (isBackup) {
-    myObject = GeomValidators_Tools::getObject(anAttribute);
-    myShape = getShape();
-    myRefAttribute = NULL;
-    myIsObject = false;
-    AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
-    if (aRefAttr) {
-      myIsObject = aRefAttr->isObject();
-      myRefAttribute = aRefAttr->attr();
-    }
-    myExternalObject = NULL;
+  myObject = GeomValidators_Tools::getObject(anAttribute);
+  myShape = getShape();
+  myRefAttribute = NULL;
+  myIsObject = false;
+  AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
+  if (aRefAttr) {
+    myIsObject = aRefAttr->isObject();
+    myRefAttribute = aRefAttr->attr();
   }
-  else {
-    storeAttributeValues(myObject, myShape);
-    AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
-    if (aRefAttr) {
-      if (!myIsObject)
-        aRefAttr->setAttr(myRefAttribute);
-    }
-    if (myExternalObject.get()) {
-      DocumentPtr aDoc = myExternalObject->document();
-      FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject);
-      if (aFeature.get() != NULL) {
-        aDoc->removeFeature(aFeature);
-      }
-    }
+}
+
+//********************************************************************
+void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid)
+{
+  DataPtr aData = myFeature->data();
+  AttributePtr anAttribute = myFeature->attribute(attributeID());
+
+  storeAttributeValues(myObject, myShape);
+  AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
+  if (aRefAttr) {
+    if (!myIsObject)
+      aRefAttr->setAttr(myRefAttribute);
   }
 }
 
index 34c4c0212545a75448215b15b2ef7ea6cdce03f6..ea5ef10a702b2f4664ba1d8da8bdff2c5e019bc4 100644 (file)
@@ -109,9 +109,13 @@ Q_OBJECT
   /// 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 isBackup a boolean flag, if true, store values from the attribute
-  /// to backup, otherwise set the backed up values to the attribute
-  virtual void backupAttributeValue(const bool isBackup);
+  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
+  /// \param theValid a boolean flag, if restore happens for valid parameters
+  virtual void restoreAttributeValue(const bool theValid);
 
   /// Computes and updates name of selected object in the widget
   void updateSelectionName();
@@ -164,8 +168,6 @@ Q_OBJECT
   AttributePtr myRefAttribute;
   /// A boolean value whether refAttr uses reference of object
   bool myIsObject;
-  /// An external object
-  ObjectPtr myExternalObject;
 };
 
 #endif
index 506eeca2a858427465374e62b80fc41f18cc8bb5..2dd78afc614a4ce83c47426a911bb9c589579986 100644 (file)
@@ -42,7 +42,7 @@ bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue)
 bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& theOwner)
 {
   // stores the current values of the widget attribute
-  backupAttributeValue(true);
+  storeAttributeValue();
 
   // saves the owner value to the widget attribute
   setSelection(theOwner);
@@ -51,7 +51,7 @@ bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& the
   bool aValid = isValidAttribute();
 
   // restores the current values of the widget attribute
-  backupAttributeValue(false);
+  restoreAttributeValue(aValid);
 
   return aValid;
 }
index eea1bca0fa2707b69a799cce4d13a3bed144a662..31e7b81ac27a43e2167c06f44355b97db40e129a 100644 (file)
@@ -54,14 +54,20 @@ 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 isBackup a boolean flag, if true, store values from the attribute
-  /// to backup, otherwise set the backed up values to the attribute
-  virtual void backupAttributeValue(const bool isBackup) = 0;
+  virtual void storeAttributeValue() = 0;
+
+  /// 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
+  virtual void restoreAttributeValue(const bool theValid) = 0;
 
   /// Fills the attribute with the value of the selected owner
   /// \param theOwner a selected owner
   virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner) = 0;
 
+  virtual void removePresentations() {};
+
   /// Checks the current attibute in all attribute validators
   // \return true if all validators return that the attribute is valid
   bool isValidAttribute() const;
index f54e0fbc338c6903339998bfad411f606ee88b05..ca6f8837af133539eea5461489f6ebb84a86b29d 100644 (file)
@@ -21,11 +21,10 @@ bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSe
     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
     if ((!aSPFeature) && (!theShape->isNull())) {
-      ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
-                                                                  aSelectedObject, mySketch);
-      if (aObj) {
-        aSelectedObject = aObj;
-        myExternalObject = aObj;
+      createExternal(theSelectedObject, theShape);
+
+      if (myExternalObject) {
+        aSelectedObject = myExternalObject;
       } else 
         return false;
     }
index ea8bbaa9e7a1a2b0eb657e29f897a22826e15b16..c20eee6f35b79139a57a4a874d03020f4bd7cfbe 100644 (file)
 
 #include "PartSet.h"
 
-#include <ModuleBase_WidgetShapeSelector.h>
+#include <PartSet_WidgetShapeSelector.h>
 
 #include <ModelAPI_CompositeFeature.h>
 
 
 /**
 * \ingroup Modules
-* Customosation of ModuleBase_WidgetShapeSelector in order to provide 
+* Customosation of PartSet_WidgetShapeSelector in order to provide 
 * working with constraints.
 */
-class PARTSET_EXPORT PartSet_WidgetConstraintShapeSelector: public ModuleBase_WidgetShapeSelector
+class PARTSET_EXPORT PartSet_WidgetConstraintShapeSelector: public PartSet_WidgetShapeSelector
 {
 Q_OBJECT
  public:
@@ -31,16 +31,16 @@ Q_OBJECT
   /// \param theParentId is Id of a parent of the current attribute
   PartSet_WidgetConstraintShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
     const Config_WidgetAPI* theData, const std::string& theParentId)
-    : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) {}
+    : PartSet_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) {}
 
   virtual ~PartSet_WidgetConstraintShapeSelector() {}
 
   /// Set sketcher
   /// \param theSketch a sketcher object
-  void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
+  //void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
 
   /// Retrurns installed sketcher
-  CompositeFeaturePtr sketch() const { return mySketch; }
+  //CompositeFeaturePtr sketch() const { return mySketch; }
 
 protected:
   /// Store the values to the model attribute of the widget. It casts this attribute to
@@ -49,9 +49,9 @@ protected:
   /// \param theShape a selected shape, which is used in the selection attribute
   virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
 
-private:
+//private:
   /// Pointer to a sketch 
-  CompositeFeaturePtr mySketch;
+  //CompositeFeaturePtr mySketch;
 };
 
 #endif
\ No newline at end of file
index a7ada4a646c433a8f79b2a82c518debf7ff881c2..5c68a10159daacf2db318642c05626a5ccddb2f3 100644 (file)
 #include <PartSet_Tools.h>
 #include <SketchPlugin_Feature.h>
 
+#include <ModuleBase_IWorkshop.h>
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_Displayer.h>
+
 bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape)
 {
   ObjectPtr aSelectedObject = theSelectedObject;
@@ -25,13 +30,10 @@ bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObje
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
   if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull()) {
     // Processing of external (non-sketch) object
-    ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(aShape->impl<TopoDS_Shape>(),
-                                                                aSelectedObject, mySketch);
-    if (aObj) {
-      PartSet_WidgetShapeSelector* that = (PartSet_WidgetShapeSelector*) this;
-      aSelectedObject = aObj;
-      myExternalObject = aObj;
-    } else 
+    createExternal(theSelectedObject, theShape);
+    if (myExternalObject)
+      aSelectedObject = myExternalObject;
+    else
       return false;
   } else {
     // Processing of sketch object
@@ -74,3 +76,51 @@ bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObje
   return ModuleBase_WidgetShapeSelector::storeAttributeValues(aSelectedObject, aShape);
 }
 
+//********************************************************************
+void PartSet_WidgetShapeSelector::storeAttributeValue()
+{
+  /// this is a temporary code, will be removed when master is merged to this branch
+  /*XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  aWorkshop->displayer()->enableUpdateViewer(false);
+  */
+  ModuleBase_WidgetShapeSelector::storeAttributeValue();
+}
+
+//********************************************************************
+void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid)
+{
+  ModuleBase_WidgetShapeSelector::restoreAttributeValue(theValid);
+  //if (!theValid)
+  removeExternal();
+  /*
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  aWorkshop->displayer()->enableUpdateViewer(false);//->erase(myExternalObject);
+  aWorkshop->displayer()->enableUpdateViewer(true);*/
+}
+
+//********************************************************************
+void PartSet_WidgetShapeSelector::createExternal(ObjectPtr theSelectedObject,
+                                                 GeomShapePtr theShape)
+{
+  ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
+                                                              theSelectedObject, mySketch);
+  if (aObj != myExternalObject) {
+    removeExternal();
+    myExternalObject = aObj;
+  }
+}
+
+//********************************************************************
+void PartSet_WidgetShapeSelector::removeExternal()
+{
+  if (myExternalObject.get()) {
+    DocumentPtr aDoc = myExternalObject->document();
+    FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject);
+    if (aFeature.get() != NULL) {
+      aDoc->removeFeature(aFeature);
+    }
+    myExternalObject = NULL;
+  }
+}
index f7d075b48cfa3436574e11db2fb3c8fd15df71cb..c342e07014ccaf0f14ea7e9d45c7f3624e86258f 100644 (file)
@@ -49,9 +49,31 @@ protected:
   /// \param theShape a selected shape, which is used in the selection attribute
   virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
 
-private:
+  /// 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
+  /// \param theValid a boolean flag, if restore happens for valid parameters
+  void restoreAttributeValue(const bool theValid);
+
+  // Removes the external presentation from the model
+  /// \param theSelectedObject an object
+  /// \param theShape a selected shape, which is used in the selection attribute
+  void createExternal(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+
+  // Removes the external presentation from the model
+  void removeExternal();
+
+protected:
   /// Pointer to a sketch 
   CompositeFeaturePtr mySketch;
+
+  /// An external object
+  ObjectPtr myExternalObject;
 };
 
 #endif
\ No newline at end of file
index 9f41c9453966513889e52b16646b6e50adf9ceda..e70a8a0975dedcdab221a48d4d8c8ad9fae1e85f 100644 (file)
@@ -150,18 +150,20 @@ void PartSet_WidgetSketchLabel::enableFocusProcessing()
   myLabel->installEventFilter(this);
 }
 
-void PartSet_WidgetSketchLabel::backupAttributeValue(const bool isBackup)
+void PartSet_WidgetSketchLabel::storeAttributeValue()
+{
+}
+
+void PartSet_WidgetSketchLabel::restoreAttributeValue(const bool theValid)
 {
   // it is not necessary to save the previous plane value because the plane is chosen once
-  if (!isBackup) {
-    DataPtr aData = feature()->data();
-    AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-      (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
-    if (aSelAttr) {
-      ResultPtr anEmptyResult;
-      GeomShapePtr anEmptyShape;
-      aSelAttr->setValue(anEmptyResult, anEmptyShape);
-    }
+  DataPtr aData = feature()->data();
+  AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+    (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+  if (aSelAttr) {
+    ResultPtr anEmptyResult;
+    GeomShapePtr anEmptyShape;
+    aSelAttr->setValue(anEmptyResult, anEmptyShape);
   }
 }
 
index 3e277c68ddd585b59468e6ce4cc2335259eebc3c..a0a069f785d1248ddd8ae637da275c02dfb82904 100644 (file)
@@ -82,9 +82,13 @@ 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 isBackup a boolean flag, if true, store values from the attribute
-  /// to backup, otherwise set the backed up values to the attribute
-  virtual void backupAttributeValue(const bool isBackup);
+  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
+  /// \param theValid a boolean flag, if restore happens for valid parameters
+  virtual void restoreAttributeValue(const bool theValid);
 
   /// Fills the attribute with the value of the selected owner
   /// \param theOwner a selected owner
index 673816d770f9ea20824b9e86d6f2f614fd1d0a52..f1bc36d9b27c41994d0a79f142c99c07659b778b 100644 (file)
@@ -67,7 +67,7 @@
                 shape_types="edge vertex">
           <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
-          <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
+          <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
           <validator id="GeomValidators_EdgeOrVertex"/>
         </sketch_shape_selector>