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"
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 "LightApp_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(GeometryGUI* theGeometryGUI, QWidget* parent,
56 const char* name, bool modal, WFlags fl)
57 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, fl)
59 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUBSHAPE")));
60 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
62 setCaption(tr("GEOM_SUBSHAPE_TITLE"));
64 /***************************************************************/
65 GroupConstructors->setTitle(tr("GEOM_SUB_SHAPE"));
66 RadioButton1->setPixmap(image0);
67 RadioButton2->close(TRUE);
68 RadioButton3->close(TRUE);
70 GroupPoints = new DlgRef_1Sel1Check1List_QTD(this, "GroupPoints");
71 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
73 GroupPoints->TextLabel2->setText(tr("GEOM_SUBSHAPE_TYPE"));
74 GroupPoints->CheckButton1->setText(tr("GEOM_SUBSHAPE_SELECT"));
75 GroupPoints->PushButton1->setPixmap(image1);
76 GroupPoints->LineEdit1->setReadOnly( true );
78 Layout1->addWidget(GroupPoints, 1, 0);
79 /***************************************************************/
81 setHelpFileName("explode.htm");
87 //=================================================================================
88 // function : ~EntityGUI_SubShapeDlg()
89 // purpose : Destroys the object and frees any allocated resources
90 //=================================================================================
91 EntityGUI_SubShapeDlg::~EntityGUI_SubShapeDlg()
96 //=================================================================================
99 //=================================================================================
100 void EntityGUI_SubShapeDlg::Init()
103 myEditCurrentArgument = GroupPoints->LineEdit1;
104 myObject = GEOM::GEOM_Object::_nil();
108 /* type for sub shape selection */
109 GroupPoints->ComboBox1->insertItem("Compound");
110 GroupPoints->ComboBox1->insertItem("Compsolid");
111 GroupPoints->ComboBox1->insertItem("Solid");
112 GroupPoints->ComboBox1->insertItem("Shell");
113 GroupPoints->ComboBox1->insertItem("Face");
114 GroupPoints->ComboBox1->insertItem("Wire");
115 GroupPoints->ComboBox1->insertItem("Edge");
116 GroupPoints->ComboBox1->insertItem("Vertex");
117 GroupPoints->ComboBox1->insertItem("Shape");
119 if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
120 != OCCViewer_Viewer::Type())
121 GroupPoints->CheckButton1->setEnabled(false);
123 /* signals and slots connections */
124 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
126 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
127 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
129 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
133 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(SubShapeToggled()));
135 connect(myGeomGUI->getApp()->selectionMgr(),
136 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
140 SelectionIntoArgument();
144 //=================================================================================
145 // function : ClickOnOk()
147 //=================================================================================
148 void EntityGUI_SubShapeDlg::ClickOnOk()
150 if ( ClickOnApply() )
155 //=================================================================================
156 // function : ClickOnApply()
158 //=================================================================================
159 bool EntityGUI_SubShapeDlg::ClickOnApply()
161 SUIT_Session::session()->activeApplication()->putInfo(tr(""));
163 /* Explode all sub shapes */
164 if( isAllSubShapes() ) {
165 /* More than 30 subshapes : ask confirmation */
166 unsigned int nb = NumberOfSubShapes(myShape, shapeType());
168 const QString caption = tr("GEOM_CONFIRM");
169 const QString text = tr("GEOM_CONFIRM_INFO").arg(nb);
170 const QString button0 = tr("GEOM_BUT_EXPLODE");
171 const QString button1 = tr("GEOM_BUT_CANCEL");
173 if(QMessageBox::warning(this, caption, text, button0, button1) != 0)
174 return false; /* aborted */
178 bool isOk = onAccept();
180 // restore selection, corresponding to current selection mode
187 //=================================================================================
188 // function : SelectionIntoArgument()
189 // purpose : Called when selection as changed or other case
190 // : used only by SelectButtonC1A1 (LineEditC1A1)
191 //=================================================================================
192 void EntityGUI_SubShapeDlg::SelectionIntoArgument()
194 if ( !isAllSubShapes() )
197 ResetStateOfDialog();
199 QString aString = ""; /* name of selection */
201 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
206 Handle(SALOME_InteractiveObject) IO = firstIObject();
207 if ( !IO->hasEntry() )
209 SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_SHAPE_IN_STUDY" ) );
214 if ( !GEOMBase::GetTopoFromSelection( selectedIO(), S ) ||
216 S.ShapeType() == TopAbs_VERTEX )
223 Standard_Boolean testResult;
224 myObject = GEOMBase::ConvertIOinGEOMObject( IO, testResult );
225 if ( !testResult || myObject->_is_nil() )
232 GroupPoints->LineEdit1->setText( aString );
235 int SelectedShapeType = GroupPoints->ComboBox1->currentItem();
236 int count = GroupPoints->ComboBox1->count();
243 if ( myShape.ShapeType() == TopAbs_COMPOUND ) {
244 unsigned int nb = NumberOfSubShapes(myShape, TopAbs_COMPOUND);
248 while ( i <= myShape.ShapeType())
250 GroupPoints->ComboBox1->removeItem( 0 );
254 if ( myShape.ShapeType() == TopAbs_COMPOUND )
256 if ( myWithShape == false )
258 GroupPoints->ComboBox1->insertItem( "Shape" );
264 if ( myWithShape == true )
266 GroupPoints->ComboBox1->removeItem( GroupPoints->ComboBox1->count() - 1 );
271 int count1 = GroupPoints->ComboBox1->count();
275 if ( SelectedShapeType > myShape.ShapeType() )
277 if ( SelectedShapeType == 8 )
279 if ( myShape.ShapeType() != TopAbs_COMPOUND )
281 GroupPoints->ComboBox1->setCurrentItem( 0 );
286 GroupPoints->ComboBox1->setCurrentItem(count1 - count + SelectedShapeType);
290 GroupPoints->ComboBox1->setCurrentItem( 0 );
298 //=================================================================================
299 // function : SetEditCurrentArgument()
301 //=================================================================================
302 void EntityGUI_SubShapeDlg::SetEditCurrentArgument()
304 GroupPoints->LineEdit1->setFocus();
305 myEditCurrentArgument = GroupPoints->LineEdit1;
307 GroupPoints->CheckButton1->setChecked( FALSE );
309 SelectionIntoArgument();
313 //=================================================================================
314 // function : LineEditReturnPressed()
316 //=================================================================================
317 void EntityGUI_SubShapeDlg::LineEditReturnPressed()
319 QLineEdit* send = (QLineEdit*)sender();
320 if(send == GroupPoints->LineEdit1)
321 SetEditCurrentArgument();
325 GEOMBase_Skeleton::LineEditReturnPressed();
329 //=================================================================================
330 // function : DeactivateActiveDialog()
332 //=================================================================================
333 void EntityGUI_SubShapeDlg::DeactivateActiveDialog()
335 if (GroupConstructors->isEnabled()) {
336 GEOMBase_Skeleton::DeactivateActiveDialog();
341 //=================================================================================
342 // function : ActivateThisDialog()
344 //=================================================================================
345 void EntityGUI_SubShapeDlg::ActivateThisDialog()
347 GEOMBase_Skeleton::ActivateThisDialog();
348 connect(myGeomGUI->getApp()->selectionMgr(),
349 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
355 //=================================================================================
356 // function : enterEvent()
358 //=================================================================================
359 void EntityGUI_SubShapeDlg::enterEvent(QEvent* e)
361 if (!GroupConstructors->isEnabled())
362 ActivateThisDialog();
365 //=================================================================================
366 // function : ResetStateOfDialog()
367 // purpose : Completely reset the state of method including local context
368 //=================================================================================
369 void EntityGUI_SubShapeDlg::ResetStateOfDialog()
371 myObject = GEOM::GEOM_Object::_nil();
373 myEditCurrentArgument->setText("");
375 int SelectedShapeType = GroupPoints->ComboBox1->currentItem();
376 int count = GroupPoints->ComboBox1->count();
380 /* type for sub shape selection */
381 GroupPoints->ComboBox1->clear();
382 GroupPoints->ComboBox1->insertItem("Compound");
383 GroupPoints->ComboBox1->insertItem("Compsolid");
384 GroupPoints->ComboBox1->insertItem("Solid");
385 GroupPoints->ComboBox1->insertItem("Shell");
386 GroupPoints->ComboBox1->insertItem("Face");
387 GroupPoints->ComboBox1->insertItem("Wire");
388 GroupPoints->ComboBox1->insertItem("Edge");
389 GroupPoints->ComboBox1->insertItem("Vertex");
390 GroupPoints->ComboBox1->insertItem("Shape");
394 GroupPoints->ComboBox1->setCurrentItem( 8 - count + SelectedShapeType );
401 //=================================================================================
402 // function : SubShapeToggled()
403 // purpose : Allow user selection of all or only selected sub shapes
404 // : Called when 'CheckButton1' state change
405 //=================================================================================
406 void EntityGUI_SubShapeDlg::SubShapeToggled()
408 if ( isAllSubShapes() )
409 globalSelection( GEOM_ALLSHAPES );
411 localSelection( myObject, shapeType() );
415 //=================================================================================
416 // function : ComboTextChanged()
418 //=================================================================================
419 void EntityGUI_SubShapeDlg::ComboTextChanged()
421 /* Select sub shapes mode not checked */
427 //=================================================================================
428 // function : NumberOfSubShapes()
430 //=================================================================================
431 unsigned int EntityGUI_SubShapeDlg::NumberOfSubShapes (const TopoDS_Shape& S,
432 const int shapeType) const
437 unsigned int index = 0;
438 TopTools_MapOfShape M;
440 if (S.ShapeType() == TopAbs_COMPOUND &&
441 (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
442 TopAbs_ShapeEnum(shapeType) == TopAbs_COMPSOLID ||
443 TopAbs_ShapeEnum(shapeType) == TopAbs_COMPOUND)) {
444 TopoDS_Iterator It (S, Standard_True, Standard_True);
445 for (; It.More(); It.Next()) {
446 if (M.Add(It.Value())) {
447 if (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
448 TopAbs_ShapeEnum(shapeType) == It.Value().ShapeType()) {
454 TopExp_Explorer Exp (S, TopAbs_ShapeEnum(shapeType));
455 for (; Exp.More(); Exp.Next()) {
456 if (M.Add(Exp.Current())) {
466 //=================================================================================
467 // function : updateButtonState
469 //=================================================================================
470 void EntityGUI_SubShapeDlg::updateButtonState()
472 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() != OCCViewer_Viewer::Type() ||
473 myObject->_is_nil() || shapeType() == TopAbs_SHAPE || shapeType() == TopAbs_COMPOUND ) {
474 GroupPoints->CheckButton1->setChecked( FALSE );
475 GroupPoints->CheckButton1->setEnabled( FALSE );
478 GroupPoints->CheckButton1->setEnabled( TRUE );
481 //=================================================================================
482 // function : isAllSubShapes
484 //=================================================================================
485 bool EntityGUI_SubShapeDlg::isAllSubShapes() const
487 return !GroupPoints->CheckButton1->isChecked() || !GroupPoints->CheckButton1->isEnabled();
490 //=================================================================================
491 // function : shapeType
493 //=================================================================================
494 int EntityGUI_SubShapeDlg::shapeType() const
496 int type = GroupPoints->ComboBox1->currentItem();
498 if (myObject->_is_nil())
502 type += myShape.ShapeType() + 1;
503 if (myShape.ShapeType() == TopAbs_COMPOUND &&
504 NumberOfSubShapes(myShape, TopAbs_COMPOUND) > 0) {
511 //=================================================================================
512 // function : createOperation
514 //=================================================================================
515 GEOM::GEOM_IOperations_ptr EntityGUI_SubShapeDlg::createOperation()
517 return getGeomEngine()->GetIShapesOperations( getStudyId() );
520 //=================================================================================
521 // function : isValid
523 //=================================================================================
524 bool EntityGUI_SubShapeDlg::isValid( QString& msg )
527 if ( !myObject->_is_nil() ) {
528 if ( isAllSubShapes() )
530 else if ( IObjectCount() == 1 ) {
531 Standard_Boolean aResult = Standard_False;
532 GEOM::GEOM_Object_var anObj =
533 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
535 if ( aResult && !anObj->_is_nil() ) {
536 TColStd_IndexedMapOfInteger aMapIndex;
537 myGeomGUI->getApp()->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
538 isOk = aMapIndex.Extent() > 0;
540 msg += tr( "NO_SUBSHAPES_SELECTED" );
547 //=================================================================================
548 // function : execute
550 //=================================================================================
551 bool EntityGUI_SubShapeDlg::execute( ObjectList& objects )
553 GEOM::ListOfGO_var aList = GEOM::GEOM_IShapesOperations::_narrow(
554 getOperation() )->MakeExplode( myObject, shapeType(), true );
556 if ( !aList->length() )
559 // Throw away sub-shapes not selected by user if not in preview mode
560 // and manual selection is active
561 if ( !isAllSubShapes() )
563 if ( IObjectCount() == 1 ) {
564 Standard_Boolean aResult = Standard_False;
565 GEOM::GEOM_Object_var anObj =
566 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
568 if ( aResult && !anObj->_is_nil() ) {
569 TColStd_IndexedMapOfInteger aMapIndex;
570 myGeomGUI->getApp()->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
572 GEOM::GEOM_ILocalOperations_var aLocOp =
573 getGeomEngine()->GetILocalOperations( getStudyId() );
575 for ( int i = 0, n = aList->length(); i < n; i++ )
576 if ( aMapIndex.Contains( aLocOp->GetSubShapeIndex( myObject, aList[i] ) ) )
577 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
582 for ( int i = 0, n = aList->length(); i < n; i++ )
583 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
585 return objects.size();
588 //================================================================
589 // Function : getFather
590 // Purpose : Get father object for object to be added in study
591 // ( called with addInStudy method )
592 //================================================================
593 GEOM::GEOM_Object_ptr EntityGUI_SubShapeDlg::getFather( GEOM::GEOM_Object_ptr )
598 const char* EntityGUI_SubShapeDlg::getNewObjectName() const