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