1 // Copyright (C) 2007-2008 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : BasicGUI_LineDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "BasicGUI_LineDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 #include <TopoDS_Shape.hxx>
38 #include <TColStd_IndexedMapOfInteger.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
43 #include "GEOMImpl_Types.hxx"
45 #include "utilities.h"
49 //=================================================================================
50 // class : BasicGUI_LineDlg()
51 // purpose : Constructs a BasicGUI_LineDlg which is a child of 'parent', with the
52 // name 'name' and widget flags set to 'f'.
53 // The dialog will by default be modeless, unless you set 'modal' to
54 // TRUE to construct a modal dialog.
55 //=================================================================================
56 BasicGUI_LineDlg::BasicGUI_LineDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
57 const char* name, bool modal, WFlags fl)
58 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
59 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
61 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_2P")));
62 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr("ICON_SELECT")));
63 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_2F")));
65 setCaption(tr("GEOM_LINE_TITLE"));
67 QGroupBox* aFrame = new QGroupBox( 1, Qt::Horizontal, this );
68 aFrame->setInsideMargin( 0 );
69 aFrame->setFrameStyle( QFrame::NoFrame );
71 /***************************************************************/
72 GroupConstructors->setTitle(tr("GEOM_LINE"));
73 RadioButton1->setPixmap(image0);
74 RadioButton2->setPixmap(image2);
75 RadioButton3->close(TRUE);
77 GroupPoints = new DlgRef_2Sel_QTD( aFrame, "GroupPoints");
78 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
79 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
80 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
81 GroupPoints->PushButton1->setPixmap(image1);
82 GroupPoints->PushButton2->setPixmap(image1);
83 GroupPoints->LineEdit1->setReadOnly( true );
84 GroupPoints->LineEdit2->setReadOnly( true );
86 GroupFaces = new DlgRef_2Sel_QTD( aFrame, "GroupFaces");
87 GroupFaces->GroupBox1->setTitle(tr("GEOM_FACES"));
88 GroupFaces->TextLabel1->setText(tr("GEOM_FACE_I").arg("1"));
89 GroupFaces->TextLabel2->setText(tr("GEOM_FACE_I").arg("2"));
90 GroupFaces->PushButton1->setPixmap(image1);
91 GroupFaces->PushButton2->setPixmap(image1);
92 GroupFaces->LineEdit1->setReadOnly( true );
93 GroupFaces->LineEdit2->setReadOnly( true );
95 Layout1->addWidget(aFrame, 2, 0);
96 /***************************************************************/
98 setHelpFileName("create_line_page.html");
103 //=================================================================================
104 // function : ~BasicGUI_LineDlg()
105 // purpose : Destroys the object and frees any allocated resources
106 //=================================================================================
107 BasicGUI_LineDlg::~BasicGUI_LineDlg()
111 //=================================================================================
114 //=================================================================================
115 void BasicGUI_LineDlg::Init()
118 //myEditCurrentArgument = GroupPoints->LineEdit1;
119 //myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
120 //globalSelection(); // close local contexts, if any
121 //localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
123 /* signals and slots connections */
124 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
125 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
126 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
127 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
129 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
130 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
132 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
134 connect(GroupFaces->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(GroupFaces->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
139 connect(GroupFaces->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
140 connect(GroupFaces->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
143 this, SLOT(SelectionIntoArgument()));
145 ConstructorsClicked(0);
146 initName( tr("GEOM_LINE") );
149 //=================================================================================
150 // function : ClickOnOk()
152 //=================================================================================
153 void BasicGUI_LineDlg::ClickOnOk()
155 if ( ClickOnApply() )
159 //=================================================================================
160 // function : ClickOnCancel()
162 //=================================================================================
163 void BasicGUI_LineDlg::ClickOnCancel()
165 GEOMBase_Skeleton::ClickOnCancel();
168 //=================================================================================
169 // function : ClickOnApply()
171 //=================================================================================
172 bool BasicGUI_LineDlg::ClickOnApply()
179 myEditCurrentArgument->setText("");
180 ConstructorsClicked(getConstructorId());
184 //=================================================================================
185 // function : ConstructorsClicked()
186 // purpose : Radio button management
187 //=================================================================================
188 void BasicGUI_LineDlg::ConstructorsClicked(int constructorId)
190 switch ( constructorId )
194 globalSelection(); // close local contexts, if any
195 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
197 myEditCurrentArgument = GroupPoints->LineEdit1;
198 myEditCurrentArgument->setText("");
199 myPoint1 = GEOM::GEOM_Object::_nil();
200 myPoint2 = GEOM::GEOM_Object::_nil();
207 globalSelection(); // close local contexts, if any
208 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
210 myEditCurrentArgument = GroupFaces->LineEdit1;
211 myEditCurrentArgument->setText("");
212 myFace1 = GEOM::GEOM_Object::_nil();
213 myFace2 = GEOM::GEOM_Object::_nil();
221 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)
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)
247 QString aName = GEOMBase::GetName(aSelectedObject);
250 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
252 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
253 if (myEditCurrentArgument == GroupFaces->LineEdit1 ||
254 myEditCurrentArgument == GroupFaces->LineEdit2)
255 aNeedType = TopAbs_FACE;
257 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
258 TColStd_IndexedMapOfInteger aMap;
259 aSelMgr->GetIndexes(firstIObject(), aMap);
260 if (aMap.Extent() == 1) // Local Selection
262 int anIndex = aMap( 1 );
263 if (aNeedType == TopAbs_FACE)
264 aName += QString(":face_%1").arg(anIndex);
266 aName += QString(":vertex_%1").arg(anIndex);
268 //Find SubShape Object in Father
269 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
271 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
272 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
273 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
276 aSelectedObject = aFindedObject; // get Object from study
278 else // Global Selection
280 if (aShape.ShapeType() != aNeedType) {
281 aSelectedObject = GEOM::GEOM_Object::_nil();
287 myEditCurrentArgument->setText(aName);
289 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
290 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
291 else if ( myEditCurrentArgument == GroupFaces->LineEdit1 ) myFace1 = aSelectedObject;
292 else if ( myEditCurrentArgument == GroupFaces->LineEdit2 ) myFace2 = aSelectedObject;
298 //=================================================================================
299 // function : SetEditCurrentArgument()
301 //=================================================================================
302 void BasicGUI_LineDlg::SetEditCurrentArgument()
304 QPushButton* send = (QPushButton*)sender();
305 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
306 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
307 else if ( send == GroupFaces->PushButton1 ) myEditCurrentArgument = GroupFaces->LineEdit1;
308 else if ( send == GroupFaces->PushButton2 ) myEditCurrentArgument = GroupFaces->LineEdit2;
309 myEditCurrentArgument->setFocus();
310 SelectionIntoArgument();
313 //=================================================================================
314 // function : LineEditReturnPressed()
316 //=================================================================================
317 void BasicGUI_LineDlg::LineEditReturnPressed()
319 QLineEdit* send = (QLineEdit*)sender();
320 if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
321 else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
322 else if ( send == GroupFaces->LineEdit1 ) myEditCurrentArgument = GroupFaces->LineEdit1;
323 else if ( send == GroupFaces->LineEdit2 ) myEditCurrentArgument = GroupFaces->LineEdit2;
325 GEOMBase_Skeleton::LineEditReturnPressed();
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* e)
356 if ( !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 )
375 const int id = getConstructorId();
377 return !myPoint1->_is_nil() && !myPoint2->_is_nil();
379 return !myFace1->_is_nil() && !myFace2->_is_nil();
383 //=================================================================================
384 // function : execute
386 //=================================================================================
387 bool BasicGUI_LineDlg::execute( ObjectList& objects )
390 GEOM::GEOM_Object_var anObj;
391 switch ( getConstructorId() )
395 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoPnt( myPoint1, myPoint2 );
401 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoFaces( myFace1, myFace2 );
406 if ( !anObj->_is_nil() )
407 objects.push_back( anObj._retn() );
412 //=================================================================================
413 // function : closeEvent
415 //=================================================================================
416 void BasicGUI_LineDlg::closeEvent( QCloseEvent* e )
418 GEOMBase_Skeleton::closeEvent( e );
421 //=================================================================================
422 // function : addSubshapeToStudy
423 // purpose : virtual method to add new SubObjects if local selection
424 //=================================================================================
425 void BasicGUI_LineDlg::addSubshapesToStudy()
427 QMap<QString, GEOM::GEOM_Object_var> objMap;
428 switch ( getConstructorId() )
431 objMap[GroupPoints->LineEdit1->text()] = myPoint1;
432 objMap[GroupPoints->LineEdit2->text()] = myPoint2;
435 objMap[GroupFaces->LineEdit1->text()] = myFace1;
436 objMap[GroupFaces->LineEdit2->text()] = myFace2;
439 addSubshapesToFather( objMap );