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 : RepairGUI_SuppressFacesDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "RepairGUI_SuppressFacesDlg.h"
32 #include "QAD_RightFrame.h"
33 #include "QAD_Desktop.h"
34 #include "OCCViewer_Viewer3d.h"
35 #include "SALOME_ListIteratorOfListIO.hxx"
37 #include "GEOMImpl_Types.hxx"
42 //=================================================================================
43 // class : RepairGUI_SuppressFacesDlg()
44 // purpose : Constructs a RepairGUI_SuppressFacesDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 RepairGUI_SuppressFacesDlg::RepairGUI_SuppressFacesDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SUPRESS_FACE")));
53 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
55 setCaption(tr("GEOM_SUPRESSFACE_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_SUPRESSFACE"));
59 RadioButton1->setPixmap(image0);
60 RadioButton2->close(TRUE);
61 RadioButton3->close(TRUE);
63 GroupPoints = new DlgRef_1Sel_QTD(this, "GroupPoints");
64 GroupPoints->GroupBox1->setTitle(tr("Faces to remove"));
65 GroupPoints->TextLabel1->setText(tr("Faces"));
66 GroupPoints->PushButton1->setPixmap(image1);
67 GroupPoints->LineEdit1->setReadOnly( true );
69 Layout1->addWidget(GroupPoints, 2, 0);
70 /***************************************************************/
76 //=================================================================================
77 // function : ~RepairGUI_SuppressFacesDlg()
78 // purpose : Destroys the object and frees any allocated resources
79 //=================================================================================
80 RepairGUI_SuppressFacesDlg::~RepairGUI_SuppressFacesDlg()
85 //=================================================================================
88 //=================================================================================
89 void RepairGUI_SuppressFacesDlg::Init()
92 myEditCurrentArgument = GroupPoints->LineEdit1;
94 myObjects = new GEOM::ListOfGO();
95 myObjects->length( 0 );
97 myGeomGUI->SetState( 0 );
100 /* signals and slots connections */
101 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
102 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
103 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
105 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
106 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
108 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
111 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
113 initName( tr( "SUPRESS_FACE_NEW_OBJ_NAME" ) );
117 //=================================================================================
118 // function : ClickOnOk()
119 // purpose : Same than click on apply but close this dialog.
120 //=================================================================================
121 void RepairGUI_SuppressFacesDlg::ClickOnOk()
123 if ( ClickOnApply() )
129 //=================================================================================
130 // function : ClickOnApply()
132 //=================================================================================
133 bool RepairGUI_SuppressFacesDlg::ClickOnApply()
140 myEditCurrentArgument->setText("");
141 myObjects->length( 0 );
150 //=================================================================================
151 // function : ClickOnCancel()
153 //=================================================================================
154 void RepairGUI_SuppressFacesDlg::ClickOnCancel()
156 GEOMBase_Skeleton::ClickOnCancel();
160 //=================================================================================
161 // function : SelectionIntoArgument()
162 // purpose : Called when selection as changed or other case
163 // : used only by SelectButtonC1A1 (LineEditC1A1)
164 //=================================================================================
165 void RepairGUI_SuppressFacesDlg::SelectionIntoArgument()
167 myEditCurrentArgument->setText("");
169 Standard_Boolean aRes = Standard_False;
172 myObjects->length( mySelection->IObjectCount() );
174 for ( SALOME_ListIteratorOfListIO anIt( mySelection->StoredIObjects() ); anIt.More(); anIt.Next() )
176 Handle(SALOME_InteractiveObject) anIO = anIt.Value();
177 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
178 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
181 if ( myGeomBase->GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) )
183 if ( aShape.ShapeType() <= TopAbs_FACE ) // FACE, SHELL, SOLID, COMPOUND
185 GEOM::short_array anIndexes;
186 if ( mySelection->HasIndex( anIO ) )
188 TColStd_IndexedMapOfInteger aMap;
189 mySelection->GetIndex( anIO, aMap );
190 Convert( aMap, anIndexes );
191 myObjects[i++] = aSelectedObject; // append the object
192 myFaces.append( anIndexes ); // append faces' indexes
193 numFaces += anIndexes.length();// just for text field output
199 myObjects->length( i ); // this is the right length, smaller of equal to the previously set
201 myEditCurrentArgument->setText( QString::number( numFaces ) + "_" + tr( "GEOM_FACE" ) + tr( "_S_" ) );
204 //=================================================================================
205 // function : Convert()
207 //=================================================================================
208 void RepairGUI_SuppressFacesDlg::Convert( const TColStd_IndexedMapOfInteger& theMap, GEOM::short_array& theOutSeq )
210 const int n = theMap.Extent();
211 theOutSeq.length( n );
212 for ( int i = 0; i < n; i++ )
213 theOutSeq[i] = theMap( i+1 );
216 //=================================================================================
217 // function : SetEditCurrentArgument()
219 //=================================================================================
220 void RepairGUI_SuppressFacesDlg::SetEditCurrentArgument()
222 if( sender() == GroupPoints->PushButton1 )
224 GroupPoints->LineEdit1->setFocus();
225 myEditCurrentArgument = GroupPoints->LineEdit1;
227 SelectionIntoArgument();
231 //=================================================================================
232 // function : LineEditReturnPressed()
234 //=================================================================================
235 void RepairGUI_SuppressFacesDlg::LineEditReturnPressed()
237 if( sender() == GroupPoints->LineEdit1 )
239 myEditCurrentArgument = GroupPoints->LineEdit1;
240 GEOMBase_Skeleton::LineEditReturnPressed();
245 //=================================================================================
246 // function : DeactivateActiveDialog()
248 //=================================================================================
249 void RepairGUI_SuppressFacesDlg::DeactivateActiveDialog()
251 myGeomGUI->SetState( -1 );
252 GEOMBase_Skeleton::DeactivateActiveDialog();
256 //=================================================================================
257 // function : ActivateThisDialog()
259 //=================================================================================
260 void RepairGUI_SuppressFacesDlg::ActivateThisDialog()
262 GEOMBase_Skeleton::ActivateThisDialog();
263 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
265 myGeomGUI->SetState( 0 );
270 //=================================================================================
271 // function : enterEvent()
272 // purpose : Mouse enter onto the dialog to activate it
273 //=================================================================================
274 void RepairGUI_SuppressFacesDlg::enterEvent(QEvent* e)
276 if ( !GroupConstructors->isEnabled() )
277 ActivateThisDialog();
281 //=================================================================================
282 // function : closeEvent()
284 //=================================================================================
285 void RepairGUI_SuppressFacesDlg::closeEvent(QCloseEvent* e)
287 myGeomGUI->SetState( -1 );
288 GEOMBase_Skeleton::closeEvent( e );
291 //=================================================================================
292 // function : createOperation
294 //=================================================================================
295 GEOM::GEOM_IOperations_ptr RepairGUI_SuppressFacesDlg::createOperation()
297 return getGeomEngine()->GetIHealingOperations( getStudyId() );
300 //=================================================================================
301 // function : isValid
303 //=================================================================================
304 bool RepairGUI_SuppressFacesDlg::isValid( QString& msg )
306 const int objL = myObjects->length(), facesL = myFaces.size();
307 return ( objL && objL == facesL );
310 //=================================================================================
311 // function : execute
313 //=================================================================================
314 bool RepairGUI_SuppressFacesDlg::execute( ObjectList& objects )
316 QStringList anErrorObjNames;
317 for ( int i = 0; i < myObjects->length(); i++ )
319 GEOM::GEOM_Object_var obj = myObjects[i];
320 GEOM::short_array faces = myFaces[i];
321 //MESSAGE(">>>> Dlg, passing faces.. len = " << faces.length());
322 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->SuppressFaces( obj, faces );
323 if ( anObj->_is_nil() )
324 anErrorObjNames << GEOMBase::GetName( obj );
326 objects.push_back( anObj._retn() );
329 if ( !anErrorObjNames.empty() )
330 MESSAGE("ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ));
332 return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
335 //=================================================================================
336 // function : initSelection
338 //=================================================================================
339 void RepairGUI_SuppressFacesDlg::initSelection()
341 GEOM::GEOM_Object_var aNullGeomObject;
342 localSelection( aNullGeomObject, TopAbs_FACE ); // load local selection on ALL objects