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 myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
128 /* Get setting of step value from file configuration */
129 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
130 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
132 /* min, max, step and decimals for spin boxes & initial values */
133 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
134 GroupPoints->SpinBox_DX->SetValue(100.0);
136 /* signals and slots connections */
137 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
138 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
140 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
142 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
148 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
149 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
151 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
154 connect(GroupPoints2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
155 connect(GroupPoints2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 connect(GroupPoints2->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158 connect(GroupPoints2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159 connect(GroupPoints2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
160 connect(GroupPoints2->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
163 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
164 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
166 initName(tr("GEOM_EXTRUSION"));
167 ConstructorsClicked(0);
171 //=================================================================================
172 // function : ConstructorsClicked()
173 // purpose : Radio button management
174 //=================================================================================
175 void GenerationGUI_PrismDlg::ConstructorsClicked(int constructorId)
178 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
180 switch (constructorId)
184 globalSelection( GEOM_POINT );
186 GroupPoints2->hide();
190 myEditCurrentArgument = GroupPoints->LineEdit1;
191 GroupPoints->LineEdit1->setText("");
192 GroupPoints->LineEdit2->setText("");
193 GroupPoints2->LineEdit1->setText("");
194 GroupPoints2->LineEdit2->setText("");
195 GroupPoints2->LineEdit3->setText("");
196 myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
197 myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
203 globalSelection( GEOM_ALLSHAPES );
207 GroupPoints2->show();
209 myEditCurrentArgument = GroupPoints2->LineEdit1;
210 GroupPoints2->LineEdit1->setText("");
211 GroupPoints2->LineEdit2->setText("");
212 GroupPoints2->LineEdit3->setText("");
213 myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
214 myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
215 GroupPoints->LineEdit1->setText("");
216 GroupPoints->LineEdit2->setText("");
222 myEditCurrentArgument->setFocus();
223 connect(myGeomGUI->getApp()->selectionMgr(),
224 SIGNAL(currentSelectionChanged()), this, SLOT(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));
292 else // getConstructorId()==1 - extrusion using 2 points
294 if (IObjectCount() != 1) {
295 if (myEditCurrentArgument == GroupPoints2->LineEdit1)
297 else if (myEditCurrentArgument == GroupPoints2->LineEdit2) {
298 myPoint1 = GEOM::GEOM_Object::_nil();
301 else if (myEditCurrentArgument == GroupPoints2->LineEdit3) {
302 myPoint2 = GEOM::GEOM_Object::_nil();
309 Standard_Boolean testResult = Standard_False;
310 GEOM::GEOM_Object_var aSelectedObject =
311 GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
313 if (!testResult || CORBA::is_nil( aSelectedObject ))
316 if (myEditCurrentArgument == GroupPoints2->LineEdit1) {
317 myBase = aSelectedObject;
320 else if (myEditCurrentArgument == GroupPoints2->LineEdit2) {
321 myPoint1 = aSelectedObject;
324 else if (myEditCurrentArgument == GroupPoints2->LineEdit3) {
325 myPoint2 = aSelectedObject;
329 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 return myOkBase && ( myOkVec || (myOkPnt1 && myOkPnt2) );
456 //=================================================================================
457 // function : execute
459 //=================================================================================
460 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
462 GEOM::GEOM_Object_var anObj;
464 switch ( getConstructorId() )
468 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
469 MakePrismVecH(myBase, myVec, getHeight());
474 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
475 MakePrismTwoPnt(myBase, myPoint1, myPoint2);
479 if ( !anObj->_is_nil() )
480 objects.push_back( anObj._retn() );
486 //=================================================================================
487 // function : onReverse()
489 //=================================================================================
490 void GenerationGUI_PrismDlg::onReverse()
492 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
493 GroupPoints->SpinBox_DX->SetValue( -anOldValue );