1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : BasicGUI_LineDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "BasicGUI_LineDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <TopoDS_Shape.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <GEOMImpl_Types.hxx>
46 //=================================================================================
47 // class : BasicGUI_LineDlg()
48 // purpose : Constructs a BasicGUI_LineDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 BasicGUI_LineDlg::BasicGUI_LineDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
54 bool modal, Qt::WindowFlags fl )
55 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
57 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_LINE_2P" ) ) );
58 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
59 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_LINE_2F" ) ) );
61 setWindowTitle( tr( "GEOM_LINE_TITLE" ) );
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_LINE" ) );
65 mainFrame()->RadioButton1->setIcon( image0 );
66 mainFrame()->RadioButton2->setIcon( image2 );
67 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
68 mainFrame()->RadioButton3->close();
70 GroupPoints = new DlgRef_2Sel( centralWidget() );
72 GroupPoints->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
73 GroupPoints->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
74 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
75 GroupPoints->PushButton1->setIcon( image1 );
76 GroupPoints->PushButton2->setIcon( image1 );
77 GroupPoints->LineEdit1->setReadOnly( true );
78 GroupPoints->LineEdit2->setReadOnly( true );
79 GroupPoints->LineEdit1->setEnabled( true );
80 GroupPoints->LineEdit2->setEnabled( false );
82 GroupFaces = new DlgRef_2Sel( centralWidget() );
83 GroupFaces->GroupBox1->setTitle( tr( "GEOM_FACES" ) );
84 GroupFaces->TextLabel1->setText( tr( "GEOM_FACE_I" ).arg( "1" ) );
85 GroupFaces->TextLabel2->setText( tr( "GEOM_FACE_I" ).arg( "2" ) );
86 GroupFaces->PushButton1->setIcon( image1 );
87 GroupFaces->PushButton2->setIcon( image1 );
88 GroupFaces->LineEdit1->setReadOnly( true );
89 GroupFaces->LineEdit2->setReadOnly( true );
90 GroupFaces->LineEdit1->setEnabled( true );
91 GroupFaces->LineEdit2->setEnabled( false );
93 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
94 layout->setMargin( 0 ); layout->setSpacing( 6 );
95 layout->addWidget( GroupPoints );
96 layout->addWidget( GroupFaces );
98 /***************************************************************/
100 setHelpFileName( "create_line_page.html" );
106 //=================================================================================
107 // function : ~BasicGUI_LineDlg()
108 // purpose : Destroys the object and frees any allocated resources
109 //=================================================================================
110 BasicGUI_LineDlg::~BasicGUI_LineDlg()
115 //=================================================================================
118 //=================================================================================
119 void BasicGUI_LineDlg::Init()
122 myEditCurrentArgument = GroupPoints->LineEdit1;
128 GroupPoints->PushButton1->setDown(true);
130 /* signals and slots connections */
131 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
132 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
134 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
136 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
137 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
139 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
140 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
141 connect( GroupFaces->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
142 connect( GroupFaces->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
144 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
145 this, SLOT( SelectionIntoArgument() ) );
147 initName( tr( "GEOM_LINE" ) );
149 ConstructorsClicked( 0 );
153 //=================================================================================
154 // function : ClickOnOk()
156 //=================================================================================
157 void BasicGUI_LineDlg::ClickOnOk()
159 if ( ClickOnApply() )
163 //=================================================================================
164 // function : ClickOnApply()
166 //=================================================================================
167 bool BasicGUI_LineDlg::ClickOnApply()
174 myEditCurrentArgument->setText( "" );
175 ConstructorsClicked( getConstructorId() );
180 //=================================================================================
181 // function : ConstructorsClicked()
182 // purpose : Radio button management
183 //=================================================================================
184 void BasicGUI_LineDlg::ConstructorsClicked( int constructorId )
186 switch ( constructorId ) {
189 myEditCurrentArgument = GroupPoints->LineEdit1;
190 myEditCurrentArgument->setText( "" );
191 GroupPoints->LineEdit2->setText( "" );
194 GroupPoints->PushButton1->setDown(true);
195 GroupPoints->PushButton2->setDown(false);
196 GroupPoints->LineEdit1->setEnabled(true);
197 GroupPoints->LineEdit2->setEnabled(false);
204 myEditCurrentArgument = GroupFaces->LineEdit1;
205 myEditCurrentArgument->setText("");
208 GroupFaces->PushButton1->setDown(true);
209 GroupFaces->PushButton2->setDown(false);
210 GroupFaces->LineEdit1->setEnabled(true);
211 GroupFaces->LineEdit2->setEnabled(false);
218 TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupFaces->LineEdit1 ||
219 myEditCurrentArgument == GroupFaces->LineEdit2 ) ?
220 TopAbs_FACE : TopAbs_VERTEX;
221 globalSelection(); // close local selection to clear it
222 localSelection( GEOM::GEOM_Object::_nil(), aNeedType );
224 qApp->processEvents();
226 resize( minimumSizeHint() );
227 SelectionIntoArgument();
230 //=================================================================================
231 // function : SelectionIntoArgument()
232 // purpose : Called when selection as changed or other case
233 //=================================================================================
234 void BasicGUI_LineDlg::SelectionIntoArgument()
236 myEditCurrentArgument->setText( "" );
238 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
239 SALOME_ListIO aSelList;
240 aSelMgr->selectedObjects(aSelList);
242 if (aSelList.Extent() != 1) {
243 if (myEditCurrentArgument == GroupPoints->LineEdit1) myPoint1.nullify();
244 else if (myEditCurrentArgument == GroupPoints->LineEdit2) myPoint2.nullify();
245 else if (myEditCurrentArgument == GroupFaces->LineEdit1) myFace1.nullify();
246 else if (myEditCurrentArgument == GroupFaces->LineEdit2) myFace2.nullify();
247 displayPreview(true);
251 TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupFaces->LineEdit1 ||
252 myEditCurrentArgument == GroupFaces->LineEdit2 ) ?
253 TopAbs_FACE : TopAbs_VERTEX;
254 GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
256 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
257 QString aName = GEOMBase::GetName( aSelectedObject.get() );
258 myEditCurrentArgument->setText( aName );
259 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
260 myPoint1 = aSelectedObject;
261 if ( myPoint1 && !myPoint2 )
262 GroupPoints->PushButton2->click();
264 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
265 myPoint2 = aSelectedObject;
266 if ( myPoint2 && !myPoint1 )
267 GroupPoints->PushButton1->click();
269 else if ( myEditCurrentArgument == GroupFaces->LineEdit1 ) {
270 myFace1 = aSelectedObject;
271 if ( myFace1 && !myFace2 )
272 GroupFaces->PushButton2->click();
274 else if ( myEditCurrentArgument == GroupFaces->LineEdit2 ) {
275 myFace2 = aSelectedObject;
276 if ( myFace2 && !myFace1 )
277 GroupFaces->PushButton1->click();
281 displayPreview(true);
284 //=================================================================================
285 // function : SetEditCurrentArgument()
287 //=================================================================================
288 void BasicGUI_LineDlg::SetEditCurrentArgument()
290 QPushButton* send = (QPushButton*)sender();
291 if ( send == GroupPoints->PushButton1 ) {
292 myEditCurrentArgument = GroupPoints->LineEdit1;
293 GroupPoints->PushButton2->setDown(false);
294 GroupPoints->LineEdit1->setEnabled(true);
295 GroupPoints->LineEdit2->setEnabled(false);
297 else if ( send == GroupPoints->PushButton2 ) {
298 myEditCurrentArgument = GroupPoints->LineEdit2;
299 GroupPoints->PushButton1->setDown(false);
300 GroupPoints->LineEdit1->setEnabled(false);
301 GroupPoints->LineEdit2->setEnabled(true);
303 else if ( send == GroupFaces->PushButton1 ) {
304 myEditCurrentArgument = GroupFaces->LineEdit1;
305 GroupFaces->PushButton2->setDown(false);
306 GroupFaces->LineEdit1->setEnabled(true);
307 GroupFaces->LineEdit2->setEnabled(false);
309 else if ( send == GroupFaces->PushButton2 ) {
310 myEditCurrentArgument = GroupFaces->LineEdit2;
311 GroupFaces->PushButton1->setDown(false);
312 GroupFaces->LineEdit1->setEnabled(false);
313 GroupFaces->LineEdit2->setEnabled(true);
316 TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupFaces->LineEdit1 ||
317 myEditCurrentArgument == GroupFaces->LineEdit2 ) ?
318 TopAbs_FACE : TopAbs_VERTEX;
319 globalSelection(); // close local selection to clear it
320 localSelection( GEOM::GEOM_Object::_nil(), aNeedType );
322 myEditCurrentArgument->setFocus();
323 // SelectionIntoArgument();
325 displayPreview(true);
328 //=================================================================================
329 // function : ActivateThisDialog()
331 //=================================================================================
332 void BasicGUI_LineDlg::ActivateThisDialog()
334 GEOMBase_Skeleton::ActivateThisDialog();
335 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
336 this, SLOT( SelectionIntoArgument() ) );
338 ConstructorsClicked( getConstructorId() );
341 //=================================================================================
342 // function : DeactivateActiveDialog()
343 // purpose : public slot to deactivate if active
344 //=================================================================================
345 void BasicGUI_LineDlg::DeactivateActiveDialog()
347 GEOMBase_Skeleton::DeactivateActiveDialog();
350 //=================================================================================
351 // function : enterEvent()
353 //=================================================================================
354 void BasicGUI_LineDlg::enterEvent( QEvent* )
356 if ( !mainFrame()->GroupConstructors->isEnabled() )
357 ActivateThisDialog();
360 //=================================================================================
361 // function : createOperation
363 //=================================================================================
364 GEOM::GEOM_IOperations_ptr BasicGUI_LineDlg::createOperation()
366 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
369 //=================================================================================
370 // function : isValid
372 //=================================================================================
373 bool BasicGUI_LineDlg::isValid( QString& msg )
376 switch ( getConstructorId() ) {
378 ok = myPoint1 && myPoint2;
381 ok = myFace1 && myFace2;
389 //=================================================================================
390 // function : execute
392 //=================================================================================
393 bool BasicGUI_LineDlg::execute( ObjectList& objects )
396 GEOM::GEOM_Object_var anObj;
397 GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
398 switch ( getConstructorId() ) {
400 anObj = anOper->MakeLineTwoPnt( myPoint1.get(), myPoint2.get() );
404 anObj = anOper->MakeLineTwoFaces( myFace1.get(), myFace2.get() );
409 if ( !anObj->_is_nil() )
410 objects.push_back( anObj._retn() );
415 //=================================================================================
416 // function : addSubshapeToStudy
417 // purpose : virtual method to add new SubObjects if local selection
418 //=================================================================================
419 void BasicGUI_LineDlg::addSubshapesToStudy()
421 switch ( getConstructorId() ) {
423 GEOMBase::PublishSubObject( myPoint1.get() );
424 GEOMBase::PublishSubObject( myPoint2.get() );
427 GEOMBase::PublishSubObject( myFace1.get() );
428 GEOMBase::PublishSubObject( myFace2.get() );