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 : BuildGUI_EdgeDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "BuildGUI_EdgeDlg.h"
29 #include <GeometryGUI.h>
32 #include <GEOMImpl_Types.hxx>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
39 //=================================================================================
40 // class : BuildGUI_EdgeDlg()
41 // purpose : Constructs a BuildGUI_EdgeDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 BuildGUI_EdgeDlg::BuildGUI_EdgeDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
47 : GEOMBase_Skeleton( theGeometryGUI, parent )
49 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_EDGE" ) ) );
50 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
52 setWindowTitle( tr( "GEOM_EDGE_TITLE" ) );
54 /***************************************************************/
55 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_EDGE" ) );
56 mainFrame()->RadioButton1->setIcon( image0 );
57 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
58 mainFrame()->RadioButton2->close();
59 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
60 mainFrame()->RadioButton3->close();
62 GroupPoints = new DlgRef_2Sel( centralWidget() );
64 GroupPoints->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
65 GroupPoints->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
66 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
67 GroupPoints->PushButton1->setIcon( image1 );
68 GroupPoints->PushButton2->setIcon( image1 );
70 GroupPoints->LineEdit1->setReadOnly( true );
71 GroupPoints->LineEdit2->setReadOnly( true );
73 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
74 layout->setMargin( 0 ); layout->setSpacing( 6 );
75 layout->addWidget( GroupPoints );
76 /***************************************************************/
78 setHelpFileName("create_edge_page.html");
85 //=================================================================================
86 // function : ~BuildGUI_EdgeDlg()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 BuildGUI_EdgeDlg::~BuildGUI_EdgeDlg()
91 // no need to delete child widgets, Qt does it all for us
95 //=================================================================================
98 //=================================================================================
99 void BuildGUI_EdgeDlg::Init()
102 myEditCurrentArgument = GroupPoints->LineEdit1;
103 GroupPoints->LineEdit1->setReadOnly( true );
104 GroupPoints->LineEdit2->setReadOnly( true );
106 myOkPoint1 = myOkPoint2 = false;
108 globalSelection( GEOM_POINT );
110 /* signals and slots connections */
111 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
112 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
114 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
115 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
117 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
118 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
120 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
121 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
123 initName( tr( "GEOM_EDGE" ) );
127 //=================================================================================
128 // function : ClickOnOk()
130 //=================================================================================
131 void BuildGUI_EdgeDlg::ClickOnOk()
133 if ( ClickOnApply() )
138 //=================================================================================
139 // function : ClickOnApply()
141 //=================================================================================
142 bool BuildGUI_EdgeDlg::ClickOnApply()
152 //=================================================================================
153 // function : SelectionIntoArgument()
154 // purpose : Called when selection as changed or other case
155 //=================================================================================
156 void BuildGUI_EdgeDlg::SelectionIntoArgument()
159 myEditCurrentArgument->setText( "" );
161 if ( IObjectCount() != 1 ) {
162 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
164 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
170 Standard_Boolean testResult = Standard_False;
171 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
176 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
177 myPoint1 = aSelectedObject;
180 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
181 myPoint2 = aSelectedObject;
185 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
191 //=================================================================================
192 // function : LineEditReturnPressed()
194 //=================================================================================
195 void BuildGUI_EdgeDlg::LineEditReturnPressed()
197 QLineEdit* send = (QLineEdit*)sender();
198 if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 ) {
199 myEditCurrentArgument = send;
200 GEOMBase_Skeleton::LineEditReturnPressed();
205 //=================================================================================
206 // function : SetEditCurrentArgument()
208 //=================================================================================
209 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
212 QPushButton* send = (QPushButton*)sender();
215 if ( send == GroupPoints->PushButton1 ) {
216 myEditCurrentArgument = GroupPoints->LineEdit1;
217 globalSelection( GEOM_POINT );
219 else if ( send == GroupPoints->PushButton2 ) {
220 myEditCurrentArgument = GroupPoints->LineEdit2;
221 globalSelection( GEOM_POINT );
224 myEditCurrentArgument->setFocus();
225 SelectionIntoArgument();
229 //=================================================================================
230 // function : ActivateThisDialog()
232 //=================================================================================
233 void BuildGUI_EdgeDlg::ActivateThisDialog()
235 GEOMBase_Skeleton::ActivateThisDialog();
236 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
237 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
238 globalSelection( GEOM_POINT );
243 //=================================================================================
244 // function : enterEvent()
246 //=================================================================================
247 void BuildGUI_EdgeDlg::enterEvent( QEvent* )
249 if ( !mainFrame()->GroupConstructors->isEnabled() )
250 ActivateThisDialog();
253 //=================================================================================
254 // function : createOperation
256 //=================================================================================
257 GEOM::GEOM_IOperations_ptr BuildGUI_EdgeDlg::createOperation()
259 return getGeomEngine()->GetIShapesOperations( getStudyId() );
262 //=================================================================================
263 // function : isValid
265 //=================================================================================
266 bool BuildGUI_EdgeDlg::isValid( QString& )
268 return myOkPoint1 && myOkPoint2;
271 //=================================================================================
272 // function : execute
274 //=================================================================================
275 bool BuildGUI_EdgeDlg::execute( ObjectList& objects )
277 GEOM::GEOM_Object_var anObj;
279 anObj = GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->MakeEdge( myPoint1, myPoint2 );
281 if ( !anObj->_is_nil() )
282 objects.push_back( anObj._retn() );