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 <BRepPrimAPI_MakePrism.hxx>
37 #include <BRepAdaptor_Curve.hxx>
39 #include "GEOMImpl_Types.hxx"
42 #include <qcheckbox.h>
44 #include "utilities.h"
46 //=================================================================================
47 // class : GenerationGUI_PrismDlg()
48 // purpose : Constructs a GenerationGUI_PrismDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 GenerationGUI_PrismDlg::GenerationGUI_PrismDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
54 const char* name, bool modal, WFlags fl)
55 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
56 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
58 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PRISM")));
59 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PRISM_2P")));
62 setCaption(tr("GEOM_PRISM_TITLE"));
64 /***************************************************************/
65 GroupConstructors->setTitle(tr("GEOM_PRISM"));
66 RadioButton1->setPixmap(image0);
67 RadioButton2->setPixmap(image2);
68 //RadioButton2->close(TRUE);
69 RadioButton3->close(TRUE);
71 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
72 //GroupPoints->CheckButton1->hide();
73 GroupPoints->GroupBox1->setTitle(tr("GEOM_PRISM_BSV"));
74 GroupPoints->TextLabel1->setText(tr("GEOM_BASE"));
75 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
76 GroupPoints->TextLabel3->setText(tr("GEOM_HEIGHT"));
77 GroupPoints->PushButton1->setPixmap(image1);
78 GroupPoints->PushButton2->setPixmap(image1);
79 GroupPoints->LineEdit1->setReadOnly( true );
80 GroupPoints->LineEdit2->setReadOnly( true );
81 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
83 GroupPoints2 = new DlgRef_3Sel_QTD(this, "GroupPoints2");
84 GroupPoints2->GroupBox1->setTitle(tr("GEOM_PRISM_BSV_2P"));
85 GroupPoints2->TextLabel1->setText(tr("GEOM_BASE"));
86 GroupPoints2->TextLabel2->setText(tr("GEOM_POINT_I").arg("1"));
87 GroupPoints2->TextLabel3->setText(tr("GEOM_POINT_I").arg("2"));
88 GroupPoints2->PushButton1->setPixmap(image1);
89 GroupPoints2->PushButton2->setPixmap(image1);
90 GroupPoints2->PushButton3->setPixmap(image1);
92 Layout1->addWidget(GroupPoints, 2, 0);
93 Layout1->addWidget(GroupPoints2, 2, 0);
94 /***************************************************************/
96 setHelpFileName("extrusion.htm");
103 //=================================================================================
104 // function : ~GenerationGUI_PrismDlg()
105 // purpose : Destroys the object and frees any allocated resources
106 //=================================================================================
107 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
109 /* no need to delete child widgets, Qt does it all for us */
113 //=================================================================================
116 //=================================================================================
117 void GenerationGUI_PrismDlg::Init()
120 myEditCurrentArgument = GroupPoints->LineEdit1;
121 GroupPoints->LineEdit1->setReadOnly( true );
122 GroupPoints->LineEdit2->setReadOnly( true );
124 GroupPoints2->LineEdit1->setReadOnly( true );
125 GroupPoints2->LineEdit2->setReadOnly( true );
126 GroupPoints2->LineEdit3->setReadOnly( true );
128 //myOkBase = myOkVec = false;
129 myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
131 /* Get setting of step value from file configuration */
132 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
133 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
135 /* min, max, step and decimals for spin boxes & initial values */
136 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, +999.999, step, 3);
137 GroupPoints->SpinBox_DX->SetValue(100.0);
139 /* signals and slots connections */
140 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
141 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
143 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
145 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
149 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
151 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
152 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
154 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
157 connect(GroupPoints2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158 connect(GroupPoints2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
159 connect(GroupPoints2->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
161 connect(GroupPoints2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162 connect(GroupPoints2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
163 connect(GroupPoints2->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
166 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
167 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
169 initName(tr("GEOM_PRISM"));
171 globalSelection( GEOM_ALLSHAPES );
172 ConstructorsClicked(0);
176 //=================================================================================
177 // function : ConstructorsClicked()
178 // purpose : Radio button management
179 //=================================================================================
180 void GenerationGUI_PrismDlg::ConstructorsClicked(int constructorId)
182 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
184 switch (constructorId)
188 globalSelection( GEOM_POINT );
190 GroupPoints2->hide();
194 //GroupPoints->LineEdit1->setFocus();
195 //myEditCurrentArgument = GroupPoints->LineEdit1;
204 GroupPoints2->show();
206 myEditCurrentArgument = GroupPoints2->LineEdit1;
207 GroupPoints2->LineEdit1->setText("");
208 GroupPoints2->LineEdit2->setText("");
209 GroupPoints2->LineEdit3->setText("");
210 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
219 //=================================================================================
220 // function : ClickOnOk()
222 //=================================================================================
223 void GenerationGUI_PrismDlg::ClickOnOk()
225 if ( ClickOnApply() )
230 //=================================================================================
231 // function : ClickOnApply()
233 //=================================================================================
234 bool GenerationGUI_PrismDlg::ClickOnApply()
244 //=================================================================================
245 // function : SelectionIntoArgument()
246 // purpose : Called when selection has changed
247 //=================================================================================
248 void GenerationGUI_PrismDlg::SelectionIntoArgument()
251 myEditCurrentArgument->setText("");
253 if ( getConstructorId()==0 ) {
255 if (IObjectCount() != 1) {
256 if (myEditCurrentArgument == GroupPoints->LineEdit1)
258 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
264 Standard_Boolean testResult = Standard_False;
265 GEOM::GEOM_Object_ptr aSelectedObject =
266 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
271 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
275 if (!GEOMBase::GetShape(aSelectedObject, S) ||
279 myBase = aSelectedObject;
282 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
283 myVec = aSelectedObject;
286 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 : SetEditCurrentArgument()
338 //=================================================================================
339 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
341 QPushButton* send = (QPushButton*)sender();
342 globalSelection( GEOM_ALLSHAPES );
344 if(send == GroupPoints->PushButton1) {
345 GroupPoints->LineEdit1->setFocus();
346 myEditCurrentArgument = GroupPoints->LineEdit1;
348 else if(send == GroupPoints->PushButton2) {
349 GroupPoints->LineEdit2->setFocus();
350 myEditCurrentArgument = GroupPoints->LineEdit2;
351 globalSelection( GEOM_LINE );
353 else if(send == GroupPoints2->PushButton1) {
354 GroupPoints2->LineEdit1->setFocus();
355 myEditCurrentArgument = GroupPoints2->LineEdit1;
357 else if(send == GroupPoints2->PushButton2) {
358 GroupPoints2->LineEdit2->setFocus();
359 myEditCurrentArgument = GroupPoints2->LineEdit2;
360 globalSelection( GEOM_POINT );
362 else if(send == GroupPoints2->PushButton3) {
363 GroupPoints2->LineEdit3->setFocus();
364 myEditCurrentArgument = GroupPoints2->LineEdit3;
365 globalSelection( GEOM_POINT );
367 SelectionIntoArgument();
371 //=================================================================================
372 // function : LineEditReturnPressed()
374 //=================================================================================
375 void GenerationGUI_PrismDlg::LineEditReturnPressed()
377 QLineEdit* send = (QLineEdit*)sender();
378 if(send == GroupPoints->LineEdit1 ||
379 send == GroupPoints->LineEdit2 ||
380 send == GroupPoints2->LineEdit1 ||
381 send == GroupPoints2->LineEdit2 ||
382 send == GroupPoints2->LineEdit3 )
384 myEditCurrentArgument = send;
385 GEOMBase_Skeleton::LineEditReturnPressed();
389 //=================================================================================
390 // function : enterEvent()
391 // purpose : when mouse enter onto the QWidget
392 //=================================================================================
393 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
395 if ( !GroupConstructors->isEnabled() )
396 ActivateThisDialog();
400 //=================================================================================
401 // function : ActivateThisDialog()
403 //=================================================================================
404 void GenerationGUI_PrismDlg::ActivateThisDialog()
406 GEOMBase_Skeleton::ActivateThisDialog();
407 globalSelection( GEOM_ALLSHAPES );
408 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
409 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
410 //GroupPoints->LineEdit1->setFocus();
411 //myEditCurrentArgument = GroupPoints->LineEdit1;
413 ConstructorsClicked( getConstructorId() );
417 //=================================================================================
418 // function : ValueChangedInSpinBox()
420 //=================================================================================
421 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
427 //=================================================================================
428 // function : getHeight()
430 //=================================================================================
431 double GenerationGUI_PrismDlg::getHeight() const
433 return GroupPoints->SpinBox_DX->GetValue();
436 //=================================================================================
437 // function : createOperation
439 //=================================================================================
440 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
442 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
445 //=================================================================================
446 // function : isValid
448 //=================================================================================
449 bool GenerationGUI_PrismDlg::isValid( QString& )
451 return myOkBase && ( myOkVec || (myOkPnt1 && myOkPnt2) );
454 //=================================================================================
455 // function : execute
457 //=================================================================================
458 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
460 GEOM::GEOM_Object_var anObj;
462 switch ( getConstructorId() )
466 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
467 MakePrismVecH(myBase, myVec, getHeight());
472 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
473 MakePrismTwoPnt(myBase, myPoint1, myPoint2);
477 if ( !anObj->_is_nil() )
478 objects.push_back( anObj._retn() );
484 //=================================================================================
485 // function : onReverse()
487 //=================================================================================
488 void GenerationGUI_PrismDlg::onReverse()
490 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
491 GroupPoints->SpinBox_DX->SetValue( -anOldValue );