1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : RepairGUI_DivideEdgeDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "RepairGUI_DivideEdgeDlg.h"
31 #include "SalomeApp_Application.h"
32 #include "SalomeApp_SelectionMgr.h"
33 #include "SUIT_Session.h"
34 #include "SALOME_ListIteratorOfListIO.hxx"
36 #include "GEOMImpl_Types.hxx"
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)
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")));
57 setCaption(tr("GEOM_DIVIDE_EDGE_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_DIVIDE_EDGE_TITLE"));
61 RadioButton1->setPixmap(image0);
62 RadioButton2->close(TRUE);
63 RadioButton3->close(TRUE);
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 );
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();
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 );
86 Layout1->addWidget(GroupPoints, 2, 0);
87 GroupPoints->getGroupBoxLayout()->addMultiCellWidget(myIsParameterGr, 1, 1, 0, 2);
88 GroupPoints->getGroupBoxLayout()->addLayout( aLay, 2, 0 );
89 /***************************************************************/
95 //=================================================================================
96 // function : ~RepairGUI_DivideEdgeDlg()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 RepairGUI_DivideEdgeDlg::~RepairGUI_DivideEdgeDlg()
104 //=================================================================================
107 //=================================================================================
108 void RepairGUI_DivideEdgeDlg::Init()
111 myEditCurrentArgument = GroupPoints->LineEdit1;
113 myObject = GEOM::GEOM_Object::_nil();
116 //myGeomGUI->SetState( 0 );
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()));
124 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
125 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
127 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
131 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
133 initName( tr( "DEVIDE_EDGE_NEW_OBJECT_NAME" ) );
137 //=================================================================================
138 // function : ClickOnOk()
139 // purpose : Same than click on apply but close this dialog.
140 //=================================================================================
141 void RepairGUI_DivideEdgeDlg::ClickOnOk()
143 if ( ClickOnApply() )
149 //=================================================================================
150 // function : ClickOnApply()
152 //=================================================================================
153 bool RepairGUI_DivideEdgeDlg::ClickOnApply()
160 myEditCurrentArgument->setText("");
161 myObject = GEOM::GEOM_Object::_nil();
170 //=================================================================================
171 // function : ClickOnCancel()
173 //=================================================================================
174 void RepairGUI_DivideEdgeDlg::ClickOnCancel()
176 GEOMBase_Skeleton::ClickOnCancel();
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()
187 myEditCurrentArgument->setText("");
189 myObject = GEOM::GEOM_Object::_nil();
192 if ( IObjectCount() == 1 )
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 )
200 if ( myGeomBase->GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) )
202 const int aType = aShape.ShapeType();
203 if ( aType <= TopAbs_EDGE ) // edge, wire, face, shell, solid, compound
205 GEOM::short_array anIndexes;
207 TColStd_IndexedMapOfInteger aMap;
208 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
210 if ( !aMap.IsEmpty() ) // subshape selection
213 myObject = aSelectedObj;
214 myEditCurrentArgument->setText( tr( "GEOM_EDGE" ) + "_1" );
216 else if ( aType == TopAbs_EDGE ) // single shape selection
219 myObject = aSelectedObj;
220 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
222 else // face, shell, solid or compound was selected, and NOT its subshape.
225 myObject = GEOM::GEOM_Object::_nil();
233 //=================================================================================
234 // function : SetEditCurrentArgument()
236 //=================================================================================
237 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
239 if( sender() == GroupPoints->PushButton1 )
241 GroupPoints->LineEdit1->setFocus();
242 myEditCurrentArgument = GroupPoints->LineEdit1;
244 SelectionIntoArgument();
248 //=================================================================================
249 // function : LineEditReturnPressed()
251 //=================================================================================
252 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
254 if( sender() == GroupPoints->LineEdit1 )
256 myEditCurrentArgument = GroupPoints->LineEdit1;
257 GEOMBase_Skeleton::LineEditReturnPressed();
262 //=================================================================================
263 // function : DeactivateActiveDialog()
265 //=================================================================================
266 void RepairGUI_DivideEdgeDlg::DeactivateActiveDialog()
268 //myGeomGUI->SetState( -1 );
269 GEOMBase_Skeleton::DeactivateActiveDialog();
273 //=================================================================================
274 // function : ActivateThisDialog()
276 //=================================================================================
277 void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
279 GEOMBase_Skeleton::ActivateThisDialog();
280 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
281 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
283 myObject = GEOM::GEOM_Object::_nil();
286 //myGeomGUI->SetState( 0 );
291 //=================================================================================
292 // function : enterEvent()
293 // purpose : Mouse enter onto the dialog to activate it
294 //=================================================================================
295 void RepairGUI_DivideEdgeDlg::enterEvent(QEvent* e)
297 if ( !GroupConstructors->isEnabled() )
298 ActivateThisDialog();
302 //=================================================================================
303 // function : closeEvent()
305 //=================================================================================
306 void RepairGUI_DivideEdgeDlg::closeEvent(QCloseEvent* e)
308 //myGeomGUI->SetState( -1 );
309 GEOMBase_Skeleton::closeEvent( e );
312 //=================================================================================
313 // function : createOperation
315 //=================================================================================
316 GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
318 return getGeomEngine()->GetIHealingOperations( getStudyId() );
321 //=================================================================================
322 // function : isValid
324 //=================================================================================
325 bool RepairGUI_DivideEdgeDlg::isValid( QString& msg )
327 return !myObject->_is_nil();
330 //=================================================================================
331 // function : execute
333 //=================================================================================
334 bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
336 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->DivideEdge(
337 myObject, myIndex, myValEdt->value(), getIsByParameter() );
338 bool aResult = !anObj->_is_nil();
340 objects.push_back( anObj._retn() );
345 //=================================================================================
346 // function : getIsByParameter
348 //=================================================================================
349 bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
351 return myIsParameterGr->find( 0 )->isOn();
354 //=================================================================================
355 // function : initSelection
357 //=================================================================================
358 void RepairGUI_DivideEdgeDlg::initSelection()
360 GEOM::GEOM_Object_var aNullGeomObject;
361 localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects