Salome HOME
2ec52ea0ac3bb1fe8bc377e21aa75f35c9a27e81
[modules/geom.git] / RepairGUI_RemoveExtraEdgesDlg.cxx
1 // GEOM RepairGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : RepairGUI_RemoveExtraEdgesDlg.cxx
23 // Author : Michael Zorin, Open CASCADE S.A.S.
24 //
25
26 #include "RepairGUI_RemoveExtraEdgesDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36
37 #include <GEOMImpl_Types.hxx>
38
39 #include <TColStd_MapOfInteger.hxx>
40
41 //=================================================================================
42 // class    : RepairGUI_RemoveExtraEdgesDlg()
43 // purpose  : Constructs a RepairGUI_RemoveExtraEdgesDlg which is a child of 'parent', with the
44 //            name 'name' and widget flags set to 'f'.
45 //            The dialog will by default be modeless, unless you set 'modal' to
46 //            TRUE to construct a modal dialog.
47 //=================================================================================
48 RepairGUI_RemoveExtraEdgesDlg::RepairGUI_RemoveExtraEdgesDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
49                                                               bool modal )
50   : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
51 {
52   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
53   QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_REMOVE_EXTRA_EDGES" ) ) );
54   QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
55     
56   setWindowTitle( tr( "GEOM_REMOVE_EXTRA_EDGES_TITLE" ) );
57
58   /***************************************************************/
59   mainFrame()->GroupConstructors->setTitle(tr("GEOM_REMOVE_EXTRA_EDGES_TITLE"));
60   mainFrame()->RadioButton1->setIcon( image0 );
61   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
62   mainFrame()->RadioButton2->close();
63   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
64   mainFrame()->RadioButton3->close();
65
66   GroupPoints = new DlgRef_1Sel( centralWidget() );
67   GroupPoints->GroupBox1->setTitle( tr( "GEOM_REMOVE_EXTRA_EDGES" ) );
68   GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
69   GroupPoints->PushButton1->setIcon( image1 );
70   GroupPoints->LineEdit1->setReadOnly( true );
71
72   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
73   layout->setMargin( 0 ); layout->setSpacing( 6 );
74   layout->addWidget( GroupPoints );
75
76   /***************************************************************/
77   
78   setHelpFileName( "remove_extra_edges_operation_page.html" );
79
80   Init();
81 }
82
83
84 //=================================================================================
85 // function : ~RepairGUI_RemoveExtraEdgesDlg()
86 // purpose  : Destroys the object and frees any allocated resources
87 //=================================================================================
88 RepairGUI_RemoveExtraEdgesDlg::~RepairGUI_RemoveExtraEdgesDlg()
89 {
90 }
91
92
93 //=================================================================================
94 // function : Init()
95 // purpose  :
96 //=================================================================================
97 void RepairGUI_RemoveExtraEdgesDlg::Init()
98 {
99   /* init variables */
100   myEditCurrentArgument = GroupPoints->LineEdit1;
101   
102   myOkObject = false;
103
104   activateSelection();
105   
106   mainFrame()->GroupBoxPublish->show();
107
108   /* signals and slots connections */
109   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
110   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
111
112   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
113   connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
114
115   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
116            this, SLOT( SelectionIntoArgument() ) );
117
118   initName( tr( "REMOVE_EXTRA_EDGES_NEW_OBJ_NAME" ) );
119 }
120
121
122 //=================================================================================
123 // function : ClickOnOk()
124 // purpose  : Same than click on apply but close this dialog.
125 //=================================================================================
126 void RepairGUI_RemoveExtraEdgesDlg::ClickOnOk()
127 {
128   if ( ClickOnApply() )
129     ClickOnCancel();
130 }
131
132 //=================================================================================
133 // function : ClickOnApply()
134 // purpose  :
135 //=================================================================================
136 bool RepairGUI_RemoveExtraEdgesDlg::ClickOnApply()
137 {
138   if ( !onAccept() )
139     return false;
140
141   initName();
142
143   myEditCurrentArgument->setText( "" );
144   myObject = GEOM::GEOM_Object::_nil();
145   
146   myOkObject = false;
147
148   activateSelection();
149
150   return true;
151 }
152
153
154 //=================================================================================
155 // function : SelectionIntoArgument()
156 // purpose  : Called when selection as changed or other case
157 //          : used only by SelectButtonC1A1 (LineEditC1A1)
158 //=================================================================================
159 void RepairGUI_RemoveExtraEdgesDlg::SelectionIntoArgument()
160 {
161   myEditCurrentArgument->setText( "" );
162   QString aName;
163   
164   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
165     if ( IObjectCount() != 1 ) {
166       if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
167         myOkObject = false;
168       return;
169     }
170   }
171   
172   // nbSel == 1
173   Standard_Boolean testResult = Standard_False;
174   GEOM::GEOM_Object_ptr aSelectedObject =
175     GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
176
177   if ( !testResult )
178     return;
179   
180   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
181     myObject = aSelectedObject;
182     myOkObject = true;
183   }
184
185   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
186 }
187
188 //=================================================================================
189 // function : SetEditCurrentArgument()
190 // purpose  :
191 //=================================================================================
192 void RepairGUI_RemoveExtraEdgesDlg::SetEditCurrentArgument()
193 {
194   if( sender() == GroupPoints->PushButton1 ) {
195     GroupPoints->LineEdit1->setFocus();
196     myEditCurrentArgument = GroupPoints->LineEdit1;
197   }
198   SelectionIntoArgument();
199 }
200
201
202 //=================================================================================
203 // function : LineEditReturnPressed()
204 // purpose  :
205 //=================================================================================
206 void RepairGUI_RemoveExtraEdgesDlg::LineEditReturnPressed()
207 {
208   if ( sender() == GroupPoints->LineEdit1 ) {
209     myEditCurrentArgument = GroupPoints->LineEdit1;
210     GEOMBase_Skeleton::LineEditReturnPressed();
211   }
212 }
213
214
215 //=================================================================================
216 // function : ActivateThisDialog()
217 // purpose  :
218 //=================================================================================
219 void RepairGUI_RemoveExtraEdgesDlg::ActivateThisDialog()
220 {
221   GEOMBase_Skeleton::ActivateThisDialog();
222   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
223            this, SLOT( SelectionIntoArgument() ) );
224
225   activateSelection();
226 }
227
228
229 //=================================================================================
230 // function : enterEvent()
231 // purpose  : Mouse enter onto the dialog to activate it
232 //=================================================================================
233 void RepairGUI_RemoveExtraEdgesDlg::enterEvent(QEvent* e)
234 {
235   if ( !mainFrame()->GroupConstructors->isEnabled() )
236     ActivateThisDialog();
237 }
238
239
240 //=================================================================================
241 // function : activateSelection
242 // purpose  : activate selection of solids and compounds
243 //=================================================================================
244 void RepairGUI_RemoveExtraEdgesDlg::activateSelection()
245 {
246   TColStd_MapOfInteger aTypes;
247   aTypes.Add( GEOM_SOLID );
248   aTypes.Add( GEOM_COMPOUND );
249   globalSelection( aTypes );
250 }
251
252 //=================================================================================
253 // function : createOperation
254 // purpose  :
255 //=================================================================================
256 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveExtraEdgesDlg::createOperation()
257 {
258   return getGeomEngine()->GetIBlocksOperations( getStudyId() );
259 }
260
261 //=================================================================================
262 // function : isValid
263 // purpose  :
264 //=================================================================================
265 bool RepairGUI_RemoveExtraEdgesDlg::isValid( QString& msg )
266 {
267   return myOkObject;
268 }
269
270 //=================================================================================
271 // function : execute
272 // purpose  :
273 //=================================================================================
274 bool RepairGUI_RemoveExtraEdgesDlg::execute( ObjectList& objects )
275 {
276   GEOM::GEOM_Object_var anObj;
277   
278   anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->RemoveExtraEdges( myObject );
279   
280   if ( !anObj->_is_nil() )
281     objects.push_back( anObj._retn() );
282
283   return true;
284 }
285
286 //=================================================================================
287 // function : restoreSubShapes
288 // purpose  :
289 //=================================================================================
290 void RepairGUI_RemoveExtraEdgesDlg::restoreSubShapes( SALOMEDS::Study_ptr   theStudy,
291                                                       SALOMEDS::SObject_ptr theSObject )
292 {
293   if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
294     // empty list of arguments means that all arguments should be restored
295     getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
296                                          /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GetInPlaceByHistory
297                                          /*theInheritFirstArg=*/true );
298   }
299 }