1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : EntityGUI_SubShapeDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "EntityGUI_SubShapeDlg.h"
31 #include "GeometryGUI.h"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_ResourceMgr.h"
36 #include "SUIT_Session.h"
37 #include "SUIT_ViewManager.h"
38 #include "SUIT_ViewWindow.h"
39 #include "OCCViewer_ViewModel.h"
40 #include "SalomeApp_Application.h"
41 #include "LightApp_SelectionMgr.h"
43 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <TopoDS_Iterator.hxx>
45 #include <TopExp_Explorer.hxx>
46 #include <TopTools_MapOfShape.hxx>
48 #include <QMessageBox>
50 //=================================================================================
51 // class : EntityGUI_SubShapeDlg
52 // purpose : Constructs a EntityGUI_SubShapeDlg which is a child of 'parent', with the
53 // name 'name' and widget flags set to 'f'.
54 // The dialog will by default be modeless, unless you set 'modal' to
55 // TRUE to construct a modal dialog.
56 //=================================================================================
57 EntityGUI_SubShapeDlg::EntityGUI_SubShapeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
58 const char* name, bool modal, Qt::WindowFlags fl)
59 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, fl)
61 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUBSHAPE")));
62 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
64 setWindowTitle(tr("GEOM_SUBSHAPE_TITLE"));
66 /***************************************************************/
67 GroupConstructors->setTitle(tr("GEOM_SUB_SHAPE"));
68 RadioButton1->setIcon(image0);
69 RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
70 RadioButton2->close();
71 RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
72 RadioButton3->close();
74 GroupPoints = new Ui::DlgRef_1Sel1Check1List_QTD();
75 QWidget* aGroupPointsWidget = new QWidget(this);
76 GroupPoints->setupUi(aGroupPointsWidget);
77 aGroupPointsWidget->setObjectName("GroupPoints");
79 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
80 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
81 GroupPoints->TextLabel2->setText(tr("GEOM_SUBSHAPE_TYPE"));
82 GroupPoints->CheckButton1->setText(tr("GEOM_SUBSHAPE_SELECT"));
83 GroupPoints->PushButton1->setIcon(image1);
84 GroupPoints->LineEdit1->setReadOnly( true );
86 gridLayout1->addWidget(aGroupPointsWidget, 1, 0);
87 /***************************************************************/
89 setHelpFileName("explode.htm");
95 //=================================================================================
96 // function : ~EntityGUI_SubShapeDlg()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 EntityGUI_SubShapeDlg::~EntityGUI_SubShapeDlg()
104 //=================================================================================
107 //=================================================================================
108 void EntityGUI_SubShapeDlg::Init()
111 myEditCurrentArgument = GroupPoints->LineEdit1;
112 myObject = GEOM::GEOM_Object::_nil();
116 /* type for sub shape selection */
117 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compound");
118 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compsolid");
119 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Solid");
120 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shell");
121 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Face");
122 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Wire");
123 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Edge");
124 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Vertex");
125 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
127 if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
128 != OCCViewer_Viewer::Type())
129 GroupPoints->CheckButton1->setEnabled(false);
131 /* signals and slots connections */
132 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
134 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
135 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
137 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
140 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
141 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(SubShapeToggled()));
143 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
144 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
148 SelectionIntoArgument();
152 //=================================================================================
153 // function : ClickOnOk()
155 //=================================================================================
156 void EntityGUI_SubShapeDlg::ClickOnOk()
158 if ( ClickOnApply() )
163 //=================================================================================
164 // function : ClickOnApply()
166 //=================================================================================
167 bool EntityGUI_SubShapeDlg::ClickOnApply()
169 SUIT_Session::session()->activeApplication()->putInfo(tr(""));
171 /* Explode all sub shapes */
172 if( isAllSubShapes() ) {
173 /* More than 30 subshapes : ask confirmation */
174 unsigned int nb = NumberOfSubShapes(myShape, shapeType());
176 const QString caption = tr("GEOM_CONFIRM");
177 const QString text = tr("GEOM_CONFIRM_INFO").arg(nb);
178 const QString button0 = tr("GEOM_BUT_EXPLODE");
179 const QString button1 = tr("GEOM_BUT_CANCEL");
181 if(QMessageBox::warning(this, caption, text, button0, button1) != 0)
182 return false; /* aborted */
190 //=================================================================================
191 // function : SelectionIntoArgument()
192 // purpose : Called when selection as changed or other case
193 // : used only by SelectButtonC1A1 (LineEditC1A1)
194 //=================================================================================
195 void EntityGUI_SubShapeDlg::SelectionIntoArgument()
197 if ( !isAllSubShapes() )
200 ResetStateOfDialog();
202 QString aString = ""; /* name of selection */
204 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
209 Handle(SALOME_InteractiveObject) IO = firstIObject();
210 if ( !IO->hasEntry() )
212 SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_SHAPE_IN_STUDY" ) );
217 if ( !GEOMBase::GetTopoFromSelection( selectedIO(), S ) ||
219 S.ShapeType() == TopAbs_VERTEX )
226 Standard_Boolean testResult;
227 myObject = GEOMBase::ConvertIOinGEOMObject( IO, testResult );
228 if ( !testResult || myObject->_is_nil() )
235 GroupPoints->LineEdit1->setText( aString );
238 int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
239 int count = GroupPoints->ComboBox1->count();
246 if ( myShape.ShapeType() == TopAbs_COMPOUND ) {
247 unsigned int nb = NumberOfSubShapes(myShape, TopAbs_COMPOUND);
251 while ( i <= myShape.ShapeType())
253 GroupPoints->ComboBox1->removeItem( 0 );
257 if ( myShape.ShapeType() == TopAbs_COMPOUND )
259 if ( myWithShape == false )
261 GroupPoints->ComboBox1->insertItem( GroupPoints->ComboBox1->count(), "Shape" );
267 if ( myWithShape == true )
269 GroupPoints->ComboBox1->removeItem( GroupPoints->ComboBox1->count() - 1 );
274 int count1 = GroupPoints->ComboBox1->count();
278 if ( SelectedShapeType > myShape.ShapeType() )
280 if ( SelectedShapeType == 8 )
282 if ( myShape.ShapeType() != TopAbs_COMPOUND )
284 GroupPoints->ComboBox1->setCurrentIndex( 0 );
289 GroupPoints->ComboBox1->setCurrentIndex(count1 - count + SelectedShapeType);
293 GroupPoints->ComboBox1->setCurrentIndex( 0 );
301 //=================================================================================
302 // function : SetEditCurrentArgument()
304 //=================================================================================
305 void EntityGUI_SubShapeDlg::SetEditCurrentArgument()
307 GroupPoints->LineEdit1->setFocus();
308 myEditCurrentArgument = GroupPoints->LineEdit1;
310 GroupPoints->CheckButton1->setChecked( FALSE );
312 SelectionIntoArgument();
316 //=================================================================================
317 // function : LineEditReturnPressed()
319 //=================================================================================
320 void EntityGUI_SubShapeDlg::LineEditReturnPressed()
322 QLineEdit* send = (QLineEdit*)sender();
323 if(send == GroupPoints->LineEdit1)
324 SetEditCurrentArgument();
328 GEOMBase_Skeleton::LineEditReturnPressed();
332 //=================================================================================
333 // function : DeactivateActiveDialog()
335 //=================================================================================
336 void EntityGUI_SubShapeDlg::DeactivateActiveDialog()
338 if (GroupConstructors->isEnabled()) {
339 GEOMBase_Skeleton::DeactivateActiveDialog();
344 //=================================================================================
345 // function : ActivateThisDialog()
347 //=================================================================================
348 void EntityGUI_SubShapeDlg::ActivateThisDialog()
350 GEOMBase_Skeleton::ActivateThisDialog();
351 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
352 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
358 //=================================================================================
359 // function : enterEvent()
361 //=================================================================================
362 void EntityGUI_SubShapeDlg::enterEvent(QEvent* e)
364 if (!GroupConstructors->isEnabled())
365 ActivateThisDialog();
368 //=================================================================================
369 // function : ResetStateOfDialog()
370 // purpose : Completely reset the state of method including local context
371 //=================================================================================
372 void EntityGUI_SubShapeDlg::ResetStateOfDialog()
374 myObject = GEOM::GEOM_Object::_nil();
376 myEditCurrentArgument->setText("");
378 int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
379 int count = GroupPoints->ComboBox1->count();
383 /* type for sub shape selection */
384 GroupPoints->ComboBox1->clear();
385 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compound");
386 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compsolid");
387 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Solid");
388 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shell");
389 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Face");
390 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Wire");
391 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Edge");
392 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Vertex");
393 GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
397 GroupPoints->ComboBox1->setCurrentIndex( 8 - count + SelectedShapeType );
404 //=================================================================================
405 // function : SubShapeToggled()
406 // purpose : Allow user selection of all or only selected sub shapes
407 // : Called when 'CheckButton1' state change
408 //=================================================================================
409 void EntityGUI_SubShapeDlg::SubShapeToggled()
411 if ( isAllSubShapes() )
412 globalSelection( GEOM_ALLSHAPES );
414 localSelection( myObject, shapeType() );
418 //=================================================================================
419 // function : ComboTextChanged()
421 //=================================================================================
422 void EntityGUI_SubShapeDlg::ComboTextChanged()
424 /* Select sub shapes mode not checked */
430 //=================================================================================
431 // function : NumberOfSubShapes()
433 //=================================================================================
434 unsigned int EntityGUI_SubShapeDlg::NumberOfSubShapes (const TopoDS_Shape& S,
435 const int shapeType) const
440 unsigned int index = 0;
441 TopTools_MapOfShape M;
443 if (S.ShapeType() == TopAbs_COMPOUND &&
444 (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
445 TopAbs_ShapeEnum(shapeType) == TopAbs_COMPSOLID ||
446 TopAbs_ShapeEnum(shapeType) == TopAbs_COMPOUND)) {
447 TopoDS_Iterator It (S, Standard_True, Standard_True);
448 for (; It.More(); It.Next()) {
449 if (M.Add(It.Value())) {
450 if (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
451 TopAbs_ShapeEnum(shapeType) == It.Value().ShapeType()) {
457 TopExp_Explorer Exp (S, TopAbs_ShapeEnum(shapeType));
458 for (; Exp.More(); Exp.Next()) {
459 if (M.Add(Exp.Current())) {
469 //=================================================================================
470 // function : updateButtonState
472 //=================================================================================
473 void EntityGUI_SubShapeDlg::updateButtonState()
475 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() != OCCViewer_Viewer::Type() ||
476 myObject->_is_nil() || shapeType() == TopAbs_SHAPE || shapeType() == TopAbs_COMPOUND ) {
477 GroupPoints->CheckButton1->setChecked( FALSE );
478 GroupPoints->CheckButton1->setEnabled( FALSE );
481 GroupPoints->CheckButton1->setEnabled( TRUE );
484 //=================================================================================
485 // function : isAllSubShapes
487 //=================================================================================
488 bool EntityGUI_SubShapeDlg::isAllSubShapes() const
490 return !GroupPoints->CheckButton1->isChecked() || !GroupPoints->CheckButton1->isEnabled();
493 //=================================================================================
494 // function : shapeType
496 //=================================================================================
497 int EntityGUI_SubShapeDlg::shapeType() const
499 int type = GroupPoints->ComboBox1->currentIndex();
501 if (myObject->_is_nil())
505 type += myShape.ShapeType() + 1;
506 if (myShape.ShapeType() == TopAbs_COMPOUND &&
507 NumberOfSubShapes(myShape, TopAbs_COMPOUND) > 0) {
514 //=================================================================================
515 // function : createOperation
517 //=================================================================================
518 GEOM::GEOM_IOperations_ptr EntityGUI_SubShapeDlg::createOperation()
520 return getGeomEngine()->GetIShapesOperations( getStudyId() );
523 //=================================================================================
524 // function : isValid
526 //=================================================================================
527 bool EntityGUI_SubShapeDlg::isValid( QString& msg )
530 if ( !myObject->_is_nil() ) {
531 if ( isAllSubShapes() )
533 else if ( IObjectCount() == 1 ) {
534 Standard_Boolean aResult = Standard_False;
535 GEOM::GEOM_Object_var anObj =
536 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
538 if ( aResult && !anObj->_is_nil() ) {
539 TColStd_IndexedMapOfInteger aMapIndex;
540 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
541 isOk = aMapIndex.Extent() > 0;
543 msg += tr( "NO_SUBSHAPES_SELECTED" );
550 //=================================================================================
551 // function : execute
553 //=================================================================================
554 bool EntityGUI_SubShapeDlg::execute( ObjectList& objects )
556 GEOM::ListOfGO_var aList = GEOM::GEOM_IShapesOperations::_narrow(
557 getOperation() )->MakeExplode( myObject, shapeType(), true );
559 if ( !aList->length() )
562 // Throw away sub-shapes not selected by user if not in preview mode
563 // and manual selection is active
564 if ( !isAllSubShapes() )
566 if ( IObjectCount() == 1 ) {
567 Standard_Boolean aResult = Standard_False;
568 GEOM::GEOM_Object_var anObj =
569 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
571 if ( aResult && !anObj->_is_nil() ) {
572 TColStd_IndexedMapOfInteger aMapIndex;
573 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
575 GEOM::GEOM_ILocalOperations_var aLocOp =
576 getGeomEngine()->GetILocalOperations( getStudyId() );
578 for ( int i = 0, n = aList->length(); i < n; i++ )
579 if ( aMapIndex.Contains( aLocOp->GetSubShapeIndex( myObject, aList[i] ) ) )
580 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
585 for ( int i = 0, n = aList->length(); i < n; i++ )
586 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
588 return objects.size();
591 //================================================================
592 // Function : getFather
593 // Purpose : Get father object for object to be added in study
594 // ( called with addInStudy method )
595 //================================================================
596 GEOM::GEOM_Object_ptr EntityGUI_SubShapeDlg::getFather( GEOM::GEOM_Object_ptr )
601 const char* EntityGUI_SubShapeDlg::getNewObjectName() const