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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GenerationGUI_PrismDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "GenerationGUI_PrismDlg.h"
31 #include <BRepPrimAPI_MakePrism.hxx>
32 #include <BRepAdaptor_Curve.hxx>
34 #include "QAD_Config.h"
35 #include "QAD_Desktop.h"
36 #include "GEOMImpl_Types.hxx"
38 #include <qcheckbox.h>
40 #include "utilities.h"
42 //=================================================================================
43 // class : GenerationGUI_PrismDlg()
44 // purpose : Constructs a GenerationGUI_PrismDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 GenerationGUI_PrismDlg::GenerationGUI_PrismDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PRISM")));
53 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
55 setCaption(tr("GEOM_PRISM_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_PRISM"));
59 RadioButton1->setPixmap(image0);
60 RadioButton2->close(TRUE);
61 RadioButton3->close(TRUE);
63 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
64 GroupPoints->CheckButton1->hide();
65 GroupPoints->GroupBox1->setTitle(tr("GEOM_PRISM_BSV"));
66 GroupPoints->TextLabel1->setText(tr("GEOM_BASE"));
67 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
68 GroupPoints->TextLabel3->setText(tr("GEOM_HEIGHT"));
69 GroupPoints->PushButton1->setPixmap(image1);
70 GroupPoints->PushButton2->setPixmap(image1);
71 GroupPoints->LineEdit1->setReadOnly( true );
72 GroupPoints->LineEdit2->setReadOnly( true );
73 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
75 Layout1->addWidget(GroupPoints, 2, 0);
76 /***************************************************************/
83 //=================================================================================
84 // function : ~GenerationGUI_PrismDlg()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
89 /* no need to delete child widgets, Qt does it all for us */
93 //=================================================================================
96 //=================================================================================
97 void GenerationGUI_PrismDlg::Init()
100 myEditCurrentArgument = GroupPoints->LineEdit1;
101 GroupPoints->LineEdit1->setReadOnly( true );
102 GroupPoints->LineEdit2->setReadOnly( true );
104 myOkBase = myOkVec = false;
106 /* Get setting of step value from file configuration */
107 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
108 double step = St.toDouble();
110 /* min, max, step and decimals for spin boxes & initial values */
111 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, +999.999, step, 3);
112 GroupPoints->SpinBox_DX->SetValue(100.0);
114 /* signals and slots connections */
115 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
116 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
118 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
119 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
122 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
124 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
125 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
127 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
129 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
131 initName(tr("GEOM_PRISM"));
133 globalSelection( GEOM_ALLSHAPES );
137 //=================================================================================
138 // function : ClickOnOk()
140 //=================================================================================
141 void GenerationGUI_PrismDlg::ClickOnOk()
143 if ( ClickOnApply() )
148 //=================================================================================
149 // function : ClickOnApply()
151 //=================================================================================
152 bool GenerationGUI_PrismDlg::ClickOnApply()
162 //=================================================================================
163 // function : SelectionIntoArgument()
164 // purpose : Called when selection has changed
165 //=================================================================================
166 void GenerationGUI_PrismDlg::SelectionIntoArgument()
169 myEditCurrentArgument->setText("");
171 if(mySelection->IObjectCount() != 1)
173 if(myEditCurrentArgument == GroupPoints->LineEdit1)
175 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
181 Standard_Boolean testResult = Standard_False;
182 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
187 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
191 if ( !GEOMBase::GetShape(aSelectedObject, S) ||
195 myBase = aSelectedObject;
198 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
199 myVec = aSelectedObject;
202 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
208 //=================================================================================
209 // function : SetEditCurrentArgument()
211 //=================================================================================
212 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
214 QPushButton* send = (QPushButton*)sender();
215 globalSelection( GEOM_ALLSHAPES );
217 if(send == GroupPoints->PushButton1) {
218 GroupPoints->LineEdit1->setFocus();
219 myEditCurrentArgument = GroupPoints->LineEdit1;
221 else if(send == GroupPoints->PushButton2) {
222 GroupPoints->LineEdit2->setFocus();
223 myEditCurrentArgument = GroupPoints->LineEdit2;
224 globalSelection( GEOM_LINE );
226 SelectionIntoArgument();
230 //=================================================================================
231 // function : LineEditReturnPressed()
233 //=================================================================================
234 void GenerationGUI_PrismDlg::LineEditReturnPressed()
236 QLineEdit* send = (QLineEdit*)sender();
237 if(send == GroupPoints->LineEdit1 ||
238 send == GroupPoints->LineEdit2)
240 myEditCurrentArgument = send;
241 GEOMBase_Skeleton::LineEditReturnPressed();
245 //=================================================================================
246 // function : enterEvent()
247 // purpose : when mouse enter onto the QWidget
248 //=================================================================================
249 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
251 if ( !GroupConstructors->isEnabled() )
252 ActivateThisDialog();
256 //=================================================================================
257 // function : ActivateThisDialog()
259 //=================================================================================
260 void GenerationGUI_PrismDlg::ActivateThisDialog()
262 GEOMBase_Skeleton::ActivateThisDialog();
263 globalSelection( GEOM_ALLSHAPES );
264 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
265 GroupPoints->LineEdit1->setFocus();
266 myEditCurrentArgument = GroupPoints->LineEdit1;
271 //=================================================================================
272 // function : ValueChangedInSpinBox()
274 //=================================================================================
275 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
282 //=================================================================================
283 // function : getHeight()
285 //=================================================================================
286 double GenerationGUI_PrismDlg::getHeight() const
288 return GroupPoints->SpinBox_DX->GetValue();
291 //=================================================================================
292 // function : createOperation
294 //=================================================================================
295 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
297 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
300 //=================================================================================
301 // function : isValid
303 //=================================================================================
304 bool GenerationGUI_PrismDlg::isValid( QString& )
306 return myOkBase && myOkVec;
309 //=================================================================================
310 // function : execute
312 //=================================================================================
313 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
315 GEOM::GEOM_Object_var anObj;
317 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation() )->MakePrismVecH ( myBase, myVec, getHeight() );
319 if ( !anObj->_is_nil() )
320 objects.push_back( anObj._retn() );
326 //=================================================================================
327 // function : onReverse()
329 //=================================================================================
330 void GenerationGUI_PrismDlg::onReverse()
332 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
333 GroupPoints->SpinBox_DX->SetValue( -anOldValue );