Salome HOME
Use AttributeSelection for Extrusion operation
[modules/shaper.git] / src / XGUI / XGUI_Displayer.cpp
index 57befeb24cb8958c3aac8acd0b1f935a1452cf8d..6ac7aca9a875a3d77fe8e5e1aaac85302ec4e01e 100644 (file)
@@ -20,7 +20,6 @@
 #include <AIS_ListOfInteractive.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <AIS_DimensionSelectionMode.hxx>
-
 #include <AIS_Shape.hxx>
 
 #include <set>
@@ -36,7 +35,7 @@ XGUI_Displayer::~XGUI_Displayer()
 {
 }
 
-bool XGUI_Displayer::isVisible(ObjectPtr theObject)
+bool XGUI_Displayer::isVisible(ObjectPtr theObject) const
 {
   return myResult2AISObjectMap.find(theObject) != myResult2AISObjectMap.end();
 }
@@ -49,6 +48,7 @@ void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
     boost::shared_ptr<GeomAPI_AISObject> anAIS;
 
     GeomPresentablePtr aPrs = boost::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
+    bool isShading = false;
     if (aPrs) {
       anAIS = aPrs->getAISObject(boost::shared_ptr<GeomAPI_AISObject>());
     } else {
@@ -58,23 +58,27 @@ void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
         if (aShapePtr) {
           anAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
           anAIS->createShape(aShapePtr);
+          isShading = true;
         }
       }
     }
     if (anAIS)
-      display(theObject, anAIS, isUpdateViewer);
+      display(theObject, anAIS, isShading, isUpdateViewer);
   }
 }
 
-void XGUI_Displayer::display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS,
-                             bool isUpdateViewer)
+void XGUI_Displayer::display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS, 
+                             bool isShading, bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return;
 
   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
   if (!anAISIO.IsNull()) {
     myResult2AISObjectMap[theObject] = theAIS;
-    aContext->Display(anAISIO, isUpdateViewer);
+    aContext->Display(anAISIO, false);
+    aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, isUpdateViewer);
   }
 }
 
@@ -84,6 +88,8 @@ void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
     return;
 
   Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return;
   boost::shared_ptr<GeomAPI_AISObject> anObject = myResult2AISObjectMap[theObject];
   if (anObject) {
     Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
@@ -94,36 +100,6 @@ void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
   myResult2AISObjectMap.erase(theObject);
 }
 
-/*bool XGUI_Displayer::redisplay(ObjectPtr theObject,
- boost::shared_ptr<GeomAPI_AISObject> theAIS,
- const bool isUpdateViewer)
- {
- bool isCreated = false;
- Handle(AIS_InteractiveObject) anAIS = 
- theAIS ? theAIS->impl<Handle(AIS_InteractiveObject)>() : Handle(AIS_InteractiveObject)();
- Handle(AIS_InteractiveContext) aContext = AISContext();
- // Open local context if there is no one
- if (!aContext->HasOpenedContext()) {
- aContext->ClearCurrents(false);
- aContext->OpenLocalContext(false /use displayed objects/, true /allow shape decomposition/);
- // set mouse sensitivity
- //aContext->SetSensitivityMode(StdSelect_SM_WINDOW);
- //aContext->SetPixelTolerance(MOUSE_SENSITIVITY_IN_PIXEL);
- }
- // display or redisplay presentation
- boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[theObject];
- if (isVisible(theObject) && anObj && !anObj->empty()) {
- aContext->Redisplay(anAIS, isUpdateViewer);
- //aContext->RecomputeSelectionOnly(anAIS);
- }
- else {
- myResult2AISObjectMap[theObject] = theAIS;
- aContext->Display(anAIS, isUpdateViewer);
- isCreated = true;
- }
- return isCreated;
- }*/
-
 void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
 {
   if (!isVisible(theObject))
@@ -155,6 +131,8 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
   }
   if (!aAISIO.IsNull()) {
     Handle(AIS_InteractiveContext) aContext = AISContext();
+    if (aContext.IsNull())
+      return;
     aContext->Redisplay(aAISIO, isUpdateViewer);
     //if (aContext->HasOpenedContext()) {
     //  aContext->Load(aAISIO, -1, true/*allow decomposition*/);
@@ -166,10 +144,14 @@ void XGUI_Displayer::activateInLocalContext(ObjectPtr theResult, const std::list
                                             const bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return;
   // Open local context if there is no one
   if (!aContext->HasOpenedContext()) {
     aContext->ClearCurrents(false);
-    aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/);
+    //aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/);
+    aContext->OpenLocalContext();
+    aContext->NotUseDisplayedObjects();
   }
   // display or redisplay presentation
   Handle(AIS_InteractiveObject) anAIS;
@@ -200,6 +182,8 @@ void XGUI_Displayer::deactivate(ObjectPtr theObject)
 {
   if (isVisible(theObject)) {
     Handle(AIS_InteractiveContext) aContext = AISContext();
+    if (aContext.IsNull())
+      return;
 
     boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[theObject];
     Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
@@ -211,6 +195,8 @@ void XGUI_Displayer::activate(ObjectPtr theObject)
 {
   if (isVisible(theObject)) {
     Handle(AIS_InteractiveContext) aContext = AISContext();
+    if (aContext.IsNull())
+      return;
 
     boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[theObject];
     Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
@@ -218,10 +204,28 @@ void XGUI_Displayer::activate(ObjectPtr theObject)
   }
 }
 
+bool XGUI_Displayer::isActive(ObjectPtr theObject) const
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return false;
+  if (!isVisible(theObject))
+    return false;
+    
+  boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap.at(theObject);
+  Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
+
+  TColStd_ListOfInteger aModes;
+  aContext->ActivatedModes(anAIS, aModes);
+  return aModes.Extent() > 0;
+}
+
 void XGUI_Displayer::stopSelection(const QList<ObjectPtr>& theResults, const bool isStop,
                                    const bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return;
 
   Handle(AIS_Shape) anAIS;
   QList<ObjectPtr>::const_iterator anIt = theResults.begin(), aLast = theResults.end();
@@ -278,29 +282,30 @@ void XGUI_Displayer::setSelected(const QList<ObjectPtr>& theResults, const bool
     updateViewer();
 }
 
-/*void XGUI_Displayer::EraseAll(const bool isUpdateViewer)
- {
- Handle(AIS_InteractiveContext) ic = AISContext();
-
- AIS_ListOfInteractive aList;
- ic->DisplayedObjects(aList);
- AIS_ListIteratorOfListOfInteractive anIter(aList);
- for (; anIter.More(); anIter.Next()) {
- if ((anIter.Value()->DynamicType() == STANDARD_TYPE(AIS_Trihedron)))
- continue;
+void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
+{
+  Handle(AIS_InteractiveContext) ic = AISContext();
+  if (ic.IsNull())
+    return;
 
- // erase an object
- Handle(AIS_InteractiveObject) anIO = anIter.Value();
- ic->Erase(anIO, false);
+   ResultToAISMap::iterator aIt;
+   for (aIt = myResult2AISObjectMap.begin(); aIt != myResult2AISObjectMap.end(); aIt++) {
+     // erase an object
+     boost::shared_ptr<GeomAPI_AISObject> aAISObj = (*aIt).second;
+     Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+     if (!anIO.IsNull())
+      ic->Remove(anIO, false);
+   }
+   myResult2AISObjectMap.clear();
+   if (isUpdateViewer)
+     updateViewer();
  }
- myResult2AISObjectMap.clear();
- if (isUpdateViewer)
- updateViewer();
- }*/
 
 void XGUI_Displayer::eraseDeletedResults(const bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return;
 
   ResultToAISMap::const_iterator aFIt = myResult2AISObjectMap.begin(), aFLast =
       myResult2AISObjectMap.end();
@@ -327,8 +332,23 @@ void XGUI_Displayer::eraseDeletedResults(const bool isUpdateViewer)
     updateViewer();
 }
 
+void XGUI_Displayer::openLocalContext()
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return;
+  // Open local context if there is no one
+  if (!aContext->HasOpenedContext()) {
+    aContext->ClearCurrents(false);
+    //aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/);
+    aContext->OpenLocalContext();
+    aContext->NotUseDisplayedObjects();
+  }
+}
+
 void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
 {
+  AISContext()->ClearSelected(false);
   closeAllContexts(true);
 }
 
@@ -396,3 +416,66 @@ void XGUI_Displayer::erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bo
   }
 }
 
+void XGUI_Displayer::activateObjectsOutOfContext(const std::list<int>& theModes, 
+                                                 Handle(SelectMgr_Filter) theFilter)
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  // Open local context if there is no one
+  if (!aContext->HasOpenedContext()) 
+    return;
+
+  aContext->UseDisplayedObjects();
+  std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
+  for (; anIt != aLast; anIt++) {
+    aContext->ActivateStandardMode((TopAbs_ShapeEnum)(*anIt));
+  }
+
+  if (!theFilter.IsNull())
+    aContext->AddFilter(theFilter);
+}
+
+
+void XGUI_Displayer::deactivateObjectsOutOfContext()
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  // Open local context if there is no one
+  if (!aContext->HasOpenedContext()) 
+    return;
+
+  aContext->RemoveFilters();
+  aContext->NotUseDisplayedObjects();
+}
+
+
+void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate)
+{
+  if (theMode == NoMode)
+    return;
+
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return;
+
+  boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(theObject);
+  if (!aAISObj)
+    return;
+
+  Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+  aContext->SetDisplayMode(aAISIO, theMode, toUpdate);
+}
+
+
+XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return NoMode;
+
+  boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(theObject);
+  if (!aAISObj)
+    return NoMode;
+
+  Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+  return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
+}
+