1 // Copyright (C) 2007-2024 CEA, EDF, 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, or (at your option) any later version.
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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : RepairGUI_FreeFacesDlg.cxx
25 // Author : Vladimir KLYACHIN, Open CASCADE S.A.S. (vladimir.klyachin@opencascade.com)
27 #include "RepairGUI_FreeFacesDlg.h"
30 #include <GeometryGUI.h>
31 #include <GEOMImpl_Types.hxx>
32 #include <GEOM_Constants.h>
34 #include <LightApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36 #include <SalomeApp_Application.h>
37 #include <SalomeApp_Study.h>
38 #include <SalomeApp_Tools.h>
39 #include <SUIT_Desktop.h>
40 #include <SUIT_OverrideCursor.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_ViewManager.h>
44 #include <SUIT_ViewWindow.h>
46 #include <TColStd_MapOfInteger.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <QHBoxLayout>
54 #include <QPushButton>
55 #include <QRadioButton>
56 #include <QVBoxLayout>
63 //=================================================================================
64 // class : RepairGUI_FreeFacesDlg()
65 // purpose : Constructs a RepairGUI_FreeFacesDlg which is a child of 'parent', with the
66 // name 'name' and widget flags set to 'f'.
67 // The dialog will by default be modeless, unless you set 'modal' to
68 // TRUE to construct a modal dialog.
69 //=================================================================================
70 RepairGUI_FreeFacesDlg::RepairGUI_FreeFacesDlg( GeometryGUI* GUI, QWidget* parent,
72 : GEOMBase_Skeleton(GUI, parent, modal),
76 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FREE_FACES")));
77 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
79 setWindowTitle( tr( "GEOM_FREE_FACES_TITLE" ) );
81 /***************************************************************/
83 mainFrame()->GroupConstructors->setTitle(tr("GEOM_FREE_FACES"));
84 mainFrame()->RadioButton1->setIcon(image0);
85 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
86 mainFrame()->RadioButton2->close();
87 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
88 mainFrame()->RadioButton3->close();
90 mainFrame()->GroupBoxName->hide();
92 QGroupBox* aMainGrp = new QGroupBox( tr( "GEOM_SELECTED_SHAPE" ), this );
94 QLabel* lab = new QLabel( tr( "GEOM_OBJECT" ), aMainGrp );
95 QPushButton *aSelBtn = new QPushButton( aMainGrp );
96 aSelBtn->setIcon( image1 );
97 myEdit = new QLineEdit( aMainGrp );
98 myEdit->setReadOnly( true );
99 myEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
100 myEdit->setMinimumWidth( MIN_WIDTH );
102 QHBoxLayout* aMainLay = new QHBoxLayout( aMainGrp );
103 aMainLay->setSpacing( SPACING );
104 aMainLay->setMargin( MARGIN );
105 aMainLay->addWidget( lab );
106 aMainLay->addWidget( aSelBtn );
107 aMainLay->addWidget( myEdit );
109 QVBoxLayout* aLay = new QVBoxLayout (centralWidget());
110 aLay->setSpacing(SPACING);
111 aLay->setMargin(MARGIN);
112 aLay->addWidget(aMainGrp);
114 resize(minimumSizeHint());
115 /***************************************************************/
117 myHelpFileName = "free_faces_page.html";
123 //=================================================================================
124 // function : ~RepairGUI_FreeFacesDlg()
125 // purpose : Destroys the object and frees any allocated resources
126 //=================================================================================
127 RepairGUI_FreeFacesDlg::~RepairGUI_FreeFacesDlg()
132 //=================================================================================
135 //=================================================================================
136 void RepairGUI_FreeFacesDlg::Init()
138 myObj = GEOM::GEOM_Object::_nil();
139 myEditCurrentArgument = myEdit;
141 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
142 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
143 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
144 this, SLOT(SelectionIntoArgument()));
146 initName(tr("GEOM_FREE_FACES_NAME"));
147 buttonOk()->setEnabled(false);
148 buttonApply()->setEnabled(false);
150 SelectionIntoArgument();
153 //=================================================================================
154 // function : ClickOnOk()
156 //=================================================================================
157 void RepairGUI_FreeFacesDlg::ClickOnOk()
163 //=================================================================================
164 // function : ClickOnApply()
166 //=================================================================================
167 bool RepairGUI_FreeFacesDlg::ClickOnApply()
176 //=================================================================================
177 // function : ActivateThisDialog()
179 //=================================================================================
180 void RepairGUI_FreeFacesDlg::ActivateThisDialog()
182 GEOMBase_Skeleton::ActivateThisDialog();
184 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
185 this, SLOT(SelectionIntoArgument()));
188 displayPreview(true);
191 //=================================================================================
192 // function : enterEvent()
194 //=================================================================================
195 void RepairGUI_FreeFacesDlg::enterEvent(QEvent*)
197 if (!mainFrame()->GroupConstructors->isEnabled())
198 ActivateThisDialog();
201 //=================================================================================
202 // function : SelectionIntoArgument
203 // purpose : SLOT. Called when selection changed.
204 //=================================================================================
205 void RepairGUI_FreeFacesDlg::SelectionIntoArgument()
207 myEditCurrentArgument->setText("");
208 myObj = GEOM::GEOM_Object::_nil();
211 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
212 SALOME_ListIO aSelList;
213 aSelMgr->selectedObjects(aSelList);
215 if ( aSelList.Extent() != 1 ) {
216 buttonOk()->setEnabled(false);
217 buttonApply()->setEnabled(false);
221 GEOM::GEOM_Object_var anObj =
222 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
224 if ( !GEOMBase::IsShape( anObj ) ) {
225 buttonOk()->setEnabled(false);
226 buttonApply()->setEnabled(false);
230 myEditCurrentArgument->setText(GEOMBase::GetName(myObj));
231 displayPreview( true, false, true, true, 3 );
235 //=================================================================================
236 // function : activateSelection
237 // purpose : activate selection of solids
238 //=================================================================================
239 void RepairGUI_FreeFacesDlg::activateSelection()
241 TColStd_MapOfInteger aMap;
242 aMap.Add( GEOM_SOLID );
243 aMap.Add( GEOM_COMPOUND );
244 globalSelection( aMap );
247 //=================================================================================
248 // function : createOperation
250 //=================================================================================
251 GEOM::GEOM_IOperations_ptr RepairGUI_FreeFacesDlg::createOperation()
253 return getGeomEngine()->GetIShapesOperations();
256 //=================================================================================
257 // function : isValid
259 //=================================================================================
260 bool RepairGUI_FreeFacesDlg::isValid( QString& )
262 return !myObj->_is_nil() ;
265 //=================================================================================
266 // function : execute
268 //=================================================================================
269 bool RepairGUI_FreeFacesDlg::execute( ObjectList& objects )
271 bool aResult = false;
272 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
273 GEOM::ListOfLong_var aFaceLst = anOper->GetFreeFacesIDs( myObj );
274 TopoDS_Shape aSelShape;
276 TopTools_IndexedMapOfShape anIndices;
279 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
280 myEdit->setText( GEOMBase::GetName( myObj ) );
282 if ( !isValid( aMess ) ) {
283 erasePreview( true );
284 buttonOk()->setEnabled(false);
285 buttonApply()->setEnabled(false);
289 SUIT_OverrideCursor wc;
291 TopExp::MapShapes( aSelShape, anIndices);
292 SALOME_Prs* aPrs = 0;
294 //Get object trancparency and set it to preview
295 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
296 double transparency = 1.0;
298 SUIT_ViewWindow* window = app->desktop( )->activeWindow( );
299 if( window && window->getViewManager() ) {
301 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
303 int aMgrId = window->getViewManager()->getGlobalId();
304 CORBA::String_var aMainEntry = myObj->GetStudyEntry();
305 QString anEntry = aMainEntry.in();
306 QVariant v = aStudy->getObjectProperty( aMgrId , anEntry , GEOM::propertyName( GEOM::Transparency ) , transparency );
307 if( v.canConvert( QVariant::Double ) ) {
308 transparency = v.toDouble();
316 int n = aFaceLst->length();
318 for (i = 0; i < n; i++ ) {
319 aFace = anIndices.FindKey( aFaceLst[i] );
321 getDisplayer()->SetColor( Quantity_NOC_RED );
322 getDisplayer()->SetTransparency( transparency );
323 getDisplayer()->SetWidth( 2 );
324 getDisplayer()->SetNbIsos( 1 );
325 getDisplayer()->SetIsosWidth( 1 );
326 getDisplayer()->SetIsosColor( Quantity_NOC_RED );
327 getDisplayer()->SetDisplayMode( 0 );
328 getDisplayer()->SetToActivate( false );
329 aPrs = !aFace.IsNull() ? getDisplayer()->BuildPrs( aFace ) : 0;
331 displayPreview( aPrs, true );
333 catch( const SALOME::SALOME_Exception& e )
335 SalomeApp_Tools::QtCatchCorbaException( e );
336 buttonOk()->setEnabled(false);
337 buttonApply()->setEnabled(false);
342 // Create sub-objects
343 GEOM::ListOfGO_var aList = anOper->MakeSubShapes(myObj, aFaceLst);
345 aNbObj = aList->length();
347 for (i = 0; i < aNbObj; i++) {
348 objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
354 buttonOk()->setEnabled(aNbObj > 0);
355 buttonApply()->setEnabled(aNbObj > 0);
360 //================================================================
361 // Function : getDisplayer
363 //================================================================
364 GEOM_Displayer* RepairGUI_FreeFacesDlg::getDisplayer()
367 myDisplayer = new GEOM_Displayer();
371 //================================================================
372 // Function : getFather
373 // Purpose : Get father object for object to be added in study
374 // (called with addInStudy method)
375 //================================================================
376 GEOM::GEOM_Object_ptr RepairGUI_FreeFacesDlg::getFather (GEOM::GEOM_Object_ptr)
381 //=================================================================================
382 // function : getSourceObjects
383 // purpose : virtual method to get source objects
384 //=================================================================================
385 QList<GEOM::GeomObjPtr> RepairGUI_FreeFacesDlg::getSourceObjects()
387 QList<GEOM::GeomObjPtr> res;
388 GEOM::GeomObjPtr aGeomObjPtr(myObj);