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 : MeasureGUI_NormaleDlg.cxx
23 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
26 #include "MeasureGUI_NormaleDlg.h"
30 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include "GEOMImpl_Types.hxx"
39 //=================================================================================
40 // class : MeasureGUI_NormaleDlg()
41 // purpose : Constructs a MeasureGUI_NormaleDlg 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 MeasureGUI_NormaleDlg::MeasureGUI_NormaleDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
47 : GEOMBase_Skeleton( theGeometryGUI, parent, false )
49 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
50 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_NORMALE" ) ) );
51 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
53 setWindowTitle( tr( "GEOM_NORMALE_TITLE" ) );
55 /***************************************************************/
56 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_NORMALE" ) );
57 mainFrame()->RadioButton1->setIcon( image0 );
58 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
59 mainFrame()->RadioButton2->close();
60 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->RadioButton3->close();
63 GroupArgs = new DlgRef_2Sel ( centralWidget() );
64 GroupArgs->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
66 GroupArgs->TextLabel1->setText( tr( "GEOM_FACE" ) );
67 GroupArgs->TextLabel2->setText( tr( "GEOM_POINT" ) );
69 GroupArgs->PushButton1->setIcon( image1 );
70 GroupArgs->PushButton2->setIcon( image1 );
72 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
73 layout->setMargin( 0 ); layout->setSpacing( 6 );
74 layout->addWidget( GroupArgs );
76 /***************************************************************/
78 setHelpFileName("using_measurement_tools_page.html#normale_anchor");
83 //=================================================================================
84 // function : ~MeasureGUI_NormaleDlg()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 MeasureGUI_NormaleDlg::~MeasureGUI_NormaleDlg()
91 //=================================================================================
94 //=================================================================================
95 void MeasureGUI_NormaleDlg::Init()
98 GroupArgs->LineEdit1->setReadOnly( true );
99 GroupArgs->LineEdit2->setReadOnly( true );
101 myFace = GEOM::GEOM_Object::_nil();
102 myPoint = GEOM::GEOM_Object::_nil();
104 myEditCurrentArgument = GroupArgs->LineEdit1;
105 globalSelection( GEOM_FACE );
107 /* signals and slots connections */
108 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
109 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
111 connect( GroupArgs->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
112 connect( GroupArgs->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
114 connect( GroupArgs->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
115 connect( GroupArgs->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
117 connect( myGeomGUI->getApp()->selectionMgr(),
118 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
120 initName(tr("GEOM_VECTOR_NORMALE"));
122 SelectionIntoArgument();
125 //=================================================================================
126 // function : ClickOnOk()
128 //=================================================================================
129 void MeasureGUI_NormaleDlg::ClickOnOk()
131 if ( ClickOnApply() )
135 //=================================================================================
136 // function : ClickOnApply()
138 //=================================================================================
139 bool MeasureGUI_NormaleDlg::ClickOnApply()
148 //=================================================================================
149 // function : SelectionIntoArgument()
150 // purpose : Called when selection as changed or other case
151 //=================================================================================
152 void MeasureGUI_NormaleDlg::SelectionIntoArgument()
155 myEditCurrentArgument->setText( "" );
157 if ( myEditCurrentArgument == GroupArgs->LineEdit1 ) {
158 myFace = GEOM::GEOM_Object::_nil();
160 else if ( myEditCurrentArgument == GroupArgs->LineEdit2 ) {
161 myPoint = GEOM::GEOM_Object::_nil();
164 if ( IObjectCount() != 1 )
168 Standard_Boolean testResult = Standard_False;
169 GEOM::GEOM_Object_var aSelectedObject =
170 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
175 if ( myEditCurrentArgument == GroupArgs->LineEdit1 ) {
176 myFace = aSelectedObject;
178 else if ( myEditCurrentArgument == GroupArgs->LineEdit2 ) {
179 myPoint = aSelectedObject;
182 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
187 //=================================================================================
188 // function : LineEditReturnPressed()
190 //=================================================================================
191 void MeasureGUI_NormaleDlg::LineEditReturnPressed()
193 QLineEdit* send = (QLineEdit*)sender();
194 if ( send == GroupArgs->LineEdit1 ||
195 send == GroupArgs->LineEdit2 ) {
196 myEditCurrentArgument = send;
197 GEOMBase_Skeleton::LineEditReturnPressed();
201 //=================================================================================
202 // function : SetEditCurrentArgument()
204 //=================================================================================
205 void MeasureGUI_NormaleDlg::SetEditCurrentArgument()
207 QPushButton* send = (QPushButton*)sender();
209 if ( send == GroupArgs->PushButton1 ) {
210 myEditCurrentArgument = GroupArgs->LineEdit1;
211 globalSelection( GEOM_FACE );
213 else if ( send == GroupArgs->PushButton2 ) {
214 myEditCurrentArgument = GroupArgs->LineEdit2;
215 globalSelection( GEOM_POINT );
218 myEditCurrentArgument->setFocus();
219 SelectionIntoArgument();
222 //=================================================================================
223 // function : ActivateThisDialog()
225 //=================================================================================
226 void MeasureGUI_NormaleDlg::ActivateThisDialog()
228 GEOMBase_Skeleton::ActivateThisDialog();
230 SelectionIntoArgument();
233 //=================================================================================
234 // function : enterEvent()
236 //=================================================================================
237 void MeasureGUI_NormaleDlg::enterEvent( QEvent* e )
239 if ( !mainFrame()->GroupConstructors->isEnabled() )
240 ActivateThisDialog();
243 //=================================================================================
244 // function : createOperation
246 //=================================================================================
247 GEOM::GEOM_IOperations_ptr MeasureGUI_NormaleDlg::createOperation()
249 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
252 //=================================================================================
253 // function : isValid
255 //=================================================================================
256 bool MeasureGUI_NormaleDlg::isValid( QString& )
258 //return !CORBA::is_nil(myFace) && !CORBA::is_nil(myPoint);
259 return !CORBA::is_nil( myFace );
262 //=================================================================================
263 // function : execute
265 //=================================================================================
266 bool MeasureGUI_NormaleDlg::execute( ObjectList& objects )
268 GEOM::GEOM_Object_var anObj =
269 GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetNormal( myFace, myPoint );
271 if ( !anObj->_is_nil() )
272 objects.push_back( anObj._retn() );