Salome HOME
Remove "MAC" ends of lines
[modules/geom.git] / src / GroupGUI / GroupGUI_GroupDlg.cxx
index fc31bb34c213d763c50201544f31f2552b825b4d..356b9e1a1095b6f896d29f6cb4ff4f530dc770df 100644 (file)
@@ -1,29 +1,28 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-//
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 
 //  GEOM GEOMGUI : GUI for Geometry component
 //  File   : GroupGUI_GroupDlg.cxx
 //  Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
-//
+
 #include "GroupGUI_GroupDlg.h"
 
 #include <DlgRef.h>
@@ -72,7 +71,8 @@ GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QW
   : GEOMBase_Skeleton(theGeometryGUI, parent, false),
     myMode(mode),
     myBusy(false),
-    myIsShapeType(false)
+    myIsShapeType(false),
+    myIsHiddenMain(false)
 {
   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
 
@@ -169,7 +169,7 @@ GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QW
   aMedLayout->addWidget(myAddBtn,           6, 3);
   aMedLayout->addWidget(myRemBtn,           7, 3);
 
-  aMedLayout->setColumnStretch( 2, 5 );
+  aMedLayout->setColumnStretch(2, 5);
   aMedLayout->setRowStretch(5, 5);
   aMedLayout->setRowStretch(8, 5);
 
@@ -180,10 +180,16 @@ GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QW
   setHelpFileName("work_with_groups_page.html");
 
   Init();
+  updateState();
 }
 
 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
 {
+  if (myIsHiddenMain) {
+    GEOM_Displayer* aDisplayer = getDisplayer();
+    aDisplayer->Display(myMainObj);
+    myIsHiddenMain = false;
+  }
 }
 
 //=================================================================================
@@ -214,9 +220,9 @@ void GroupGUI_GroupDlg::Init()
 
     if (aSelList.Extent()) {
       GEOM::GEOM_Object_var anObj =
-        GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
+        GEOMBase::ConvertIOinGEOMObject(aSelList.First());
 
-      if ( !CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP ) {
+      if (!CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
         myGroup = anObj;
 
         mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
@@ -287,7 +293,7 @@ void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
 //=================================================================================
 void GroupGUI_GroupDlg::ClickOnOk()
 {
-  setIsApplyAndClose( true );
+  setIsApplyAndClose(true);
   if (ClickOnApply())
     ClickOnCancel();
 }
@@ -377,8 +383,8 @@ void GroupGUI_GroupDlg::onGetInPlace()
     return;
 
   GEOM::GEOM_Object_var anObj =
-    GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
-  if ( GEOMBase::IsShape(anObj) ) {
+    GEOMBase::ConvertIOinGEOMObject(aSelList.First());
+  if (GEOMBase::IsShape(anObj)) {
     if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
       SUIT_OverrideCursor wc;
       myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
@@ -422,10 +428,13 @@ void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool i
     GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
     for (int i = 0; i < aSubObjects->length(); i++)
     {
-      CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex(myMainObj, aSubObjects[i]);
-      CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex(myInPlaceObj, aSubObjects[i]);
-      if (aMainIndex >= 0 && aPlaceIndex > 0)
-        myMain2InPlaceIndices.Bind(aMainIndex, aPlaceIndex);
+      GEOM::GEOM_Object_var aSS = aShapesOp->GetSame(myMainObj, aSubObjects[i]);
+      if (!CORBA::is_nil(aSS)) {
+        CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex(myMainObj, aSS);
+        CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex(myInPlaceObj, aSubObjects[i]);
+        if (aMainIndex >= 0 && aPlaceIndex > 0)
+          myMain2InPlaceIndices.Bind(aMainIndex, aPlaceIndex);
+      }
     }
   }
   myInPlaceObjSelectState = subSelectionWay();
@@ -455,9 +464,14 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
 
     if (nbSel == 1) {
       GEOM::GEOM_Object_var anObj =
-        GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
+        GEOMBase::ConvertIOinGEOMObject(aSelList.First());
 
-      if ( GEOMBase::IsShape(anObj) ) {
+      if (GEOMBase::IsShape(anObj)) {
+        if (myIsHiddenMain) {
+          GEOM_Displayer* aDisplayer = getDisplayer();
+          aDisplayer->Display(myMainObj);
+          myIsHiddenMain = false;
+        }
         myMainObj = anObj;
         myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
         // activate subshapes selection by default
@@ -467,11 +481,16 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
       }
     }
     else {
+      if (myIsHiddenMain) {
+        GEOM_Displayer* aDisplayer = getDisplayer();
+        aDisplayer->Display(myMainObj);
+        myIsHiddenMain = false;
+      }
       myMainObj = GEOM::GEOM_Object::_nil();
     }
   }
   else { // an attempt to synchronize list box selection with 3d viewer
-    if ( myBusy || myMainObj->_is_nil() ) {
+    if (myBusy || myMainObj->_is_nil()) {
       return;
     }
 
@@ -494,7 +513,7 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
           highlight = true;
         }
       }
-      if ( highlight )
+      if (highlight)
         highlightSubShapes();
     }
     myIdList->blockSignals(isBlocked);
@@ -598,11 +617,28 @@ void GroupGUI_GroupDlg::showOnlySelected()
   GEOM_Displayer* aDisplayer = getDisplayer();
 
   if (send == myHideSelBtn) {
-    aDisplayer->Erase(aSelList, false, true);
+    aDisplayer->Erase(aSelList, /*forced=*/false, /*updateViewer=*/true);
   }
   else {
-    aDisplayer->EraseAll();
+    // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
+    SALOME_View* view = GEOM_Displayer::GetActiveView();
+    if (view) {
+      CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
+      Handle(SALOME_InteractiveObject) io =
+        new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
+      if (view->isVisible(io)) myIsHiddenMain = true;
+    }
+
+    aDisplayer->EraseAll(/*forced = false, updateViewer = true*/);
     aDisplayer->Display(aSelList, true);
+
+    // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
+    if (getShapeType() == TopAbs_VERTEX && myIsHiddenMain) {
+      aDisplayer->Display(myMainObj);
+    }
+
+    // for the case when selected ids were not displayed in the viewer: Mantis issue 0021367
+    highlightSubShapes();
   }
 }
 
@@ -615,7 +651,7 @@ int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMap
   theMapIndex.Clear();
 
   SalomeApp_Application* app = myGeomGUI->getApp();
-  if ( !app || myMainObj->_is_nil() )
+  if (!app || myMainObj->_is_nil())
     return 0;
 
   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
@@ -785,6 +821,25 @@ void GroupGUI_GroupDlg::activateSelection()
       myIsShapeType) // check if shape type is already choosen by user
   {
     GEOM_Displayer* aDisplayer = getDisplayer();
+
+    // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
+    if (getShapeType() == TopAbs_VERTEX) {
+      if (myIsHiddenMain)
+        aDisplayer->Display(myMainObj);
+    }
+    else {
+      SALOME_View* view = GEOM_Displayer::GetActiveView();
+      if (view) {
+        CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
+        Handle(SALOME_InteractiveObject) io =
+          new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
+        if (view->isVisible(io)) {
+          aDisplayer->Erase(myMainObj, false, false);
+          myIsHiddenMain = true;
+        }
+      }
+    }
+
     int prevDisplayMode = aDisplayer->SetDisplayMode(0);
 
     SUIT_ViewWindow* aViewWindow = 0;
@@ -804,29 +859,48 @@ void GroupGUI_GroupDlg::activateSelection()
 
     TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
     TopoDS_Shape aRestrictionShape;
-    if (subSelectionWay() == ALL_SUBSHAPES)
-      aRestrictionShape = aMainShape;
-    else if (!myInPlaceObj->_is_nil())
-      aRestrictionShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myInPlaceObj);
-    else ;
-
-    TopTools_IndexedMapOfShape aSubShapesMap;
-    TopExp::MapShapes(aMainShape, aSubShapesMap);
-    CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
-    QString anEntryBase = aMainEntry.in();
 
-    TopExp_Explorer anExp (aRestrictionShape, getShapeType());
-    for (; anExp.More(); anExp.Next())
-    {
-      TopoDS_Shape aSubShape = anExp.Current();
-      int index = aSubShapesMap.FindIndex(aSubShape);
-      QString anEntry = anEntryBase + QString("_%1").arg(index);
+    if (subSelectionWay() == ALL_SUBSHAPES) {
+      aRestrictionShape = aMainShape;
 
-      SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
-      if (aPrs) {
-        displayPreview(aPrs, true, false); // append, do not update
+      TopTools_IndexedMapOfShape aSubShapesMap;
+      TopExp::MapShapes(aMainShape, aSubShapesMap);
+      CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
+      QString anEntryBase = aMainEntry.in();
+
+      TopExp_Explorer anExp (aRestrictionShape, getShapeType());
+      for (; anExp.More(); anExp.Next()) {
+        TopoDS_Shape aSubShape = anExp.Current();
+        int index = aSubShapesMap.FindIndex(aSubShape);
+        QString anEntry = anEntryBase + QString("_%1").arg(index);
+
+        SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
+        if (aPrs) {
+          displayPreview(aPrs, true, false); // append, do not update
+          // TODO: map or delete Prs
+        }
       }
     }
+    else if (!myInPlaceObj->_is_nil()) {
+      TopTools_IndexedMapOfShape aSubShapesMap;
+      TopExp::MapShapes(aMainShape, aSubShapesMap);
+      CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
+      QString anEntryBase = aMainEntry.in();
+
+      TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
+      for (; aM2IPit.More(); aM2IPit.Next()) {
+        int index = aM2IPit.Key();
+        TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
+        QString anEntry = anEntryBase + QString("_%1").arg(index);
+
+        SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
+        if (aPrs) {
+          displayPreview(aPrs, true, false); // append, do not update
+        }
+      }
+    }
+    else ;
+
     aDisplayer->UpdateViewer();
     aDisplayer->SetDisplayMode(prevDisplayMode);
   }
@@ -851,7 +925,7 @@ void GroupGUI_GroupDlg::updateState (bool isAdd)
   myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
   mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
 
-  mySelBtn2->setEnabled(   subSelectionWay() != ALL_SUBSHAPES);
+  mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
   myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
   if (subSelectionWay() == ALL_SUBSHAPES)
     setInPlaceObj(GEOM::GEOM_Object::_nil());
@@ -886,7 +960,7 @@ void GroupGUI_GroupDlg::highlightSubShapes()
       int id = myIdList->item(ii)->text().toInt();
       if (subSelectionWay() != ALL_SUBSHAPES &&
           !myMain2InPlaceIndices.IsBound(id)) {
-        myIdList->item(ii)->setSelected(false);
+        //myIdList->item(ii)->setSelected(false);
       }
       else {
         anIds.Add(id);
@@ -912,16 +986,17 @@ void GroupGUI_GroupDlg::highlightSubShapes()
   SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
   if (aView == 0) return;
 
-  // TODO: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
+  // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
 
   OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
   Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
   AIS_ListOfInteractive List;
-  ic->DisplayedObjects(List);
+  //ic->DisplayedObjects(List);
+  ic->ObjectsInside(List); // Mantis issue 0021367
 
   SALOME_ListIO aSelList;
 
-  // To highlight the selected subshape in Object Browser, if it's already pudlished under the main shape
+  // To highlight the selected subshape in Object Browser, if it's already published under the main shape
   GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
   QMap<int, QString> childsMap;
   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
@@ -930,10 +1005,10 @@ void GroupGUI_GroupDlg::highlightSubShapes()
     CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
     QString anEntry = aMainEntry.in();
     _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
-    _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
-    for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
+    _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
+    for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
       GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
-      if ( !CORBA::is_nil( aChild ) ) {
+      if (!CORBA::is_nil(aChild)) {
         int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
         CORBA::String_var aChildEntry = aChild->GetStudyEntry();
         QString anEntry = aChildEntry.in();
@@ -952,13 +1027,13 @@ void GroupGUI_GroupDlg::highlightSubShapes()
         int index = anEntry.lastIndexOf("_");
         anEntry.remove(0, index+1);
         int anIndex = anEntry.toInt();
-        if ( anIds.Contains(anIndex) ) {
+        if (anIds.Contains(anIndex)) {
           aSelList.Append(anIO);
-          if ( childsMap.contains ( anIndex )) {
-            Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject( childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO" );
+          if (childsMap.contains (anIndex)) {
+            Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
             aSelList.Append(tmpIO);
           }
-        } 
+        }
       }
     }
   }
@@ -1075,7 +1150,7 @@ bool GroupGUI_GroupDlg::execute(ObjectList& objects)
 //================================================================
 // Function : getFather
 // Purpose  : Get father object for object to be added in study
-//            ( called with addInStudy method )
+//            (called with addInStudy method)
 //================================================================
 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
 {