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 myPoint1 = GEOM::GEOM_Object::_nil();
194 myPoint2 = GEOM::GEOM_Object::_nil();
195 GroupPoints->PushButton1->setDown(true);
196 GroupPoints->PushButton2->setDown(false);
203 globalSelection(); // close local contexts, if any
204 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
206 myEditCurrentArgument = GroupFaces->LineEdit1;
207 myEditCurrentArgument->setText("");
208 myFace1 = GEOM::GEOM_Object::_nil();
209 myFace2 = GEOM::GEOM_Object::_nil();
210 GroupFaces->PushButton1->setDown(true);
211 GroupFaces->PushButton2->setDown(false);
218 qApp->processEvents();
220 resize( minimumSize() );
222 SelectionIntoArgument();
225 //=================================================================================
226 // function : SelectionIntoArgument()
227 // purpose : Called when selection as changed or other case
228 //=================================================================================
229 void BasicGUI_LineDlg::SelectionIntoArgument()
231 myEditCurrentArgument->setText( "" );
233 if ( IObjectCount() != 1 ) {
234 // printf ( "IObjectCount() != 1 \n" );
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();
242 // printf ( "IObjectCount() == 1 \n" );
244 Standard_Boolean aRes = Standard_False;
245 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
246 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
247 QString aName = GEOMBase::GetName( aSelectedObject );
250 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
251 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
252 if ( myEditCurrentArgument == GroupFaces->LineEdit1 ||
253 myEditCurrentArgument == GroupFaces->LineEdit2 )
254 aNeedType = TopAbs_FACE;
256 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
257 TColStd_IndexedMapOfInteger aMap;
258 aSelMgr->GetIndexes( firstIObject(), aMap );
259 if ( aMap.Extent() == 1 ) { // Local Selection
260 int anIndex = aMap( 1 );
261 if ( aNeedType == TopAbs_FACE )
262 aName += QString( ":face_%1" ).arg( anIndex );
264 aName += QString( ":vertex_%1" ).arg( anIndex );
266 //Find SubShape Object in Father
267 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
269 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
270 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
271 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
274 aSelectedObject = aFindedObject; // get Object from study
277 else { // Global Selection
278 if ( aShape.ShapeType() != aNeedType ) {
279 aSelectedObject = GEOM::GEOM_Object::_nil();
285 myEditCurrentArgument->setText( aName );
287 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
288 myPoint1 = aSelectedObject;
289 if ( !myPoint1->_is_nil() && myPoint2->_is_nil() ) {
290 globalSelection(); // close local selection to clear it
291 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
292 GroupPoints->PushButton2->click();
295 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
296 myPoint2 = aSelectedObject;
297 if ( !myPoint2->_is_nil() && myPoint1->_is_nil() ) {
298 globalSelection(); // close local selection to clear it
299 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
300 GroupPoints->PushButton1->click();
303 else if ( myEditCurrentArgument == GroupFaces->LineEdit1 ) myFace1 = aSelectedObject;
304 else if ( myEditCurrentArgument == GroupFaces->LineEdit2 ) myFace2 = aSelectedObject;
311 //=================================================================================
312 // function : SetEditCurrentArgument()
314 //=================================================================================
315 void BasicGUI_LineDlg::SetEditCurrentArgument()
317 QPushButton* send = (QPushButton*)sender();
318 if ( send == GroupPoints->PushButton1 ) {
319 myEditCurrentArgument = GroupPoints->LineEdit1;
320 GroupPoints->PushButton2->setDown(false);
322 else if ( send == GroupPoints->PushButton2 ) {
323 myEditCurrentArgument = GroupPoints->LineEdit2;
324 GroupPoints->PushButton1->setDown(false);
326 else if ( send == GroupFaces->PushButton1 ) {
327 myEditCurrentArgument = GroupFaces->LineEdit1;
328 GroupFaces->PushButton2->setDown(false);
330 else if ( send == GroupFaces->PushButton2 ) {
331 myEditCurrentArgument = GroupFaces->LineEdit2;
332 GroupFaces->PushButton1->setDown(false);
334 myEditCurrentArgument->setFocus();
335 SelectionIntoArgument();
340 //=================================================================================
341 // function : LineEditReturnPressed()
343 //=================================================================================
344 void BasicGUI_LineDlg::LineEditReturnPressed()
346 QLineEdit* send = (QLineEdit*)sender();
347 if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
348 else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
349 else if ( send == GroupFaces->LineEdit1 ) myEditCurrentArgument = GroupFaces->LineEdit1;
350 else if ( send == GroupFaces->LineEdit2 ) myEditCurrentArgument = GroupFaces->LineEdit2;
352 GEOMBase_Skeleton::LineEditReturnPressed();
356 //=================================================================================
357 // function : ActivateThisDialog()
359 //=================================================================================
360 void BasicGUI_LineDlg::ActivateThisDialog()
362 GEOMBase_Skeleton::ActivateThisDialog();
363 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
364 this, SLOT( SelectionIntoArgument() ) );
366 ConstructorsClicked( getConstructorId() );
369 //=================================================================================
370 // function : DeactivateActiveDialog()
371 // purpose : public slot to deactivate if active
372 //=================================================================================
373 void BasicGUI_LineDlg::DeactivateActiveDialog()
375 GEOMBase_Skeleton::DeactivateActiveDialog();
378 //=================================================================================
379 // function : enterEvent()
381 //=================================================================================
382 void BasicGUI_LineDlg::enterEvent( QEvent* )
384 if ( !mainFrame()->GroupConstructors->isEnabled() )
385 ActivateThisDialog();
388 //=================================================================================
389 // function : createOperation
391 //=================================================================================
392 GEOM::GEOM_IOperations_ptr BasicGUI_LineDlg::createOperation()
394 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
397 //=================================================================================
398 // function : isValid
400 //=================================================================================
401 bool BasicGUI_LineDlg::isValid( QString& msg )
403 const int id = getConstructorId();
405 return !myPoint1->_is_nil() && !myPoint2->_is_nil();
407 return !myFace1->_is_nil() && !myFace2->_is_nil();
411 //=================================================================================
412 // function : execute
414 //=================================================================================
415 bool BasicGUI_LineDlg::execute( ObjectList& objects )
418 GEOM::GEOM_Object_var anObj;
419 switch ( getConstructorId() ) {
421 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoPnt( myPoint1, myPoint2 );
425 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoFaces( myFace1, myFace2 );
430 if ( !anObj->_is_nil() )
431 objects.push_back( anObj._retn() );
436 //=================================================================================
437 // function : addSubshapeToStudy
438 // purpose : virtual method to add new SubObjects if local selection
439 //=================================================================================
440 void BasicGUI_LineDlg::addSubshapesToStudy()
442 QMap<QString, GEOM::GEOM_Object_var> objMap;
443 switch ( getConstructorId() ) {
445 objMap[GroupPoints->LineEdit1->text()] = myPoint1;
446 objMap[GroupPoints->LineEdit2->text()] = myPoint2;
449 objMap[GroupFaces->LineEdit1->text()] = myFace1;
450 objMap[GroupFaces->LineEdit2->text()] = myFace2;
453 addSubshapesToFather( objMap );