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, 1, 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()));
115 //=================================================================================
116 // function : ClickOnOk()
117 // purpose : Same than click on apply but close this dialog.
118 //=================================================================================
119 void RepairGUI_SuppressFacesDlg::ClickOnOk()
121 if ( ClickOnApply() )
127 //=================================================================================
128 // function : ClickOnApply()
130 //=================================================================================
131 bool RepairGUI_SuppressFacesDlg::ClickOnApply()
136 myEditCurrentArgument->setText("");
137 myObjects->length( 0 );
146 //=================================================================================
147 // function : ClickOnCancel()
149 //=================================================================================
150 void RepairGUI_SuppressFacesDlg::ClickOnCancel()
152 GEOMBase_Skeleton::ClickOnCancel();
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose : Called when selection as changed or other case
159 // : used only by SelectButtonC1A1 (LineEditC1A1)
160 //=================================================================================
161 void RepairGUI_SuppressFacesDlg::SelectionIntoArgument()
163 myEditCurrentArgument->setText("");
165 Standard_Boolean aRes = Standard_False;
168 myObjects->length( mySelection->IObjectCount() );
170 for ( SALOME_ListIteratorOfListIO anIt( mySelection->StoredIObjects() ); anIt.More(); anIt.Next() )
172 Handle(SALOME_InteractiveObject) anIO = anIt.Value();
173 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
174 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
177 if ( myGeomBase->GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) )
179 if ( aShape.ShapeType() <= TopAbs_FACE ) // FACE, SHELL, SOLID, COMPOUND
181 GEOM::short_array anIndexes;
182 if ( mySelection->HasIndex( anIO ) )
184 TColStd_IndexedMapOfInteger aMap;
185 mySelection->GetIndex( anIO, aMap );
186 Convert( aMap, anIndexes );
187 myObjects[i++] = aSelectedObject; // append the object
188 myFaces.append( anIndexes ); // append faces' indexes
189 numFaces += anIndexes.length();// just for text field output
195 myObjects->length( i ); // this is the right length, smaller of equal to the previously set
197 myEditCurrentArgument->setText( QString::number( numFaces ) + "_" + tr( "GEOM_FACE" ) + tr( "_S_" ) );
200 //=================================================================================
201 // function : Convert()
203 //=================================================================================
204 void RepairGUI_SuppressFacesDlg::Convert( const TColStd_IndexedMapOfInteger& theMap, GEOM::short_array& theOutSeq )
206 const int n = theMap.Extent();
207 theOutSeq.length( n );
208 for ( int i = 0; i < n; i++ )
209 theOutSeq[i] = theMap( i+1 );
212 //=================================================================================
213 // function : SetEditCurrentArgument()
215 //=================================================================================
216 void RepairGUI_SuppressFacesDlg::SetEditCurrentArgument()
218 if( sender() == GroupPoints->PushButton1 )
220 GroupPoints->LineEdit1->setFocus();
221 myEditCurrentArgument = GroupPoints->LineEdit1;
223 SelectionIntoArgument();
227 //=================================================================================
228 // function : LineEditReturnPressed()
230 //=================================================================================
231 void RepairGUI_SuppressFacesDlg::LineEditReturnPressed()
233 if( sender() == GroupPoints->LineEdit1 )
235 myEditCurrentArgument = GroupPoints->LineEdit1;
236 GEOMBase_Skeleton::LineEditReturnPressed();
241 //=================================================================================
242 // function : DeactivateActiveDialog()
244 //=================================================================================
245 void RepairGUI_SuppressFacesDlg::DeactivateActiveDialog()
247 myGeomGUI->SetState( -1 );
248 GEOMBase_Skeleton::DeactivateActiveDialog();
252 //=================================================================================
253 // function : ActivateThisDialog()
255 //=================================================================================
256 void RepairGUI_SuppressFacesDlg::ActivateThisDialog()
258 GEOMBase_Skeleton::ActivateThisDialog();
259 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
261 myGeomGUI->SetState( 0 );
266 //=================================================================================
267 // function : enterEvent()
268 // purpose : Mouse enter onto the dialog to activate it
269 //=================================================================================
270 void RepairGUI_SuppressFacesDlg::enterEvent(QEvent* e)
272 if ( !GroupConstructors->isEnabled() )
273 ActivateThisDialog();
277 //=================================================================================
278 // function : closeEvent()
280 //=================================================================================
281 void RepairGUI_SuppressFacesDlg::closeEvent(QCloseEvent* e)
283 myGeomGUI->SetState( -1 );
284 GEOMBase_Skeleton::closeEvent( e );
287 //=================================================================================
288 // function : createOperation
290 //=================================================================================
291 GEOM::GEOM_IOperations_ptr RepairGUI_SuppressFacesDlg::createOperation()
293 return getGeomEngine()->GetIHealingOperations( getStudyId() );
296 //=================================================================================
297 // function : isValid
299 //=================================================================================
300 bool RepairGUI_SuppressFacesDlg::isValid( QString& msg )
302 const int objL = myObjects->length(), facesL = myFaces.size();
303 return ( objL && objL == facesL );
306 //=================================================================================
307 // function : execute
309 //=================================================================================
310 bool RepairGUI_SuppressFacesDlg::execute( ObjectList& objects )
312 QStringList anErrorObjNames;
313 for ( int i = 0; i < myObjects->length(); i++ )
315 GEOM::GEOM_Object_var obj = myObjects[i];
316 GEOM::short_array faces = myFaces[i];
317 //MESSAGE(">>>> Dlg, passing faces.. len = " << faces.length());
318 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->SuppressFaces( obj, faces );
319 if ( anObj->_is_nil() )
320 anErrorObjNames << GEOMBase::GetName( obj );
322 objects.push_back( anObj._retn() );
325 if ( !anErrorObjNames.empty() )
326 MESSAGE("ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ));
328 return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
331 //=================================================================================
332 // function : initSelection
334 //=================================================================================
335 void RepairGUI_SuppressFacesDlg::initSelection()
337 GEOM::GEOM_Object_var aNullGeomObject;
338 localSelection( aNullGeomObject, TopAbs_FACE ); // load local selection on ALL objects