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
22 // File : RepairGUI_DivideEdgeDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "RepairGUI_DivideEdgeDlg.h"
28 #include <GEOM_DlgRef.h>
29 #include <GeometryGUI.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
37 #include <GEOMImpl_Types.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
42 //=================================================================================
43 // class : RepairGUI_DivideEdgeDlg()
44 // purpose : Constructs a RepairGUI_DivideEdgeDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 RepairGUI_DivideEdgeDlg::RepairGUI_DivideEdgeDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
51 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
53 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_DIVIDE_EDGE" ) ) );
54 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
56 setWindowTitle( tr( "GEOM_DIVIDE_EDGE_TITLE" ) );
58 /***************************************************************/
59 mainFrame()->GroupConstructors->setTitle(tr("GEOM_DIVIDE_EDGE_TITLE"));
60 mainFrame()->RadioButton1->setIcon( image0 );
61 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton2->close();
63 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
64 mainFrame()->RadioButton3->close();
66 GroupPoints = new DlgRef_1SelExt( centralWidget() );
67 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ADD_POINT" ) );
68 GroupPoints->TextLabel1->setText( tr( "GEOM_EDGE" ) );
69 GroupPoints->PushButton1->setIcon( image1 );
70 GroupPoints->LineEdit1->setReadOnly( true );
72 QRadioButton* rb1 = new QRadioButton( tr( "GEOM_BY_PARAMETER" ), GroupPoints->Box );
73 QRadioButton* rb2 = new QRadioButton( tr( "GEOM_BY_LENGTH" ), GroupPoints->Box );
75 myIsParameterGr = new QButtonGroup( GroupPoints->Box );
76 myIsParameterGr->addButton( rb1, 0 );
77 myIsParameterGr->addButton( rb2, 1 );
78 rb1->setChecked( true );
80 myValEdt = new QDoubleSpinBox( GroupPoints->Box );
81 initSpinBox( myValEdt, 0., 1., 0.1, 3 );
82 myValEdt->setValue( 0.5 );
83 QLabel* aLbl1 = new QLabel( tr( "GEOM_VALUE" ), GroupPoints->Box );
85 QGridLayout* l = new QGridLayout( GroupPoints->Box );
86 l->setMargin( 0 ); l->setSpacing( 6 );
87 l->addWidget( rb1, 0, 0, 1, 2 );
88 l->addWidget( rb2, 1, 0, 1, 2 );
89 l->addWidget( aLbl1, 2, 0 );
90 l->addWidget( myValEdt, 2, 1 );
92 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
93 layout->setMargin( 0 ); layout->setSpacing( 6 );
94 layout->addWidget( GroupPoints );
96 /***************************************************************/
98 setHelpFileName( "add_point_on_edge.htm" );
103 //=================================================================================
104 // function : ~RepairGUI_DivideEdgeDlg()
105 // purpose : Destroys the object and frees any allocated resources
106 //=================================================================================
107 RepairGUI_DivideEdgeDlg::~RepairGUI_DivideEdgeDlg()
111 //=================================================================================
114 //=================================================================================
115 void RepairGUI_DivideEdgeDlg::Init()
118 myEditCurrentArgument = GroupPoints->LineEdit1;
120 myObject = GEOM::GEOM_Object::_nil();
123 //myGeomGUI->SetState( 0 );
126 /* signals and slots connections */
127 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
128 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
130 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
131 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
133 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
134 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
136 initName( tr( "DEVIDE_EDGE_NEW_OBJECT_NAME" ) );
140 //=================================================================================
141 // function : ClickOnOk()
142 // purpose : Same than click on apply but close this dialog.
143 //=================================================================================
144 void RepairGUI_DivideEdgeDlg::ClickOnOk()
146 if ( ClickOnApply() )
151 //=================================================================================
152 // function : ClickOnApply()
154 //=================================================================================
155 bool RepairGUI_DivideEdgeDlg::ClickOnApply()
162 myEditCurrentArgument->setText( "" );
163 myObject = GEOM::GEOM_Object::_nil();
172 //=================================================================================
173 // function : SelectionIntoArgument()
174 // purpose : Called when selection as changed or other case
175 // : used only by SelectButtonC1A1 (LineEditC1A1)
176 //=================================================================================
177 void RepairGUI_DivideEdgeDlg::SelectionIntoArgument()
179 myEditCurrentArgument->setText( "" );
181 myObject = GEOM::GEOM_Object::_nil();
184 if ( IObjectCount() == 1 ) {
185 Handle(SALOME_InteractiveObject) anIO = firstIObject();
186 Standard_Boolean aRes;
187 GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
188 if ( !CORBA::is_nil( aSelectedObj ) && aRes ) {
190 if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) ) {
191 const int aType = aShape.ShapeType();
192 if ( aType <= TopAbs_EDGE ) {
193 // edge, wire, face, shell, solid, compound
194 GEOM::short_array anIndexes;
196 TColStd_IndexedMapOfInteger aMap;
197 SalomeApp_Application* anApp =
198 (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
199 anApp->selectionMgr()->GetIndexes( anIO, aMap );
201 if ( !aMap.IsEmpty() ) {
202 // subshape selection
204 myObject = aSelectedObj;
205 myEditCurrentArgument->setText( tr( "GEOM_EDGE" ) + "_1" );
207 else if ( aType == TopAbs_EDGE ) {
208 // single shape selection
210 myObject = aSelectedObj;
211 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
214 // face, shell, solid or compound was selected, and NOT its subshape.
216 myObject = GEOM::GEOM_Object::_nil();
224 //=================================================================================
225 // function : SetEditCurrentArgument()
227 //=================================================================================
228 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
230 if ( sender() == GroupPoints->PushButton1 ) {
231 GroupPoints->LineEdit1->setFocus();
232 myEditCurrentArgument = GroupPoints->LineEdit1;
234 SelectionIntoArgument();
238 //=================================================================================
239 // function : LineEditReturnPressed()
241 //=================================================================================
242 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
244 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* )
274 if ( !mainFrame()->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& )
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->button( 0 )->isChecked();
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