1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : RepairGUI_DivideEdgeDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "RepairGUI_DivideEdgeDlg.h"
30 #include "SalomeApp_Application.h"
31 #include "LightApp_SelectionMgr.h"
32 #include "SUIT_Session.h"
33 #include "SALOME_ListIteratorOfListIO.hxx"
35 #include "GEOMImpl_Types.hxx"
43 //=================================================================================
44 // class : RepairGUI_DivideEdgeDlg()
45 // purpose : Constructs a RepairGUI_DivideEdgeDlg which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 RepairGUI_DivideEdgeDlg::RepairGUI_DivideEdgeDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
51 const char* name, bool modal, WFlags fl)
52 : GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
53 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_DIVIDE_EDGE")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_DIVIDE_EDGE_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_DIVIDE_EDGE_TITLE"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->close(TRUE);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_ADD_POINT"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_EDGE"));
69 GroupPoints->PushButton1->setPixmap(image1);
70 GroupPoints->LineEdit1->setReadOnly( true );
72 myIsParameterGr = new QButtonGroup( 2, Qt::Vertical, GroupPoints );
73 myIsParameterGr->setFrameStyle( QFrame::NoFrame );
74 myIsParameterGr->setRadioButtonExclusive( true );
75 myIsParameterGr->insert( new QRadioButton( tr( "GEOM_BY_PARAMETER" ), myIsParameterGr ), 0 );
76 myIsParameterGr->insert( new QRadioButton( tr( "GEOM_BY_LENGTH" ), myIsParameterGr ), 1 );
77 myIsParameterGr->find( 0 )->toggle();
79 QGridLayout* aLay = new QGridLayout( 0, 1, 2, 0, 6, "aLay" );
80 myValEdt = new QtxDblSpinBox(0., 1., 0.1, GroupPoints->GroupBox1);
81 myValEdt->setPrecision( 3 );
82 myValEdt->setValue( 0.5 );
83 QLabel* aLbl1 = new QLabel( tr( "GEOM_VALUE" ), GroupPoints->GroupBox1 );
84 aLay->addWidget( aLbl1, 0, 0 );
85 aLay->addWidget( myValEdt, 0, 1 );
87 Layout1->addWidget(GroupPoints, 2, 0);
88 GroupPoints->getGroupBoxLayout()->addMultiCellWidget(myIsParameterGr, 1, 1, 0, 2);
89 GroupPoints->getGroupBoxLayout()->addLayout( aLay, 2, 0 );
90 /***************************************************************/
92 setHelpFileName("add_point_on_edge_operation_page.html");
97 //=================================================================================
98 // function : ~RepairGUI_DivideEdgeDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 RepairGUI_DivideEdgeDlg::~RepairGUI_DivideEdgeDlg()
105 //=================================================================================
108 //=================================================================================
109 void RepairGUI_DivideEdgeDlg::Init()
112 myEditCurrentArgument = GroupPoints->LineEdit1;
114 myObject = GEOM::GEOM_Object::_nil();
117 //myGeomGUI->SetState( 0 );
120 /* signals and slots connections */
121 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
122 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
124 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
125 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
127 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
128 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
130 initName( tr( "DEVIDE_EDGE_NEW_OBJECT_NAME" ) );
134 //=================================================================================
135 // function : ClickOnOk()
136 // purpose : Same than click on apply but close this dialog.
137 //=================================================================================
138 void RepairGUI_DivideEdgeDlg::ClickOnOk()
140 if ( ClickOnApply() )
145 //=================================================================================
146 // function : ClickOnApply()
148 //=================================================================================
149 bool RepairGUI_DivideEdgeDlg::ClickOnApply()
156 myEditCurrentArgument->setText("");
157 myObject = GEOM::GEOM_Object::_nil();
166 //=================================================================================
167 // function : SelectionIntoArgument()
168 // purpose : Called when selection as changed or other case
169 // : used only by SelectButtonC1A1 (LineEditC1A1)
170 //=================================================================================
171 void RepairGUI_DivideEdgeDlg::SelectionIntoArgument()
173 myEditCurrentArgument->setText("");
175 myObject = GEOM::GEOM_Object::_nil();
178 if ( IObjectCount() == 1 )
180 Handle(SALOME_InteractiveObject) anIO = firstIObject();
181 Standard_Boolean aRes;
182 GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
183 if ( !CORBA::is_nil( aSelectedObj ) && aRes )
186 if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) )
188 const int aType = aShape.ShapeType();
189 if ( aType <= TopAbs_EDGE ) // edge, wire, face, shell, solid, compound
191 GEOM::short_array anIndexes;
193 TColStd_IndexedMapOfInteger aMap;
194 SalomeApp_Application* anApp =
195 (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
196 anApp->selectionMgr()->GetIndexes( anIO, aMap );
198 if ( !aMap.IsEmpty() ) // subshape selection
201 myObject = aSelectedObj;
202 myEditCurrentArgument->setText( tr( "GEOM_EDGE" ) + "_1" );
204 else if ( aType == TopAbs_EDGE ) // single shape selection
207 myObject = aSelectedObj;
208 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
210 else // face, shell, solid or compound was selected, and NOT its subshape.
213 myObject = GEOM::GEOM_Object::_nil();
221 //=================================================================================
222 // function : SetEditCurrentArgument()
224 //=================================================================================
225 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
227 if( sender() == GroupPoints->PushButton1 )
229 GroupPoints->LineEdit1->setFocus();
230 myEditCurrentArgument = GroupPoints->LineEdit1;
232 SelectionIntoArgument();
236 //=================================================================================
237 // function : LineEditReturnPressed()
239 //=================================================================================
240 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
242 if( sender() == GroupPoints->LineEdit1 )
244 myEditCurrentArgument = GroupPoints->LineEdit1;
245 GEOMBase_Skeleton::LineEditReturnPressed();
250 //=================================================================================
251 // function : ActivateThisDialog()
253 //=================================================================================
254 void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
256 GEOMBase_Skeleton::ActivateThisDialog();
257 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
258 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
260 // myObject = GEOM::GEOM_Object::_nil();
263 //myGeomGUI->SetState( 0 );
267 //=================================================================================
268 // function : enterEvent()
269 // purpose : Mouse enter onto the dialog to activate it
270 //=================================================================================
271 void RepairGUI_DivideEdgeDlg::enterEvent(QEvent* e)
273 if ( !GroupConstructors->isEnabled() )
274 ActivateThisDialog();
277 //=================================================================================
278 // function : closeEvent()
280 //=================================================================================
281 void RepairGUI_DivideEdgeDlg::closeEvent(QCloseEvent* e)
283 //myGeomGUI->SetState( -1 );
284 GEOMBase_Skeleton::closeEvent( e );
288 //=================================================================================
289 // function : createOperation
291 //=================================================================================
292 GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
294 return getGeomEngine()->GetIHealingOperations( getStudyId() );
297 //=================================================================================
298 // function : isValid
300 //=================================================================================
301 bool RepairGUI_DivideEdgeDlg::isValid( QString& msg )
303 return !myObject->_is_nil();
306 //=================================================================================
307 // function : execute
309 //=================================================================================
310 bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
312 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->DivideEdge
313 ( myObject, myIndex, myValEdt->value(), getIsByParameter() );
314 bool aResult = !anObj->_is_nil();
316 objects.push_back( anObj._retn() );
321 //=================================================================================
322 // function : getIsByParameter
324 //=================================================================================
325 bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
327 return myIsParameterGr->find( 0 )->isOn();
330 //=================================================================================
331 // function : initSelection
333 //=================================================================================
334 void RepairGUI_DivideEdgeDlg::initSelection()
336 GEOM::GEOM_Object_var aNullGeomObject;
337 localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects