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 : RepairGUI_SuppressFacesDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "RepairGUI_SuppressFacesDlg.h"
30 #include "SalomeApp_Application.h"
31 #include "LightApp_SelectionMgr.h"
32 #include "SUIT_Session.h"
33 #include "SALOME_ListIteratorOfListIO.hxx"
35 #include "GEOMImpl_Types.hxx"
43 //=================================================================================
44 // class : RepairGUI_SuppressFacesDlg()
45 // purpose : Constructs a RepairGUI_SuppressFacesDlg 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 RepairGUI_SuppressFacesDlg::RepairGUI_SuppressFacesDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
51 const char* name, bool modal, WFlags fl)
52 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
53 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUPRESS_FACE")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_SUPRESSFACE_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_SUPRESSFACE"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->close(TRUE);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_1Sel_QTD(this, "GroupPoints");
67 GroupPoints->GroupBox1->setTitle(tr("Faces to remove"));
68 GroupPoints->TextLabel1->setText(tr("Faces"));
69 GroupPoints->PushButton1->setPixmap(image1);
70 GroupPoints->LineEdit1->setReadOnly( true );
72 Layout1->addWidget(GroupPoints, 2, 0);
73 /***************************************************************/
75 setHelpFileName("suppress_faces_operation_page.html");
81 //=================================================================================
82 // function : ~RepairGUI_SuppressFacesDlg()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 RepairGUI_SuppressFacesDlg::~RepairGUI_SuppressFacesDlg()
90 //=================================================================================
93 //=================================================================================
94 void RepairGUI_SuppressFacesDlg::Init()
97 myEditCurrentArgument = GroupPoints->LineEdit1;
99 myObjects = new GEOM::ListOfGO();
100 myObjects->length( 0 );
102 //myGeomGUI->SetState( 0 );
105 /* signals and slots connections */
106 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
107 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
109 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
110 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
112 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
113 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
115 initName( tr( "SUPRESS_FACE_NEW_OBJ_NAME" ) );
119 //=================================================================================
120 // function : ClickOnOk()
121 // purpose : Same than click on apply but close this dialog.
122 //=================================================================================
123 void RepairGUI_SuppressFacesDlg::ClickOnOk()
125 if ( ClickOnApply() )
129 //=================================================================================
130 // function : ClickOnApply()
132 //=================================================================================
133 bool RepairGUI_SuppressFacesDlg::ClickOnApply()
140 myEditCurrentArgument->setText("");
141 myObjects->length( 0 );
150 //=================================================================================
151 // function : SelectionIntoArgument()
152 // purpose : Called when selection as changed or other case
153 // : used only by SelectButtonC1A1 (LineEditC1A1)
154 //=================================================================================
155 void RepairGUI_SuppressFacesDlg::SelectionIntoArgument()
157 myEditCurrentArgument->setText("");
159 Standard_Boolean aRes = Standard_False;
162 myObjects->length( IObjectCount() );
164 for ( SALOME_ListIteratorOfListIO anIt( selectedIO() ); anIt.More(); anIt.Next() )
166 Handle(SALOME_InteractiveObject) anIO = anIt.Value();
167 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
168 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
171 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) )
173 if ( aShape.ShapeType() <= TopAbs_FACE ) // FACE, SHELL, SOLID, COMPOUND
175 GEOM::short_array anIndexes;
177 TColStd_IndexedMapOfInteger aMap;
178 myGeomGUI->getApp()->selectionMgr()->GetIndexes( anIO, aMap );
180 if ( !aMap.IsEmpty() )
182 Convert( aMap, anIndexes );
183 myObjects[i++] = aSelectedObject; // append the object
184 myFaces.append( anIndexes ); // append faces' indexes
185 numFaces += anIndexes.length();// just for text field output
191 myObjects->length( i ); // this is the right length, smaller of equal to the previously set
193 myEditCurrentArgument->setText( QString::number( numFaces ) + "_" + tr( "GEOM_FACE" ) + tr( "_S_" ) );
196 //=================================================================================
197 // function : Convert()
199 //=================================================================================
200 void RepairGUI_SuppressFacesDlg::Convert( const TColStd_IndexedMapOfInteger& theMap, GEOM::short_array& theOutSeq )
202 const int n = theMap.Extent();
203 theOutSeq.length( n );
204 for ( int i = 0; i < n; i++ )
205 theOutSeq[i] = theMap( i+1 );
208 //=================================================================================
209 // function : SetEditCurrentArgument()
211 //=================================================================================
212 void RepairGUI_SuppressFacesDlg::SetEditCurrentArgument()
214 if( sender() == GroupPoints->PushButton1 )
216 GroupPoints->LineEdit1->setFocus();
217 myEditCurrentArgument = GroupPoints->LineEdit1;
219 SelectionIntoArgument();
223 //=================================================================================
224 // function : LineEditReturnPressed()
226 //=================================================================================
227 void RepairGUI_SuppressFacesDlg::LineEditReturnPressed()
229 if( sender() == GroupPoints->LineEdit1 )
231 myEditCurrentArgument = GroupPoints->LineEdit1;
232 GEOMBase_Skeleton::LineEditReturnPressed();
237 //=================================================================================
238 // function : ActivateThisDialog()
240 //=================================================================================
241 void RepairGUI_SuppressFacesDlg::ActivateThisDialog()
243 GEOMBase_Skeleton::ActivateThisDialog();
244 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
245 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
247 //myGeomGUI->SetState( 0 );
252 //=================================================================================
253 // function : enterEvent()
254 // purpose : Mouse enter onto the dialog to activate it
255 //=================================================================================
256 void RepairGUI_SuppressFacesDlg::enterEvent(QEvent* e)
258 if ( !GroupConstructors->isEnabled() )
259 ActivateThisDialog();
263 //=================================================================================
264 // function : closeEvent()
266 //=================================================================================
267 void RepairGUI_SuppressFacesDlg::closeEvent(QCloseEvent* e)
269 //myGeomGUI->SetState( -1 );
270 GEOMBase_Skeleton::closeEvent( e );
273 //=================================================================================
274 // function : createOperation
276 //=================================================================================
277 GEOM::GEOM_IOperations_ptr RepairGUI_SuppressFacesDlg::createOperation()
279 return getGeomEngine()->GetIHealingOperations( getStudyId() );
282 //=================================================================================
283 // function : isValid
285 //=================================================================================
286 bool RepairGUI_SuppressFacesDlg::isValid( QString& msg )
288 const int objL = myObjects->length(), facesL = myFaces.size();
289 return ( objL && objL == facesL );
292 //=================================================================================
293 // function : execute
295 //=================================================================================
296 bool RepairGUI_SuppressFacesDlg::execute( ObjectList& objects )
298 QStringList anErrorObjNames;
299 for ( int i = 0; i < myObjects->length(); i++ )
301 GEOM::GEOM_Object_var obj = myObjects[i];
302 GEOM::short_array faces = myFaces[i];
303 //MESSAGE(">>>> Dlg, passing faces.. len = " << faces.length());
304 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->SuppressFaces( obj, faces );
305 if ( anObj->_is_nil() )
306 anErrorObjNames << GEOMBase::GetName( obj );
308 objects.push_back( anObj._retn() );
311 if ( !anErrorObjNames.empty() )
312 MESSAGE("ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ));
314 return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
317 //=================================================================================
318 // function : initSelection
320 //=================================================================================
321 void RepairGUI_SuppressFacesDlg::initSelection()
323 GEOM::GEOM_Object_var aNullGeomObject;
324 localSelection( aNullGeomObject, TopAbs_FACE ); // load local selection on ALL objects