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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : EntityGUI_SubShapeDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "EntityGUI_SubShapeDlg.h"
30 #include "GEOM_Displayer.h"
32 #include "SUIT_Desktop.h"
33 #include "SUIT_Session.h"
34 #include "OCCViewer_ViewModel.h"
35 #include "SalomeApp_Application.h"
36 #include "SalomeApp_SelectionMgr.h"
37 #include "SALOME_ListIteratorOfListIO.hxx"
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopoDS_Iterator.hxx>
41 #include <TopExp_Explorer.hxx>
42 #include <TopTools_MapOfShape.hxx>
44 #include <qmessagebox.h>
46 #include <qcombobox.h>
48 //=================================================================================
49 // class : EntityGUI_SubShapeDlg
50 // purpose : Constructs a EntityGUI_SubShapeDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 EntityGUI_SubShapeDlg::EntityGUI_SubShapeDlg(QWidget* parent, const char* name, bool modal, WFlags fl)
56 :GEOMBase_Skeleton(parent, name, modal, fl)
58 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUBSHAPE")));
59 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
61 setCaption(tr("GEOM_SUBSHAPE_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_SUB_SHAPE"));
65 RadioButton1->setPixmap(image0);
66 RadioButton2->close(TRUE);
67 RadioButton3->close(TRUE);
69 GroupPoints = new DlgRef_1Sel1Check1List_QTD(this, "GroupPoints");
70 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
71 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
72 GroupPoints->TextLabel2->setText(tr("GEOM_SUBSHAPE_TYPE"));
73 GroupPoints->CheckButton1->setText(tr("GEOM_SUBSHAPE_SELECT"));
74 GroupPoints->PushButton1->setPixmap(image1);
75 GroupPoints->LineEdit1->setReadOnly( true );
77 Layout1->addWidget(GroupPoints, 1, 0);
78 /***************************************************************/
84 //=================================================================================
85 // function : ~EntityGUI_SubShapeDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 EntityGUI_SubShapeDlg::~EntityGUI_SubShapeDlg()
93 //=================================================================================
96 //=================================================================================
97 void EntityGUI_SubShapeDlg::Init()
100 myEditCurrentArgument = GroupPoints->LineEdit1;
101 myObject = GEOM::GEOM_Object::_nil();
105 /* type for sub shape selection */
106 GroupPoints->ComboBox1->insertItem("Compound");
107 GroupPoints->ComboBox1->insertItem("Compsolid");
108 GroupPoints->ComboBox1->insertItem("Solid");
109 GroupPoints->ComboBox1->insertItem("Shell");
110 GroupPoints->ComboBox1->insertItem("Face");
111 GroupPoints->ComboBox1->insertItem("Wire");
112 GroupPoints->ComboBox1->insertItem("Edge");
113 GroupPoints->ComboBox1->insertItem("Vertex");
114 GroupPoints->ComboBox1->insertItem("Shape");
116 if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
117 != OCCViewer_Viewer::Type())
118 GroupPoints->CheckButton1->setEnabled(false);
120 /* signals and slots connections */
121 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
122 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
123 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
125 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
126 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
128 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
132 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(SubShapeToggled()));
134 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
135 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
139 SelectionIntoArgument();
143 //=================================================================================
144 // function : ClickOnOk()
146 //=================================================================================
147 void EntityGUI_SubShapeDlg::ClickOnOk()
149 if ( ClickOnApply() )
154 //=================================================================================
155 // function : ClickOnApply()
157 //=================================================================================
158 bool EntityGUI_SubShapeDlg::ClickOnApply()
160 SUIT_Session::session()->activeApplication()->putInfo(tr(""));
162 /* Explode all sub shapes */
163 if( isAllSubShapes() ) {
164 /* More than 30 subshapes : ask confirmation */
165 unsigned int nb = NumberOfSubShapes(myShape, shapeType());
167 const QString caption = tr("GEOM_CONFIRM");
168 const QString text = tr("GEOM_CONFIRM_INFO").arg(nb);
169 const QString button0 = tr("GEOM_BUT_EXPLODE");
170 const QString button1 = tr("GEOM_BUT_CANCEL");
172 if(QMessageBox::warning(this, caption, text, button0, button1) != 0)
173 return false; /* aborted */
181 //=================================================================================
182 // function : SelectionIntoArgument()
183 // purpose : Called when selection as changed or other case
184 // : used only by SelectButtonC1A1 (LineEditC1A1)
185 //=================================================================================
186 void EntityGUI_SubShapeDlg::SelectionIntoArgument()
188 if ( !isAllSubShapes() )
191 ResetStateOfDialog();
193 QString aString = ""; /* name of selection */
195 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
200 Handle(SALOME_InteractiveObject) IO = firstIObject();
201 if ( !IO->hasEntry() )
203 SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_SHAPE_IN_STUDY" ) );
208 if ( !myGeomBase->GetTopoFromSelection( selectedIO(), S ) ||
210 S.ShapeType() == TopAbs_VERTEX )
217 Standard_Boolean testResult;
218 myObject = GEOMBase::ConvertIOinGEOMObject( IO, testResult );
219 if ( !testResult || myObject->_is_nil() )
226 GroupPoints->LineEdit1->setText( aString );
229 int SelectedShapeType = GroupPoints->ComboBox1->currentItem();
230 int count = GroupPoints->ComboBox1->count();
237 if ( myShape.ShapeType() == TopAbs_COMPOUND ) {
238 unsigned int nb = NumberOfSubShapes(myShape, TopAbs_COMPOUND);
242 while ( i <= myShape.ShapeType())
244 GroupPoints->ComboBox1->removeItem( 0 );
248 if ( myShape.ShapeType() == TopAbs_COMPOUND )
250 if ( myWithShape == false )
252 GroupPoints->ComboBox1->insertItem( "Shape" );
258 if ( myWithShape == true )
260 GroupPoints->ComboBox1->removeItem( GroupPoints->ComboBox1->count() - 1 );
265 int count1 = GroupPoints->ComboBox1->count();
269 if ( SelectedShapeType > myShape.ShapeType() )
271 if ( SelectedShapeType == 8 )
273 if ( myShape.ShapeType() != TopAbs_COMPOUND )
275 GroupPoints->ComboBox1->setCurrentItem( 0 );
280 GroupPoints->ComboBox1->setCurrentItem(count1 - count + SelectedShapeType);
284 GroupPoints->ComboBox1->setCurrentItem( 0 );
292 //=================================================================================
293 // function : SetEditCurrentArgument()
295 //=================================================================================
296 void EntityGUI_SubShapeDlg::SetEditCurrentArgument()
298 GroupPoints->LineEdit1->setFocus();
299 myEditCurrentArgument = GroupPoints->LineEdit1;
301 GroupPoints->CheckButton1->setChecked( FALSE );
303 SelectionIntoArgument();
307 //=================================================================================
308 // function : LineEditReturnPressed()
310 //=================================================================================
311 void EntityGUI_SubShapeDlg::LineEditReturnPressed()
313 QLineEdit* send = (QLineEdit*)sender();
314 if(send == GroupPoints->LineEdit1)
315 SetEditCurrentArgument();
319 GEOMBase_Skeleton::LineEditReturnPressed();
323 //=================================================================================
324 // function : DeactivateActiveDialog()
326 //=================================================================================
327 void EntityGUI_SubShapeDlg::DeactivateActiveDialog()
329 if(GroupConstructors->isEnabled()) {
330 GEOMBase_Skeleton::DeactivateActiveDialog();
335 //=================================================================================
336 // function : ActivateThisDialog()
338 //=================================================================================
339 void EntityGUI_SubShapeDlg::ActivateThisDialog()
341 GEOMBase_Skeleton::ActivateThisDialog();
342 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
343 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
349 //=================================================================================
350 // function : enterEvent()
352 //=================================================================================
353 void EntityGUI_SubShapeDlg::enterEvent(QEvent* e)
355 if(GroupConstructors->isEnabled())
357 ActivateThisDialog();
360 //=================================================================================
361 // function : ResetStateOfDialog()
362 // purpose : Completely reset the state of method including local context
363 //=================================================================================
364 void EntityGUI_SubShapeDlg::ResetStateOfDialog()
366 myObject = GEOM::GEOM_Object::_nil();
368 myEditCurrentArgument->setText("");
370 int SelectedShapeType = GroupPoints->ComboBox1->currentItem();
371 int count = GroupPoints->ComboBox1->count();
375 /* type for sub shape selection */
376 GroupPoints->ComboBox1->clear();
377 GroupPoints->ComboBox1->insertItem("Compound");
378 GroupPoints->ComboBox1->insertItem("Compsolid");
379 GroupPoints->ComboBox1->insertItem("Solid");
380 GroupPoints->ComboBox1->insertItem("Shell");
381 GroupPoints->ComboBox1->insertItem("Face");
382 GroupPoints->ComboBox1->insertItem("Wire");
383 GroupPoints->ComboBox1->insertItem("Edge");
384 GroupPoints->ComboBox1->insertItem("Vertex");
385 GroupPoints->ComboBox1->insertItem("Shape");
389 GroupPoints->ComboBox1->setCurrentItem( 8 - count + SelectedShapeType );
396 //=================================================================================
397 // function : SubShapeToggled()
398 // purpose : Allow user selection of all or only selected sub shapes
399 // : Called when 'CheckButton1' state change
400 //=================================================================================
401 void EntityGUI_SubShapeDlg::SubShapeToggled()
403 if ( isAllSubShapes() )
404 globalSelection( GEOM_ALLSHAPES );
406 localSelection( myObject, shapeType() );
410 //=================================================================================
411 // function : ComboTextChanged()
413 //=================================================================================
414 void EntityGUI_SubShapeDlg::ComboTextChanged()
416 /* Select sub shapes mode not checked */
422 //=================================================================================
423 // function : NumberOfSubShapes()
425 //=================================================================================
426 unsigned int EntityGUI_SubShapeDlg::NumberOfSubShapes (const TopoDS_Shape& S,
427 const int shapeType) const
432 unsigned int index = 0;
433 TopTools_MapOfShape M;
435 if (S.ShapeType() == TopAbs_COMPOUND &&
436 (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
437 TopAbs_ShapeEnum(shapeType) == TopAbs_COMPSOLID ||
438 TopAbs_ShapeEnum(shapeType) == TopAbs_COMPOUND)) {
439 TopoDS_Iterator It (S, Standard_True, Standard_True);
440 for (; It.More(); It.Next()) {
441 if (M.Add(It.Value())) {
442 if (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
443 TopAbs_ShapeEnum(shapeType) == It.Value().ShapeType()) {
449 TopExp_Explorer Exp (S, TopAbs_ShapeEnum(shapeType));
450 for (; Exp.More(); Exp.Next()) {
451 if (M.Add(Exp.Current())) {
461 //=================================================================================
462 // function : updateButtonState
464 //=================================================================================
465 void EntityGUI_SubShapeDlg::updateButtonState()
467 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() != OCCViewer_Viewer::Type() ||
468 myObject->_is_nil() || shapeType() == TopAbs_SHAPE || shapeType() == TopAbs_COMPOUND ) {
469 GroupPoints->CheckButton1->setChecked( FALSE );
470 GroupPoints->CheckButton1->setEnabled( FALSE );
473 GroupPoints->CheckButton1->setEnabled( TRUE );
476 //=================================================================================
477 // function : isAllSubShapes
479 //=================================================================================
480 bool EntityGUI_SubShapeDlg::isAllSubShapes() const
482 return !GroupPoints->CheckButton1->isChecked() || !GroupPoints->CheckButton1->isEnabled();
485 //=================================================================================
486 // function : shapeType
488 //=================================================================================
489 int EntityGUI_SubShapeDlg::shapeType() const
491 int type = GroupPoints->ComboBox1->currentItem();
493 if (myObject->_is_nil())
497 type += myShape.ShapeType() + 1;
498 if (myShape.ShapeType() == TopAbs_COMPOUND &&
499 NumberOfSubShapes(myShape, TopAbs_COMPOUND) > 0) {
506 //=================================================================================
507 // function : createOperation
509 //=================================================================================
510 GEOM::GEOM_IOperations_ptr EntityGUI_SubShapeDlg::createOperation()
512 return getGeomEngine()->GetIShapesOperations( getStudyId() );
515 //=================================================================================
516 // function : isValid
518 //=================================================================================
519 bool EntityGUI_SubShapeDlg::isValid( QString& msg )
522 if ( !myObject->_is_nil() ) {
523 if ( isAllSubShapes() )
525 else if ( IObjectCount() == 1 ) {
526 Standard_Boolean aResult = Standard_False;
527 GEOM::GEOM_Object_var anObj =
528 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
530 if ( aResult && !anObj->_is_nil() ) {
531 TColStd_IndexedMapOfInteger aMapIndex;
532 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
533 isOk = aMapIndex.Extent() > 0;
535 msg += tr( "NO_SUBSHAPES_SELECTED" );
542 //=================================================================================
543 // function : execute
545 //=================================================================================
546 bool EntityGUI_SubShapeDlg::execute( ObjectList& objects )
548 GEOM::ListOfGO_var aList = GEOM::GEOM_IShapesOperations::_narrow(
549 getOperation() )->MakeExplode( myObject, shapeType(), false );
551 if ( !aList->length() )
554 // Throw away sub-shapes not selected by user if not in preview mode
555 // and manual selection is active
556 if ( !isAllSubShapes() )
558 if ( IObjectCount() == 1 ) {
559 Standard_Boolean aResult = Standard_False;
560 GEOM::GEOM_Object_var anObj =
561 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
563 if ( aResult && !anObj->_is_nil() ) {
564 TColStd_IndexedMapOfInteger aMapIndex;
565 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
567 GEOM::GEOM_ILocalOperations_var aLocOp =
568 getGeomEngine()->GetILocalOperations( getStudyId() );
570 for ( int i = 0, n = aList->length(); i < n; i++ )
571 if ( aMapIndex.Contains( aLocOp->GetSubShapeIndex( myObject, aList[i] ) ) )
572 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
577 for ( int i = 0, n = aList->length(); i < n; i++ )
578 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
580 return objects.size();
583 //================================================================
584 // Function : getFather
585 // Purpose : Get father object for object to be added in study
586 // ( called with addInStudy method )
587 //================================================================
588 GEOM::GEOM_Object_ptr EntityGUI_SubShapeDlg::getFather( GEOM::GEOM_Object_ptr )
593 const char* EntityGUI_SubShapeDlg::getNewObjectName() const