1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : EntityGUI_SubShapeDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "EntityGUI_SubShapeDlg.h"
29 #include "GEOM_Displayer.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "OCCViewer_ViewModel.h"
34 #include "SalomeApp_Application.h"
35 #include "LightApp_SelectionMgr.h"
36 #include "SALOME_ListIteratorOfListIO.hxx"
38 #include <TColStd_IndexedMapOfInteger.hxx>
39 #include <TopoDS_Iterator.hxx>
40 #include <TopExp_Explorer.hxx>
41 #include <TopTools_MapOfShape.hxx>
43 #include <qmessagebox.h>
45 #include <qcombobox.h>
47 //=================================================================================
48 // class : EntityGUI_SubShapeDlg
49 // purpose : Constructs a EntityGUI_SubShapeDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 EntityGUI_SubShapeDlg::EntityGUI_SubShapeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
55 const char* name, bool modal, WFlags fl)
56 :GEOMBase_Skeleton(theGeometryGUI, 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 /***************************************************************/
80 setHelpFileName("create_explode_page.html");
86 //=================================================================================
87 // function : ~EntityGUI_SubShapeDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 EntityGUI_SubShapeDlg::~EntityGUI_SubShapeDlg()
95 //=================================================================================
98 //=================================================================================
99 void EntityGUI_SubShapeDlg::Init()
102 myEditCurrentArgument = GroupPoints->LineEdit1;
103 myObject = GEOM::GEOM_Object::_nil();
107 /* type for sub shape selection */
108 GroupPoints->ComboBox1->insertItem("Compound");
109 GroupPoints->ComboBox1->insertItem("Compsolid");
110 GroupPoints->ComboBox1->insertItem("Solid");
111 GroupPoints->ComboBox1->insertItem("Shell");
112 GroupPoints->ComboBox1->insertItem("Face");
113 GroupPoints->ComboBox1->insertItem("Wire");
114 GroupPoints->ComboBox1->insertItem("Edge");
115 GroupPoints->ComboBox1->insertItem("Vertex");
116 GroupPoints->ComboBox1->insertItem("Shape");
118 if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
119 != OCCViewer_Viewer::Type())
120 GroupPoints->CheckButton1->setEnabled(false);
122 /* signals and slots connections */
123 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
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(myGeomGUI->getApp()->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 */
177 bool isOk = onAccept();
179 // restore selection, corresponding to current selection mode
186 //=================================================================================
187 // function : SelectionIntoArgument()
188 // purpose : Called when selection as changed or other case
189 // : used only by SelectButtonC1A1 (LineEditC1A1)
190 //=================================================================================
191 void EntityGUI_SubShapeDlg::SelectionIntoArgument()
193 if ( !isAllSubShapes() )
196 ResetStateOfDialog();
198 QString aString = ""; /* name of selection */
200 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
205 Handle(SALOME_InteractiveObject) IO = firstIObject();
206 if ( !IO->hasEntry() )
208 SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_SHAPE_IN_STUDY" ) );
213 if ( !GEOMBase::GetTopoFromSelection( selectedIO(), S ) ||
215 S.ShapeType() == TopAbs_VERTEX )
217 myObject = GEOM::GEOM_Object::_nil();
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 globalSelection( GEOM_ALLSHAPES );
410 if ( !isAllSubShapes() )
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 Standard_Boolean testResult;
528 GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
529 if ( !testResult || myObject->_is_nil() ) {
533 if ( !myObject->_is_nil() ) {
534 if ( isAllSubShapes() )
536 else if ( IObjectCount() == 1 ) {
537 if ( testResult && !anObj->_is_nil() ) {
538 TColStd_IndexedMapOfInteger aMapIndex;
539 myGeomGUI->getApp()->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
540 isOk = aMapIndex.Extent() > 0;
542 msg += tr( "NO_SUBSHAPES_SELECTED" );
549 //=================================================================================
550 // function : execute
552 //=================================================================================
553 bool EntityGUI_SubShapeDlg::execute( ObjectList& objects )
555 GEOM::ListOfGO_var aList = GEOM::GEOM_IShapesOperations::_narrow(
556 getOperation() )->MakeExplode( myObject, shapeType(), true );
558 if ( !aList->length() )
561 // Throw away sub-shapes not selected by user if not in preview mode
562 // and manual selection is active
563 if ( !isAllSubShapes() )
565 if ( IObjectCount() == 1 ) {
566 Standard_Boolean aResult = Standard_False;
567 GEOM::GEOM_Object_var anObj =
568 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
570 if ( aResult && !anObj->_is_nil() ) {
571 TColStd_IndexedMapOfInteger aMapIndex;
572 myGeomGUI->getApp()->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
574 GEOM::GEOM_ILocalOperations_var aLocOp =
575 getGeomEngine()->GetILocalOperations( getStudyId() );
577 for ( int i = 0, n = aList->length(); i < n; i++ )
578 if ( aMapIndex.Contains( aLocOp->GetSubShapeIndex( myObject, aList[i] ) ) )
579 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
584 for ( int i = 0, n = aList->length(); i < n; i++ )
585 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
587 return objects.size();
590 //================================================================
591 // Function : getFather
592 // Purpose : Get father object for object to be added in study
593 // ( called with addInStudy method )
594 //================================================================
595 GEOM::GEOM_Object_ptr EntityGUI_SubShapeDlg::getFather( GEOM::GEOM_Object_ptr )
600 const char* EntityGUI_SubShapeDlg::getNewObjectName() const