X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FEntityGUI%2FEntityGUI_SubShapeDlg.cxx;h=9dc4679bfc4f164a8f15f9a726ed1e29b2566ef6;hb=d2046800b5f3ab6a56c3b9a72766f5d317a235e7;hp=28923363f96328ddce47784d36515dc984595c52;hpb=c577ca78d7a6e286526662cf54df6de1f4f2f449;p=modules%2Fgeom.git diff --git a/src/EntityGUI/EntityGUI_SubShapeDlg.cxx b/src/EntityGUI/EntityGUI_SubShapeDlg.cxx index 28923363f..9dc4679bf 100644 --- a/src/EntityGUI/EntityGUI_SubShapeDlg.cxx +++ b/src/EntityGUI/EntityGUI_SubShapeDlg.cxx @@ -1,77 +1,93 @@ -// GEOM GEOMGUI : GUI for Geometry component +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 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 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// 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 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 +// +// GEOM GEOMGUI : GUI for Geometry component +// File : EntityGUI_SubShapeDlg.cxx +// Author : Lucien PIGNOLONI, Open CASCADE S.A.S. // -// File : EntityGUI_SubShapeDlg.cxx -// Author : Lucien PIGNOLONI -// Module : GEOM -// $Header$ - -using namespace std; #include "EntityGUI_SubShapeDlg.h" -#include "DisplayGUI.h" -#include "QAD_RightFrame.h" -#include "OCCViewer_Viewer3d.h" - +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include #include #include -#include +#include //================================================================================= -// class : EntityGUI_SubShapeDlg() +// class : EntityGUI_SubShapeDlg // purpose : Constructs a EntityGUI_SubShapeDlg which is a child of 'parent', with the // name 'name' and widget flags set to 'f'. // The dialog will by default be modeless, unless you set 'modal' to // TRUE to construct a modal dialog. //================================================================================= -EntityGUI_SubShapeDlg::EntityGUI_SubShapeDlg(QWidget* parent, const char* name, EntityGUI* theEntityGUI, SALOME_Selection* Sel, Handle(AIS_InteractiveContext) ic, bool modal, WFlags fl) - :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) +EntityGUI_SubShapeDlg::EntityGUI_SubShapeDlg( GeometryGUI* theGeometryGUI, QWidget* parent, + bool modal, Qt::WindowFlags fl ) + : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ) { - QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SUBSHAPE"))); - QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT"))); + QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SUBSHAPE" ) ) ); + QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); - setCaption(tr("GEOM_SUBSHAPE_TITLE")); + setWindowTitle( tr( "GEOM_SUBSHAPE_TITLE" ) ); /***************************************************************/ - GroupConstructors->setTitle(tr("GEOM_SUB_SHAPE")); - RadioButton1->setPixmap(image0); - RadioButton2->close(TRUE); - RadioButton3->close(TRUE); - - GroupPoints = new DlgRef_1Sel1Check1List_QTD(this, "GroupPoints"); - GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS")); - GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT")); - GroupPoints->TextLabel2->setText(tr("GEOM_SUBSHAPE_TYPE")); - GroupPoints->CheckButton1->setText(tr("GEOM_SUBSHAPE_SELECT")); - GroupPoints->PushButton1->setPixmap(image1); - - Layout1->addWidget(GroupPoints, 1, 0); + mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SUB_SHAPE" ) ); + mainFrame()->RadioButton1->setIcon( image0 ); + mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose ); + mainFrame()->RadioButton2->close(); + mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose ); + mainFrame()->RadioButton3->close(); + + GroupPoints = new DlgRef_1Sel1Check1List( centralWidget() ); + + GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) ); + GroupPoints->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) ); + GroupPoints->TextLabel2->setText( tr( "GEOM_SUBSHAPE_TYPE" ) ); + GroupPoints->CheckButton1->setText( tr( "GEOM_SUBSHAPE_SELECT" ) ); + GroupPoints->PushButton1->setIcon( image1 ); + GroupPoints->LineEdit1->setReadOnly( true ); + + QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); + layout->setMargin( 0 ); layout->setSpacing( 6 ); + layout->addWidget( GroupPoints ); /***************************************************************/ - /* Initialisations */ - myEntityGUI = theEntityGUI; - Init(ic); + setHelpFileName( "create_explode_page.html" ); + + mainFrame()->GroupBoxName->hide(); + + Init(); } @@ -81,7 +97,6 @@ EntityGUI_SubShapeDlg::EntityGUI_SubShapeDlg(QWidget* parent, const char* name, //================================================================================= EntityGUI_SubShapeDlg::~EntityGUI_SubShapeDlg() { - // no need to delete child widgets, Qt does it all for us } @@ -89,54 +104,47 @@ EntityGUI_SubShapeDlg::~EntityGUI_SubShapeDlg() // function : Init() // purpose : //================================================================================= -void EntityGUI_SubShapeDlg::Init(Handle(AIS_InteractiveContext) ic) +void EntityGUI_SubShapeDlg::Init() { /* init variables */ myEditCurrentArgument = GroupPoints->LineEdit1; + myObject = GEOM::GEOM_Object::_nil(); myWithShape = true; - myAbort = myOkShape = myUseLocalContext = false; - myIC = ic; - myLocalContextId = -1; /* type for sub shape selection */ - GroupPoints->ComboBox1->insertItem("Compound"); - GroupPoints->ComboBox1->insertItem("Compsolid"); - GroupPoints->ComboBox1->insertItem("Solid"); - GroupPoints->ComboBox1->insertItem("Shell"); - GroupPoints->ComboBox1->insertItem("Face"); - GroupPoints->ComboBox1->insertItem("Wire"); - GroupPoints->ComboBox1->insertItem("Edge"); - GroupPoints->ComboBox1->insertItem("Vertex"); - GroupPoints->ComboBox1->insertItem("Shape"); - - myShapeType = GroupPoints->ComboBox1->currentItem(); - myOkSelectSubMode = GroupPoints->CheckButton1->isChecked(); - - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC) - GroupPoints->CheckButton1->setEnabled(false); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Compound" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Compsolid" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Solid" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shell" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Face" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Wire" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Edge" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Vertex" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shape" ); + + if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() + != OCCViewer_Viewer::Type() ) + GroupPoints->CheckButton1->setEnabled( false ); /* signals and slots connections */ - connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel())); - connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog())); - connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel())); + connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ); - connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk())); - connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply())); + connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); + connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); - connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); + connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged())); - connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(AllOrNotAll())); - - connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); + connect( GroupPoints->ComboBox1, SIGNAL( activated( int ) ), this, SLOT( ComboTextChanged() ) ); + connect( GroupPoints->CheckButton1, SIGNAL( stateChanged( int ) ), this, SLOT( SubShapeToggled() ) ); - /* displays Dialog */ - GroupPoints->show(); - this->show(); + connect( myGeomGUI->getApp()->selectionMgr(), + SIGNAL( currentSelectionChanged( )), this, SLOT( SelectionIntoArgument() ) ); - return; + updateButtonState(); + resize(100,100); + SelectionIntoArgument(); } @@ -146,15 +154,8 @@ void EntityGUI_SubShapeDlg::Init(Handle(AIS_InteractiveContext) ic) //================================================================================= void EntityGUI_SubShapeDlg::ClickOnOk() { - this->ClickOnApply(); - - /* User has aborted or not operation of explode all with many sub shapes */ - if(myAbort == false) - this->ClickOnCancel(); - else - myAbort = false; - - return; + if ( ClickOnApply() ) + ClickOnCancel(); } @@ -162,65 +163,31 @@ void EntityGUI_SubShapeDlg::ClickOnOk() // function : ClickOnApply() // purpose : //================================================================================= -void EntityGUI_SubShapeDlg::ClickOnApply() +bool EntityGUI_SubShapeDlg::ClickOnApply() { - QAD_Application::getDesktop()->putInfo(tr("")); - bool testResult = false; - myAbort = false; /* Not aborted by default */ + SUIT_Session::session()->activeApplication()->putInfo( "" ); /* Explode all sub shapes */ - if(myOkShape && !myOkSelectSubMode) { + if ( isAllSubShapes() ) { /* More than 30 subshapes : ask confirmation */ - unsigned int nb = NumberOfSubShapes(myShape, myShapeType); - if(nb > 30) { - const QString caption = tr("GEOM_CONFIRM"); - const QString text = tr("GEOM_CONFIRM_INFO").arg(nb); - const QString button0 = tr("GEOM_BUT_EXPLODE"); - const QString button1 = tr("GEOM_BUT_CANCEL"); - - if(QMessageBox::warning(this, caption, text, button0, button1) == 0) - testResult = myEntityGUI->OnSubShapeGetAll(myShape, myShapeIOR, myShapeType); - else - myAbort = true; /* aborted */ + unsigned int nb = NumberOfSubShapes( myShape, shapeType() ); + if ( nb > 30 ) { + const QString caption = tr( "GEOM_CONFIRM" ); + const QString text = tr( "GEOM_CONFIRM_INFO" ).arg( nb ); + const QString button0 = tr( "GEOM_BUT_EXPLODE" ); + const QString button1 = tr( "GEOM_BUT_CANCEL" ); + + if ( QMessageBox::warning( this, caption, text, button0, button1 ) != 0 ) + return false; /* aborted */ } - else - testResult = myEntityGUI->OnSubShapeGetAll(myShape, myShapeIOR, myShapeType); - } - /* explode only selected sub shapes */ - else if(myOkShape && myOkSelectSubMode) - testResult = myEntityGUI->OnSubShapeGetSelected(myShape, myShapeIOR, myShapeType, myLocalContextId, myUseLocalContext); - - if(!testResult) { - QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT")); - myAbort = true; } - else - QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE")); - /* Reset all arguments and local context to allow user a new selection ...*/ - this->ResetStateOfDialog(); - return; -} + bool isOk = onAccept(); + // restore selection, corresponding to current selection mode + SubShapeToggled(); -//================================================================================= -// function : ClickOnCancel() -// purpose : -//================================================================================= -void EntityGUI_SubShapeDlg::ClickOnCancel() -{ - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - myIC = v3d->getAISContext(); - if(myUseLocalContext) { - myIC->CloseLocalContext(myLocalContextId); - myUseLocalContext = false; - } - DisplayGUI* myDisplayGUI = new DisplayGUI(); - myDisplayGUI->OnDisplayAll(true); - } - GEOMBase_Skeleton::ClickOnCancel(); - return; + return isOk; } @@ -231,98 +198,98 @@ void EntityGUI_SubShapeDlg::ClickOnCancel() //================================================================================= void EntityGUI_SubShapeDlg::SelectionIntoArgument() { - myEditCurrentArgument->setText(""); - this->ResetStateOfDialog(); + if (!isAllSubShapes()) + return; + + ResetStateOfDialog(); + QString aString = ""; /* name of selection */ - int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString); - if(nbSel != 1) { - myOkShape = false; + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); + + int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true); + if (nbSel != 1) return; - } - - /* nbSel == 1 */ + TopoDS_Shape S; - Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject(); - if(!myGeomBase->GetTopoFromSelection(mySelection, S)) + Handle(SALOME_InteractiveObject) IO = aSelList.First(); + if ( !IO->hasEntry() ) { + SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_SHAPE_IN_STUDY" ) ); + updateButtonState(); return; - - if(!IO->hasEntry()) { - QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY")); + } + + if (!GEOMBase::GetTopoFromSelection(aSelList, S) || + S.IsNull() || + S.ShapeType() == TopAbs_VERTEX) { + myObject = GEOM::GEOM_Object::_nil(); + updateButtonState(); return; } - if(!S.IsNull() && S.ShapeType() != TopAbs_VERTEX) { - if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) { - Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO ); - myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */ - myEditCurrentArgument->setText(aString); - myShape = S; - myOkShape = true; - } - else { - SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); - SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if(!obj->_is_nil()) { - if(obj->FindAttribute(anAttr, "AttributeIOR")) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - myShapeIOR = anIOR->Value(); - myOkShape = true; - myShape = S; - GroupPoints->LineEdit1->setText(aString); - } - } - } - - int SelectedShapeType = GroupPoints->ComboBox1->currentItem(); - int count = GroupPoints->ComboBox1->count(); + Standard_Boolean testResult; + myObject = GEOMBase::ConvertIOinGEOMObject(IO, testResult); + if (!testResult || myObject->_is_nil()) { + updateButtonState(); + return; + } - if(myWithShape) - count = count - 1; + myShape = S; + GroupPoints->LineEdit1->setText(aString); - int i = 0; - while(i <= myShape.ShapeType()) { - GroupPoints->ComboBox1->removeItem(0); + int SelectedShapeType = GroupPoints->ComboBox1->currentIndex(); + int count = GroupPoints->ComboBox1->count(); + + if (myWithShape) + count = count - 1; + + int i = 0; + // Solving PAL5590 + if (myShape.ShapeType() == TopAbs_COMPOUND) { + unsigned int nb = NumberOfSubShapes(myShape, TopAbs_COMPOUND); + if ( nb > 0 ) i++; - } + } + while (i <= myShape.ShapeType()) { + GroupPoints->ComboBox1->removeItem(0); + i++; + } - if(myShape.ShapeType()==TopAbs_COMPOUND) { - if(myWithShape == false) { - GroupPoints->ComboBox1->insertItem("Shape"); - myWithShape = true; - } + if (myShape.ShapeType() == TopAbs_COMPOUND) { + if (myWithShape == false) { + GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape"); + myWithShape = true; } - else { - if(myWithShape == true) { - GroupPoints->ComboBox1->removeItem(GroupPoints->ComboBox1->count() - 1); - myWithShape = false; - } + } + else { + if ( myWithShape == true ) { + GroupPoints->ComboBox1->removeItem( GroupPoints->ComboBox1->count() - 1 ); + myWithShape = false; } - - int count1 = GroupPoints->ComboBox1->count(); - if(myWithShape) - count1 = count1 - 1; - - if(SelectedShapeType > myShape.ShapeType()) { - if(SelectedShapeType == 8) { - if(myShape.ShapeType() != TopAbs_COMPOUND) { - GroupPoints->ComboBox1->setCurrentItem(0); - myShapeType = 8 - count1; - } - } - else { - GroupPoints->ComboBox1->setCurrentItem(count1 - count + SelectedShapeType); - myShapeType = 8 - count1 + GroupPoints->ComboBox1->currentItem(); + } + + int count1 = GroupPoints->ComboBox1->count(); + if ( myWithShape ) + count1 = count1 - 1; + + if ( SelectedShapeType > myShape.ShapeType() ) { + if ( SelectedShapeType == 8 ) { + if ( myShape.ShapeType() != TopAbs_COMPOUND ) { + GroupPoints->ComboBox1->setCurrentIndex( 0 ); + ComboTextChanged(); } - } - else { - GroupPoints->ComboBox1->setCurrentItem(0); - myShapeType = 8 - count1; - } + } + else + GroupPoints->ComboBox1->setCurrentIndex( count1 - count + SelectedShapeType ); + } + else { + GroupPoints->ComboBox1->setCurrentIndex( 0 ); + ComboTextChanged(); } - return; + + updateButtonState(); } @@ -332,15 +299,12 @@ void EntityGUI_SubShapeDlg::SelectionIntoArgument() //================================================================================= void EntityGUI_SubShapeDlg::SetEditCurrentArgument() { - QPushButton* send = (QPushButton*)sender(); - - if(send == GroupPoints->PushButton1) { - GroupPoints->LineEdit1->setFocus(); - myEditCurrentArgument = GroupPoints->LineEdit1; - } - this->SelectionIntoArgument(); - - return; + GroupPoints->LineEdit1->setFocus(); + myEditCurrentArgument = GroupPoints->LineEdit1; + + GroupPoints->CheckButton1->setChecked( false ); + SubShapeToggled(); + SelectionIntoArgument(); } @@ -351,13 +315,12 @@ void EntityGUI_SubShapeDlg::SetEditCurrentArgument() void EntityGUI_SubShapeDlg::LineEditReturnPressed() { QLineEdit* send = (QLineEdit*)sender(); - if(send == GroupPoints->LineEdit1) - myEditCurrentArgument = GroupPoints->LineEdit1; + if ( send == GroupPoints->LineEdit1 ) + SetEditCurrentArgument(); else return; GEOMBase_Skeleton::LineEditReturnPressed(); - return; } @@ -367,11 +330,9 @@ void EntityGUI_SubShapeDlg::LineEditReturnPressed() //================================================================================= void EntityGUI_SubShapeDlg::DeactivateActiveDialog() { - if(GroupConstructors->isEnabled()) { - this->ResetStateOfDialog(); + if ( mainFrame()->GroupConstructors->isEnabled() ) { GEOMBase_Skeleton::DeactivateActiveDialog(); } - return; } @@ -382,12 +343,10 @@ void EntityGUI_SubShapeDlg::DeactivateActiveDialog() void EntityGUI_SubShapeDlg::ActivateThisDialog() { GEOMBase_Skeleton::ActivateThisDialog(); - connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) - GroupPoints->CheckButton1->setEnabled(true); - else - GroupPoints->CheckButton1->setEnabled(false); - return; + connect( myGeomGUI->getApp()->selectionMgr(), + SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + SubShapeToggled(); + updateButtonState(); } @@ -395,178 +354,259 @@ void EntityGUI_SubShapeDlg::ActivateThisDialog() // function : enterEvent() // purpose : //================================================================================= -void EntityGUI_SubShapeDlg::enterEvent(QEvent* e) +void EntityGUI_SubShapeDlg::enterEvent( QEvent* ) { - if(GroupConstructors->isEnabled()) - return; - this->ActivateThisDialog(); - return; + if ( !mainFrame()->GroupConstructors->isEnabled() ) + ActivateThisDialog(); } - -//================================================================================= -// function : closeEvent() -// purpose : -//================================================================================= -void EntityGUI_SubShapeDlg::closeEvent(QCloseEvent* e) -{ - /* same than click on cancel button */ - this->ClickOnCancel(); - return; -} - - //================================================================================= // function : ResetStateOfDialog() // purpose : Completely reset the state of method including local context //================================================================================= void EntityGUI_SubShapeDlg::ResetStateOfDialog() { - if(myAbort == true) { - myOkShape = false; - myEditCurrentArgument->setText(""); - } + myObject = GEOM::GEOM_Object::_nil(); + myShape.Nullify(); + myEditCurrentArgument->setText( "" ); - int SelectedShapeType = GroupPoints->ComboBox1->currentItem(); + int SelectedShapeType = GroupPoints->ComboBox1->currentIndex(); int count = GroupPoints->ComboBox1->count(); - if(myWithShape) + if ( myWithShape ) count = count - 1; /* type for sub shape selection */ GroupPoints->ComboBox1->clear(); - GroupPoints->ComboBox1->insertItem("Compound"); - GroupPoints->ComboBox1->insertItem("Compsolid"); - GroupPoints->ComboBox1->insertItem("Solid"); - GroupPoints->ComboBox1->insertItem("Shell"); - GroupPoints->ComboBox1->insertItem("Face"); - GroupPoints->ComboBox1->insertItem("Wire"); - GroupPoints->ComboBox1->insertItem("Edge"); - GroupPoints->ComboBox1->insertItem("Vertex"); - GroupPoints->ComboBox1->insertItem("Shape"); - myWithShape=true; - GroupPoints->ComboBox1->setCurrentItem(8 - count + SelectedShapeType); - myOkSelectSubMode = false; - - /* unpress buttons : due to abort box*/ - buttonApply->setDown(FALSE); - buttonOk->setDown(FALSE); - GroupPoints->CheckButton1->setChecked(FALSE); - - /* Close its local contact if opened */ - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - myIC = v3d->getAISContext(); - if(myUseLocalContext) { - myIC->CloseLocalContext(myLocalContextId); - myUseLocalContext = false; - } - DisplayGUI* myDisplayGUI = new DisplayGUI(); - myDisplayGUI->OnDisplayAll(true); - } - return; + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Compound" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Compsolid" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Solid" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shell" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Face" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Wire" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Edge" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Vertex" ); + GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shape" ); + + myWithShape = true; + + GroupPoints->ComboBox1->setCurrentIndex( 8 - count + SelectedShapeType ); + ComboTextChanged(); + + updateButtonState(); } //================================================================================= -// function : AllOrNotAll() +// function : SubShapeToggled() // purpose : Allow user selection of all or only selected sub shapes // : Called when 'CheckButton1' state change //================================================================================= -void EntityGUI_SubShapeDlg::AllOrNotAll() +void EntityGUI_SubShapeDlg::SubShapeToggled() { - /* No sub shape selection if main shape not selected */ - if(!myOkShape) { - this->ResetStateOfDialog(); - QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SELECT_FIRST")); - return; - } - - if(myShapeType ==TopAbs_SHAPE && myShape.ShapeType()==TopAbs_COMPOUND) { - /* Select sub shapes mode not checked */ - myOkSelectSubMode = false; - GroupPoints->CheckButton1->setChecked( FALSE ); - //no meaning to allow user selection for type = shape - //TODO - add another message - //QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SELECT_FIRST")) ; - return; - } + globalSelection( GEOM_ALLSHAPES ); + + if ( !isAllSubShapes() ) + localSelection( myObject, shapeType() ); +} + + +//================================================================================= +// function : ComboTextChanged() +// purpose : +//================================================================================= +void EntityGUI_SubShapeDlg::ComboTextChanged() +{ + /* Select sub shapes mode not checked */ + updateButtonState(); + SubShapeToggled(); +} - myOkSelectSubMode = GroupPoints->CheckButton1->isChecked(); - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - myIC = v3d->getAISContext(); +//================================================================================= +// function : NumberOfSubShapes() +// purpose : +//================================================================================= +unsigned int EntityGUI_SubShapeDlg::NumberOfSubShapes( const TopoDS_Shape& S, + const int shapeType ) const +{ + if ( S.IsNull() ) + return 0; - if(myUseLocalContext) { - myIC->CloseLocalContext(myLocalContextId); - myUseLocalContext = false; + unsigned int index = 0; + TopTools_MapOfShape M; + + if ( S.ShapeType() == TopAbs_COMPOUND && + ( TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE || + TopAbs_ShapeEnum(shapeType) == TopAbs_COMPSOLID || + TopAbs_ShapeEnum(shapeType) == TopAbs_COMPOUND ) ) { + TopoDS_Iterator It( S, Standard_True, Standard_True ); + for ( ; It.More(); It.Next() ) { + if ( M.Add( It.Value() ) ) { + if ( TopAbs_ShapeEnum( shapeType ) == TopAbs_SHAPE || + TopAbs_ShapeEnum( shapeType ) == It.Value().ShapeType() ) { + index++; + } + } } - DisplayGUI* myDisplayGUI = new DisplayGUI(); - myDisplayGUI->OnDisplayAll(true); - } + } else { - QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NOT_FOR_VTK_VIEWER")); - return; + TopExp_Explorer Exp ( S, TopAbs_ShapeEnum( shapeType ) ); + for ( ; Exp.More(); Exp.Next() ) { + if ( M.Add( Exp.Current() ) ) { + index++; + } + } } - if(myOkShape && myOkSelectSubMode) { - /* local context is defined into the method */ - DisplayGUI* myDisplayGUI = new DisplayGUI(); - myDisplayGUI->PrepareSubShapeSelection(myShapeType, myLocalContextId); - myUseLocalContext = true; - QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SELECT_FACE")); + M.Clear(); + return index; +} + +//================================================================================= +// function : updateButtonState +// purpose : +//================================================================================= +void EntityGUI_SubShapeDlg::updateButtonState() +{ + if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() != OCCViewer_Viewer::Type() || + myObject->_is_nil() || shapeType() == TopAbs_SHAPE || shapeType() == TopAbs_COMPOUND ) { + GroupPoints->CheckButton1->setChecked( false ); + GroupPoints->CheckButton1->setEnabled( false ); } - return; + else + GroupPoints->CheckButton1->setEnabled( true ); } +//================================================================================= +// function : isAllSubShapes +// purpose : +//================================================================================= +bool EntityGUI_SubShapeDlg::isAllSubShapes() const +{ + return !GroupPoints->CheckButton1->isChecked() || !GroupPoints->CheckButton1->isEnabled(); +} //================================================================================= -// function : ComboTextChanged() -// purpose : +// function : shapeType +// purpose : //================================================================================= -void EntityGUI_SubShapeDlg::ComboTextChanged() +int EntityGUI_SubShapeDlg::shapeType() const { - if(myOkShape) - myShapeType = GroupPoints->ComboBox1->currentItem() + myShape.ShapeType() + 1; - else - myShapeType = GroupPoints->ComboBox1->currentItem(); + int type = GroupPoints->ComboBox1->currentIndex(); - /* Select sub shapes mode not checked */ - GroupPoints->CheckButton1->setChecked(FALSE); - myOkSelectSubMode = FALSE; + if ( myObject->_is_nil() ) + return type; - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - myIC = v3d->getAISContext(); + // Solving PAL5590 + type += myShape.ShapeType() + 1; + if ( myShape.ShapeType() == TopAbs_COMPOUND && + NumberOfSubShapes( myShape, TopAbs_COMPOUND ) > 0 ) { + type--; + } + + return type; +} + +//================================================================================= +// function : createOperation +// purpose : +//================================================================================= +GEOM::GEOM_IOperations_ptr EntityGUI_SubShapeDlg::createOperation() +{ + return getGeomEngine()->GetIShapesOperations( getStudyId() ); +} + +//================================================================================= +// function : isValid +// purpose : +//================================================================================= +bool EntityGUI_SubShapeDlg::isValid (QString& msg) +{ + bool isOk = false; + + if (myObject->_is_nil()) { + updateButtonState(); + return isOk; + } - if(myUseLocalContext) { - myIC->CloseLocalContext(myLocalContextId); - myUseLocalContext = false; + if (isAllSubShapes()) + isOk = true; + else { + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); + + if (aSelList.Extent() == 1) { + Standard_Boolean testResult; + GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult); + if (testResult && !anObj->_is_nil()) { + TColStd_IndexedMapOfInteger aMapIndex; + aSelMgr->GetIndexes(aSelList.First(), aMapIndex); + isOk = aMapIndex.Extent() > 0; + if (!isOk) + msg += tr("NO_SUBSHAPES_SELECTED"); + } } - DisplayGUI* myDisplayGUI = new DisplayGUI(); - myDisplayGUI->OnDisplayAll(true); } - return; -} + return isOk; +} //================================================================================= -// function : NumberOfSubShapes() +// function : execute // purpose : //================================================================================= -unsigned int EntityGUI_SubShapeDlg::NumberOfSubShapes(const TopoDS_Shape& S, const int shapeType) +bool EntityGUI_SubShapeDlg::execute (ObjectList& objects) { - if(S.IsNull()) - return 0; - - unsigned int index = 0; - TopExp_Explorer Exp(S, TopAbs_ShapeEnum(shapeType)); - TopTools_MapOfShape M; - while(Exp.More()) { - if(M.Add(Exp.Current())) - index++; - Exp.Next(); + GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation()); + GEOM::ListOfGO_var aList = anOper->MakeExplode(myObject, shapeType(), true); + + if (!aList->length()) + return false; + + // Throw away sub-shapes not selected by user if not in preview mode + // and manual selection is active + if (!isAllSubShapes()) { + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); + + if (aSelList.Extent() == 1) { + Standard_Boolean aResult = Standard_False; + GEOM::GEOM_Object_var anObj = + GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult); + + if (aResult && !anObj->_is_nil()) { + TColStd_IndexedMapOfInteger aMapIndex; + aSelMgr->GetIndexes(aSelList.First(), aMapIndex); + + GEOM::GEOM_ILocalOperations_var aLocOp = + getGeomEngine()->GetILocalOperations(getStudyId()); + + for (int i = 0, n = aList->length(); i < n; i++) + if (aMapIndex.Contains(aLocOp->GetSubShapeIndex(myObject, aList[i]))) + objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i])); + } + } } - M.Clear(); - return index; + else + for (int i = 0, n = aList->length(); i < n; i++) + objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i])); + + return objects.size(); +} + +//================================================================ +// Function : getFather +// Purpose : Get father object for object to be added in study +// ( called with addInStudy method ) +//================================================================ +GEOM::GEOM_Object_ptr EntityGUI_SubShapeDlg::getFather( GEOM::GEOM_Object_ptr ) +{ + return myObject; +} + +QString EntityGUI_SubShapeDlg::getNewObjectName() const +{ + return QString::null; }