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_EXTRUSION_TITLE"));
64 /***************************************************************/
65 GroupConstructors->setTitle(tr("GEOM_EXTRUSION"));
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_EXTRUSION_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_EXTRUSION_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(COORD_MIN, COORD_MAX, 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_EXTRUSION"));
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;
198 myEditCurrentArgument = GroupPoints->LineEdit1;
199 GroupPoints->LineEdit1->setText("");
200 GroupPoints->LineEdit2->setText("");
201 GroupPoints2->LineEdit1->setText("");
202 GroupPoints2->LineEdit2->setText("");
203 GroupPoints2->LineEdit3->setText("");
204 myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
205 myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
213 GroupPoints2->show();
215 myEditCurrentArgument = GroupPoints2->LineEdit1;
216 GroupPoints2->LineEdit1->setText("");
217 GroupPoints2->LineEdit2->setText("");
218 GroupPoints2->LineEdit3->setText("");
219 myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
220 myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
221 GroupPoints->LineEdit1->setText("");
222 GroupPoints->LineEdit2->setText("");
231 //=================================================================================
232 // function : ClickOnOk()
234 //=================================================================================
235 void GenerationGUI_PrismDlg::ClickOnOk()
237 if ( ClickOnApply() )
242 //=================================================================================
243 // function : ClickOnApply()
245 //=================================================================================
246 bool GenerationGUI_PrismDlg::ClickOnApply()
256 //=================================================================================
257 // function : SelectionIntoArgument()
258 // purpose : Called when selection has changed
259 //=================================================================================
260 void GenerationGUI_PrismDlg::SelectionIntoArgument()
263 myEditCurrentArgument->setText("");
265 if ( getConstructorId()==0 ) {
267 if (IObjectCount() != 1) {
268 if (myEditCurrentArgument == GroupPoints->LineEdit1)
270 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
276 Standard_Boolean testResult = Standard_False;
277 GEOM::GEOM_Object_ptr aSelectedObject =
278 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
283 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
284 myBase = aSelectedObject;
287 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
288 myVec = aSelectedObject;
291 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
296 else { // getConstructorId()==1 - extrusion using 2 points
298 if (IObjectCount() != 1) {
299 if (myEditCurrentArgument == GroupPoints2->LineEdit1)
301 else if (myEditCurrentArgument == GroupPoints2->LineEdit2) {
302 myPoint1 = GEOM::GEOM_Object::_nil();
305 else if (myEditCurrentArgument == GroupPoints2->LineEdit3) {
306 myPoint2 = GEOM::GEOM_Object::_nil();
313 Standard_Boolean testResult = Standard_False;
314 GEOM::GEOM_Object_var aSelectedObject =
315 GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
317 if (!testResult || CORBA::is_nil( aSelectedObject ))
320 if (myEditCurrentArgument == GroupPoints2->LineEdit1) {
321 myBase = aSelectedObject;
324 else if (myEditCurrentArgument == GroupPoints2->LineEdit2) {
325 myPoint1 = aSelectedObject;
328 else if (myEditCurrentArgument == GroupPoints2->LineEdit3) {
329 myPoint2 = aSelectedObject;
333 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
340 //=================================================================================
341 // function : SetEditCurrentArgument()
343 //=================================================================================
344 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
346 QPushButton* send = (QPushButton*)sender();
347 globalSelection( GEOM_ALLSHAPES );
349 if(send == GroupPoints->PushButton1) {
350 GroupPoints->LineEdit1->setFocus();
351 myEditCurrentArgument = GroupPoints->LineEdit1;
353 else if(send == GroupPoints->PushButton2) {
354 GroupPoints->LineEdit2->setFocus();
355 myEditCurrentArgument = GroupPoints->LineEdit2;
356 globalSelection( GEOM_LINE );
358 else if(send == GroupPoints2->PushButton1) {
359 GroupPoints2->LineEdit1->setFocus();
360 myEditCurrentArgument = GroupPoints2->LineEdit1;
362 else if(send == GroupPoints2->PushButton2) {
363 GroupPoints2->LineEdit2->setFocus();
364 myEditCurrentArgument = GroupPoints2->LineEdit2;
365 globalSelection( GEOM_POINT );
367 else if(send == GroupPoints2->PushButton3) {
368 GroupPoints2->LineEdit3->setFocus();
369 myEditCurrentArgument = GroupPoints2->LineEdit3;
370 globalSelection( GEOM_POINT );
372 SelectionIntoArgument();
376 //=================================================================================
377 // function : LineEditReturnPressed()
379 //=================================================================================
380 void GenerationGUI_PrismDlg::LineEditReturnPressed()
382 QLineEdit* send = (QLineEdit*)sender();
383 if(send == GroupPoints->LineEdit1 ||
384 send == GroupPoints->LineEdit2 ||
385 send == GroupPoints2->LineEdit1 ||
386 send == GroupPoints2->LineEdit2 ||
387 send == GroupPoints2->LineEdit3 )
389 myEditCurrentArgument = send;
390 GEOMBase_Skeleton::LineEditReturnPressed();
394 //=================================================================================
395 // function : enterEvent()
396 // purpose : when mouse enter onto the QWidget
397 //=================================================================================
398 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
400 if ( !GroupConstructors->isEnabled() )
401 ActivateThisDialog();
405 //=================================================================================
406 // function : ActivateThisDialog()
408 //=================================================================================
409 void GenerationGUI_PrismDlg::ActivateThisDialog()
411 GEOMBase_Skeleton::ActivateThisDialog();
412 globalSelection( GEOM_ALLSHAPES );
413 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
414 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
415 //GroupPoints->LineEdit1->setFocus();
416 //myEditCurrentArgument = GroupPoints->LineEdit1;
418 ConstructorsClicked( getConstructorId() );
422 //=================================================================================
423 // function : ValueChangedInSpinBox()
425 //=================================================================================
426 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
432 //=================================================================================
433 // function : getHeight()
435 //=================================================================================
436 double GenerationGUI_PrismDlg::getHeight() const
438 return GroupPoints->SpinBox_DX->GetValue();
441 //=================================================================================
442 // function : createOperation
444 //=================================================================================
445 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
447 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
450 //=================================================================================
451 // function : isValid
453 //=================================================================================
454 bool GenerationGUI_PrismDlg::isValid( QString& )
456 return myOkBase && ( myOkVec || (myOkPnt1 && myOkPnt2) );
459 //=================================================================================
460 // function : execute
462 //=================================================================================
463 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
465 GEOM::GEOM_Object_var anObj;
467 switch ( getConstructorId() )
471 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
472 MakePrismVecH(myBase, myVec, getHeight());
477 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
478 MakePrismTwoPnt(myBase, myPoint1, myPoint2);
482 if ( !anObj->_is_nil() )
483 objects.push_back( anObj._retn() );
489 //=================================================================================
490 // function : onReverse()
492 //=================================================================================
493 void GenerationGUI_PrismDlg::onReverse()
495 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
496 GroupPoints->SpinBox_DX->SetValue( -anOldValue );