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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : RepairGUI_DivideEdgeDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "RepairGUI_DivideEdgeDlg.h"
31 #include "SalomeApp_Application.h"
32 #include "LightApp_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(theGeometryGUI, parent, name, modal, WStyle_Customize |
54 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
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")));
59 setCaption(tr("GEOM_DIVIDE_EDGE_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_DIVIDE_EDGE_TITLE"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->close(TRUE);
65 RadioButton3->close(TRUE);
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 );
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();
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 );
88 Layout1->addWidget(GroupPoints, 2, 0);
89 GroupPoints->getGroupBoxLayout()->addMultiCellWidget(myIsParameterGr, 1, 1, 0, 2);
90 GroupPoints->getGroupBoxLayout()->addLayout( aLay, 2, 0 );
91 /***************************************************************/
93 setHelpFileName("add_point_on_edge_operation_page.html");
98 //=================================================================================
99 // function : ~RepairGUI_DivideEdgeDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 RepairGUI_DivideEdgeDlg::~RepairGUI_DivideEdgeDlg()
106 //=================================================================================
109 //=================================================================================
110 void RepairGUI_DivideEdgeDlg::Init()
113 myEditCurrentArgument = GroupPoints->LineEdit1;
115 myObject = GEOM::GEOM_Object::_nil();
118 //myGeomGUI->SetState( 0 );
121 /* signals and slots connections */
122 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
123 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
128 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
129 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
131 initName( tr( "DEVIDE_EDGE_NEW_OBJECT_NAME" ) );
135 //=================================================================================
136 // function : ClickOnOk()
137 // purpose : Same than click on apply but close this dialog.
138 //=================================================================================
139 void RepairGUI_DivideEdgeDlg::ClickOnOk()
141 if ( ClickOnApply() )
146 //=================================================================================
147 // function : ClickOnApply()
149 //=================================================================================
150 bool RepairGUI_DivideEdgeDlg::ClickOnApply()
157 myEditCurrentArgument->setText("");
158 myObject = GEOM::GEOM_Object::_nil();
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()
174 myEditCurrentArgument->setText("");
176 myObject = GEOM::GEOM_Object::_nil();
179 if ( IObjectCount() == 1 )
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 )
187 if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) )
189 const int aType = aShape.ShapeType();
190 if ( aType <= TopAbs_EDGE ) // edge, wire, face, shell, solid, compound
192 GEOM::short_array anIndexes;
194 TColStd_IndexedMapOfInteger aMap;
195 SalomeApp_Application* anApp =
196 (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
197 anApp->selectionMgr()->GetIndexes( anIO, aMap );
199 if ( !aMap.IsEmpty() ) // subshape selection
202 myObject = aSelectedObj;
203 myEditCurrentArgument->setText( tr( "GEOM_EDGE" ) + "_1" );
205 else if ( aType == TopAbs_EDGE ) // single shape selection
208 myObject = aSelectedObj;
209 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
211 else // face, shell, solid or compound was selected, and NOT its subshape.
214 myObject = GEOM::GEOM_Object::_nil();
222 //=================================================================================
223 // function : SetEditCurrentArgument()
225 //=================================================================================
226 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
228 if( sender() == GroupPoints->PushButton1 )
230 GroupPoints->LineEdit1->setFocus();
231 myEditCurrentArgument = GroupPoints->LineEdit1;
233 SelectionIntoArgument();
237 //=================================================================================
238 // function : LineEditReturnPressed()
240 //=================================================================================
241 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
243 if( sender() == GroupPoints->LineEdit1 )
245 myEditCurrentArgument = GroupPoints->LineEdit1;
246 GEOMBase_Skeleton::LineEditReturnPressed();
251 //=================================================================================
252 // function : ActivateThisDialog()
254 //=================================================================================
255 void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
257 GEOMBase_Skeleton::ActivateThisDialog();
258 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
259 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
261 // myObject = GEOM::GEOM_Object::_nil();
264 //myGeomGUI->SetState( 0 );
268 //=================================================================================
269 // function : enterEvent()
270 // purpose : Mouse enter onto the dialog to activate it
271 //=================================================================================
272 void RepairGUI_DivideEdgeDlg::enterEvent(QEvent* e)
274 if ( !GroupConstructors->isEnabled() )
275 ActivateThisDialog();
278 //=================================================================================
279 // function : closeEvent()
281 //=================================================================================
282 void RepairGUI_DivideEdgeDlg::closeEvent(QCloseEvent* e)
284 //myGeomGUI->SetState( -1 );
285 GEOMBase_Skeleton::closeEvent( e );
289 //=================================================================================
290 // function : createOperation
292 //=================================================================================
293 GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
295 return getGeomEngine()->GetIHealingOperations( getStudyId() );
298 //=================================================================================
299 // function : isValid
301 //=================================================================================
302 bool RepairGUI_DivideEdgeDlg::isValid( QString& msg )
304 return !myObject->_is_nil();
307 //=================================================================================
308 // function : execute
310 //=================================================================================
311 bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
313 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->DivideEdge
314 ( myObject, myIndex, myValEdt->value(), getIsByParameter() );
315 bool aResult = !anObj->_is_nil();
317 objects.push_back( anObj._retn() );
322 //=================================================================================
323 // function : getIsByParameter
325 //=================================================================================
326 bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
328 return myIsParameterGr->find( 0 )->isOn();
331 //=================================================================================
332 // function : initSelection
334 //=================================================================================
335 void RepairGUI_DivideEdgeDlg::initSelection()
337 GEOM::GEOM_Object_var aNullGeomObject;
338 localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects