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 ); // to close previous local selection
112 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
114 /* signals and slots connections */
115 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
116 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
118 connect( GroupArgs->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
119 connect( GroupArgs->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
121 connect( GroupArgs->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
122 connect( GroupArgs->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
124 connect( myGeomGUI->getApp()->selectionMgr(),
125 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
127 initName(tr("GEOM_VECTOR_NORMALE"));
129 SelectionIntoArgument();
132 //=================================================================================
133 // function : ClickOnOk()
135 //=================================================================================
136 void MeasureGUI_NormaleDlg::ClickOnOk()
138 if ( ClickOnApply() )
142 //=================================================================================
143 // function : ClickOnApply()
145 //=================================================================================
146 bool MeasureGUI_NormaleDlg::ClickOnApply()
155 //=================================================================================
156 // function : SelectionIntoArgument()
157 // purpose : Called when selection as changed or other case
158 //=================================================================================
159 void MeasureGUI_NormaleDlg::SelectionIntoArgument()
162 myEditCurrentArgument->setText( "" );
164 if ( myEditCurrentArgument == GroupArgs->LineEdit1 ) {
165 myFace = GEOM::GEOM_Object::_nil();
167 else if ( myEditCurrentArgument == GroupArgs->LineEdit2 ) {
168 myPoint = GEOM::GEOM_Object::_nil();
171 if ( IObjectCount() != 1 )
175 Standard_Boolean testResult = Standard_False;
176 GEOM::GEOM_Object_var aSelectedObject =
177 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
182 QString aName = GEOMBase::GetName( aSelectedObject );
184 if ( myEditCurrentArgument == GroupArgs->LineEdit1 ) {
186 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
188 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
189 TColStd_IndexedMapOfInteger aMap;
190 aSelMgr->GetIndexes( firstIObject(), aMap );
191 if ( aMap.Extent() == 1 ) // Local Selection
193 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
194 int anIndex = aMap( 1 );
195 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
196 aName += QString( ":face_%1" ).arg( anIndex );
198 else // Global Selection
200 if ( aShape.ShapeType() != TopAbs_FACE ) {
201 aSelectedObject = GEOM::GEOM_Object::_nil();
206 myFace = aSelectedObject;
208 else if ( myEditCurrentArgument == GroupArgs->LineEdit2 ) {
210 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
212 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
213 TColStd_IndexedMapOfInteger aMap;
214 aSelMgr->GetIndexes( firstIObject(), aMap );
215 if ( aMap.Extent() == 1 ) // Local Selection
217 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
218 int anIndex = aMap( 1 );
219 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
220 aName += QString( ":vertex_%1" ).arg( anIndex );
222 else // Global Selection
224 if ( aShape.ShapeType() != TopAbs_VERTEX ) {
225 aSelectedObject = GEOM::GEOM_Object::_nil();
230 myPoint = aSelectedObject;
233 myEditCurrentArgument->setText( aName );
238 //=================================================================================
239 // function : LineEditReturnPressed()
241 //=================================================================================
242 void MeasureGUI_NormaleDlg::LineEditReturnPressed()
244 QLineEdit* send = (QLineEdit*)sender();
245 if ( send == GroupArgs->LineEdit1 ||
246 send == GroupArgs->LineEdit2 ) {
247 myEditCurrentArgument = send;
248 GEOMBase_Skeleton::LineEditReturnPressed();
252 //=================================================================================
253 // function : SetEditCurrentArgument()
255 //=================================================================================
256 void MeasureGUI_NormaleDlg::SetEditCurrentArgument()
258 QPushButton* send = (QPushButton*)sender();
259 globalSelection( GEOM_FACE );
261 if ( send == GroupArgs->PushButton1 ) {
262 myEditCurrentArgument = GroupArgs->LineEdit1;
263 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
265 else if ( send == GroupArgs->PushButton2 ) {
266 myEditCurrentArgument = GroupArgs->LineEdit2;
267 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
270 myEditCurrentArgument->setFocus();
271 SelectionIntoArgument();
274 //=================================================================================
275 // function : ActivateThisDialog()
277 //=================================================================================
278 void MeasureGUI_NormaleDlg::ActivateThisDialog()
280 GEOMBase_Skeleton::ActivateThisDialog();
282 SelectionIntoArgument();
285 //=================================================================================
286 // function : enterEvent()
288 //=================================================================================
289 void MeasureGUI_NormaleDlg::enterEvent( QEvent* e )
291 if ( !mainFrame()->GroupConstructors->isEnabled() )
292 ActivateThisDialog();
295 //=================================================================================
296 // function : createOperation
298 //=================================================================================
299 GEOM::GEOM_IOperations_ptr MeasureGUI_NormaleDlg::createOperation()
301 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
304 //=================================================================================
305 // function : isValid
307 //=================================================================================
308 bool MeasureGUI_NormaleDlg::isValid( QString& )
310 //return !CORBA::is_nil(myFace) && !CORBA::is_nil(myPoint);
311 return !CORBA::is_nil( myFace );
314 //=================================================================================
315 // function : execute
317 //=================================================================================
318 bool MeasureGUI_NormaleDlg::execute( ObjectList& objects )
320 GEOM::GEOM_Object_var anObj =
321 GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetNormal( myFace, myPoint );
323 if ( !anObj->_is_nil() )
324 objects.push_back( anObj._retn() );