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 : GenerationGUI_PrismDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "GenerationGUI_PrismDlg.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>
36 #include <TopoDS_Edge.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <qcheckbox.h>
45 #include "GEOMImpl_Types.hxx"
47 #include "utilities.h"
49 //=================================================================================
50 // class : GenerationGUI_PrismDlg()
51 // purpose : Constructs a GenerationGUI_PrismDlg 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 GenerationGUI_PrismDlg::GenerationGUI_PrismDlg(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 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
62 QPixmap image0(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PRISM")));
63 QPixmap image1(aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
64 QPixmap image2(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PRISM_2P")));
66 setCaption(tr("GEOM_EXTRUSION_TITLE"));
68 /***************************************************************/
69 GroupConstructors->setTitle(tr("GEOM_EXTRUSION"));
70 RadioButton1->setPixmap(image0);
71 RadioButton2->setPixmap(image2);
72 RadioButton3->close(TRUE);
74 RadioButton1->setChecked(true);
75 myBothway = myBothway2 = false;
77 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
78 GroupPoints->GroupBox1->setTitle(tr("GEOM_EXTRUSION_BSV"));
79 GroupPoints->TextLabel1->setText(tr("GEOM_BASE"));
80 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
81 GroupPoints->TextLabel3->setText(tr("GEOM_HEIGHT"));
82 GroupPoints->PushButton1->setPixmap(image1);
83 GroupPoints->PushButton2->setPixmap(image1);
84 GroupPoints->LineEdit1->setReadOnly( true );
85 GroupPoints->LineEdit2->setReadOnly( true );
86 GroupPoints->CheckButton1->setText(tr("GEOM_BOTHWAY"));
87 GroupPoints->CheckButton1->setChecked(myBothway);
88 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
90 GroupPoints2 = new DlgRef_3Sel1Check_QTD(this, "GroupPoints2");
91 GroupPoints2->GroupBox1->setTitle(tr("GEOM_EXTRUSION_BSV_2P"));
92 GroupPoints2->TextLabel1->setText(tr("GEOM_BASE"));
93 GroupPoints2->TextLabel2->setText(tr("GEOM_POINT_I").arg("1"));
94 GroupPoints2->TextLabel3->setText(tr("GEOM_POINT_I").arg("2"));
95 GroupPoints2->PushButton1->setPixmap(image1);
96 GroupPoints2->PushButton2->setPixmap(image1);
97 GroupPoints2->PushButton3->setPixmap(image1);
98 GroupPoints2->CheckButton1->setText(tr("GEOM_BOTHWAY"));
99 GroupPoints2->CheckButton1->setChecked(myBothway2);
101 Layout1->addWidget(GroupPoints, 2, 0);
102 Layout1->addWidget(GroupPoints2, 2, 0);
103 /***************************************************************/
105 setHelpFileName("create_extrusion_page.html");
111 //=================================================================================
112 // function : ~GenerationGUI_PrismDlg()
113 // purpose : Destroys the object and frees any allocated resources
114 //=================================================================================
115 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
117 // no need to delete child widgets, Qt does it all for us
121 //=================================================================================
124 //=================================================================================
125 void GenerationGUI_PrismDlg::Init()
128 myEditCurrentArgument = GroupPoints->LineEdit1;
129 GroupPoints->LineEdit1->setReadOnly( true );
130 GroupPoints->LineEdit2->setReadOnly( true );
132 GroupPoints2->LineEdit1->setReadOnly( true );
133 GroupPoints2->LineEdit2->setReadOnly( true );
134 GroupPoints2->LineEdit3->setReadOnly( true );
136 myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
137 myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
139 /* Get setting of step value from file configuration */
140 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
141 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
143 /* min, max, step and decimals for spin boxes & initial values */
144 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
145 GroupPoints->SpinBox_DX->SetValue(100.0);
147 /* signals and slots connections */
148 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
149 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
151 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
153 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
157 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
160 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
161 GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
163 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(onBothway()));
164 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
166 connect(GroupPoints2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
167 connect(GroupPoints2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
168 connect(GroupPoints2->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
169 connect(GroupPoints2->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(onBothway2()));
171 connect(GroupPoints2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
172 connect(GroupPoints2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
173 connect(GroupPoints2->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
176 connect(myGeomGUI->getApp()->selectionMgr(),
177 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
179 initName(tr("GEOM_EXTRUSION"));
180 ConstructorsClicked(0);
184 //=================================================================================
185 // function : ConstructorsClicked()
186 // purpose : Radio button management
187 //=================================================================================
188 void GenerationGUI_PrismDlg::ConstructorsClicked(int constructorId)
191 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
193 switch (constructorId)
197 globalSelection( GEOM_ALLSHAPES );
199 GroupPoints2->hide();
203 myEditCurrentArgument = GroupPoints->LineEdit1;
204 GroupPoints->LineEdit1->setText(GroupPoints2->LineEdit1->text()); // keep base
205 GroupPoints->LineEdit2->setText("");
206 myVec = GEOM::GEOM_Object::_nil();
213 globalSelection( GEOM_ALLSHAPES );
217 GroupPoints2->show();
219 myEditCurrentArgument = GroupPoints2->LineEdit1;
220 GroupPoints2->LineEdit1->setText(GroupPoints->LineEdit1->text()); // keep base
221 GroupPoints2->LineEdit2->setText("");
222 GroupPoints2->LineEdit3->setText("");
223 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
224 myOkPnt1 = myOkPnt2 = false;
230 myEditCurrentArgument->setFocus();
231 connect(myGeomGUI->getApp()->selectionMgr(),
232 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
235 SelectionIntoArgument();
239 //=================================================================================
240 // function : ClickOnOk()
242 //=================================================================================
243 void GenerationGUI_PrismDlg::ClickOnOk()
245 if ( ClickOnApply() )
250 //=================================================================================
251 // function : ClickOnApply()
253 //=================================================================================
254 bool GenerationGUI_PrismDlg::ClickOnApply()
264 //=================================================================================
265 // function : SelectionIntoArgument()
266 // purpose : Called when selection has changed
267 //=================================================================================
268 void GenerationGUI_PrismDlg::SelectionIntoArgument()
271 myEditCurrentArgument->setText("");
273 if (getConstructorId() == 0)
275 if (IObjectCount() != 1) {
276 if (myEditCurrentArgument == GroupPoints->LineEdit1)
278 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
284 Standard_Boolean testResult = Standard_False;
285 GEOM::GEOM_Object_var aSelectedObject =
286 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
293 QString aName = GEOMBase::GetName( aSelectedObject );
294 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
296 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
297 TColStd_IndexedMapOfInteger aMap;
298 aSelMgr->GetIndexes( firstIObject(), aMap );
299 if ( aMap.Extent() == 1 )
301 int anIndex = aMap( 1 );
302 aName.append( ":edge_" + QString::number( anIndex ) );
304 //Find SubShape Object in Father
305 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
307 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
308 GEOM::GEOM_IShapesOperations_var aShapesOp =
309 getGeomEngine()->GetIShapesOperations( getStudyId() );
310 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
313 aSelectedObject = aFindedObject; // get Object from study
316 if (aShape.ShapeType() != TopAbs_EDGE && myEditCurrentArgument == GroupPoints->LineEdit2) {
317 aSelectedObject = GEOM::GEOM_Object::_nil();
324 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
325 myBase = aSelectedObject;
328 else if (myEditCurrentArgument == GroupPoints->LineEdit2 && myOk) {
330 myVec = aSelectedObject;
332 myEditCurrentArgument->setText( aName );
334 else // getConstructorId()==1 - extrusion using 2 points
336 if (IObjectCount() != 1) {
337 if (myEditCurrentArgument == GroupPoints2->LineEdit1)
339 else if (myEditCurrentArgument == GroupPoints2->LineEdit2) {
340 myPoint1 = GEOM::GEOM_Object::_nil();
343 else if (myEditCurrentArgument == GroupPoints2->LineEdit3) {
344 myPoint2 = GEOM::GEOM_Object::_nil();
351 Standard_Boolean testResult = Standard_False;
352 GEOM::GEOM_Object_var aSelectedObject =
353 GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
355 if (!testResult || CORBA::is_nil( aSelectedObject ))
358 QString aName = GEOMBase::GetName( aSelectedObject );
361 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
363 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
364 TColStd_IndexedMapOfInteger aMap;
365 aSelMgr->GetIndexes( firstIObject(), aMap );
366 if (aMap.Extent() == 1)
368 int anIndex = aMap(1);
369 aName.append(":vertex_" + QString::number(anIndex));
371 //Find SubShape Object in Father
372 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
374 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
375 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
376 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
379 aSelectedObject = aFindedObject;
383 if ((aShape.ShapeType() != TopAbs_VERTEX && myEditCurrentArgument == GroupPoints2->LineEdit2) ||
384 (aShape.ShapeType() != TopAbs_VERTEX && myEditCurrentArgument == GroupPoints2->LineEdit3))
386 aSelectedObject = GEOM::GEOM_Object::_nil();
393 myEditCurrentArgument->setText(aName);
395 if (myEditCurrentArgument == GroupPoints2->LineEdit1) {
396 myBase = aSelectedObject;
399 else if (myEditCurrentArgument == GroupPoints2->LineEdit2 && myOk) {
401 myPoint1 = aSelectedObject;
403 else if (myEditCurrentArgument == GroupPoints2->LineEdit3 && myOk) {
405 myPoint2 = aSelectedObject;
412 //=================================================================================
413 // function : LineEditReturnPressed()
415 //=================================================================================
416 void GenerationGUI_PrismDlg::LineEditReturnPressed()
418 QLineEdit* send = (QLineEdit*)sender();
419 if (send == GroupPoints->LineEdit1 ||
420 send == GroupPoints->LineEdit2 ||
421 send == GroupPoints2->LineEdit1 ||
422 send == GroupPoints2->LineEdit2 ||
423 send == GroupPoints2->LineEdit3 )
425 myEditCurrentArgument = send;
426 GEOMBase_Skeleton::LineEditReturnPressed();
431 //=================================================================================
432 // function : SetEditCurrentArgument()
434 //=================================================================================
435 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
437 QPushButton* send = (QPushButton*)sender();
438 globalSelection( GEOM_ALLSHAPES );
440 if (send == GroupPoints->PushButton1) {
441 GroupPoints->LineEdit1->setFocus();
442 myEditCurrentArgument = GroupPoints->LineEdit1;
444 else if (send == GroupPoints->PushButton2) {
445 GroupPoints->LineEdit2->setFocus();
446 myEditCurrentArgument = GroupPoints->LineEdit2;
447 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
449 else if (send == GroupPoints2->PushButton1) {
450 GroupPoints2->LineEdit1->setFocus();
451 myEditCurrentArgument = GroupPoints2->LineEdit1;
453 else if (send == GroupPoints2->PushButton2) {
454 GroupPoints2->LineEdit2->setFocus();
455 myEditCurrentArgument = GroupPoints2->LineEdit2;
456 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
458 else if (send == GroupPoints2->PushButton3) {
459 GroupPoints2->LineEdit3->setFocus();
460 myEditCurrentArgument = GroupPoints2->LineEdit3;
461 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
464 myEditCurrentArgument->setFocus();
465 SelectionIntoArgument();
469 //=================================================================================
470 // function : ActivateThisDialog()
472 //=================================================================================
473 void GenerationGUI_PrismDlg::ActivateThisDialog()
475 GEOMBase_Skeleton::ActivateThisDialog();
477 connect(myGeomGUI->getApp()->selectionMgr(),
478 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
480 ConstructorsClicked( getConstructorId() );
484 //=================================================================================
485 // function : enterEvent()
486 // purpose : when mouse enter onto the QWidget
487 //=================================================================================
488 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
490 if (!GroupConstructors->isEnabled())
491 ActivateThisDialog();
495 //=================================================================================
496 // function : ValueChangedInSpinBox()
498 //=================================================================================
499 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
505 //=================================================================================
506 // function : getHeight()
508 //=================================================================================
509 double GenerationGUI_PrismDlg::getHeight() const
511 return GroupPoints->SpinBox_DX->GetValue();
514 //=================================================================================
515 // function : createOperation
517 //=================================================================================
518 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
520 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
523 //=================================================================================
524 // function : isValid
526 //=================================================================================
527 bool GenerationGUI_PrismDlg::isValid( QString& )
529 if (getConstructorId() == 0)
530 return (myOkBase && myOkVec); // by vector and height
532 return (myOkBase && myOkPnt1 && myOkPnt2); // by two points
535 //=================================================================================
536 // function : execute
538 //=================================================================================
539 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
541 GEOM::GEOM_Object_var anObj;
543 switch ( getConstructorId() )
548 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
549 MakePrismVecH(myBase, myVec, getHeight());
551 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
552 MakePrismVecH2Ways(myBase, myVec, getHeight() );
558 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
559 MakePrismTwoPnt(myBase, myPoint1, myPoint2);
561 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
562 MakePrismTwoPnt2Ways(myBase, myPoint1, myPoint2);
566 if ( !anObj->_is_nil() )
567 objects.push_back( anObj._retn() );
573 //=================================================================================
574 // function : onReverse()
576 //=================================================================================
577 void GenerationGUI_PrismDlg::onReverse()
579 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
580 GroupPoints->SpinBox_DX->SetValue( -anOldValue );
583 //=================================================================================
584 // function : onBothway()
586 //=================================================================================
587 void GenerationGUI_PrismDlg::onBothway()
589 bool anOldValue = myBothway;
590 myBothway = !anOldValue;
591 GroupPoints->CheckButton2->setEnabled(!myBothway);
595 void GenerationGUI_PrismDlg::onBothway2()
597 bool anOldValue = myBothway2;
598 myBothway2 = !anOldValue;
602 //=================================================================================
603 // function : addSubshapeToStudy
604 // purpose : virtual method to add new SubObjects if local selection
605 //=================================================================================
606 void GenerationGUI_PrismDlg::addSubshapesToStudy()
608 QMap<QString, GEOM::GEOM_Object_var> objMap;
610 switch (getConstructorId())
613 objMap[GroupPoints->LineEdit2->text()] = myVec;
616 objMap[GroupPoints2->LineEdit2->text()] = myPoint1;
617 objMap[GroupPoints2->LineEdit3->text()] = myPoint2;
620 addSubshapesToFather( objMap );