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 Standard_Boolean testResult = Standard_False;
250 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
252 if ( testResult && !aSelectedObject->_is_nil() ) {
253 QString aName = GEOMBase::GetName( aSelectedObject );
254 TopAbs_ShapeEnum aNeedType = myEditCurrentArgument == GroupWire->LineEdit1 ? TopAbs_WIRE : TopAbs_VERTEX;
257 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
258 TColStd_IndexedMapOfInteger aMap;
259 aSelMgr->GetIndexes( aSelList.First(), aMap );
260 if ( aMap.Extent() == 1 ) { // Local Selection
261 int anIndex = aMap( 1 );
262 aName += ( aNeedType == TopAbs_WIRE ? QString( ":wire_%1" ).arg( anIndex ) : QString( ":vertex_%1" ).arg( anIndex ) );
264 //Find SubShape Object in Father
265 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
266 if ( CORBA::is_nil( aFindedObject ) ) { // Object not found in study
267 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
268 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
271 aSelectedObject = aFindedObject; // get Object from study
274 else { // Global Selection
275 if ( aShape.ShapeType() != aNeedType ) {
276 aSelectedObject = GEOM::GEOM_Object::_nil();
282 myEditCurrentArgument->setText( aName );
284 if (!aSelectedObject->_is_nil()) { // clear selection if something selected
286 localSelection( GEOM::GEOM_Object::_nil(), aNeedType );
289 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
290 myPoint1 = aSelectedObject;
291 if ( !myPoint1->_is_nil() && myPoint2->_is_nil() )
292 GroupPoints->PushButton2->click();
294 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
295 myPoint2 = aSelectedObject;
296 if ( !myPoint2->_is_nil() && myPoint1->_is_nil() )
297 GroupPoints->PushButton1->click();
299 else if ( myEditCurrentArgument == GroupWire->LineEdit1 ) {
300 myWire = aSelectedObject;
307 //=================================================================================
308 // function : SetEditCurrentArgument()
310 //=================================================================================
311 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
313 QPushButton* send = (QPushButton*)sender();
315 if (send == GroupPoints->PushButton1) {
316 myEditCurrentArgument = GroupPoints->LineEdit1;
317 GroupPoints->PushButton2->setDown(false);
318 GroupPoints->LineEdit2->setEnabled(false);
320 else if (send == GroupPoints->PushButton2) {
321 myEditCurrentArgument = GroupPoints->LineEdit2;
322 GroupPoints->PushButton1->setDown(false);
323 GroupPoints->LineEdit1->setEnabled(false);
325 else if (send == GroupWire->PushButton1) {
326 myEditCurrentArgument = GroupWire->LineEdit1;
330 myEditCurrentArgument->setEnabled(true);
331 myEditCurrentArgument->setFocus();
336 //=================================================================================
337 // function : LineEditReturnPressed()
339 //=================================================================================
340 void BuildGUI_EdgeDlg::LineEditReturnPressed()
342 QLineEdit* send = (QLineEdit*)sender();
343 if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 || send == GroupWire->LineEdit1 ) {
344 myEditCurrentArgument = send;
345 GEOMBase_Skeleton::LineEditReturnPressed();
349 //=================================================================================
350 // function : ActivateThisDialog()
352 //=================================================================================
353 void BuildGUI_EdgeDlg::ActivateThisDialog()
355 GEOMBase_Skeleton::ActivateThisDialog();
357 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
358 this, SLOT( SelectionIntoArgument() ) );
360 ConstructorsClicked( getConstructorId() );
363 //=================================================================================
364 // function : enterEvent()
366 //=================================================================================
367 void BuildGUI_EdgeDlg::enterEvent (QEvent*)
369 if (!mainFrame()->GroupConstructors->isEnabled())
370 ActivateThisDialog();
373 //=================================================================================
374 // function : createOperation
376 //=================================================================================
377 GEOM::GEOM_IOperations_ptr BuildGUI_EdgeDlg::createOperation()
379 return getGeomEngine()->GetIShapesOperations(getStudyId());
382 //=================================================================================
383 // function : isValid
385 //=================================================================================
386 bool BuildGUI_EdgeDlg::isValid (QString& msg)
389 if ( getConstructorId() == 0 ) {
390 ok = !myPoint1->_is_nil() && !myPoint2->_is_nil();
393 ok = !myWire->_is_nil();
394 ok = ok && GroupWire->SpinBox_DX->isValid( msg, !IsPreview() );
395 ok = ok && GroupWire->SpinBox_DY->isValid( msg, !IsPreview() );
400 //=================================================================================
401 // function : execute
403 //=================================================================================
404 bool BuildGUI_EdgeDlg::execute (ObjectList& objects)
407 GEOM::GEOM_Object_var anObj;
409 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
411 switch ( getConstructorId() ) {
414 anObj = anOper->MakeEdge( myPoint1, myPoint2 );
420 double aLinearTolerance = GroupWire->SpinBox_DX->value();
421 double anAngularTolerance = GroupWire->SpinBox_DY->value();
423 QStringList aParameters;
424 aParameters << GroupWire->SpinBox_DX->text();
425 aParameters << GroupWire->SpinBox_DY->text();
427 anObj = anOper->MakeEdgeWire( myWire, aLinearTolerance, anAngularTolerance );
429 if ( !anObj->_is_nil() && !IsPreview() )
430 anObj->SetParameters( aParameters.join(":").toLatin1().constData() );
437 if ( !anObj->_is_nil() ) objects.push_back( anObj._retn() );
442 //=================================================================================
443 // function : addSubshapeToStudy
444 // purpose : virtual method to add new SubObjects if local selection
445 //=================================================================================
446 void BuildGUI_EdgeDlg::addSubshapesToStudy()
448 QMap<QString, GEOM::GEOM_Object_var> objMap;
449 switch ( getConstructorId() ) {
451 objMap[GroupPoints->LineEdit1->text()] = myPoint1;
452 objMap[GroupPoints->LineEdit2->text()] = myPoint2;
455 objMap[GroupWire->LineEdit1->text()] = myWire;
458 addSubshapesToFather( objMap );