X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGroupGUI%2FGroupGUI_GroupDlg.cxx;h=356b9e1a1095b6f896d29f6cb4ff4f530dc770df;hb=216b66c8535dccf000200f2207a2977302abb821;hp=2586fee8463a148487077a4b05b5c58f082d4c8b;hpb=dcd2885db2a2e63c230337b4746f820888e2cf08;p=modules%2Fgeom.git diff --git a/src/GroupGUI/GroupGUI_GroupDlg.cxx b/src/GroupGUI/GroupGUI_GroupDlg.cxx index 2586fee84..356b9e1a1 100644 --- a/src/GroupGUI/GroupGUI_GroupDlg.cxx +++ b/src/GroupGUI/GroupGUI_GroupDlg.cxx @@ -1,24 +1,24 @@ -// Copyright (C) 2007-2008 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) @@ -71,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(); @@ -140,9 +141,9 @@ GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QW myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj)); allSubs->setChecked(true); - myShowOnlyBtn = new QPushButton(tr("Show only selected"), GroupMedium); - myHideSelBtn = new QPushButton(tr("Hide selected"), GroupMedium); - myShowAllBtn = new QPushButton(tr("Show all sub-shapes"), GroupMedium); + myShowOnlyBtn = new QPushButton(tr("SHOW_ONLY_SELECTED"), GroupMedium); + myHideSelBtn = new QPushButton(tr("HIDE_SELECTED"), GroupMedium); + myShowAllBtn = new QPushButton(tr("SHOW_ALL_SUB_SHAPES"), GroupMedium); mySelAllBtn = new QPushButton(tr("SELECT_ALL"), GroupMedium); myAddBtn = new QPushButton(tr("ADD"), GroupMedium); @@ -168,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); @@ -179,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; + } } //================================================================================= @@ -212,11 +219,10 @@ void GroupGUI_GroupDlg::Init() aSelMgr->selectedObjects(aSelList); if (aSelList.Extent()) { - Standard_Boolean aResult = Standard_False; GEOM::GEOM_Object_var anObj = - GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult); + GEOMBase::ConvertIOinGEOMObject(aSelList.First()); - if (aResult && !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,6 +293,7 @@ void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e) //================================================================================= void GroupGUI_GroupDlg::ClickOnOk() { + setIsApplyAndClose(true); if (ClickOnApply()) ClickOnCancel(); } @@ -375,10 +382,9 @@ void GroupGUI_GroupDlg::onGetInPlace() if (aSelList.Extent() != 1) return; - Standard_Boolean aResult = Standard_False; GEOM::GEOM_Object_var anObj = - GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult); - if (aResult && !anObj->_is_nil() && 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(); @@ -454,11 +463,15 @@ void GroupGUI_GroupDlg::SelectionIntoArgument() int nbSel = aSelList.Extent(); if (nbSel == 1) { - Standard_Boolean aResult = Standard_False; GEOM::GEOM_Object_var anObj = - GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult); + GEOMBase::ConvertIOinGEOMObject(aSelList.First()); - if (aResult && !anObj->_is_nil() && 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 @@ -468,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) { + if (myBusy || myMainObj->_is_nil()) { return; } @@ -488,10 +506,15 @@ void GroupGUI_GroupDlg::SelectionIntoArgument() for (int i = 0, n = myIdList->count(); i < n; i++) aMap.insert(myIdList->item(i)->text().toInt(), i); + bool highlight = false; for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) { - if (aMap.contains(aMapIndex(ii))) + if (aMap.contains(aMapIndex(ii))) { myIdList->item(aMap[aMapIndex(ii)])->setSelected(true); + highlight = true; + } } + if (highlight) + highlightSubShapes(); } myIdList->blockSignals(isBlocked); @@ -594,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(); } } @@ -611,7 +651,8 @@ int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMap theMapIndex.Clear(); SalomeApp_Application* app = myGeomGUI->getApp(); - if (!app) return 0; + if (!app || myMainObj->_is_nil()) + return 0; LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); SALOME_ListIO aSelList; @@ -647,7 +688,7 @@ int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMap if (GEOMBase::GetShape(aGeomObj, aShape)) { if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) { TopTools_IndexedMapOfShape aMainMap; - TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myMainObj); + TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj); TopExp::MapShapes(aMainShape, aMainMap); TopExp_Explorer anExp (aShape, getShapeType()); @@ -781,6 +822,26 @@ void GroupGUI_GroupDlg::activateSelection() { 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; SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy(); if (activeStudy) @@ -796,32 +857,52 @@ void GroupGUI_GroupDlg::activateSelection() SALOME_View* aView = dynamic_cast(aViewModel); if (aView == 0) return; - TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myMainObj); + 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().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); } globalSelection(GEOM_ALLSHAPES); @@ -844,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()); @@ -879,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); @@ -905,15 +986,37 @@ void GroupGUI_GroupDlg::highlightSubShapes() SALOME_View* aView = dynamic_cast(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 published under the main shape + GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId()); + QMap childsMap; + SalomeApp_Study* appStudy = dynamic_cast(app->activeStudy()); + if (appStudy) { + _PTR(Study) aStudy = appStudy->studyDS(); + 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()) { + GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value())); + if (!CORBA::is_nil(aChild)) { + int index = aLocOp->GetSubShapeIndex(myMainObj, aChild); + CORBA::String_var aChildEntry = aChild->GetStudyEntry(); + QString anEntry = aChildEntry.in(); + childsMap.insert(index, anEntry); + } + } + } + AIS_ListIteratorOfListOfInteractive ite (List); for (; ite.More(); ite.Next()) { if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { @@ -924,8 +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"); + aSelList.Append(tmpIO); + } + } } } } @@ -1024,11 +1132,9 @@ bool GroupGUI_GroupDlg::execute(ObjectList& objects) SalomeApp_Study* study = getStudy(); if (study) { - char* objIOR = GEOMBase::GetIORFromObject(aGroup); - std::string IOR(objIOR); - free(objIOR); - if (IOR != "") { - _PTR(SObject) SO (study->studyDS()->FindObjectIOR(IOR)); + QString objIOR = GEOMBase::GetIORFromObject(aGroup); + if (objIOR != "") { + _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData())); if (SO) { _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder()); aBuilder->SetName(SO, getNewObjectName().toLatin1().constData()); @@ -1044,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) {