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