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 : GenerationGUI_PrismDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "GenerationGUI_PrismDlg.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>
37 #include <TopoDS_Edge.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <qcheckbox.h>
46 #include "GEOMImpl_Types.hxx"
48 #include "utilities.h"
50 //=================================================================================
51 // class : GenerationGUI_PrismDlg()
52 // purpose : Constructs a GenerationGUI_PrismDlg 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 GenerationGUI_PrismDlg::GenerationGUI_PrismDlg(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 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
63 QPixmap image0(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PRISM")));
64 QPixmap image1(aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
65 QPixmap image2(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PRISM_2P")));
67 setCaption(tr("GEOM_EXTRUSION_TITLE"));
69 /***************************************************************/
70 GroupConstructors->setTitle(tr("GEOM_EXTRUSION"));
71 RadioButton1->setPixmap(image0);
72 RadioButton2->setPixmap(image2);
73 RadioButton3->close(TRUE);
75 RadioButton1->setChecked(true);
76 myBothway = myBothway2 = false;
78 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
79 GroupPoints->GroupBox1->setTitle(tr("GEOM_EXTRUSION_BSV"));
80 GroupPoints->TextLabel1->setText(tr("GEOM_BASE"));
81 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
82 GroupPoints->TextLabel3->setText(tr("GEOM_HEIGHT"));
83 GroupPoints->PushButton1->setPixmap(image1);
84 GroupPoints->PushButton2->setPixmap(image1);
85 GroupPoints->LineEdit1->setReadOnly( true );
86 GroupPoints->LineEdit2->setReadOnly( true );
87 GroupPoints->CheckButton1->setText(tr("GEOM_BOTHWAY"));
88 GroupPoints->CheckButton1->setChecked(myBothway);
89 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
91 GroupPoints2 = new DlgRef_3Sel1Check_QTD(this, "GroupPoints2");
92 GroupPoints2->GroupBox1->setTitle(tr("GEOM_EXTRUSION_BSV_2P"));
93 GroupPoints2->TextLabel1->setText(tr("GEOM_BASE"));
94 GroupPoints2->TextLabel2->setText(tr("GEOM_POINT_I").arg("1"));
95 GroupPoints2->TextLabel3->setText(tr("GEOM_POINT_I").arg("2"));
96 GroupPoints2->PushButton1->setPixmap(image1);
97 GroupPoints2->PushButton2->setPixmap(image1);
98 GroupPoints2->PushButton3->setPixmap(image1);
99 GroupPoints2->CheckButton1->setText(tr("GEOM_BOTHWAY"));
100 GroupPoints2->CheckButton1->setChecked(myBothway2);
102 Layout1->addWidget(GroupPoints, 2, 0);
103 Layout1->addWidget(GroupPoints2, 2, 0);
104 /***************************************************************/
106 setHelpFileName("create_extrusion_page.html");
112 //=================================================================================
113 // function : ~GenerationGUI_PrismDlg()
114 // purpose : Destroys the object and frees any allocated resources
115 //=================================================================================
116 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
118 // no need to delete child widgets, Qt does it all for us
122 //=================================================================================
125 //=================================================================================
126 void GenerationGUI_PrismDlg::Init()
129 myEditCurrentArgument = GroupPoints->LineEdit1;
130 GroupPoints->LineEdit1->setReadOnly( true );
131 GroupPoints->LineEdit2->setReadOnly( true );
133 GroupPoints2->LineEdit1->setReadOnly( true );
134 GroupPoints2->LineEdit2->setReadOnly( true );
135 GroupPoints2->LineEdit3->setReadOnly( true );
137 myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
138 myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
140 /* Get setting of step value from file configuration */
141 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
142 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
144 /* min, max, step and decimals for spin boxes & initial values */
145 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
146 GroupPoints->SpinBox_DX->SetValue(100.0);
148 /* signals and slots connections */
149 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
150 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
152 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
154 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
155 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
157 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
158 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
160 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
161 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
162 GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
164 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(onBothway()));
165 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
167 connect(GroupPoints2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
168 connect(GroupPoints2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
169 connect(GroupPoints2->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
170 connect(GroupPoints2->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(onBothway2()));
172 connect(GroupPoints2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
173 connect(GroupPoints2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
174 connect(GroupPoints2->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
177 connect(myGeomGUI->getApp()->selectionMgr(),
178 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
180 initName(tr("GEOM_EXTRUSION"));
181 ConstructorsClicked(0);
185 //=================================================================================
186 // function : ConstructorsClicked()
187 // purpose : Radio button management
188 //=================================================================================
189 void GenerationGUI_PrismDlg::ConstructorsClicked(int constructorId)
192 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
194 switch (constructorId)
198 globalSelection( GEOM_ALLSHAPES );
200 GroupPoints2->hide();
204 myEditCurrentArgument = GroupPoints->LineEdit1;
205 GroupPoints->LineEdit1->setText(GroupPoints2->LineEdit1->text()); // keep base
206 GroupPoints->LineEdit2->setText("");
207 myVec = GEOM::GEOM_Object::_nil();
214 globalSelection( GEOM_ALLSHAPES );
218 GroupPoints2->show();
220 myEditCurrentArgument = GroupPoints2->LineEdit1;
221 GroupPoints2->LineEdit1->setText(GroupPoints->LineEdit1->text()); // keep base
222 GroupPoints2->LineEdit2->setText("");
223 GroupPoints2->LineEdit3->setText("");
224 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
225 myOkPnt1 = myOkPnt2 = false;
231 myEditCurrentArgument->setFocus();
232 connect(myGeomGUI->getApp()->selectionMgr(),
233 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
236 SelectionIntoArgument();
240 //=================================================================================
241 // function : ClickOnOk()
243 //=================================================================================
244 void GenerationGUI_PrismDlg::ClickOnOk()
246 if ( ClickOnApply() )
251 //=================================================================================
252 // function : ClickOnApply()
254 //=================================================================================
255 bool GenerationGUI_PrismDlg::ClickOnApply()
265 //=================================================================================
266 // function : SelectionIntoArgument()
267 // purpose : Called when selection has changed
268 //=================================================================================
269 void GenerationGUI_PrismDlg::SelectionIntoArgument()
272 myEditCurrentArgument->setText("");
274 if (getConstructorId() == 0)
276 if (IObjectCount() != 1) {
277 if (myEditCurrentArgument == GroupPoints->LineEdit1)
279 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
285 Standard_Boolean testResult = Standard_False;
286 GEOM::GEOM_Object_var aSelectedObject =
287 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
294 QString aName = GEOMBase::GetName( aSelectedObject );
295 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
297 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
298 TColStd_IndexedMapOfInteger aMap;
299 aSelMgr->GetIndexes( firstIObject(), aMap );
300 if ( aMap.Extent() == 1 )
302 int anIndex = aMap( 1 );
303 aName.append( ":edge_" + QString::number( anIndex ) );
305 //Find SubShape Object in Father
306 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
308 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
309 GEOM::GEOM_IShapesOperations_var aShapesOp =
310 getGeomEngine()->GetIShapesOperations( getStudyId() );
311 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
314 aSelectedObject = aFindedObject; // get Object from study
317 if (aShape.ShapeType() != TopAbs_EDGE && myEditCurrentArgument == GroupPoints->LineEdit2) {
318 aSelectedObject = GEOM::GEOM_Object::_nil();
325 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
326 myBase = aSelectedObject;
329 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && myOk) {
331 myVec = aSelectedObject;
333 myEditCurrentArgument->setText( aName );
335 else // getConstructorId()==1 - extrusion using 2 points
337 if (IObjectCount() != 1) {
338 if (myEditCurrentArgument == GroupPoints2->LineEdit1)
340 else if (myEditCurrentArgument == GroupPoints2->LineEdit2) {
341 myPoint1 = GEOM::GEOM_Object::_nil();
344 else if (myEditCurrentArgument == GroupPoints2->LineEdit3) {
345 myPoint2 = GEOM::GEOM_Object::_nil();
352 Standard_Boolean testResult = Standard_False;
353 GEOM::GEOM_Object_var aSelectedObject =
354 GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
356 if (!testResult || CORBA::is_nil( aSelectedObject ))
359 QString aName = GEOMBase::GetName( aSelectedObject );
362 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
364 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
365 TColStd_IndexedMapOfInteger aMap;
366 aSelMgr->GetIndexes( firstIObject(), aMap );
367 if (aMap.Extent() == 1)
369 int anIndex = aMap(1);
370 aName.append(":vertex_" + QString::number(anIndex));
372 //Find SubShape Object in Father
373 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
375 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
376 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
377 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
380 aSelectedObject = aFindedObject;
384 if ((aShape.ShapeType() != TopAbs_VERTEX && myEditCurrentArgument == GroupPoints2->LineEdit2) ||
385 (aShape.ShapeType() != TopAbs_VERTEX && myEditCurrentArgument == GroupPoints2->LineEdit3))
387 aSelectedObject = GEOM::GEOM_Object::_nil();
394 myEditCurrentArgument->setText(aName);
396 if (myEditCurrentArgument == GroupPoints2->LineEdit1) {
397 myBase = aSelectedObject;
400 else if (myEditCurrentArgument == GroupPoints2->LineEdit2 && myOk) {
402 myPoint1 = aSelectedObject;
404 else if (myEditCurrentArgument == GroupPoints2->LineEdit3 && myOk) {
406 myPoint2 = aSelectedObject;
413 //=================================================================================
414 // function : LineEditReturnPressed()
416 //=================================================================================
417 void GenerationGUI_PrismDlg::LineEditReturnPressed()
419 QLineEdit* send = (QLineEdit*)sender();
420 if (send == GroupPoints->LineEdit1 ||
421 send == GroupPoints->LineEdit2 ||
422 send == GroupPoints2->LineEdit1 ||
423 send == GroupPoints2->LineEdit2 ||
424 send == GroupPoints2->LineEdit3 )
426 myEditCurrentArgument = send;
427 GEOMBase_Skeleton::LineEditReturnPressed();
432 //=================================================================================
433 // function : SetEditCurrentArgument()
435 //=================================================================================
436 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
438 QPushButton* send = (QPushButton*)sender();
439 globalSelection( GEOM_ALLSHAPES );
441 if (send == GroupPoints->PushButton1) {
442 GroupPoints->LineEdit1->setFocus();
443 myEditCurrentArgument = GroupPoints->LineEdit1;
445 else if (send == GroupPoints->PushButton2) {
446 GroupPoints->LineEdit2->setFocus();
447 myEditCurrentArgument = GroupPoints->LineEdit2;
448 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
450 else if (send == GroupPoints2->PushButton1) {
451 GroupPoints2->LineEdit1->setFocus();
452 myEditCurrentArgument = GroupPoints2->LineEdit1;
454 else if (send == GroupPoints2->PushButton2) {
455 GroupPoints2->LineEdit2->setFocus();
456 myEditCurrentArgument = GroupPoints2->LineEdit2;
457 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
459 else if (send == GroupPoints2->PushButton3) {
460 GroupPoints2->LineEdit3->setFocus();
461 myEditCurrentArgument = GroupPoints2->LineEdit3;
462 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
465 myEditCurrentArgument->setFocus();
466 SelectionIntoArgument();
470 //=================================================================================
471 // function : ActivateThisDialog()
473 //=================================================================================
474 void GenerationGUI_PrismDlg::ActivateThisDialog()
476 GEOMBase_Skeleton::ActivateThisDialog();
478 connect(myGeomGUI->getApp()->selectionMgr(),
479 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
481 ConstructorsClicked( getConstructorId() );
485 //=================================================================================
486 // function : enterEvent()
487 // purpose : when mouse enter onto the QWidget
488 //=================================================================================
489 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
491 if (!GroupConstructors->isEnabled())
492 ActivateThisDialog();
496 //=================================================================================
497 // function : ValueChangedInSpinBox()
499 //=================================================================================
500 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
506 //=================================================================================
507 // function : getHeight()
509 //=================================================================================
510 double GenerationGUI_PrismDlg::getHeight() const
512 return GroupPoints->SpinBox_DX->GetValue();
515 //=================================================================================
516 // function : createOperation
518 //=================================================================================
519 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
521 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
524 //=================================================================================
525 // function : isValid
527 //=================================================================================
528 bool GenerationGUI_PrismDlg::isValid( QString& )
530 if (getConstructorId() == 0)
531 return (myOkBase && myOkVec); // by vector and height
533 return (myOkBase && myOkPnt1 && myOkPnt2); // by two points
536 //=================================================================================
537 // function : execute
539 //=================================================================================
540 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
542 GEOM::GEOM_Object_var anObj;
544 switch ( getConstructorId() )
549 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
550 MakePrismVecH(myBase, myVec, getHeight());
552 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
553 MakePrismVecH2Ways(myBase, myVec, getHeight() );
559 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
560 MakePrismTwoPnt(myBase, myPoint1, myPoint2);
562 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
563 MakePrismTwoPnt2Ways(myBase, myPoint1, myPoint2);
567 if ( !anObj->_is_nil() )
568 objects.push_back( anObj._retn() );
574 //=================================================================================
575 // function : onReverse()
577 //=================================================================================
578 void GenerationGUI_PrismDlg::onReverse()
580 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
581 GroupPoints->SpinBox_DX->SetValue( -anOldValue );
584 //=================================================================================
585 // function : onBothway()
587 //=================================================================================
588 void GenerationGUI_PrismDlg::onBothway()
590 bool anOldValue = myBothway;
591 myBothway = !anOldValue;
592 GroupPoints->CheckButton2->setEnabled(!myBothway);
596 void GenerationGUI_PrismDlg::onBothway2()
598 bool anOldValue = myBothway2;
599 myBothway2 = !anOldValue;
603 //=================================================================================
604 // function : addSubshapeToStudy
605 // purpose : virtual method to add new SubObjects if local selection
606 //=================================================================================
607 void GenerationGUI_PrismDlg::addSubshapesToStudy()
609 QMap<QString, GEOM::GEOM_Object_var> objMap;
611 switch (getConstructorId())
614 objMap[GroupPoints->LineEdit2->text()] = myVec;
617 objMap[GroupPoints2->LineEdit2->text()] = myPoint1;
618 objMap[GroupPoints2->LineEdit3->text()] = myPoint2;
621 addSubshapesToFather( objMap );