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")));
61 setCaption(tr("GEOM_PRISM_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_PRISM"));
65 RadioButton1->setPixmap(image0);
66 RadioButton2->close(TRUE);
67 RadioButton3->close(TRUE);
69 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
70 GroupPoints->CheckButton1->hide();
71 GroupPoints->GroupBox1->setTitle(tr("GEOM_PRISM_BSV"));
72 GroupPoints->TextLabel1->setText(tr("GEOM_BASE"));
73 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
74 GroupPoints->TextLabel3->setText(tr("GEOM_HEIGHT"));
75 GroupPoints->PushButton1->setPixmap(image1);
76 GroupPoints->PushButton2->setPixmap(image1);
77 GroupPoints->LineEdit1->setReadOnly( true );
78 GroupPoints->LineEdit2->setReadOnly( true );
79 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
81 Layout1->addWidget(GroupPoints, 2, 0);
82 /***************************************************************/
84 setHelpFileName("extrusion.htm");
91 //=================================================================================
92 // function : ~GenerationGUI_PrismDlg()
93 // purpose : Destroys the object and frees any allocated resources
94 //=================================================================================
95 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
97 /* no need to delete child widgets, Qt does it all for us */
101 //=================================================================================
104 //=================================================================================
105 void GenerationGUI_PrismDlg::Init()
108 myEditCurrentArgument = GroupPoints->LineEdit1;
109 GroupPoints->LineEdit1->setReadOnly( true );
110 GroupPoints->LineEdit2->setReadOnly( true );
112 myOkBase = myOkVec = false;
114 /* Get setting of step value from file configuration */
115 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
116 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
118 /* min, max, step and decimals for spin boxes & initial values */
119 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, +999.999, step, 3);
120 GroupPoints->SpinBox_DX->SetValue(100.0);
122 /* signals and slots connections */
123 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
124 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
126 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
133 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
135 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
137 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
138 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
140 initName(tr("GEOM_PRISM"));
142 globalSelection( GEOM_ALLSHAPES );
146 //=================================================================================
147 // function : ClickOnOk()
149 //=================================================================================
150 void GenerationGUI_PrismDlg::ClickOnOk()
152 if ( ClickOnApply() )
157 //=================================================================================
158 // function : ClickOnApply()
160 //=================================================================================
161 bool GenerationGUI_PrismDlg::ClickOnApply()
171 //=================================================================================
172 // function : SelectionIntoArgument()
173 // purpose : Called when selection has changed
174 //=================================================================================
175 void GenerationGUI_PrismDlg::SelectionIntoArgument()
178 myEditCurrentArgument->setText("");
180 if (IObjectCount() != 1) {
181 if (myEditCurrentArgument == GroupPoints->LineEdit1)
183 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
189 Standard_Boolean testResult = Standard_False;
190 GEOM::GEOM_Object_ptr aSelectedObject =
191 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
196 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
200 if (!GEOMBase::GetShape(aSelectedObject, S) ||
204 myBase = aSelectedObject;
206 } else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
207 myVec = aSelectedObject;
210 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
216 //=================================================================================
217 // function : SetEditCurrentArgument()
219 //=================================================================================
220 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
222 QPushButton* send = (QPushButton*)sender();
223 globalSelection( GEOM_ALLSHAPES );
225 if(send == GroupPoints->PushButton1) {
226 GroupPoints->LineEdit1->setFocus();
227 myEditCurrentArgument = GroupPoints->LineEdit1;
229 else if(send == GroupPoints->PushButton2) {
230 GroupPoints->LineEdit2->setFocus();
231 myEditCurrentArgument = GroupPoints->LineEdit2;
232 globalSelection( GEOM_LINE );
234 SelectionIntoArgument();
238 //=================================================================================
239 // function : LineEditReturnPressed()
241 //=================================================================================
242 void GenerationGUI_PrismDlg::LineEditReturnPressed()
244 QLineEdit* send = (QLineEdit*)sender();
245 if(send == GroupPoints->LineEdit1 ||
246 send == GroupPoints->LineEdit2)
248 myEditCurrentArgument = send;
249 GEOMBase_Skeleton::LineEditReturnPressed();
253 //=================================================================================
254 // function : enterEvent()
255 // purpose : when mouse enter onto the QWidget
256 //=================================================================================
257 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
259 if ( !GroupConstructors->isEnabled() )
260 ActivateThisDialog();
264 //=================================================================================
265 // function : ActivateThisDialog()
267 //=================================================================================
268 void GenerationGUI_PrismDlg::ActivateThisDialog()
270 GEOMBase_Skeleton::ActivateThisDialog();
271 globalSelection( GEOM_ALLSHAPES );
272 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
273 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
274 GroupPoints->LineEdit1->setFocus();
275 myEditCurrentArgument = GroupPoints->LineEdit1;
280 //=================================================================================
281 // function : ValueChangedInSpinBox()
283 //=================================================================================
284 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
290 //=================================================================================
291 // function : getHeight()
293 //=================================================================================
294 double GenerationGUI_PrismDlg::getHeight() const
296 return GroupPoints->SpinBox_DX->GetValue();
299 //=================================================================================
300 // function : createOperation
302 //=================================================================================
303 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
305 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
308 //=================================================================================
309 // function : isValid
311 //=================================================================================
312 bool GenerationGUI_PrismDlg::isValid( QString& )
314 return myOkBase && myOkVec;
317 //=================================================================================
318 // function : execute
320 //=================================================================================
321 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
323 GEOM::GEOM_Object_var anObj;
325 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
326 MakePrismVecH(myBase, myVec, getHeight());
328 if ( !anObj->_is_nil() )
329 objects.push_back( anObj._retn() );
335 //=================================================================================
336 // function : onReverse()
338 //=================================================================================
339 void GenerationGUI_PrismDlg::onReverse()
341 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
342 GroupPoints->SpinBox_DX->SetValue( -anOldValue );