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 : BasicGUI_LineDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "BasicGUI_LineDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <TopoDS_Shape.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <GEOMImpl_Types.hxx>
45 //=================================================================================
46 // class : BasicGUI_LineDlg()
47 // purpose : Constructs a BasicGUI_LineDlg 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 BasicGUI_LineDlg::BasicGUI_LineDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
53 bool modal, Qt::WindowFlags fl )
54 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
56 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_LINE_2P" ) ) );
57 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
58 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_LINE_2F" ) ) );
60 setWindowTitle( tr( "GEOM_LINE_TITLE" ) );
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_LINE" ) );
64 mainFrame()->RadioButton1->setIcon( image0 );
65 mainFrame()->RadioButton2->setIcon( image2 );
66 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
67 mainFrame()->RadioButton3->close();
69 GroupPoints = new DlgRef_2Sel( centralWidget() );
71 GroupPoints->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
72 GroupPoints->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
73 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
74 GroupPoints->PushButton1->setIcon( image1 );
75 GroupPoints->PushButton2->setIcon( image1 );
76 GroupPoints->LineEdit1->setReadOnly( true );
77 GroupPoints->LineEdit2->setReadOnly( true );
79 GroupFaces = new DlgRef_2Sel( centralWidget() );
80 GroupFaces->GroupBox1->setTitle( tr( "GEOM_FACES" ) );
81 GroupFaces->TextLabel1->setText( tr( "GEOM_FACE_I" ).arg( "1" ) );
82 GroupFaces->TextLabel2->setText( tr( "GEOM_FACE_I" ).arg( "2" ) );
83 GroupFaces->PushButton1->setIcon( image1 );
84 GroupFaces->PushButton2->setIcon( image1 );
85 GroupFaces->LineEdit1->setReadOnly( true );
86 GroupFaces->LineEdit2->setReadOnly( true );
88 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
89 layout->setMargin( 0 ); layout->setSpacing( 6 );
90 layout->addWidget( GroupPoints );
91 layout->addWidget( GroupFaces );
93 /***************************************************************/
95 setHelpFileName( "create_line_page.html" );
101 //=================================================================================
102 // function : ~BasicGUI_LineDlg()
103 // purpose : Destroys the object and frees any allocated resources
104 //=================================================================================
105 BasicGUI_LineDlg::~BasicGUI_LineDlg()
110 //=================================================================================
113 //=================================================================================
114 void BasicGUI_LineDlg::Init()
117 myEditCurrentArgument = GroupPoints->LineEdit1;
118 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
119 globalSelection(); // close local contexts, if any
120 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
121 GroupPoints->PushButton1->setDown(true);
124 /* signals and slots connections */
125 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
126 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
128 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
130 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
131 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
133 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
134 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
135 connect( GroupFaces->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
136 connect( GroupFaces->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
138 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
139 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
140 connect( GroupFaces->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
141 connect( GroupFaces->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
143 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
144 this, SLOT( SelectionIntoArgument() ) );
146 initName( tr( "GEOM_LINE" ) );
148 ConstructorsClicked( 0 );
152 //=================================================================================
153 // function : ClickOnOk()
155 //=================================================================================
156 void BasicGUI_LineDlg::ClickOnOk()
158 if ( ClickOnApply() )
162 //=================================================================================
163 // function : ClickOnApply()
165 //=================================================================================
166 bool BasicGUI_LineDlg::ClickOnApply()
173 myEditCurrentArgument->setText( "" );
174 ConstructorsClicked( getConstructorId() );
179 //=================================================================================
180 // function : ConstructorsClicked()
181 // purpose : Radio button management
182 //=================================================================================
183 void BasicGUI_LineDlg::ConstructorsClicked( int constructorId )
185 switch ( constructorId ) {
188 globalSelection(); // close local contexts, if any
189 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
191 myEditCurrentArgument = GroupPoints->LineEdit1;
192 myEditCurrentArgument->setText( "" );
193 GroupPoints->LineEdit2->setText( "" );
194 myPoint1 = GEOM::GEOM_Object::_nil();
195 myPoint2 = GEOM::GEOM_Object::_nil();
196 GroupPoints->PushButton1->setDown(true);
197 GroupPoints->PushButton2->setDown(false);
204 globalSelection(); // close local contexts, if any
205 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
207 myEditCurrentArgument = GroupFaces->LineEdit1;
208 myEditCurrentArgument->setText("");
209 myFace1 = GEOM::GEOM_Object::_nil();
210 myFace2 = GEOM::GEOM_Object::_nil();
211 GroupFaces->PushButton1->setDown(true);
212 GroupFaces->PushButton2->setDown(false);
219 qApp->processEvents();
221 resize( minimumSize() );
223 SelectionIntoArgument();
226 //=================================================================================
227 // function : SelectionIntoArgument()
228 // purpose : Called when selection as changed or other case
229 //=================================================================================
230 void BasicGUI_LineDlg::SelectionIntoArgument()
232 myEditCurrentArgument->setText( "" );
234 if ( IObjectCount() != 1 ) {
235 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
236 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
237 else if ( myEditCurrentArgument == GroupFaces->LineEdit1 ) myFace1 = GEOM::GEOM_Object::_nil();
238 else if ( myEditCurrentArgument == GroupFaces->LineEdit2 ) myFace2 = GEOM::GEOM_Object::_nil();
243 Standard_Boolean aRes = Standard_False;
244 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
245 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
246 QString aName = GEOMBase::GetName( aSelectedObject );
249 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
250 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
251 if ( myEditCurrentArgument == GroupFaces->LineEdit1 ||
252 myEditCurrentArgument == GroupFaces->LineEdit2 )
253 aNeedType = TopAbs_FACE;
255 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
256 TColStd_IndexedMapOfInteger aMap;
257 aSelMgr->GetIndexes( firstIObject(), aMap );
258 if ( aMap.Extent() == 1 ) { // Local Selection
259 int anIndex = aMap( 1 );
260 if ( aNeedType == TopAbs_FACE )
261 aName += QString( ":face_%1" ).arg( anIndex );
263 aName += QString( ":vertex_%1" ).arg( anIndex );
265 //Find SubShape Object in Father
266 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
268 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
269 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
270 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
273 aSelectedObject = aFindedObject; // get Object from study
276 else { // Global Selection
277 if ( aShape.ShapeType() != aNeedType ) {
278 aSelectedObject = GEOM::GEOM_Object::_nil();
284 myEditCurrentArgument->setText( aName );
286 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
287 myPoint1 = aSelectedObject;
288 if ( !myPoint1->_is_nil() && myPoint2->_is_nil() ) {
289 globalSelection(); // close local selection to clear it
290 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
291 GroupPoints->PushButton2->click();
294 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
295 myPoint2 = aSelectedObject;
296 if ( !myPoint2->_is_nil() && myPoint1->_is_nil() ) {
297 globalSelection(); // close local selection to clear it
298 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
299 GroupPoints->PushButton1->click();
302 else if ( myEditCurrentArgument == GroupFaces->LineEdit1 ) myFace1 = aSelectedObject;
303 else if ( myEditCurrentArgument == GroupFaces->LineEdit2 ) myFace2 = aSelectedObject;
310 //=================================================================================
311 // function : SetEditCurrentArgument()
313 //=================================================================================
314 void BasicGUI_LineDlg::SetEditCurrentArgument()
316 if ( IObjectCount() != 0 ) {
317 globalSelection(); // close local selection to clear it
318 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
320 QPushButton* send = (QPushButton*)sender();
321 if ( send == GroupPoints->PushButton1 ) {
322 myEditCurrentArgument = GroupPoints->LineEdit1;
323 GroupPoints->PushButton2->setDown(false);
325 else if ( send == GroupPoints->PushButton2 ) {
326 myEditCurrentArgument = GroupPoints->LineEdit2;
327 GroupPoints->PushButton1->setDown(false);
329 else if ( send == GroupFaces->PushButton1 ) {
330 myEditCurrentArgument = GroupFaces->LineEdit1;
331 GroupFaces->PushButton2->setDown(false);
333 else if ( send == GroupFaces->PushButton2 ) {
334 myEditCurrentArgument = GroupFaces->LineEdit2;
335 GroupFaces->PushButton1->setDown(false);
337 myEditCurrentArgument->setFocus();
338 // SelectionIntoArgument();
344 //=================================================================================
345 // function : LineEditReturnPressed()
347 //=================================================================================
348 void BasicGUI_LineDlg::LineEditReturnPressed()
350 QLineEdit* send = (QLineEdit*)sender();
351 if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
352 else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
353 else if ( send == GroupFaces->LineEdit1 ) myEditCurrentArgument = GroupFaces->LineEdit1;
354 else if ( send == GroupFaces->LineEdit2 ) myEditCurrentArgument = GroupFaces->LineEdit2;
356 GEOMBase_Skeleton::LineEditReturnPressed();
360 //=================================================================================
361 // function : ActivateThisDialog()
363 //=================================================================================
364 void BasicGUI_LineDlg::ActivateThisDialog()
366 GEOMBase_Skeleton::ActivateThisDialog();
367 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
368 this, SLOT( SelectionIntoArgument() ) );
370 ConstructorsClicked( getConstructorId() );
373 //=================================================================================
374 // function : DeactivateActiveDialog()
375 // purpose : public slot to deactivate if active
376 //=================================================================================
377 void BasicGUI_LineDlg::DeactivateActiveDialog()
379 GEOMBase_Skeleton::DeactivateActiveDialog();
382 //=================================================================================
383 // function : enterEvent()
385 //=================================================================================
386 void BasicGUI_LineDlg::enterEvent( QEvent* )
388 if ( !mainFrame()->GroupConstructors->isEnabled() )
389 ActivateThisDialog();
392 //=================================================================================
393 // function : createOperation
395 //=================================================================================
396 GEOM::GEOM_IOperations_ptr BasicGUI_LineDlg::createOperation()
398 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
401 //=================================================================================
402 // function : isValid
404 //=================================================================================
405 bool BasicGUI_LineDlg::isValid( QString& msg )
407 const int id = getConstructorId();
409 return !myPoint1->_is_nil() && !myPoint2->_is_nil();
411 return !myFace1->_is_nil() && !myFace2->_is_nil();
415 //=================================================================================
416 // function : execute
418 //=================================================================================
419 bool BasicGUI_LineDlg::execute( ObjectList& objects )
422 GEOM::GEOM_Object_var anObj;
423 switch ( getConstructorId() ) {
425 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoPnt( myPoint1, myPoint2 );
429 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoFaces( myFace1, myFace2 );
434 if ( !anObj->_is_nil() )
435 objects.push_back( anObj._retn() );
440 //=================================================================================
441 // function : addSubshapeToStudy
442 // purpose : virtual method to add new SubObjects if local selection
443 //=================================================================================
444 void BasicGUI_LineDlg::addSubshapesToStudy()
446 QMap<QString, GEOM::GEOM_Object_var> objMap;
447 switch ( getConstructorId() ) {
449 objMap[GroupPoints->LineEdit1->text()] = myPoint1;
450 objMap[GroupPoints->LineEdit2->text()] = myPoint2;
453 objMap[GroupFaces->LineEdit1->text()] = myFace1;
454 objMap[GroupFaces->LineEdit2->text()] = myFace2;
457 addSubshapesToFather( objMap );