Salome HOME
51a43fd4b4c9fe0e8dad702614c757282a383e19
[modules/geom.git] / src / RepairGUI / RepairGUI_UnionFacesDlg.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  GEOM RepairGUI : GUI for Geometry component
21 //  File   : RepairGUI_UnionFacesDlg.cxx
22 //  Author : Michael Zorin, Open CASCADE S.A.S.
23 //
24 #include "RepairGUI_UnionFacesDlg.h"
25
26 #include <DlgRef.h>
27 #include <GeometryGUI.h>
28 #include <GEOMBase.h>
29
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34
35 #include <GEOMImpl_Types.hxx>
36
37 #include <TColStd_MapOfInteger.hxx>
38
39 //=================================================================================
40 // class    : RepairGUI_UnionFacesDlg()
41 // purpose  : Constructs a RepairGUI_UnionFacesDlg which is a child of 'parent', with the
42 //            name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            TRUE to construct a modal dialog.
45 //=================================================================================
46 RepairGUI_UnionFacesDlg::RepairGUI_UnionFacesDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
47                                                   bool modal )
48   : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
49 {
50   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
51   QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_UNION_FACES" ) ) );
52   QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
53     
54   setWindowTitle( tr( "GEOM_UNION_FACES_TITLE" ) );
55
56   /***************************************************************/
57   mainFrame()->GroupConstructors->setTitle(tr("GEOM_UNION_FACES_TITLE"));
58   mainFrame()->RadioButton1->setIcon( image0 );
59   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
60   mainFrame()->RadioButton2->close();
61   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62   mainFrame()->RadioButton3->close();
63
64   GroupPoints = new DlgRef_1Sel( centralWidget() );
65
66   GroupPoints->GroupBox1->setTitle( tr( "GEOM_UNION_FACES" ) );
67   GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
68   GroupPoints->PushButton1->setIcon( image1 );
69   GroupPoints->LineEdit1->setReadOnly( true );
70
71   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
72   layout->setMargin( 0 ); layout->setSpacing( 6 );
73   layout->addWidget( GroupPoints );
74
75   /***************************************************************/
76   
77   setHelpFileName( "union_faces_operation_page.html" );
78
79   Init();
80 }
81
82
83 //=================================================================================
84 // function : ~RepairGUI_UnionFacesDlg()
85 // purpose  : Destroys the object and frees any allocated resources
86 //=================================================================================
87 RepairGUI_UnionFacesDlg::~RepairGUI_UnionFacesDlg()
88 {
89 }
90
91
92 //=================================================================================
93 // function : Init()
94 // purpose  :
95 //=================================================================================
96 void RepairGUI_UnionFacesDlg::Init()
97 {
98   /* init variables */
99   myEditCurrentArgument = GroupPoints->LineEdit1;
100   
101   myOkObject = false;
102
103   activateSelection();
104   
105   mainFrame()->GroupBoxPublish->show();
106   //Hide preview checkbox
107   mainFrame()->CheckBoxPreview->hide();
108
109   /* signals and slots connections */
110   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
111   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
112
113   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
114   connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
115
116   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
117            this, SLOT( SelectionIntoArgument() ) );
118
119   initName( tr( "UNION_FACES_NEW_OBJ_NAME" ) );
120   resize(100,100);
121   SelectionIntoArgument();
122 }
123
124
125 //=================================================================================
126 // function : ClickOnOk()
127 // purpose  : Same than click on apply but close this dialog.
128 //=================================================================================
129 void RepairGUI_UnionFacesDlg::ClickOnOk()
130 {
131   setIsApplyAndClose( true );
132   if ( ClickOnApply() )
133     ClickOnCancel();
134 }
135
136 //=================================================================================
137 // function : ClickOnApply()
138 // purpose  :
139 //=================================================================================
140 bool RepairGUI_UnionFacesDlg::ClickOnApply()
141 {
142   if ( !onAccept() )
143     return false;
144
145   initName();
146
147   myEditCurrentArgument->setText( "" );
148   myObject = GEOM::GEOM_Object::_nil();
149   
150   myOkObject = false;
151
152   activateSelection();
153
154   return true;
155 }
156
157
158 //=================================================================================
159 // function : SelectionIntoArgument()
160 // purpose  : Called when selection as changed or other case
161 //          : used only by SelectButtonC1A1 (LineEditC1A1)
162 //=================================================================================
163 void RepairGUI_UnionFacesDlg::SelectionIntoArgument()
164 {
165   myEditCurrentArgument->setText( "" );
166   QString aName;
167   
168   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
169   SALOME_ListIO aSelList;
170   aSelMgr->selectedObjects(aSelList);
171
172   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
173     if ( aSelList.Extent() != 1 ) {
174       if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
175         myOkObject = false;
176       return;
177     }
178   }
179   
180   // nbSel == 1
181   GEOM::GEOM_Object_ptr aSelectedObject =
182     GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
183
184   if ( CORBA::is_nil( aSelectedObject ) )
185     return;
186   
187   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
188     myObject = aSelectedObject;
189     myOkObject = true;
190   }
191
192   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
193 }
194
195 //=================================================================================
196 // function : SetEditCurrentArgument()
197 // purpose  :
198 //=================================================================================
199 void RepairGUI_UnionFacesDlg::SetEditCurrentArgument()
200 {
201   if( sender() == GroupPoints->PushButton1 ) {
202     GroupPoints->LineEdit1->setFocus();
203     myEditCurrentArgument = GroupPoints->LineEdit1;
204   }
205   SelectionIntoArgument();
206 }
207
208
209 //=================================================================================
210 // function : LineEditReturnPressed()
211 // purpose  :
212 //=================================================================================
213 void RepairGUI_UnionFacesDlg::LineEditReturnPressed()
214 {
215   if ( sender() == GroupPoints->LineEdit1 ) {
216     myEditCurrentArgument = GroupPoints->LineEdit1;
217     GEOMBase_Skeleton::LineEditReturnPressed();
218   }
219 }
220
221
222 //=================================================================================
223 // function : ActivateThisDialog()
224 // purpose  :
225 //=================================================================================
226 void RepairGUI_UnionFacesDlg::ActivateThisDialog()
227 {
228   GEOMBase_Skeleton::ActivateThisDialog();
229   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
230            this, SLOT( SelectionIntoArgument() ) );
231
232   activateSelection();
233 }
234
235
236 //=================================================================================
237 // function : enterEvent()
238 // purpose  : Mouse enter onto the dialog to activate it
239 //=================================================================================
240 void RepairGUI_UnionFacesDlg::enterEvent(QEvent*)
241 {
242   if ( !mainFrame()->GroupConstructors->isEnabled() )
243     ActivateThisDialog();
244 }
245
246
247 //=================================================================================
248 // function : activateSelection
249 // purpose  : activate selection of solids and compounds
250 //=================================================================================
251 void RepairGUI_UnionFacesDlg::activateSelection()
252 {
253   TColStd_MapOfInteger aTypes;
254   aTypes.Add( GEOM_SHELL );
255   aTypes.Add( GEOM_SOLID );
256   aTypes.Add( GEOM_COMPOUND );
257   globalSelection( aTypes );
258 }
259
260 //=================================================================================
261 // function : createOperation
262 // purpose  :
263 //=================================================================================
264 GEOM::GEOM_IOperations_ptr RepairGUI_UnionFacesDlg::createOperation()
265 {
266   return getGeomEngine()->GetIBlocksOperations();
267 }
268
269 //=================================================================================
270 // function : isValid
271 // purpose  :
272 //=================================================================================
273 bool RepairGUI_UnionFacesDlg::isValid( QString& /*msg*/ )
274 {
275   return myOkObject;
276 }
277
278 //=================================================================================
279 // function : execute
280 // purpose  :
281 //=================================================================================
282 bool RepairGUI_UnionFacesDlg::execute( ObjectList& objects )
283 {
284   GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
285   GEOM::GEOM_Object_var anObj = anOper->UnionFaces(myObject);
286
287   if (!anObj->_is_nil())
288     objects.push_back(anObj._retn());
289
290   return true;
291 }
292
293 //=================================================================================
294 // function : restoreSubShapes
295 // purpose  :
296 //=================================================================================
297 void RepairGUI_UnionFacesDlg::restoreSubShapes( SALOMEDS::SObject_ptr theSObject )
298 {
299   if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
300     // empty list of arguments means that all arguments should be restored
301     getGeomEngine()->RestoreSubShapesSO( theSObject, GEOM::ListOfGO(),
302                                          /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GetInPlaceByHistory
303                                          /*theInheritFirstArg=*/true,
304                                          mainFrame()->CheckBoxAddPrefix->isChecked() );
305   }
306 }
307
308 //=================================================================================
309 // function : getSourceObjects
310 // purpose  : virtual method to get source objects
311 //=================================================================================
312 QList<GEOM::GeomObjPtr> RepairGUI_UnionFacesDlg::getSourceObjects()
313 {
314   QList<GEOM::GeomObjPtr> res;
315   GEOM::GeomObjPtr aGeomObjPtr(myObject);
316   res << aGeomObjPtr;
317   return res;
318 }