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"
37 #include <qcheckbox.h>
39 #include "GEOMImpl_Types.hxx"
41 #include "utilities.h"
43 //=================================================================================
44 // class : GenerationGUI_PrismDlg()
45 // purpose : Constructs a GenerationGUI_PrismDlg which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 GenerationGUI_PrismDlg::GenerationGUI_PrismDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
51 const char* name, bool modal, WFlags fl)
52 : GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
53 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
56 QPixmap image0(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PRISM")));
57 QPixmap image1(aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
58 QPixmap image2(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PRISM_2P")));
60 setCaption(tr("GEOM_EXTRUSION_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_EXTRUSION"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->setPixmap(image2);
66 RadioButton3->close(TRUE);
68 RadioButton1->setChecked(true);
70 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
71 GroupPoints->CheckButton1->hide();
72 GroupPoints->GroupBox1->setTitle(tr("GEOM_EXTRUSION_BSV"));
73 GroupPoints->TextLabel1->setText(tr("GEOM_BASE"));
74 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
75 GroupPoints->TextLabel3->setText(tr("GEOM_HEIGHT"));
76 GroupPoints->PushButton1->setPixmap(image1);
77 GroupPoints->PushButton2->setPixmap(image1);
78 GroupPoints->LineEdit1->setReadOnly( true );
79 GroupPoints->LineEdit2->setReadOnly( true );
80 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
82 GroupPoints2 = new DlgRef_3Sel_QTD(this, "GroupPoints2");
83 GroupPoints2->GroupBox1->setTitle(tr("GEOM_EXTRUSION_BSV_2P"));
84 GroupPoints2->TextLabel1->setText(tr("GEOM_BASE"));
85 GroupPoints2->TextLabel2->setText(tr("GEOM_POINT_I").arg("1"));
86 GroupPoints2->TextLabel3->setText(tr("GEOM_POINT_I").arg("2"));
87 GroupPoints2->PushButton1->setPixmap(image1);
88 GroupPoints2->PushButton2->setPixmap(image1);
89 GroupPoints2->PushButton3->setPixmap(image1);
91 Layout1->addWidget(GroupPoints, 2, 0);
92 Layout1->addWidget(GroupPoints2, 2, 0);
93 /***************************************************************/
95 setHelpFileName("extrusion.htm");
101 //=================================================================================
102 // function : ~GenerationGUI_PrismDlg()
103 // purpose : Destroys the object and frees any allocated resources
104 //=================================================================================
105 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
107 // no need to delete child widgets, Qt does it all for us
111 //=================================================================================
114 //=================================================================================
115 void GenerationGUI_PrismDlg::Init()
118 myEditCurrentArgument = GroupPoints->LineEdit1;
119 GroupPoints->LineEdit1->setReadOnly( true );
120 GroupPoints->LineEdit2->setReadOnly( true );
122 GroupPoints2->LineEdit1->setReadOnly( true );
123 GroupPoints2->LineEdit2->setReadOnly( true );
124 GroupPoints2->LineEdit3->setReadOnly( true );
126 myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
127 myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
129 /* Get setting of step value from file configuration */
130 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
131 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
133 /* min, max, step and decimals for spin boxes & initial values */
134 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
135 GroupPoints->SpinBox_DX->SetValue(100.0);
137 /* signals and slots connections */
138 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
139 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
141 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
143 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
149 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
150 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
151 GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
153 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
156 connect(GroupPoints2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
157 connect(GroupPoints2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158 connect(GroupPoints2->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
160 connect(GroupPoints2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
161 connect(GroupPoints2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162 connect(GroupPoints2->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
165 connect(myGeomGUI->getApp()->selectionMgr(),
166 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
168 initName(tr("GEOM_EXTRUSION"));
169 ConstructorsClicked(0);
173 //=================================================================================
174 // function : ConstructorsClicked()
175 // purpose : Radio button management
176 //=================================================================================
177 void GenerationGUI_PrismDlg::ConstructorsClicked(int constructorId)
180 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
182 switch (constructorId)
186 globalSelection( GEOM_ALLSHAPES );
188 GroupPoints2->hide();
192 myEditCurrentArgument = GroupPoints->LineEdit1;
193 GroupPoints->LineEdit1->setText(GroupPoints2->LineEdit1->text()); // keep base
194 GroupPoints->LineEdit2->setText("");
195 myVec = GEOM::GEOM_Object::_nil();
202 globalSelection( GEOM_ALLSHAPES );
206 GroupPoints2->show();
208 myEditCurrentArgument = GroupPoints2->LineEdit1;
209 GroupPoints2->LineEdit1->setText(GroupPoints->LineEdit1->text()); // keep base
210 GroupPoints2->LineEdit2->setText("");
211 GroupPoints2->LineEdit3->setText("");
212 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
213 myOkPnt1 = myOkPnt2 = false;
219 myEditCurrentArgument->setFocus();
220 connect(myGeomGUI->getApp()->selectionMgr(),
221 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
224 SelectionIntoArgument();
228 //=================================================================================
229 // function : ClickOnOk()
231 //=================================================================================
232 void GenerationGUI_PrismDlg::ClickOnOk()
234 if ( ClickOnApply() )
239 //=================================================================================
240 // function : ClickOnApply()
242 //=================================================================================
243 bool GenerationGUI_PrismDlg::ClickOnApply()
253 //=================================================================================
254 // function : SelectionIntoArgument()
255 // purpose : Called when selection has changed
256 //=================================================================================
257 void GenerationGUI_PrismDlg::SelectionIntoArgument()
260 myEditCurrentArgument->setText("");
262 if (getConstructorId() == 0)
264 if (IObjectCount() != 1) {
265 if (myEditCurrentArgument == GroupPoints->LineEdit1)
267 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
273 Standard_Boolean testResult = Standard_False;
274 GEOM::GEOM_Object_ptr aSelectedObject =
275 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
280 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
281 myBase = aSelectedObject;
284 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
285 myVec = aSelectedObject;
289 myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
291 else // getConstructorId()==1 - extrusion using 2 points
293 if (IObjectCount() != 1) {
294 if (myEditCurrentArgument == GroupPoints2->LineEdit1)
296 else if (myEditCurrentArgument == GroupPoints2->LineEdit2) {
297 myPoint1 = GEOM::GEOM_Object::_nil();
300 else if (myEditCurrentArgument == GroupPoints2->LineEdit3) {
301 myPoint2 = GEOM::GEOM_Object::_nil();
308 Standard_Boolean testResult = Standard_False;
309 GEOM::GEOM_Object_var aSelectedObject =
310 GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
312 if (!testResult || CORBA::is_nil( aSelectedObject ))
315 if (myEditCurrentArgument == GroupPoints2->LineEdit1) {
316 myBase = aSelectedObject;
319 else if (myEditCurrentArgument == GroupPoints2->LineEdit2) {
320 myPoint1 = aSelectedObject;
323 else if (myEditCurrentArgument == GroupPoints2->LineEdit3) {
324 myPoint2 = aSelectedObject;
328 myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
335 //=================================================================================
336 // function : LineEditReturnPressed()
338 //=================================================================================
339 void GenerationGUI_PrismDlg::LineEditReturnPressed()
341 QLineEdit* send = (QLineEdit*)sender();
342 if (send == GroupPoints->LineEdit1 ||
343 send == GroupPoints->LineEdit2 ||
344 send == GroupPoints2->LineEdit1 ||
345 send == GroupPoints2->LineEdit2 ||
346 send == GroupPoints2->LineEdit3 )
348 myEditCurrentArgument = send;
349 GEOMBase_Skeleton::LineEditReturnPressed();
354 //=================================================================================
355 // function : SetEditCurrentArgument()
357 //=================================================================================
358 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
360 QPushButton* send = (QPushButton*)sender();
362 if (send == GroupPoints->PushButton1) {
363 GroupPoints->LineEdit1->setFocus();
364 myEditCurrentArgument = GroupPoints->LineEdit1;
365 globalSelection( GEOM_ALLSHAPES );
367 else if (send == GroupPoints->PushButton2) {
368 GroupPoints->LineEdit2->setFocus();
369 myEditCurrentArgument = GroupPoints->LineEdit2;
370 globalSelection( GEOM_LINE );
372 else if (send == GroupPoints2->PushButton1) {
373 GroupPoints2->LineEdit1->setFocus();
374 myEditCurrentArgument = GroupPoints2->LineEdit1;
375 globalSelection( GEOM_ALLSHAPES );
377 else if (send == GroupPoints2->PushButton2) {
378 GroupPoints2->LineEdit2->setFocus();
379 myEditCurrentArgument = GroupPoints2->LineEdit2;
380 globalSelection( GEOM_POINT );
382 else if (send == GroupPoints2->PushButton3) {
383 GroupPoints2->LineEdit3->setFocus();
384 myEditCurrentArgument = GroupPoints2->LineEdit3;
385 globalSelection( GEOM_POINT );
388 myEditCurrentArgument->setFocus();
389 SelectionIntoArgument();
393 //=================================================================================
394 // function : ActivateThisDialog()
396 //=================================================================================
397 void GenerationGUI_PrismDlg::ActivateThisDialog()
399 GEOMBase_Skeleton::ActivateThisDialog();
401 connect(myGeomGUI->getApp()->selectionMgr(),
402 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
404 ConstructorsClicked( getConstructorId() );
408 //=================================================================================
409 // function : enterEvent()
410 // purpose : when mouse enter onto the QWidget
411 //=================================================================================
412 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
414 if (!GroupConstructors->isEnabled())
415 ActivateThisDialog();
419 //=================================================================================
420 // function : ValueChangedInSpinBox()
422 //=================================================================================
423 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
429 //=================================================================================
430 // function : getHeight()
432 //=================================================================================
433 double GenerationGUI_PrismDlg::getHeight() const
435 return GroupPoints->SpinBox_DX->GetValue();
438 //=================================================================================
439 // function : createOperation
441 //=================================================================================
442 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
444 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
447 //=================================================================================
448 // function : isValid
450 //=================================================================================
451 bool GenerationGUI_PrismDlg::isValid( QString& )
453 if (getConstructorId() == 0)
454 // by vector and height
455 return (myOkBase && myOkVec);
458 return (myOkBase && myOkPnt1 && myOkPnt2);
461 //=================================================================================
462 // function : execute
464 //=================================================================================
465 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
467 GEOM::GEOM_Object_var anObj;
469 switch ( getConstructorId() )
473 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
474 MakePrismVecH(myBase, myVec, getHeight());
479 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
480 MakePrismTwoPnt(myBase, myPoint1, myPoint2);
484 if ( !anObj->_is_nil() )
485 objects.push_back( anObj._retn() );
491 //=================================================================================
492 // function : onReverse()
494 //=================================================================================
495 void GenerationGUI_PrismDlg::onReverse()
497 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
498 GroupPoints->SpinBox_DX->SetValue( -anOldValue );