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 (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)
56 myGeomGUI = theGeometryGUI;
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")));
61 setCaption(tr("GEOM_DIVIDE_EDGE_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_DIVIDE_EDGE_TITLE"));
65 RadioButton1->setPixmap(image0);
66 RadioButton2->close(TRUE);
67 RadioButton3->close(TRUE);
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 );
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();
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 );
90 Layout1->addWidget(GroupPoints, 2, 0);
91 GroupPoints->getGroupBoxLayout()->addMultiCellWidget(myIsParameterGr, 1, 1, 0, 2);
92 GroupPoints->getGroupBoxLayout()->addLayout( aLay, 2, 0 );
93 /***************************************************************/
99 //=================================================================================
100 // function : ~RepairGUI_DivideEdgeDlg()
101 // purpose : Destroys the object and frees any allocated resources
102 //=================================================================================
103 RepairGUI_DivideEdgeDlg::~RepairGUI_DivideEdgeDlg()
108 //=================================================================================
111 //=================================================================================
112 void RepairGUI_DivideEdgeDlg::Init()
115 myEditCurrentArgument = GroupPoints->LineEdit1;
117 myObject = GEOM::GEOM_Object::_nil();
120 //myGeomGUI->SetState( 0 );
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()));
128 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
129 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
131 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
135 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
137 initName( tr( "DEVIDE_EDGE_NEW_OBJECT_NAME" ) );
141 //=================================================================================
142 // function : ClickOnOk()
143 // purpose : Same than click on apply but close this dialog.
144 //=================================================================================
145 void RepairGUI_DivideEdgeDlg::ClickOnOk()
147 if ( ClickOnApply() )
152 //=================================================================================
153 // function : ClickOnApply()
155 //=================================================================================
156 bool RepairGUI_DivideEdgeDlg::ClickOnApply()
163 myEditCurrentArgument->setText("");
164 myObject = GEOM::GEOM_Object::_nil();
173 //=================================================================================
174 // function : ClickOnCancel()
176 //=================================================================================
177 void RepairGUI_DivideEdgeDlg::ClickOnCancel()
179 GEOMBase_Skeleton::ClickOnCancel();
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()
190 myEditCurrentArgument->setText("");
192 myObject = GEOM::GEOM_Object::_nil();
195 if ( IObjectCount() == 1 )
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 )
203 if ( myGeomBase->GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) )
205 const int aType = aShape.ShapeType();
206 if ( aType <= TopAbs_EDGE ) // edge, wire, face, shell, solid, compound
208 GEOM::short_array anIndexes;
210 TColStd_IndexedMapOfInteger aMap;
211 SalomeApp_Application* anApp =
212 (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
213 anApp->selectionMgr()->GetIndexes( anIO, aMap );
215 if ( !aMap.IsEmpty() ) // subshape selection
218 myObject = aSelectedObj;
219 myEditCurrentArgument->setText( tr( "GEOM_EDGE" ) + "_1" );
221 else if ( aType == TopAbs_EDGE ) // single shape selection
224 myObject = aSelectedObj;
225 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
227 else // face, shell, solid or compound was selected, and NOT its subshape.
230 myObject = GEOM::GEOM_Object::_nil();
238 //=================================================================================
239 // function : SetEditCurrentArgument()
241 //=================================================================================
242 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
244 if( sender() == GroupPoints->PushButton1 )
246 GroupPoints->LineEdit1->setFocus();
247 myEditCurrentArgument = GroupPoints->LineEdit1;
249 SelectionIntoArgument();
253 //=================================================================================
254 // function : LineEditReturnPressed()
256 //=================================================================================
257 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
259 if( sender() == GroupPoints->LineEdit1 )
261 myEditCurrentArgument = GroupPoints->LineEdit1;
262 GEOMBase_Skeleton::LineEditReturnPressed();
267 //=================================================================================
268 // function : DeactivateActiveDialog()
270 //=================================================================================
271 void RepairGUI_DivideEdgeDlg::DeactivateActiveDialog()
273 //myGeomGUI->SetState( -1 );
274 GEOMBase_Skeleton::DeactivateActiveDialog();
277 //=================================================================================
278 // function : ActivateThisDialog()
280 //=================================================================================
281 void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
283 GEOMBase_Skeleton::ActivateThisDialog();
284 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
285 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
287 myObject = GEOM::GEOM_Object::_nil();
290 //myGeomGUI->SetState( 0 );
294 //=================================================================================
295 // function : enterEvent()
296 // purpose : Mouse enter onto the dialog to activate it
297 //=================================================================================
298 void RepairGUI_DivideEdgeDlg::enterEvent(QEvent* e)
300 if ( !GroupConstructors->isEnabled() )
301 ActivateThisDialog();
304 //=================================================================================
305 // function : closeEvent()
307 //=================================================================================
308 void RepairGUI_DivideEdgeDlg::closeEvent(QCloseEvent* e)
310 //myGeomGUI->SetState( -1 );
311 GEOMBase_Skeleton::closeEvent( e );
315 //=================================================================================
316 // function : createOperation
318 //=================================================================================
319 GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
321 return getGeomEngine()->GetIHealingOperations( getStudyId() );
324 //=================================================================================
325 // function : isValid
327 //=================================================================================
328 bool RepairGUI_DivideEdgeDlg::isValid( QString& msg )
330 return !myObject->_is_nil();
333 //=================================================================================
334 // function : execute
336 //=================================================================================
337 bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
339 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->DivideEdge
340 ( myObject, myIndex, myValEdt->value(), getIsByParameter() );
341 bool aResult = !anObj->_is_nil();
343 objects.push_back( anObj._retn() );
348 //=================================================================================
349 // function : getIsByParameter
351 //=================================================================================
352 bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
354 return myIsParameterGr->find( 0 )->isOn();
357 //=================================================================================
358 // function : initSelection
360 //=================================================================================
361 void RepairGUI_DivideEdgeDlg::initSelection()
363 GEOM::GEOM_Object_var aNullGeomObject;
364 localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects