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