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 #include <TopoDS_Shape.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
45 //=================================================================================
46 // class : MeasureGUI_NormaleDlg()
47 // purpose : Constructs a MeasureGUI_NormaleDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 MeasureGUI_NormaleDlg::MeasureGUI_NormaleDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
53 : GEOMBase_Skeleton( theGeometryGUI, parent, false )
55 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
56 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_NORMALE" ) ) );
57 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
59 setWindowTitle( tr( "GEOM_NORMALE_TITLE" ) );
61 /***************************************************************/
62 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_NORMALE" ) );
63 mainFrame()->RadioButton1->setIcon( image0 );
64 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
65 mainFrame()->RadioButton2->close();
66 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
67 mainFrame()->RadioButton3->close();
69 GroupArgs = new DlgRef_2Sel ( centralWidget() );
70 GroupArgs->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
72 GroupArgs->TextLabel1->setText( tr( "GEOM_FACE" ) );
73 GroupArgs->TextLabel2->setText( tr( "GEOM_POINT" ) );
75 GroupArgs->PushButton1->setIcon( image1 );
76 GroupArgs->PushButton2->setIcon( image1 );
78 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
79 layout->setMargin( 0 ); layout->setSpacing( 6 );
80 layout->addWidget( GroupArgs );
82 /***************************************************************/
84 setHelpFileName("using_measurement_tools_page.html#normale_anchor");
89 //=================================================================================
90 // function : ~MeasureGUI_NormaleDlg()
91 // purpose : Destroys the object and frees any allocated resources
92 //=================================================================================
93 MeasureGUI_NormaleDlg::~MeasureGUI_NormaleDlg()
97 //=================================================================================
100 //=================================================================================
101 void MeasureGUI_NormaleDlg::Init()
104 GroupArgs->LineEdit1->setReadOnly( true );
105 GroupArgs->LineEdit2->setReadOnly( true );
107 myFace = GEOM::GEOM_Object::_nil();
108 myPoint = GEOM::GEOM_Object::_nil();
110 myEditCurrentArgument = GroupArgs->LineEdit1;
111 globalSelection( GEOM_FACE );
113 /* signals and slots connections */
114 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
115 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
117 connect( GroupArgs->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
118 connect( GroupArgs->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
120 connect( GroupArgs->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
121 connect( GroupArgs->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
123 connect( myGeomGUI->getApp()->selectionMgr(),
124 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
126 initName(tr("GEOM_VECTOR_NORMALE"));
128 SelectionIntoArgument();
131 //=================================================================================
132 // function : ClickOnOk()
134 //=================================================================================
135 void MeasureGUI_NormaleDlg::ClickOnOk()
137 if ( ClickOnApply() )
141 //=================================================================================
142 // function : ClickOnApply()
144 //=================================================================================
145 bool MeasureGUI_NormaleDlg::ClickOnApply()
154 //=================================================================================
155 // function : SelectionIntoArgument()
156 // purpose : Called when selection as changed or other case
157 //=================================================================================
158 void MeasureGUI_NormaleDlg::SelectionIntoArgument()
161 myEditCurrentArgument->setText( "" );
163 if ( myEditCurrentArgument == GroupArgs->LineEdit1 ) {
164 myFace = GEOM::GEOM_Object::_nil();
166 else if ( myEditCurrentArgument == GroupArgs->LineEdit2 ) {
167 myPoint = GEOM::GEOM_Object::_nil();
170 if ( IObjectCount() != 1 )
174 Standard_Boolean testResult = Standard_False;
175 GEOM::GEOM_Object_var aSelectedObject =
176 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
181 QString aName = GEOMBase::GetName( aSelectedObject );
183 if ( myEditCurrentArgument == GroupArgs->LineEdit1 ) {
185 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
187 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
188 TColStd_IndexedMapOfInteger aMap;
189 aSelMgr->GetIndexes( firstIObject(), aMap );
190 if ( aMap.Extent() == 1 ) // Local Selection
192 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
193 int anIndex = aMap( 1 );
194 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
195 aName += QString( ":face_%1" ).arg( anIndex );
197 else // Global Selection
199 if ( aShape.ShapeType() != TopAbs_FACE ) {
200 aSelectedObject = GEOM::GEOM_Object::_nil();
205 myFace = aSelectedObject;
207 else if ( myEditCurrentArgument == GroupArgs->LineEdit2 ) {
209 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
211 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
212 TColStd_IndexedMapOfInteger aMap;
213 aSelMgr->GetIndexes( firstIObject(), aMap );
214 if ( aMap.Extent() == 1 ) // Local Selection
216 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
217 int anIndex = aMap( 1 );
218 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
219 aName += QString( ":vertex_%1" ).arg( anIndex );
221 else // Global Selection
223 if ( aShape.ShapeType() != TopAbs_VERTEX ) {
224 aSelectedObject = GEOM::GEOM_Object::_nil();
229 myPoint = aSelectedObject;
232 myEditCurrentArgument->setText( aName );
237 //=================================================================================
238 // function : LineEditReturnPressed()
240 //=================================================================================
241 void MeasureGUI_NormaleDlg::LineEditReturnPressed()
243 QLineEdit* send = (QLineEdit*)sender();
244 if ( send == GroupArgs->LineEdit1 ||
245 send == GroupArgs->LineEdit2 ) {
246 myEditCurrentArgument = send;
247 GEOMBase_Skeleton::LineEditReturnPressed();
251 //=================================================================================
252 // function : SetEditCurrentArgument()
254 //=================================================================================
255 void MeasureGUI_NormaleDlg::SetEditCurrentArgument()
257 QPushButton* send = (QPushButton*)sender();
258 globalSelection( GEOM_FACE );
260 if ( send == GroupArgs->PushButton1 ) {
261 myEditCurrentArgument = GroupArgs->LineEdit1;
262 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
264 else if ( send == GroupArgs->PushButton2 ) {
265 myEditCurrentArgument = GroupArgs->LineEdit2;
266 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
269 myEditCurrentArgument->setFocus();
270 SelectionIntoArgument();
273 //=================================================================================
274 // function : ActivateThisDialog()
276 //=================================================================================
277 void MeasureGUI_NormaleDlg::ActivateThisDialog()
279 GEOMBase_Skeleton::ActivateThisDialog();
281 SelectionIntoArgument();
284 //=================================================================================
285 // function : enterEvent()
287 //=================================================================================
288 void MeasureGUI_NormaleDlg::enterEvent( QEvent* e )
290 if ( !mainFrame()->GroupConstructors->isEnabled() )
291 ActivateThisDialog();
294 //=================================================================================
295 // function : createOperation
297 //=================================================================================
298 GEOM::GEOM_IOperations_ptr MeasureGUI_NormaleDlg::createOperation()
300 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
303 //=================================================================================
304 // function : isValid
306 //=================================================================================
307 bool MeasureGUI_NormaleDlg::isValid( QString& )
309 //return !CORBA::is_nil(myFace) && !CORBA::is_nil(myPoint);
310 return !CORBA::is_nil( myFace );
313 //=================================================================================
314 // function : execute
316 //=================================================================================
317 bool MeasureGUI_NormaleDlg::execute( ObjectList& objects )
319 GEOM::GEOM_Object_var anObj =
320 GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetNormal( myFace, myPoint );
322 if ( !anObj->_is_nil() )
323 objects.push_back( anObj._retn() );