]> SALOME platform Git repositories - modules/geom.git/blob - src/MeasureGUI/MeasureGUI_NormaleDlg.cxx
Salome HOME
Merge from V4_1_0_maintainance branch (from tag mergeto_BR_QT4_Dev_08Jul08)
[modules/geom.git] / src / MeasureGUI / MeasureGUI_NormaleDlg.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : MeasureGUI_NormaleDlg.cxx
23 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
24 //
25
26 #include "MeasureGUI_NormaleDlg.h"
27
28 #include <DlgRef.h>
29 #include <GEOMBase.h>
30 #include <GeometryGUI.h>
31
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36
37 #include <GEOMImpl_Types.hxx>
38
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS.hxx>
41 #include <TopExp.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
44
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 )
54 {
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" ) ) );
58
59   setWindowTitle( tr( "GEOM_NORMALE_TITLE" ) );
60
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();
68
69   GroupArgs = new DlgRef_2Sel ( centralWidget() );
70   GroupArgs->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
71
72   GroupArgs->TextLabel1->setText( tr( "GEOM_FACE" ) );
73   GroupArgs->TextLabel2->setText( tr( "GEOM_POINT" ) );
74
75   GroupArgs->PushButton1->setIcon( image1 );
76   GroupArgs->PushButton2->setIcon( image1 );
77
78   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
79   layout->setMargin( 0 ); layout->setSpacing( 6 );
80   layout->addWidget( GroupArgs );
81
82   /***************************************************************/
83
84   setHelpFileName("using_measurement_tools_page.html#normale_anchor");
85
86   Init();
87 }
88
89 //=================================================================================
90 // function : ~MeasureGUI_NormaleDlg()
91 // purpose  : Destroys the object and frees any allocated resources
92 //=================================================================================
93 MeasureGUI_NormaleDlg::~MeasureGUI_NormaleDlg()
94 {
95 }
96
97 //=================================================================================
98 // function : Init()
99 // purpose  :
100 //=================================================================================
101 void MeasureGUI_NormaleDlg::Init()
102 {
103   /* init variables */
104   GroupArgs->LineEdit1->setReadOnly( true );
105   GroupArgs->LineEdit2->setReadOnly( true );
106
107   myFace = GEOM::GEOM_Object::_nil();
108   myPoint = GEOM::GEOM_Object::_nil();
109
110   myEditCurrentArgument = GroupArgs->LineEdit1;
111   globalSelection( GEOM_FACE );
112
113   /* signals and slots connections */
114   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
115   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
116
117   connect( GroupArgs->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
118   connect( GroupArgs->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
119
120   connect( GroupArgs->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
121   connect( GroupArgs->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
122
123   connect( myGeomGUI->getApp()->selectionMgr(),
124            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
125
126   initName(tr("GEOM_VECTOR_NORMALE"));
127
128   SelectionIntoArgument();
129 }
130
131 //=================================================================================
132 // function : ClickOnOk()
133 // purpose  :
134 //=================================================================================
135 void MeasureGUI_NormaleDlg::ClickOnOk()
136 {
137   if ( ClickOnApply() )
138     ClickOnCancel();
139 }
140
141 //=================================================================================
142 // function : ClickOnApply()
143 // purpose  :
144 //=================================================================================
145 bool MeasureGUI_NormaleDlg::ClickOnApply()
146 {
147   if ( !onAccept() )
148     return false;
149
150   initName();
151   return true;
152 }
153
154 //=================================================================================
155 // function : SelectionIntoArgument()
156 // purpose  : Called when selection as changed or other case
157 //=================================================================================
158 void MeasureGUI_NormaleDlg::SelectionIntoArgument()
159 {
160   erasePreview();
161   myEditCurrentArgument->setText( "" );
162
163   if ( myEditCurrentArgument == GroupArgs->LineEdit1 ) {
164     myFace = GEOM::GEOM_Object::_nil();
165   }
166   else if ( myEditCurrentArgument == GroupArgs->LineEdit2 ) {
167     myPoint = GEOM::GEOM_Object::_nil();
168   }
169   
170   if ( IObjectCount() != 1 )
171     return;
172
173   // nbSel == 1
174   Standard_Boolean testResult = Standard_False;
175   GEOM::GEOM_Object_var aSelectedObject =
176     GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
177
178   if ( !testResult )
179     return;
180
181   QString aName = GEOMBase::GetName( aSelectedObject );
182
183   if ( myEditCurrentArgument == GroupArgs->LineEdit1 ) {
184     TopoDS_Shape aShape;
185     if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
186     {
187       LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
188       TColStd_IndexedMapOfInteger aMap;
189       aSelMgr->GetIndexes( firstIObject(), aMap );
190       if ( aMap.Extent() == 1 ) // Local Selection
191       {
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 );
196       }
197       else // Global Selection
198       {
199         if ( aShape.ShapeType() != TopAbs_FACE ) {
200           aSelectedObject = GEOM::GEOM_Object::_nil();
201           aName = "";
202         }
203       }
204     }
205     myFace = aSelectedObject;
206   }
207   else if ( myEditCurrentArgument == GroupArgs->LineEdit2 ) {
208     TopoDS_Shape aShape;
209     if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
210     {
211       LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
212       TColStd_IndexedMapOfInteger aMap;
213       aSelMgr->GetIndexes( firstIObject(), aMap );
214       if ( aMap.Extent() == 1 ) // Local Selection
215       {
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 );
220       }
221       else // Global Selection
222       {
223         if ( aShape.ShapeType() != TopAbs_VERTEX ) {
224           aSelectedObject = GEOM::GEOM_Object::_nil();
225           aName = "";
226         }
227       }
228     }
229     myPoint = aSelectedObject;
230   }
231
232   myEditCurrentArgument->setText( aName );
233
234   displayPreview();
235 }
236
237 //=================================================================================
238 // function : LineEditReturnPressed()
239 // purpose  :
240 //=================================================================================
241 void MeasureGUI_NormaleDlg::LineEditReturnPressed()
242 {
243   QLineEdit* send = (QLineEdit*)sender();
244   if ( send == GroupArgs->LineEdit1 ||
245        send == GroupArgs->LineEdit2 ) {
246     myEditCurrentArgument = send;
247     GEOMBase_Skeleton::LineEditReturnPressed();
248   }
249 }
250
251 //=================================================================================
252 // function : SetEditCurrentArgument()
253 // purpose  :
254 //=================================================================================
255 void MeasureGUI_NormaleDlg::SetEditCurrentArgument()
256 {
257   QPushButton* send = (QPushButton*)sender();
258   globalSelection( GEOM_FACE );
259
260   if ( send == GroupArgs->PushButton1 ) {
261     myEditCurrentArgument = GroupArgs->LineEdit1;
262     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
263   }
264   else if ( send == GroupArgs->PushButton2 ) {
265     myEditCurrentArgument = GroupArgs->LineEdit2;
266     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
267   }
268
269   myEditCurrentArgument->setFocus();
270   SelectionIntoArgument();
271 }
272
273 //=================================================================================
274 // function : ActivateThisDialog()
275 // purpose  :
276 //=================================================================================
277 void MeasureGUI_NormaleDlg::ActivateThisDialog()
278 {
279   GEOMBase_Skeleton::ActivateThisDialog();
280
281   SelectionIntoArgument();
282 }
283
284 //=================================================================================
285 // function : enterEvent()
286 // purpose  :
287 //=================================================================================
288 void MeasureGUI_NormaleDlg::enterEvent( QEvent* e )
289 {
290   if ( !mainFrame()->GroupConstructors->isEnabled() )
291     ActivateThisDialog();
292 }
293
294 //=================================================================================
295 // function : createOperation
296 // purpose  :
297 //=================================================================================
298 GEOM::GEOM_IOperations_ptr MeasureGUI_NormaleDlg::createOperation()
299 {
300   return getGeomEngine()->GetIMeasureOperations( getStudyId() );
301 }
302
303 //=================================================================================
304 // function : isValid
305 // purpose  :
306 //=================================================================================
307 bool MeasureGUI_NormaleDlg::isValid( QString& )
308 {
309   //return !CORBA::is_nil(myFace) && !CORBA::is_nil(myPoint);
310   return !CORBA::is_nil( myFace );
311 }
312
313 //=================================================================================
314 // function : execute
315 // purpose  :
316 //=================================================================================
317 bool MeasureGUI_NormaleDlg::execute( ObjectList& objects )
318 {
319   GEOM::GEOM_Object_var anObj =
320     GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetNormal( myFace, myPoint );
321
322   if ( !anObj->_is_nil() )
323     objects.push_back( anObj._retn() );
324
325   return true;
326 }