]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
authormpv <mikhail.ponikarov@opencascade.com>
Mon, 22 Dec 2014 15:22:39 +0000 (18:22 +0300)
committermpv <mikhail.ponikarov@opencascade.com>
Mon, 22 Dec 2014 15:22:39 +0000 (18:22 +0300)
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/XGUI/XGUI_Displayer.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 b0a119a709c637905a7015c9b1738e98b2c213ad..3f0846de18d86f9a4b894c193878ccf558bc29af 100644 (file)
 
 const int MOUSE_SENSITIVITY_IN_PIXEL = 10;  ///< defines the local context mouse selection sensitivity
 
+
+// Workaround for bug #25637
+void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
+{
+  // Get from null point
+  theAIS->DisplayedObjects(theList, true);
+  if (theAIS->HasOpenedContext()) {
+    // get from local context
+    const Handle(AIS_LocalContext)& aLC = theAIS->LocalContext();
+    TColStd_MapOfTransient aMap;
+    int NbDisp = aLC->DisplayedObjects(aMap);
+    TColStd_MapIteratorOfMapOfTransient aIt(aMap);
+
+    Handle(AIS_InteractiveObject) curIO;
+    Handle(Standard_Transient) Tr;
+    for(; aIt.More(); aIt.Next()){
+      Tr = aIt.Key();
+      curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
+      theList.Append(curIO);
+    }
+  }
+}
+
+
 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
   : myWorkshop(theWorkshop)
 {
@@ -81,6 +105,20 @@ void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
   }
 }
 
+bool canBeShaded(Handle(AIS_InteractiveObject) theAIS)
+{
+  Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(theAIS);
+  if (!aShapePrs.IsNull()) {
+    TopoDS_Shape aShape = aShapePrs->Shape();
+    TopAbs_ShapeEnum aType = aShape.ShapeType();
+    if ((aType == TopAbs_VERTEX) || (aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
+      return false;
+    else
+      return true;
+  }
+  return false;
+}
+
 void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, 
                              bool isShading, bool isUpdateViewer)
 {
@@ -91,9 +129,13 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
   if (!anAISIO.IsNull()) {
     myResult2AISObjectMap[theObject] = theAIS;
-
-    closeLocalContexts(false);
+    bool aCanBeShaded = canBeShaded(anAISIO);
+    // In order to avoid extra closing/opening context
+    if (aCanBeShaded)
+      closeLocalContexts(false);
     aContext->Display(anAISIO, false);
+    qDebug("### Display %i", (long)anAISIO.Access());
+
     aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
     // Customization of presentation
     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
@@ -102,20 +144,11 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
       if (aCustPrs.get() != NULL)
         aCustPrs->customisePresentation(theAIS);
     }
-    openLocalContext();
+    if (aCanBeShaded)
+      openLocalContext();
+
     aContext->Load(anAISIO, -1, true);
     activate(theObject);
-    //if (aContext->HasOpenedContext()) {
-      //if (myUseExternalObjects) {
-        //if (myActiveSelectionModes.size() == 0)
-        //  aContext->Activate(anAISIO);
-        //else {
-        //  foreach(int aMode, myActiveSelectionModes) {
-        //    aContext->Activate(anAISIO, aMode);
-        //  }
-        //}
-      //}
-    //}
   }
   if (isUpdateViewer)
     updateViewer();
@@ -178,6 +211,7 @@ void XGUI_Displayer::deactivate(ObjectPtr theObject)
     AISObjectPtr anObj = myResult2AISObjectMap[theObject];
     Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
     aContext->Deactivate(anAIS);
+    qDebug("### Deactivate obj %i", (long)anAIS.Access());
   }
 }
 
@@ -203,9 +237,12 @@ void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
     if (theModes.size() > 0) {
       foreach(int aMode, theModes) {
         aContext->Activate(anAIS, aMode);
+        qDebug("### 1. Activate obj %i, %i", (long)anAIS.Access(), aMode);
       }
-    } else 
+    } else {
       aContext->Activate(anAIS);
+      qDebug("### 2. Activate obj %i", (long)anAIS.Access());
+    }
   }
 }
 
@@ -226,26 +263,26 @@ void XGUI_Displayer::activateObjects(const QIntList& theModes)
   //myUseExternalObjects = true;
 
   AIS_ListOfInteractive aPrsList;
-  aContext->DisplayedObjects(aPrsList, true);
-  //Deactivate trihedron which can be activated in local selector
+  displayedObjects(aContext, aPrsList);
 
   Handle(AIS_Trihedron) aTrihedron;
   AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
   Handle(AIS_InteractiveObject) anAISIO;
   for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
     anAISIO = aLIt.Value();
+    aContext->Deactivate(anAISIO);
     aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO);
-    if (!aTrihedron.IsNull()) {
-      aContext->Deactivate(aTrihedron);
-    } else {
+    //Deactivate trihedron which can be activated in local selector
+    if (aTrihedron.IsNull()) {
       //aContext->Load(anAISIO, -1, true);
       // In order to clear active modes list
-      aContext->Deactivate(anAISIO);
-      if (myActiveSelectionModes.size() == 0)
+      if (myActiveSelectionModes.size() == 0) {
         aContext->Activate(anAISIO);
-      else {
+        qDebug("### 2. Activate all %i", (long)anAISIO.Access());
+      } else {
         foreach(int aMode, myActiveSelectionModes) {
           aContext->Activate(anAISIO, aMode);
+          qDebug("### 1. Activate all %i, %i", (long)anAISIO.Access(), aMode);
         }
       }
     }
@@ -261,21 +298,20 @@ void XGUI_Displayer::deactivateObjects()
   if (!aContext->HasOpenedContext()) 
     return;
 
-  aContext->NotUseDisplayedObjects();
+  //aContext->NotUseDisplayedObjects();
   AIS_ListOfInteractive aPrsList;
-  aContext->DisplayedObjects(aPrsList);
+  displayedObjects(aContext, aPrsList);
 
   AIS_ListIteratorOfListOfInteractive aLIt;
   Handle(AIS_Trihedron) aTrihedron;
   Handle(AIS_InteractiveObject) anAISIO;
   for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
     anAISIO = aLIt.Value();
+    aContext->Deactivate(anAISIO);
     aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO);
-    if (!aTrihedron.IsNull()) {
-      aContext->Deactivate(aTrihedron);
-    } else {
+    if (aTrihedron.IsNull()) {
       //aContext->Load(anAISIO, -1, true);
-      aContext->Deactivate(anAISIO);
+      qDebug("### Deactivate all %i", (long)anAISIO.Access());
       //aContext->Activate(anAISIO);
     }
   }
@@ -439,8 +475,9 @@ void XGUI_Displayer::openLocalContext()
     // in the closeLocalContex, which restore the global context filters
     aContext->RemoveFilters();
 
-    aContext->ClearCurrents();
+    //aContext->ClearCurrents();
     aContext->OpenLocalContext();
+    qDebug("### Open context");
     //aContext->NotUseDisplayedObjects();
 
     //myUseExternalObjects = false;
@@ -472,8 +509,9 @@ void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
     SelectMgr_ListOfFilter aFilters;
     aFilters.Assign(aContext->Filters());
 
-    aContext->ClearSelected();
+    //aContext->ClearSelected();
     aContext->CloseAllContexts(false);
+    qDebug("### Close context");
 
     // Redisplay all object if they were displayed in localContext
     Handle(AIS_InteractiveObject) aAISIO;
@@ -544,6 +582,7 @@ Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
   if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) {
     aContext->OpenLocalContext();
+    qDebug("### Open context");
   }
   return aContext;
 }
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);