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 );
122 /* signals and slots connections */
123 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
124 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
126 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
128 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
129 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
131 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
132 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
133 connect( GroupFaces->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
134 connect( GroupFaces->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
136 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
137 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
138 connect( GroupFaces->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
139 connect( GroupFaces->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
141 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
142 this, SLOT( SelectionIntoArgument() ) );
144 initName( tr( "GEOM_LINE" ) );
146 ConstructorsClicked( 0 );
150 //=================================================================================
151 // function : ClickOnOk()
153 //=================================================================================
154 void BasicGUI_LineDlg::ClickOnOk()
156 if ( ClickOnApply() )
160 //=================================================================================
161 // function : ClickOnApply()
163 //=================================================================================
164 bool BasicGUI_LineDlg::ClickOnApply()
171 myEditCurrentArgument->setText( "" );
172 ConstructorsClicked( getConstructorId() );
177 //=================================================================================
178 // function : ConstructorsClicked()
179 // purpose : Radio button management
180 //=================================================================================
181 void BasicGUI_LineDlg::ConstructorsClicked( int constructorId )
183 switch ( constructorId ) {
186 globalSelection(); // close local contexts, if any
187 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
189 myEditCurrentArgument = GroupPoints->LineEdit1;
190 myEditCurrentArgument->setText( "" );
191 myPoint1 = GEOM::GEOM_Object::_nil();
192 myPoint2 = GEOM::GEOM_Object::_nil();
200 globalSelection(); // close local contexts, if any
201 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
203 myEditCurrentArgument = GroupFaces->LineEdit1;
204 myEditCurrentArgument->setText("");
205 myFace1 = GEOM::GEOM_Object::_nil();
206 myFace2 = GEOM::GEOM_Object::_nil();
213 qApp->processEvents();
215 resize( minimumSize() );
217 SelectionIntoArgument();
220 //=================================================================================
221 // function : SelectionIntoArgument()
222 // purpose : Called when selection as changed or other case
223 //=================================================================================
224 void BasicGUI_LineDlg::SelectionIntoArgument()
226 myEditCurrentArgument->setText( "" );
228 if ( IObjectCount() != 1 ) {
229 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
230 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
231 else if ( myEditCurrentArgument == GroupFaces->LineEdit1 ) myFace1 = GEOM::GEOM_Object::_nil();
232 else if ( myEditCurrentArgument == GroupFaces->LineEdit2 ) myFace2 = GEOM::GEOM_Object::_nil();
237 Standard_Boolean aRes = Standard_False;
238 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
239 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
240 QString aName = GEOMBase::GetName( aSelectedObject );
243 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
244 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
245 if ( myEditCurrentArgument == GroupFaces->LineEdit1 ||
246 myEditCurrentArgument == GroupFaces->LineEdit2 )
247 aNeedType = TopAbs_FACE;
249 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
250 TColStd_IndexedMapOfInteger aMap;
251 aSelMgr->GetIndexes( firstIObject(), aMap );
252 if ( aMap.Extent() == 1 ) { // Local Selection
253 int anIndex = aMap( 1 );
254 if ( aNeedType == TopAbs_FACE )
255 aName += QString( ":face_%1" ).arg( anIndex );
257 aName += QString( ":vertex_%1" ).arg( anIndex );
259 //Find SubShape Object in Father
260 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
262 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
263 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
264 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
267 aSelectedObject = aFindedObject; // get Object from study
270 else { // Global Selection
271 if ( aShape.ShapeType() != aNeedType ) {
272 aSelectedObject = GEOM::GEOM_Object::_nil();
278 myEditCurrentArgument->setText( aName );
280 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
281 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
282 else if ( myEditCurrentArgument == GroupFaces->LineEdit1 ) myFace1 = aSelectedObject;
283 else if ( myEditCurrentArgument == GroupFaces->LineEdit2 ) myFace2 = aSelectedObject;
290 //=================================================================================
291 // function : SetEditCurrentArgument()
293 //=================================================================================
294 void BasicGUI_LineDlg::SetEditCurrentArgument()
296 QPushButton* send = (QPushButton*)sender();
297 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
298 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
299 else if ( send == GroupFaces->PushButton1 ) myEditCurrentArgument = GroupFaces->LineEdit1;
300 else if ( send == GroupFaces->PushButton2 ) myEditCurrentArgument = GroupFaces->LineEdit2;
301 myEditCurrentArgument->setFocus();
302 SelectionIntoArgument();
306 //=================================================================================
307 // function : LineEditReturnPressed()
309 //=================================================================================
310 void BasicGUI_LineDlg::LineEditReturnPressed()
312 QLineEdit* send = (QLineEdit*)sender();
313 if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
314 else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
315 else if ( send == GroupFaces->LineEdit1 ) myEditCurrentArgument = GroupFaces->LineEdit1;
316 else if ( send == GroupFaces->LineEdit2 ) myEditCurrentArgument = GroupFaces->LineEdit2;
318 GEOMBase_Skeleton::LineEditReturnPressed();
322 //=================================================================================
323 // function : ActivateThisDialog()
325 //=================================================================================
326 void BasicGUI_LineDlg::ActivateThisDialog()
328 GEOMBase_Skeleton::ActivateThisDialog();
329 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
330 this, SLOT( SelectionIntoArgument() ) );
332 ConstructorsClicked( getConstructorId() );
335 //=================================================================================
336 // function : DeactivateActiveDialog()
337 // purpose : public slot to deactivate if active
338 //=================================================================================
339 void BasicGUI_LineDlg::DeactivateActiveDialog()
341 GEOMBase_Skeleton::DeactivateActiveDialog();
344 //=================================================================================
345 // function : enterEvent()
347 //=================================================================================
348 void BasicGUI_LineDlg::enterEvent( QEvent* )
350 if ( !mainFrame()->GroupConstructors->isEnabled() )
351 ActivateThisDialog();
354 //=================================================================================
355 // function : createOperation
357 //=================================================================================
358 GEOM::GEOM_IOperations_ptr BasicGUI_LineDlg::createOperation()
360 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
363 //=================================================================================
364 // function : isValid
366 //=================================================================================
367 bool BasicGUI_LineDlg::isValid( QString& msg )
369 const int id = getConstructorId();
371 return !myPoint1->_is_nil() && !myPoint2->_is_nil();
373 return !myFace1->_is_nil() && !myFace2->_is_nil();
377 //=================================================================================
378 // function : execute
380 //=================================================================================
381 bool BasicGUI_LineDlg::execute( ObjectList& objects )
384 GEOM::GEOM_Object_var anObj;
385 switch ( getConstructorId() ) {
387 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoPnt( myPoint1, myPoint2 );
391 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoFaces( myFace1, myFace2 );
396 if ( !anObj->_is_nil() )
397 objects.push_back( anObj._retn() );
402 //=================================================================================
403 // function : addSubshapeToStudy
404 // purpose : virtual method to add new SubObjects if local selection
405 //=================================================================================
406 void BasicGUI_LineDlg::addSubshapesToStudy()
408 QMap<QString, GEOM::GEOM_Object_var> objMap;
409 switch ( getConstructorId() ) {
411 objMap[GroupPoints->LineEdit1->text()] = myPoint1;
412 objMap[GroupPoints->LineEdit2->text()] = myPoint2;
415 objMap[GroupFaces->LineEdit1->text()] = myFace1;
416 objMap[GroupFaces->LineEdit2->text()] = myFace2;
419 addSubshapesToFather( objMap );