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
24 // File : BasicGUI_LineDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BasicGUI_LineDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
36 #include <TopoDS_Shape.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
44 #include "GEOMImpl_Types.hxx"
46 #include "utilities.h"
50 //=================================================================================
51 // class : BasicGUI_LineDlg()
52 // purpose : Constructs a BasicGUI_LineDlg which is a child of 'parent', with the
53 // name 'name' and widget flags set to 'f'.
54 // The dialog will by default be modeless, unless you set 'modal' to
55 // TRUE to construct a modal dialog.
56 //=================================================================================
57 BasicGUI_LineDlg::BasicGUI_LineDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
58 const char* name, bool modal, WFlags fl)
59 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
60 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
62 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_2P")));
63 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr("ICON_SELECT")));
64 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_2F")));
66 setCaption(tr("GEOM_LINE_TITLE"));
68 QGroupBox* aFrame = new QGroupBox( 1, Qt::Horizontal, this );
69 aFrame->setInsideMargin( 0 );
70 aFrame->setFrameStyle( QFrame::NoFrame );
72 /***************************************************************/
73 GroupConstructors->setTitle(tr("GEOM_LINE"));
74 RadioButton1->setPixmap(image0);
75 RadioButton2->setPixmap(image2);
76 RadioButton3->close(TRUE);
78 GroupPoints = new DlgRef_2Sel_QTD( aFrame, "GroupPoints");
79 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
80 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
81 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
82 GroupPoints->PushButton1->setPixmap(image1);
83 GroupPoints->PushButton2->setPixmap(image1);
84 GroupPoints->LineEdit1->setReadOnly( true );
85 GroupPoints->LineEdit2->setReadOnly( true );
87 GroupFaces = new DlgRef_2Sel_QTD( aFrame, "GroupFaces");
88 GroupFaces->GroupBox1->setTitle(tr("GEOM_FACES"));
89 GroupFaces->TextLabel1->setText(tr("GEOM_FACE_I").arg("1"));
90 GroupFaces->TextLabel2->setText(tr("GEOM_FACE_I").arg("2"));
91 GroupFaces->PushButton1->setPixmap(image1);
92 GroupFaces->PushButton2->setPixmap(image1);
93 GroupFaces->LineEdit1->setReadOnly( true );
94 GroupFaces->LineEdit2->setReadOnly( true );
96 Layout1->addWidget(aFrame, 2, 0);
97 /***************************************************************/
99 setHelpFileName("line.htm");
105 //=================================================================================
106 // function : ~BasicGUI_LineDlg()
107 // purpose : Destroys the object and frees any allocated resources
108 //=================================================================================
109 BasicGUI_LineDlg::~BasicGUI_LineDlg()
114 //=================================================================================
117 //=================================================================================
118 void BasicGUI_LineDlg::Init()
121 myEditCurrentArgument = GroupPoints->LineEdit1;
123 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
125 // myGeomGUI->SetState( 0 );
126 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
128 /* signals and slots connections */
129 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
130 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
131 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
132 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
134 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
135 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
137 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 connect(GroupFaces->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(GroupFaces->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144 connect(GroupFaces->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145 connect(GroupFaces->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
148 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
150 ConstructorsClicked (0);
151 initName( tr("GEOM_LINE") );
155 //=================================================================================
156 // function : ClickOnOk()
158 //=================================================================================
159 void BasicGUI_LineDlg::ClickOnOk()
161 if ( ClickOnApply() )
165 //=======================================================================
166 // function : ClickOnCancel()
168 //=======================================================================
169 void BasicGUI_LineDlg::ClickOnCancel()
171 GEOMBase_Skeleton::ClickOnCancel();
174 //=================================================================================
175 // function : ClickOnApply()
177 //=================================================================================
178 bool BasicGUI_LineDlg::ClickOnApply()
182 GroupPoints->LineEdit1->setText( "" );
183 GroupPoints->LineEdit2->setText( "" );
184 GroupFaces->LineEdit1->setText( "" );
185 GroupFaces->LineEdit2->setText( "" );
186 myPoint1 = myPoint2 = myFace1 = myFace2 = GEOM::GEOM_Object::_nil();
187 myEditCurrentArgument = GroupPoints->LineEdit1;
188 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); //Select vertex on all shapes
193 //=================================================================================
194 // function : ConstructorsClicked()
195 // purpose : Radio button management
196 //=================================================================================
197 void BasicGUI_LineDlg::ConstructorsClicked(int constructorId)
199 switch ( constructorId )
203 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
204 myEditCurrentArgument = GroupPoints->LineEdit1;
205 myEditCurrentArgument->setText("");
206 myPoint1 = GEOM::GEOM_Object::_nil();
207 myPoint2 = GEOM::GEOM_Object::_nil();
214 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
215 myEditCurrentArgument = GroupFaces->LineEdit1;
216 myEditCurrentArgument->setText("");
217 myFace1 = GEOM::GEOM_Object::_nil();
218 myFace2 = GEOM::GEOM_Object::_nil();
226 resize( minimumSize() );
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 if ( IObjectCount() != 1 )
240 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
241 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
242 else if ( myEditCurrentArgument == GroupFaces->LineEdit1 ) myFace1 = GEOM::GEOM_Object::_nil();
243 else if ( myEditCurrentArgument == GroupFaces->LineEdit2 ) myFace2 = GEOM::GEOM_Object::_nil();
248 Standard_Boolean aRes = Standard_False;
249 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
250 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
252 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
254 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
256 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
257 TColStd_IndexedMapOfInteger aMap;
258 aSelMgr->GetIndexes( firstIObject(), aMap );
259 if ( aMap.Extent() == 1 )
261 GEOM::GEOM_IShapesOperations_var aShapesOp =
262 getGeomEngine()->GetIShapesOperations( getStudyId() );
263 int anIndex = aMap( 1 );
264 TopTools_IndexedMapOfShape aShapes;
265 TopExp::MapShapes( aShape, aShapes );
266 aShape = aShapes.FindKey( anIndex );
267 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
268 aSelMgr->clearSelected();
271 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
272 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
273 else if ( myEditCurrentArgument == GroupFaces->LineEdit1 ) myFace1 = aSelectedObject;
274 else if ( myEditCurrentArgument == GroupFaces->LineEdit2 ) myFace2 = aSelectedObject;
281 //=================================================================================
282 // function : SetEditCurrentArgument()
284 //=================================================================================
285 void BasicGUI_LineDlg::SetEditCurrentArgument()
287 QPushButton* send = (QPushButton*)sender();
288 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
289 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
290 else if ( send == GroupFaces->PushButton1 ) myEditCurrentArgument = GroupFaces->LineEdit1;
291 else if ( send == GroupFaces->PushButton2 ) myEditCurrentArgument = GroupFaces->LineEdit2;
292 myEditCurrentArgument->setFocus();
293 SelectionIntoArgument();
297 //=================================================================================
298 // function : LineEditReturnPressed()
300 //=================================================================================
301 void BasicGUI_LineDlg::LineEditReturnPressed()
303 QLineEdit* send = (QLineEdit*)sender();
304 if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
305 else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
306 else if ( send == GroupFaces->LineEdit1 ) myEditCurrentArgument = GroupFaces->LineEdit1;
307 else if ( send == GroupFaces->LineEdit2 ) myEditCurrentArgument = GroupFaces->LineEdit2;
309 GEOMBase_Skeleton::LineEditReturnPressed();
313 //=================================================================================
314 // function : ActivateThisDialog()
316 //=================================================================================
317 void BasicGUI_LineDlg::ActivateThisDialog()
319 GEOMBase_Skeleton::ActivateThisDialog();
320 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
321 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
323 // myGeomGUI->SetState( 0 );
324 // globalSelection( GEOM_POINT );
325 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
327 myEditCurrentArgument = GroupPoints->LineEdit1;
328 myEditCurrentArgument->setFocus();
330 GroupPoints->LineEdit1->setText( "" );
331 GroupPoints->LineEdit2->setText( "" );
332 GroupFaces->LineEdit1->setText( "" );
333 GroupFaces->LineEdit2->setText( "" );
334 myPoint1 = myPoint2 = myFace1 = myFace2 = GEOM::GEOM_Object::_nil();
337 //=================================================================================
338 // function : DeactivateActiveDialog()
339 // purpose : public slot to deactivate if active
340 //=================================================================================
341 void BasicGUI_LineDlg::DeactivateActiveDialog()
343 // myGeomGUI->SetState( -1 );
344 GEOMBase_Skeleton::DeactivateActiveDialog();
347 //=================================================================================
348 // function : enterEvent()
350 //=================================================================================
351 void BasicGUI_LineDlg::enterEvent(QEvent* e)
353 if ( !GroupConstructors->isEnabled() )
354 ActivateThisDialog();
357 //=================================================================================
358 // function : createOperation
360 //=================================================================================
361 GEOM::GEOM_IOperations_ptr BasicGUI_LineDlg::createOperation()
363 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
366 //=================================================================================
367 // function : isValid
369 //=================================================================================
370 bool BasicGUI_LineDlg::isValid( QString& msg )
372 const int id = getConstructorId();
374 return !myPoint1->_is_nil() && !myPoint2->_is_nil();
376 return !myFace1->_is_nil() && !myFace2->_is_nil();
380 //=================================================================================
381 // function : execute
383 //=================================================================================
384 bool BasicGUI_LineDlg::execute( ObjectList& objects )
387 GEOM::GEOM_Object_var anObj;
388 switch ( getConstructorId() )
392 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoPnt( myPoint1, myPoint2 );
398 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoFaces( myFace1, myFace2 );
403 if ( !anObj->_is_nil() )
404 objects.push_back( anObj._retn() );
409 //=================================================================================
410 // function : closeEvent
412 //=================================================================================
413 void BasicGUI_LineDlg::closeEvent( QCloseEvent* e )
415 GEOMBase_Skeleton::closeEvent( e );