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 : BuildGUI_EdgeDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "BuildGUI_EdgeDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <GEOMImpl_Types.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
41 //=================================================================================
42 // class : BuildGUI_EdgeDlg()
43 // purpose : Constructs a BuildGUI_EdgeDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 BuildGUI_EdgeDlg::BuildGUI_EdgeDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
49 : GEOMBase_Skeleton(theGeometryGUI, parent)
51 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
52 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BUILD_EDGE")));
53 QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BUILD_EDGE_WIRE")));
55 setWindowTitle(tr("GEOM_EDGE_TITLE"));
57 /***************************************************************/
58 mainFrame()->GroupConstructors->setTitle(tr("GEOM_EDGE"));
59 mainFrame()->RadioButton1->setIcon(image1);
60 mainFrame()->RadioButton2->setIcon(image2);
61 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton3->close();
66 GroupPoints = new DlgRef_2Sel(centralWidget());
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg(1));
69 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg(2));
70 GroupPoints->PushButton1->setIcon(image0);
71 GroupPoints->PushButton2->setIcon(image0);
72 GroupPoints->LineEdit1->setReadOnly(true);
73 GroupPoints->LineEdit2->setReadOnly(true);
77 GroupWire = new DlgRef_1Sel2Spin(centralWidget());
78 GroupWire->GroupBox1->setTitle(tr("GEOM_WIRE"));
79 GroupWire->TextLabel1->setText(tr("GEOM_WIRE"));
80 GroupWire->PushButton1->setIcon(image0);
81 GroupWire->LineEdit1->setReadOnly(true);
82 GroupWire->TextLabel2->setText( tr( "GEOM_LINEAR_TOLERANCE" ) );
83 GroupWire->TextLabel3->setText( tr( "GEOM_ANGULAR_TOLERANCE" ) );
84 double SpecificStep = 0.0001;
85 double prec1 = Precision::Confusion();
86 double prec2 = Precision::Angular();
87 initSpinBox(GroupWire->SpinBox_DX, prec1, MAX_NUMBER, SpecificStep, "len_tol_precision" );
88 initSpinBox(GroupWire->SpinBox_DY, prec2, MAX_NUMBER, SpecificStep, "ang_tol_precision" );
89 GroupWire->SpinBox_DX->setValue(prec1);
90 GroupWire->SpinBox_DY->setValue(prec2);
94 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
95 layout->setMargin(0); layout->setSpacing(6);
96 layout->addWidget(GroupPoints);
97 layout->addWidget(GroupWire);
98 /***************************************************************/
100 setHelpFileName("create_edge_page.html");
106 //=================================================================================
107 // function : ~BuildGUI_EdgeDlg()
108 // purpose : Destroys the object and frees any allocated resources
109 //=================================================================================
110 BuildGUI_EdgeDlg::~BuildGUI_EdgeDlg()
112 // no need to delete child widgets, Qt does it all for us
115 //=================================================================================
118 //=================================================================================
119 void BuildGUI_EdgeDlg::Init()
122 myPoint1 = myPoint2 = myWire = GEOM::GEOM_Object::_nil();
123 myEditCurrentArgument = GroupPoints->LineEdit1;
124 GroupPoints->PushButton1->setDown(true);
125 globalSelection(); // close local contexts, if any
126 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
128 // signals and slots connections
129 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
130 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
132 connect( this, SIGNAL( constructorsClicked( 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(GroupWire->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143 connect(GroupWire->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
146 this, SLOT( SelectionIntoArgument() ) );
148 initName(tr("GEOM_EDGE"));
150 ConstructorsClicked( 0 );
153 //=================================================================================
154 // function : ClickOnOk()
156 //=================================================================================
157 void BuildGUI_EdgeDlg::ClickOnOk()
163 //=================================================================================
164 // function : ClickOnApply()
166 //=================================================================================
167 bool BuildGUI_EdgeDlg::ClickOnApply()
174 myEditCurrentArgument->setText( "" );
175 ConstructorsClicked( getConstructorId() );
180 //=================================================================================
181 // function : ConstructorsClicked()
182 // purpose : Radio button management
183 //=================================================================================
184 void BuildGUI_EdgeDlg::ConstructorsClicked( int constructorId )
186 switch ( constructorId ) {
189 globalSelection(); // close local contexts, if any
190 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
192 myEditCurrentArgument = GroupPoints->LineEdit1;
193 GroupPoints->LineEdit1->setText( "" );
194 GroupPoints->LineEdit2->setText( "" );
195 myPoint1 = GEOM::GEOM_Object::_nil();
196 myPoint2 = GEOM::GEOM_Object::_nil();
197 GroupPoints->PushButton1->setDown(true);
198 GroupPoints->PushButton2->setDown(false);
199 GroupPoints->LineEdit1->setEnabled(true);
200 GroupPoints->LineEdit2->setEnabled(false);
207 globalSelection(); // close local contexts, if any
208 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_WIRE );
210 myEditCurrentArgument = GroupWire->LineEdit1;
211 GroupWire->LineEdit1->setText("");
212 myWire = GEOM::GEOM_Object::_nil();
213 GroupWire->PushButton1->setDown(true);
214 GroupWire->LineEdit1->setEnabled(true);
221 qApp->processEvents();
223 resize( minimumSizeHint() );
224 SelectionIntoArgument();
227 //=================================================================================
228 // function : SelectionIntoArgument()
229 // purpose : Called when selection is changed or on dialog initialization or activation
230 //=================================================================================
231 void BuildGUI_EdgeDlg::SelectionIntoArgument()
234 myEditCurrentArgument->setText("");
236 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
237 SALOME_ListIO aSelList;
238 aSelMgr->selectedObjects(aSelList);
240 if (aSelList.Extent() != 1) {
241 if (myEditCurrentArgument == GroupPoints->LineEdit1) myPoint1 = GEOM::GEOM_Object::_nil();
242 else if (myEditCurrentArgument == GroupPoints->LineEdit2) myPoint2 = GEOM::GEOM_Object::_nil();
243 else if (myEditCurrentArgument == GroupWire->LineEdit1) myWire = GEOM::GEOM_Object::_nil();
249 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
251 if ( !aSelectedObject->_is_nil() ) {
252 QString aName = GEOMBase::GetName( aSelectedObject );
253 TopAbs_ShapeEnum aNeedType = myEditCurrentArgument == GroupWire->LineEdit1 ? TopAbs_WIRE : TopAbs_VERTEX;
256 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
257 TColStd_IndexedMapOfInteger aMap;
258 aSelMgr->GetIndexes( aSelList.First(), aMap );
259 if ( aMap.Extent() == 1 ) { // Local Selection
260 int anIndex = aMap( 1 );
261 aName += ( aNeedType == TopAbs_WIRE ? QString( ":wire_%1" ).arg( anIndex ) : QString( ":vertex_%1" ).arg( anIndex ) );
263 //Find SubShape Object in Father
264 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
265 if ( CORBA::is_nil( aFindedObject ) ) { // Object not found in study
266 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
267 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
270 aSelectedObject = aFindedObject; // get Object from study
273 else { // Global Selection
274 if ( aShape.ShapeType() != aNeedType ) {
275 aSelectedObject = GEOM::GEOM_Object::_nil();
281 myEditCurrentArgument->setText( aName );
283 if (!aSelectedObject->_is_nil()) { // clear selection if something selected
285 localSelection( GEOM::GEOM_Object::_nil(), aNeedType );
288 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
289 myPoint1 = aSelectedObject;
290 if ( !myPoint1->_is_nil() && myPoint2->_is_nil() )
291 GroupPoints->PushButton2->click();
293 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
294 myPoint2 = aSelectedObject;
295 if ( !myPoint2->_is_nil() && myPoint1->_is_nil() )
296 GroupPoints->PushButton1->click();
298 else if ( myEditCurrentArgument == GroupWire->LineEdit1 ) {
299 myWire = aSelectedObject;
306 //=================================================================================
307 // function : SetEditCurrentArgument()
309 //=================================================================================
310 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
312 QPushButton* send = (QPushButton*)sender();
314 if (send == GroupPoints->PushButton1) {
315 myEditCurrentArgument = GroupPoints->LineEdit1;
316 GroupPoints->PushButton2->setDown(false);
317 GroupPoints->LineEdit2->setEnabled(false);
319 else if (send == GroupPoints->PushButton2) {
320 myEditCurrentArgument = GroupPoints->LineEdit2;
321 GroupPoints->PushButton1->setDown(false);
322 GroupPoints->LineEdit1->setEnabled(false);
324 else if (send == GroupWire->PushButton1) {
325 myEditCurrentArgument = GroupWire->LineEdit1;
329 myEditCurrentArgument->setEnabled(true);
330 myEditCurrentArgument->setFocus();
335 //=================================================================================
336 // function : LineEditReturnPressed()
338 //=================================================================================
339 void BuildGUI_EdgeDlg::LineEditReturnPressed()
341 QLineEdit* send = (QLineEdit*)sender();
342 if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 || send == GroupWire->LineEdit1 ) {
343 myEditCurrentArgument = send;
344 GEOMBase_Skeleton::LineEditReturnPressed();
348 //=================================================================================
349 // function : ActivateThisDialog()
351 //=================================================================================
352 void BuildGUI_EdgeDlg::ActivateThisDialog()
354 GEOMBase_Skeleton::ActivateThisDialog();
356 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
357 this, SLOT( SelectionIntoArgument() ) );
359 ConstructorsClicked( getConstructorId() );
362 //=================================================================================
363 // function : enterEvent()
365 //=================================================================================
366 void BuildGUI_EdgeDlg::enterEvent (QEvent*)
368 if (!mainFrame()->GroupConstructors->isEnabled())
369 ActivateThisDialog();
372 //=================================================================================
373 // function : createOperation
375 //=================================================================================
376 GEOM::GEOM_IOperations_ptr BuildGUI_EdgeDlg::createOperation()
378 return getGeomEngine()->GetIShapesOperations(getStudyId());
381 //=================================================================================
382 // function : isValid
384 //=================================================================================
385 bool BuildGUI_EdgeDlg::isValid (QString& msg)
388 if ( getConstructorId() == 0 ) {
389 ok = !myPoint1->_is_nil() && !myPoint2->_is_nil();
392 ok = !myWire->_is_nil();
393 ok = ok && GroupWire->SpinBox_DX->isValid( msg, !IsPreview() );
394 ok = ok && GroupWire->SpinBox_DY->isValid( msg, !IsPreview() );
399 //=================================================================================
400 // function : execute
402 //=================================================================================
403 bool BuildGUI_EdgeDlg::execute (ObjectList& objects)
406 GEOM::GEOM_Object_var anObj;
408 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
410 switch ( getConstructorId() ) {
413 anObj = anOper->MakeEdge( myPoint1, myPoint2 );
419 double aLinearTolerance = GroupWire->SpinBox_DX->value();
420 double anAngularTolerance = GroupWire->SpinBox_DY->value();
422 QStringList aParameters;
423 aParameters << GroupWire->SpinBox_DX->text();
424 aParameters << GroupWire->SpinBox_DY->text();
426 anObj = anOper->MakeEdgeWire( myWire, aLinearTolerance, anAngularTolerance );
428 if ( !anObj->_is_nil() && !IsPreview() )
429 anObj->SetParameters( aParameters.join(":").toLatin1().constData() );
436 if ( !anObj->_is_nil() ) objects.push_back( anObj._retn() );
441 //=================================================================================
442 // function : addSubshapeToStudy
443 // purpose : virtual method to add new SubObjects if local selection
444 //=================================================================================
445 void BuildGUI_EdgeDlg::addSubshapesToStudy()
447 QMap<QString, GEOM::GEOM_Object_var> objMap;
448 switch ( getConstructorId() ) {
450 objMap[GroupPoints->LineEdit1->text()] = myPoint1;
451 objMap[GroupPoints->LineEdit2->text()] = myPoint2;
454 objMap[GroupWire->LineEdit1->text()] = myWire;
457 addSubshapesToFather( objMap );