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 "QAD_RightFrame.h"
33 #include "QAD_Desktop.h"
34 #include "SALOME_ListIteratorOfListIO.hxx"
36 #include <TColStd_IndexedMapOfInteger.hxx>
37 #include <TopoDS_Iterator.hxx>
38 #include <TopExp_Explorer.hxx>
39 #include <TopTools_MapOfShape.hxx>
41 #include <qmessagebox.h>
43 //=================================================================================
44 // class : EntityGUI_SubShapeDlg
45 // purpose : Constructs a EntityGUI_SubShapeDlg which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 EntityGUI_SubShapeDlg::EntityGUI_SubShapeDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
51 :GEOMBase_Skeleton(parent, name, Sel, modal, fl)
53 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SUBSHAPE")));
54 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
56 setCaption(tr("GEOM_SUBSHAPE_TITLE"));
58 /***************************************************************/
59 GroupConstructors->setTitle(tr("GEOM_SUB_SHAPE"));
60 RadioButton1->setPixmap(image0);
61 RadioButton2->close(TRUE);
62 RadioButton3->close(TRUE);
64 GroupPoints = new DlgRef_1Sel1Check1List_QTD(this, "GroupPoints");
65 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
66 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
67 GroupPoints->TextLabel2->setText(tr("GEOM_SUBSHAPE_TYPE"));
68 GroupPoints->CheckButton1->setText(tr("GEOM_SUBSHAPE_SELECT"));
69 GroupPoints->PushButton1->setPixmap(image1);
70 GroupPoints->LineEdit1->setReadOnly( true );
72 Layout1->addWidget(GroupPoints, 1, 0);
73 /***************************************************************/
79 //=================================================================================
80 // function : ~EntityGUI_SubShapeDlg()
81 // purpose : Destroys the object and frees any allocated resources
82 //=================================================================================
83 EntityGUI_SubShapeDlg::~EntityGUI_SubShapeDlg()
88 //=================================================================================
91 //=================================================================================
92 void EntityGUI_SubShapeDlg::Init()
95 myEditCurrentArgument = GroupPoints->LineEdit1;
96 myObject = GEOM::GEOM_Object::_nil();
100 /* type for sub shape selection */
101 GroupPoints->ComboBox1->insertItem("Compound");
102 GroupPoints->ComboBox1->insertItem("Compsolid");
103 GroupPoints->ComboBox1->insertItem("Solid");
104 GroupPoints->ComboBox1->insertItem("Shell");
105 GroupPoints->ComboBox1->insertItem("Face");
106 GroupPoints->ComboBox1->insertItem("Wire");
107 GroupPoints->ComboBox1->insertItem("Edge");
108 GroupPoints->ComboBox1->insertItem("Vertex");
109 GroupPoints->ComboBox1->insertItem("Shape");
111 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC)
112 GroupPoints->CheckButton1->setEnabled(false);
114 /* signals and slots connections */
115 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
116 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
117 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
119 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
120 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
122 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
126 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(SubShapeToggled()));
128 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
132 SelectionIntoArgument();
136 //=================================================================================
137 // function : ClickOnOk()
139 //=================================================================================
140 void EntityGUI_SubShapeDlg::ClickOnOk()
142 if ( ClickOnApply() )
147 //=================================================================================
148 // function : ClickOnApply()
150 //=================================================================================
151 bool EntityGUI_SubShapeDlg::ClickOnApply()
153 QAD_Application::getDesktop()->putInfo(tr(""));
155 /* Explode all sub shapes */
156 if( isAllSubShapes() ) {
157 /* More than 30 subshapes : ask confirmation */
158 unsigned int nb = NumberOfSubShapes(myShape, shapeType());
160 const QString caption = tr("GEOM_CONFIRM");
161 const QString text = tr("GEOM_CONFIRM_INFO").arg(nb);
162 const QString button0 = tr("GEOM_BUT_EXPLODE");
163 const QString button1 = tr("GEOM_BUT_CANCEL");
165 if(QMessageBox::warning(this, caption, text, button0, button1) != 0)
166 return false; /* aborted */
174 //=================================================================================
175 // function : SelectionIntoArgument()
176 // purpose : Called when selection as changed or other case
177 // : used only by SelectButtonC1A1 (LineEditC1A1)
178 //=================================================================================
179 void EntityGUI_SubShapeDlg::SelectionIntoArgument()
181 if ( !isAllSubShapes() )
184 ResetStateOfDialog();
186 QString aString = ""; /* name of selection */
188 int nbSel = GEOMBase::GetNameOfSelectedIObjects( mySelection, aString, true );
193 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
194 if ( !IO->hasEntry() )
196 QAD_Application::getDesktop()->putInfo( tr( "GEOM_PRP_SHAPE_IN_STUDY" ) );
201 if ( !myGeomBase->GetTopoFromSelection( mySelection, S ) ||
203 S.ShapeType() == TopAbs_VERTEX )
210 Standard_Boolean testResult;
211 myObject = GEOMBase::ConvertIOinGEOMObject( IO, testResult );
212 if ( !testResult || myObject->_is_nil() )
219 GroupPoints->LineEdit1->setText( aString );
222 int SelectedShapeType = GroupPoints->ComboBox1->currentItem();
223 int count = GroupPoints->ComboBox1->count();
230 if ( myShape.ShapeType() == TopAbs_COMPOUND ) {
231 unsigned int nb = NumberOfSubShapes(myShape, TopAbs_COMPOUND);
235 while ( i <= myShape.ShapeType())
237 GroupPoints->ComboBox1->removeItem( 0 );
241 if ( myShape.ShapeType() == TopAbs_COMPOUND )
243 if ( myWithShape == false )
245 GroupPoints->ComboBox1->insertItem( "Shape" );
251 if ( myWithShape == true )
253 GroupPoints->ComboBox1->removeItem( GroupPoints->ComboBox1->count() - 1 );
258 int count1 = GroupPoints->ComboBox1->count();
262 if ( SelectedShapeType > myShape.ShapeType() )
264 if ( SelectedShapeType == 8 )
266 if ( myShape.ShapeType() != TopAbs_COMPOUND )
268 GroupPoints->ComboBox1->setCurrentItem( 0 );
273 GroupPoints->ComboBox1->setCurrentItem(count1 - count + SelectedShapeType);
277 GroupPoints->ComboBox1->setCurrentItem( 0 );
285 //=================================================================================
286 // function : SetEditCurrentArgument()
288 //=================================================================================
289 void EntityGUI_SubShapeDlg::SetEditCurrentArgument()
291 GroupPoints->LineEdit1->setFocus();
292 myEditCurrentArgument = GroupPoints->LineEdit1;
294 GroupPoints->CheckButton1->setChecked( FALSE );
296 SelectionIntoArgument();
300 //=================================================================================
301 // function : LineEditReturnPressed()
303 //=================================================================================
304 void EntityGUI_SubShapeDlg::LineEditReturnPressed()
306 QLineEdit* send = (QLineEdit*)sender();
307 if(send == GroupPoints->LineEdit1)
308 SetEditCurrentArgument();
312 GEOMBase_Skeleton::LineEditReturnPressed();
316 //=================================================================================
317 // function : DeactivateActiveDialog()
319 //=================================================================================
320 void EntityGUI_SubShapeDlg::DeactivateActiveDialog()
322 if(GroupConstructors->isEnabled()) {
323 GEOMBase_Skeleton::DeactivateActiveDialog();
328 //=================================================================================
329 // function : ActivateThisDialog()
331 //=================================================================================
332 void EntityGUI_SubShapeDlg::ActivateThisDialog()
334 GEOMBase_Skeleton::ActivateThisDialog();
335 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
341 //=================================================================================
342 // function : enterEvent()
344 //=================================================================================
345 void EntityGUI_SubShapeDlg::enterEvent(QEvent* e)
347 if(GroupConstructors->isEnabled())
349 ActivateThisDialog();
352 //=================================================================================
353 // function : ResetStateOfDialog()
354 // purpose : Completely reset the state of method including local context
355 //=================================================================================
356 void EntityGUI_SubShapeDlg::ResetStateOfDialog()
358 myObject = GEOM::GEOM_Object::_nil();
360 myEditCurrentArgument->setText("");
362 int SelectedShapeType = GroupPoints->ComboBox1->currentItem();
363 int count = GroupPoints->ComboBox1->count();
367 /* type for sub shape selection */
368 GroupPoints->ComboBox1->clear();
369 GroupPoints->ComboBox1->insertItem("Compound");
370 GroupPoints->ComboBox1->insertItem("Compsolid");
371 GroupPoints->ComboBox1->insertItem("Solid");
372 GroupPoints->ComboBox1->insertItem("Shell");
373 GroupPoints->ComboBox1->insertItem("Face");
374 GroupPoints->ComboBox1->insertItem("Wire");
375 GroupPoints->ComboBox1->insertItem("Edge");
376 GroupPoints->ComboBox1->insertItem("Vertex");
377 GroupPoints->ComboBox1->insertItem("Shape");
381 GroupPoints->ComboBox1->setCurrentItem( 8 - count + SelectedShapeType );
388 //=================================================================================
389 // function : SubShapeToggled()
390 // purpose : Allow user selection of all or only selected sub shapes
391 // : Called when 'CheckButton1' state change
392 //=================================================================================
393 void EntityGUI_SubShapeDlg::SubShapeToggled()
395 if ( isAllSubShapes() )
396 globalSelection( GEOM_ALLSHAPES );
398 localSelection( myObject, shapeType() );
402 //=================================================================================
403 // function : ComboTextChanged()
405 //=================================================================================
406 void EntityGUI_SubShapeDlg::ComboTextChanged()
408 /* Select sub shapes mode not checked */
414 //=================================================================================
415 // function : NumberOfSubShapes()
417 //=================================================================================
418 unsigned int EntityGUI_SubShapeDlg::NumberOfSubShapes (const TopoDS_Shape& S,
419 const int shapeType) const
424 unsigned int index = 0;
425 TopTools_MapOfShape M;
427 if (S.ShapeType() == TopAbs_COMPOUND &&
428 (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
429 TopAbs_ShapeEnum(shapeType) == TopAbs_COMPSOLID ||
430 TopAbs_ShapeEnum(shapeType) == TopAbs_COMPOUND)) {
431 TopoDS_Iterator It (S, Standard_True, Standard_True);
432 for (; It.More(); It.Next()) {
433 if (M.Add(It.Value())) {
434 if (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
435 TopAbs_ShapeEnum(shapeType) == It.Value().ShapeType()) {
441 TopExp_Explorer Exp (S, TopAbs_ShapeEnum(shapeType));
442 for (; Exp.More(); Exp.Next()) {
443 if (M.Add(Exp.Current())) {
453 //=================================================================================
454 // function : updateButtonState
456 //=================================================================================
457 void EntityGUI_SubShapeDlg::updateButtonState()
459 if ( QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC ||
460 myObject->_is_nil() || shapeType() == TopAbs_SHAPE || shapeType() == TopAbs_COMPOUND ) {
461 GroupPoints->CheckButton1->setChecked( FALSE );
462 GroupPoints->CheckButton1->setEnabled( FALSE );
465 GroupPoints->CheckButton1->setEnabled( TRUE );
468 //=================================================================================
469 // function : isAllSubShapes
471 //=================================================================================
472 bool EntityGUI_SubShapeDlg::isAllSubShapes() const
474 return !GroupPoints->CheckButton1->isChecked() || !GroupPoints->CheckButton1->isEnabled();
477 //=================================================================================
478 // function : shapeType
480 //=================================================================================
481 int EntityGUI_SubShapeDlg::shapeType() const
483 int type = GroupPoints->ComboBox1->currentItem();
485 if (myObject->_is_nil())
489 type += myShape.ShapeType() + 1;
490 if (myShape.ShapeType() == TopAbs_COMPOUND &&
491 NumberOfSubShapes(myShape, TopAbs_COMPOUND) > 0) {
498 //=================================================================================
499 // function : createOperation
501 //=================================================================================
502 GEOM::GEOM_IOperations_ptr EntityGUI_SubShapeDlg::createOperation()
504 return getGeomEngine()->GetIShapesOperations( getStudyId() );
507 //=================================================================================
508 // function : isValid
510 //=================================================================================
511 bool EntityGUI_SubShapeDlg::isValid( QString& msg )
514 if ( !myObject->_is_nil() ) {
515 if ( isAllSubShapes() )
517 else if ( mySelection->IObjectCount() == 1 ) {
518 Standard_Boolean aResult = Standard_False;
519 GEOM::GEOM_Object_var anObj =
520 GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aResult );
522 if ( aResult && !anObj->_is_nil() ) {
523 TColStd_IndexedMapOfInteger aMapIndex;
524 mySelection->GetIndex( mySelection->firstIObject(), aMapIndex );
525 isOk = aMapIndex.Extent() > 0;
527 msg += tr( "NO_SUBSHAPES_SELECTED" );
534 //=================================================================================
535 // function : execute
537 //=================================================================================
538 bool EntityGUI_SubShapeDlg::execute( ObjectList& objects )
540 GEOM::ListOfGO_var aList = GEOM::GEOM_IShapesOperations::_narrow(
541 getOperation() )->MakeExplode( myObject, shapeType(), false );
543 if ( !aList->length() )
546 // Throw away sub-shapes not selected by user if not in preview mode
547 // and manual selection is active
548 if ( !isAllSubShapes() )
550 if ( mySelection->IObjectCount() == 1 ) {
551 Standard_Boolean aResult = Standard_False;
552 GEOM::GEOM_Object_var anObj =
553 GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aResult );
555 if ( aResult && !anObj->_is_nil() ) {
556 TColStd_IndexedMapOfInteger aMapIndex;
557 mySelection->GetIndex( mySelection->firstIObject(), aMapIndex );
559 GEOM::GEOM_ILocalOperations_var aLocOp =
560 getGeomEngine()->GetILocalOperations( getStudyId() );
562 for ( int i = 0, n = aList->length(); i < n; i++ )
563 if ( aMapIndex.Contains( aLocOp->GetSubShapeIndex( myObject, aList[i] ) ) )
564 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
569 for ( int i = 0, n = aList->length(); i < n; i++ )
570 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
572 return objects.size();
575 //================================================================
576 // Function : getFather
577 // Purpose : Get father object for object to be added in study
578 // ( called with addInStudy method )
579 //================================================================
580 GEOM::GEOM_Object_ptr EntityGUI_SubShapeDlg::getFather( GEOM::GEOM_Object_ptr )