]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Adapt shape selector to working in local context
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 22 Dec 2014 14:58:50 +0000 (17:58 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 22 Dec 2014 14:58:50 +0000 (17:58 +0300)
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/XGUI/XGUI_ModuleConnector.cpp

index 1ef62f92a0788a56d77ea8959fb891a321d48963..73f1f9057ee7b8b31a053a424c14a06bc6d48557 100644 (file)
@@ -92,7 +92,7 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen
                                                      const Config_WidgetAPI* theData,
                                                      const std::string& theParentId)
     : ModuleBase_ModelWidget(theParent, theData, theParentId),
-      myWorkshop(theWorkshop), myIsActive(false), myUseSubShapes(false)
+      myWorkshop(theWorkshop), myIsActive(false)
 {
   myContainer = new QWidget(theParent);
   QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
@@ -120,7 +120,7 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen
   std::string aObjTypes = theData->getProperty("object_types");
   myObjectTypes = QString(aObjTypes.c_str()).split(' ', QString::SkipEmptyParts);
 
-  myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false); 
+  //myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false); 
 }
 
 //********************************************************************
@@ -137,45 +137,30 @@ bool ModuleBase_WidgetShapeSelector::storeValue() const
     return false;
 
   DataPtr aData = myFeature->data();
-  if (myUseSubShapes) {
-    ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(mySelectedObject);
-    if (aBody) {
-      AttributePtr aAttr = aData->attribute(attributeID());
-
-      // We have to check several attributes types
-      AttributeSelectionPtr aSelectAttr = 
-        std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aAttr);
-      if (aSelectAttr) {
-        aSelectAttr->setValue(aBody, myShape);
-        updateObject(myFeature);
-        return true;
-      } else {
-        AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
-        if (aRefAttr) {
-          aRefAttr->setObject(mySelectedObject);
-          updateObject(myFeature);
-          return true;
-        }
-      }
+  AttributeReferencePtr aRef = aData->reference(attributeID());
+  if (aRef) {
+    ObjectPtr aObject = aRef->value();
+    if (!(aObject && aObject->isSame(mySelectedObject))) {
+      aRef->setValue(mySelectedObject);
+      updateObject(myFeature);
+      return true;
     }
   } else {
-    AttributeReferencePtr aRef = aData->reference(attributeID());
-    if (aRef) {
-      ObjectPtr aObject = aRef->value();
+    AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
+    if (aRefAttr) {
+      ObjectPtr aObject = aRefAttr->object();
       if (!(aObject && aObject->isSame(mySelectedObject))) {
-        aRef->setValue(mySelectedObject);
+        aRefAttr->setObject(mySelectedObject);
         updateObject(myFeature);
         return true;
       }
     } else {
-      AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
-      if (aRefAttr) {
-        ObjectPtr aObject = aRefAttr->object();
-        if (!(aObject && aObject->isSame(mySelectedObject))) {
-          aRefAttr->setObject(mySelectedObject);
-          updateObject(myFeature);
-          return true;
-        }
+      AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
+      ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(mySelectedObject);
+      if (aSelectAttr && aBody && (myShape.get() != NULL)) {
+        aSelectAttr->setValue(aBody, myShape);
+        updateObject(myFeature);
+        return true;
       }
     }
   }
@@ -207,26 +192,21 @@ bool ModuleBase_WidgetShapeSelector::restoreValue()
 {
   DataPtr aData = myFeature->data();
   bool isBlocked = this->blockSignals(true);
-  if (myUseSubShapes) {
-    AttributeSelectionPtr aSelect = aData->selection(attributeID());
-    if (aSelect) {
-      mySelectedObject = aSelect->context();
-      myShape = aSelect->value();
+
+  AttributeSelectionPtr aSelect = aData->selection(attributeID());
+  if (aSelect) {
+    mySelectedObject = aSelect->context();
+    myShape = aSelect->value();
+  } else {
+    AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
+    if (aRefAttr) {
+      mySelectedObject = aRefAttr->object();
     } else {
-      AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
-      if (aRefAttr) {
-        mySelectedObject = aRefAttr->object();
+      AttributeReferencePtr aRef = aData->reference(attributeID());
+      if (aRef) {
+        mySelectedObject = aRef->value();
       }
     }
-  } else {
-    AttributeReferencePtr aRef = aData->reference(attributeID());
-    if (aRef)
-      mySelectedObject = aRef->value();
-    else {
-      AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
-      if (aRefAttr)
-        mySelectedObject = aRefAttr->object();
-    }
   }
   updateSelectionName();
 
@@ -293,21 +273,17 @@ bool ModuleBase_WidgetShapeSelector::setSelection(ModuleBase_ViewerPrs theValue)
     return false;
 
   // Get sub-shapes from local selection
-  if (myUseSubShapes) {
-    if (!theValue.shape().IsNull()) {
-      aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
-      aShape->setImpl(new TopoDS_Shape(theValue.shape()));
-    }
+  if (!theValue.shape().IsNull()) {
+    aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+    aShape->setImpl(new TopoDS_Shape(theValue.shape()));
   }
 
   // Check that the selection corresponds to selection type
-  if (myUseSubShapes) {
-    if (!acceptSubShape(aShape))
-      return false;
-  } else {
-    if (!acceptObjectShape(aObject))
-      return false;
-  }
+  if (!acceptSubShape(aShape))
+    return false;
+//  if (!acceptObjectShape(aObject))
+//      return false;
+
   if (isValid(aObject, aShape)) {
     setObject(aObject, aShape);
     return true;
@@ -328,33 +304,34 @@ void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, std::shared_ptr
 }
 
 //********************************************************************
-bool ModuleBase_WidgetShapeSelector::acceptObjectShape(const ObjectPtr theResult) const
-{
-  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theResult);
-
-  // Check that the shape of necessary type
-  std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
-  if (!aShapePtr)
-    return false;
-  TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
-  if (aShape.IsNull())
-    return false;
-
-  TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
-  if (aShapeType == TopAbs_COMPOUND) {
-    foreach (QString aType, myShapeTypes) {
-      TopExp_Explorer aEx(aShape, shapeType(aType));
-      if (aEx.More())
-        return true;
-    }
-  } else {
-    foreach (QString aType, myShapeTypes) {
-      if (shapeType(aType) == aShapeType)
-        return true;
-    }
-  }
-  return false;
-}
+//bool ModuleBase_WidgetShapeSelector::acceptObjectShape(const ObjectPtr theResult) const
+//{
+//  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theResult);
+//
+//  // Check that the shape of necessary type
+//  std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
+//  if (!aShapePtr)
+//    return false;
+//  TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
+//  if (aShape.IsNull())
+//    return false;
+//
+//  TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
+//  if (aShapeType == TopAbs_COMPOUND) {
+//    foreach (QString aType,
+//      myShapeTypes) {
+//      TopExp_Explorer aEx(aShape, shapeType(aType));
+//      if (aEx.More())
+//        return true;
+//    }
+//  } else {
+//    foreach (QString aType, myShapeTypes) {
+//      if (shapeType(aType) == aShapeType)
+//        return true;
+//    }
+//  }
+//  return false;
+//}
 
 //********************************************************************
 bool ModuleBase_WidgetShapeSelector::acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const
@@ -412,27 +389,23 @@ void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate)
 
   if (myIsActive) {
     connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
-    if (myUseSubShapes) {
-
-      QIntList aList;
-      foreach (QString aType, myShapeTypes)
-        aList.append(shapeType(aType));
-      myWorkshop->activateSubShapesSelection(aList);
-      if (!myObjectTypes.isEmpty()) {
-        myObjTypeFilter = new ModuleBase_ObjectTypesFilter(myWorkshop, myObjectTypes);
-        aViewer->clearSelectionFilters();
-        aViewer->addSelectionFilter(myObjTypeFilter);
-      }
+    QIntList aList;
+    foreach (QString aType, myShapeTypes) {
+      aList.append(shapeType(aType));
+    }
+    myWorkshop->activateSubShapesSelection(aList);
+    if (!myObjectTypes.isEmpty()) {
+      myObjTypeFilter = new ModuleBase_ObjectTypesFilter(myWorkshop, myObjectTypes);
+      aViewer->clearSelectionFilters();
+      aViewer->addSelectionFilter(myObjTypeFilter);
     }
   } else {
     disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
-    if (myUseSubShapes) {
-      if (!myObjTypeFilter.IsNull()) {
-        aViewer->removeSelectionFilter(myObjTypeFilter);
-        myObjTypeFilter.Nullify();
-      }
-      myWorkshop->deactivateSubShapesSelection();
+    if (!myObjTypeFilter.IsNull()) {
+      aViewer->removeSelectionFilter(myObjTypeFilter);
+      myObjTypeFilter.Nullify();
     }
+    myWorkshop->deactivateSubShapesSelection();
   }
   // apply filters loaded from the XML definition of the widget
   ModuleBase_FilterFactory* aFactory = myWorkshop->selectionFilters();
index a64932a247c8056265864b62b45ae6f7a1329019..7757d3141070cc520073ac17c7d3a7e7f4d971cd 100644 (file)
@@ -84,7 +84,7 @@ Q_OBJECT
 
   /// Returns true if shape of given object corresponds to requested shape type
   /// This method is called only in non sub-shapes selection mode
-  virtual bool acceptObjectShape(const ObjectPtr theObject) const;
+  //virtual bool acceptObjectShape(const ObjectPtr theObject) const;
 
   /// Returns true if selected shape corresponds to requested shape types
   /// This method is called only in sub-shapes selection mode
@@ -118,9 +118,6 @@ Q_OBJECT
   QStringList myShapeTypes;
   QStringList myObjectTypes;
 
-  /// If true then local selector has to be activated in context
-  bool myUseSubShapes;
-
   bool myIsActive;
 
   Handle(ModuleBase_ObjectTypesFilter) myObjTypeFilter;
index 04f026112ce43b54ca6d18f01898b82081209fe0..bd9a98be5be667b2989e0bb8cb8b7df8fc45127d 100644 (file)
@@ -33,7 +33,7 @@ bool PartSet_WidgetShapeSelector::storeValue() const
   } else {
     // Processing of sketch object
     DataPtr aData = myFeature->data();
-    if (myUseSubShapes && myShape) {
+    if (myShape) {
       AttributePtr aAttr = aData->attribute(attributeID());
       AttributeRefAttrPtr aRefAttr = 
         std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
index 970cb045c6aad989e23ec9d9b9dbe54ace120437..c53bc38f41cb3ed50a53b11948f59e96d0ebb6d5 100644 (file)
@@ -72,6 +72,9 @@ void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
 void XGUI_ModuleConnector::deactivateSubShapesSelection()
 {
   XGUI_Displayer* aDisp = myWorkshop->displayer();
+  // Clear selection modes
+  QIntList aModes;
+  aDisp->activateObjects(aModes);
   // The document limitation selection has to be only during operation
   //aDisp->removeSelectionFilter(myDocumentShapeFilter);
   //aDisp->closeLocalContexts(false);