Salome HOME
969b7162a38349640dac5a6ebb5786bd727ca621
[modules/geom.git] / src / RepairGUI / RepairGUI_DivideEdgeDlg.cxx
1 //  GEOM GEOMGUI : 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : RepairGUI_DivideEdgeDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "RepairGUI_DivideEdgeDlg.h"
30
31 #include "SalomeApp_Application.h"
32 #include "LightApp_SelectionMgr.h"
33 #include "SUIT_Session.h"
34 #include "SALOME_ListIteratorOfListIO.hxx"
35
36 #include "GEOMImpl_Types.hxx"
37
38 #include <TopAbs.hxx>
39
40 #include <qlabel.h>
41
42 using namespace std;
43
44 //=================================================================================
45 // class    : RepairGUI_DivideEdgeDlg()
46 // purpose  : Constructs a RepairGUI_DivideEdgeDlg  which is a child of 'parent', with the
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            TRUE to construct a modal dialog.
50 //=================================================================================
51 RepairGUI_DivideEdgeDlg::RepairGUI_DivideEdgeDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
52                                                   const char* name, bool modal, WFlags fl)
53   : GEOMBase_Skeleton(parent, name, modal, WStyle_Customize |
54                       WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 {
56   myGeomGUI = theGeometryGUI;
57
58   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_DIVIDE_EDGE")));
59   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60
61   setCaption(tr("GEOM_DIVIDE_EDGE_TITLE"));
62
63   /***************************************************************/
64   GroupConstructors->setTitle(tr("GEOM_DIVIDE_EDGE_TITLE"));
65   RadioButton1->setPixmap(image0);
66   RadioButton2->close(TRUE);
67   RadioButton3->close(TRUE);
68
69   GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
70   GroupPoints->GroupBox1->setTitle(tr("GEOM_ADD_POINT"));
71   GroupPoints->TextLabel1->setText(tr("GEOM_EDGE"));
72   GroupPoints->PushButton1->setPixmap(image1);
73   GroupPoints->LineEdit1->setReadOnly( true );
74
75   myIsParameterGr = new QButtonGroup( 2, Qt::Vertical, GroupPoints );
76   myIsParameterGr->setFrameStyle( QFrame::NoFrame );
77   myIsParameterGr->setRadioButtonExclusive( true );
78   myIsParameterGr->insert( new QRadioButton( tr( "GEOM_BY_PARAMETER" ), myIsParameterGr ), 0 );
79   myIsParameterGr->insert( new QRadioButton( tr( "GEOM_BY_LENGTH" ), myIsParameterGr ), 1 );
80   myIsParameterGr->find( 0 )->toggle();
81
82   QGridLayout* aLay = new QGridLayout( 0, 1, 2, 0, 6, "aLay" );
83   myValEdt = new QtxDblSpinBox(0., 1., 0.1, GroupPoints->GroupBox1);
84   myValEdt->setPrecision( 3 );
85   myValEdt->setValue( 0.5 );
86   QLabel* aLbl1 = new QLabel( tr( "GEOM_VALUE" ), GroupPoints->GroupBox1 );
87   aLay->addWidget( aLbl1, 0, 0 );
88   aLay->addWidget( myValEdt, 0, 1 );
89
90   Layout1->addWidget(GroupPoints, 2, 0);
91   GroupPoints->getGroupBoxLayout()->addMultiCellWidget(myIsParameterGr, 1, 1, 0, 2);
92   GroupPoints->getGroupBoxLayout()->addLayout( aLay, 2, 0 );
93   /***************************************************************/
94
95   Init();
96 }
97
98
99 //=================================================================================
100 // function : ~RepairGUI_DivideEdgeDlg()
101 // purpose  : Destroys the object and frees any allocated resources
102 //=================================================================================
103 RepairGUI_DivideEdgeDlg::~RepairGUI_DivideEdgeDlg()
104 {
105 }
106
107
108 //=================================================================================
109 // function : Init()
110 // purpose  :
111 //=================================================================================
112 void RepairGUI_DivideEdgeDlg::Init()
113 {
114   /* init variables */
115   myEditCurrentArgument = GroupPoints->LineEdit1;
116
117   myObject = GEOM::GEOM_Object::_nil();
118   myIndex = -1;
119
120   //myGeomGUI->SetState( 0 );
121   initSelection();
122
123   /* signals and slots connections */
124   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
125   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
126   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
127
128   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
129   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
130
131   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
133
134   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
135           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
136
137   initName( tr( "DEVIDE_EDGE_NEW_OBJECT_NAME" ) );
138 }
139
140
141 //=================================================================================
142 // function : ClickOnOk()
143 // purpose  : Same than click on apply but close this dialog.
144 //=================================================================================
145 void RepairGUI_DivideEdgeDlg::ClickOnOk()
146 {
147   if ( ClickOnApply() )
148     ClickOnCancel();
149 }
150
151
152 //=================================================================================
153 // function : ClickOnApply()
154 // purpose  :
155 //=================================================================================
156 bool RepairGUI_DivideEdgeDlg::ClickOnApply()
157 {
158   if ( !onAccept() )
159     return false;
160
161   initName();
162
163   myEditCurrentArgument->setText("");
164   myObject = GEOM::GEOM_Object::_nil();
165   myIndex = -1;
166
167   initSelection();
168
169   return true;
170 }
171
172
173 //=================================================================================
174 // function : ClickOnCancel()
175 // purpose  :
176 //=================================================================================
177 void RepairGUI_DivideEdgeDlg::ClickOnCancel()
178 {
179   GEOMBase_Skeleton::ClickOnCancel();
180 }
181
182
183 //=================================================================================
184 // function : SelectionIntoArgument()
185 // purpose  : Called when selection as changed or other case
186 //          : used only by SelectButtonC1A1 (LineEditC1A1)
187 //=================================================================================
188 void RepairGUI_DivideEdgeDlg::SelectionIntoArgument()
189 {
190   myEditCurrentArgument->setText("");
191
192   myObject = GEOM::GEOM_Object::_nil();
193   myIndex = -1;
194
195   if ( IObjectCount() == 1 )
196   {
197     Handle(SALOME_InteractiveObject) anIO = firstIObject();
198     Standard_Boolean aRes;
199     GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
200     if ( !CORBA::is_nil( aSelectedObj ) && aRes )
201     {
202       TopoDS_Shape aShape;
203       if ( myGeomBase->GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) )
204       {
205         const int aType = aShape.ShapeType();
206         if ( aType <= TopAbs_EDGE ) // edge, wire, face, shell, solid, compound
207         {
208           GEOM::short_array anIndexes;
209
210           TColStd_IndexedMapOfInteger aMap;
211           SalomeApp_Application* anApp =
212             (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
213           anApp->selectionMgr()->GetIndexes( anIO, aMap );
214
215           if ( !aMap.IsEmpty() ) // subshape selection
216           {
217             myIndex = aMap( 1 );
218             myObject = aSelectedObj;
219             myEditCurrentArgument->setText( tr( "GEOM_EDGE" ) + "_1" );
220           }
221           else if ( aType == TopAbs_EDGE ) // single shape selection
222           {
223             myIndex = -1;
224             myObject = aSelectedObj;
225             myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
226           }
227           else // face, shell, solid or compound was selected, and NOT its subshape.
228           {
229             myIndex = -1;
230             myObject = GEOM::GEOM_Object::_nil();
231           }
232         }
233       }
234     }
235   }
236 }
237
238 //=================================================================================
239 // function : SetEditCurrentArgument()
240 // purpose  :
241 //=================================================================================
242 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
243 {
244   if( sender() == GroupPoints->PushButton1 )
245   {
246     GroupPoints->LineEdit1->setFocus();
247     myEditCurrentArgument = GroupPoints->LineEdit1;
248   }
249   SelectionIntoArgument();
250 }
251
252
253 //=================================================================================
254 // function : LineEditReturnPressed()
255 // purpose  :
256 //=================================================================================
257 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
258 {
259   if( sender() == GroupPoints->LineEdit1 )
260   {
261     myEditCurrentArgument = GroupPoints->LineEdit1;
262     GEOMBase_Skeleton::LineEditReturnPressed();
263   }
264 }
265
266
267 //=================================================================================
268 // function : DeactivateActiveDialog()
269 // purpose  :
270 //=================================================================================
271 void RepairGUI_DivideEdgeDlg::DeactivateActiveDialog()
272 {
273   //myGeomGUI->SetState( -1 );
274   GEOMBase_Skeleton::DeactivateActiveDialog();
275 }
276
277 //=================================================================================
278 // function : ActivateThisDialog()
279 // purpose  :
280 //=================================================================================
281 void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
282 {
283   GEOMBase_Skeleton::ActivateThisDialog();
284   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
285           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
286
287   myObject = GEOM::GEOM_Object::_nil();
288   myIndex = -1;
289
290   //myGeomGUI->SetState( 0 );
291   initSelection();
292 }
293
294 //=================================================================================
295 // function : enterEvent()
296 // purpose  : Mouse enter onto the dialog to activate it
297 //=================================================================================
298 void RepairGUI_DivideEdgeDlg::enterEvent(QEvent* e)
299 {
300   if ( !GroupConstructors->isEnabled() )
301     ActivateThisDialog();
302 }
303
304 //=================================================================================
305 // function : closeEvent()
306 // purpose  :
307 //=================================================================================
308 void RepairGUI_DivideEdgeDlg::closeEvent(QCloseEvent* e)
309 {
310   //myGeomGUI->SetState( -1 );
311   GEOMBase_Skeleton::closeEvent( e );
312 }
313
314
315 //=================================================================================
316 // function : createOperation
317 // purpose  :
318 //=================================================================================
319 GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
320 {
321   return getGeomEngine()->GetIHealingOperations( getStudyId() );
322 }
323
324 //=================================================================================
325 // function : isValid
326 // purpose  :
327 //=================================================================================
328 bool RepairGUI_DivideEdgeDlg::isValid( QString& msg )
329 {
330   return !myObject->_is_nil();
331 }
332
333 //=================================================================================
334 // function : execute
335 // purpose  :
336 //=================================================================================
337 bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
338 {
339   GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->DivideEdge
340     ( myObject, myIndex, myValEdt->value(), getIsByParameter() );
341   bool aResult = !anObj->_is_nil();
342   if ( aResult )
343     objects.push_back( anObj._retn() );
344
345   return aResult;
346 }
347
348 //=================================================================================
349 // function : getIsByParameter
350 // purpose  :
351 //=================================================================================
352 bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
353 {
354   return myIsParameterGr->find( 0 )->isOn();
355 }
356
357 //=================================================================================
358 // function : initSelection
359 // purpose  :
360 //=================================================================================
361 void RepairGUI_DivideEdgeDlg::initSelection()
362 {
363   GEOM::GEOM_Object_var aNullGeomObject;
364   localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects
365 }