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 "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_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, const char* name, bool modal, WFlags fl)
54 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
56 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PRISM")));
57 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
59 setCaption(tr("GEOM_PRISM_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_PRISM"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->close(TRUE);
65 RadioButton3->close(TRUE);
67 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
68 GroupPoints->CheckButton1->hide();
69 GroupPoints->GroupBox1->setTitle(tr("GEOM_PRISM_BSV"));
70 GroupPoints->TextLabel1->setText(tr("GEOM_BASE"));
71 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
72 GroupPoints->TextLabel3->setText(tr("GEOM_HEIGHT"));
73 GroupPoints->PushButton1->setPixmap(image1);
74 GroupPoints->PushButton2->setPixmap(image1);
75 GroupPoints->LineEdit1->setReadOnly( true );
76 GroupPoints->LineEdit2->setReadOnly( true );
77 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
79 Layout1->addWidget(GroupPoints, 2, 0);
80 /***************************************************************/
87 //=================================================================================
88 // function : ~GenerationGUI_PrismDlg()
89 // purpose : Destroys the object and frees any allocated resources
90 //=================================================================================
91 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
93 /* no need to delete child widgets, Qt does it all for us */
97 //=================================================================================
100 //=================================================================================
101 void GenerationGUI_PrismDlg::Init()
104 myEditCurrentArgument = GroupPoints->LineEdit1;
105 GroupPoints->LineEdit1->setReadOnly( true );
106 GroupPoints->LineEdit2->setReadOnly( true );
108 myOkBase = myOkVec = false;
110 /* Get setting of step value from file configuration */
111 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
112 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
114 /* min, max, step and decimals for spin boxes & initial values */
115 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, +999.999, step, 3);
116 GroupPoints->SpinBox_DX->SetValue(100.0);
118 /* signals and slots connections */
119 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
120 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
122 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
125 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
126 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
128 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
129 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
131 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
133 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
134 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
136 initName(tr("GEOM_PRISM"));
138 globalSelection( GEOM_ALLSHAPES );
142 //=================================================================================
143 // function : ClickOnOk()
145 //=================================================================================
146 void GenerationGUI_PrismDlg::ClickOnOk()
148 if ( ClickOnApply() )
153 //=================================================================================
154 // function : ClickOnApply()
156 //=================================================================================
157 bool GenerationGUI_PrismDlg::ClickOnApply()
167 //=================================================================================
168 // function : SelectionIntoArgument()
169 // purpose : Called when selection has changed
170 //=================================================================================
171 void GenerationGUI_PrismDlg::SelectionIntoArgument()
174 myEditCurrentArgument->setText("");
176 if(IObjectCount() != 1)
178 if(myEditCurrentArgument == GroupPoints->LineEdit1)
180 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
186 Standard_Boolean testResult = Standard_False;
187 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
192 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
196 if ( !GEOMBase::GetShape(aSelectedObject, S) ||
200 myBase = aSelectedObject;
203 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
204 myVec = aSelectedObject;
207 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
213 //=================================================================================
214 // function : SetEditCurrentArgument()
216 //=================================================================================
217 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
219 QPushButton* send = (QPushButton*)sender();
220 globalSelection( GEOM_ALLSHAPES );
222 if(send == GroupPoints->PushButton1) {
223 GroupPoints->LineEdit1->setFocus();
224 myEditCurrentArgument = GroupPoints->LineEdit1;
226 else if(send == GroupPoints->PushButton2) {
227 GroupPoints->LineEdit2->setFocus();
228 myEditCurrentArgument = GroupPoints->LineEdit2;
229 globalSelection( GEOM_LINE );
231 SelectionIntoArgument();
235 //=================================================================================
236 // function : LineEditReturnPressed()
238 //=================================================================================
239 void GenerationGUI_PrismDlg::LineEditReturnPressed()
241 QLineEdit* send = (QLineEdit*)sender();
242 if(send == GroupPoints->LineEdit1 ||
243 send == GroupPoints->LineEdit2)
245 myEditCurrentArgument = send;
246 GEOMBase_Skeleton::LineEditReturnPressed();
250 //=================================================================================
251 // function : enterEvent()
252 // purpose : when mouse enter onto the QWidget
253 //=================================================================================
254 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
256 if ( !GroupConstructors->isEnabled() )
257 ActivateThisDialog();
261 //=================================================================================
262 // function : ActivateThisDialog()
264 //=================================================================================
265 void GenerationGUI_PrismDlg::ActivateThisDialog()
267 GEOMBase_Skeleton::ActivateThisDialog();
268 globalSelection( GEOM_ALLSHAPES );
269 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
270 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
271 GroupPoints->LineEdit1->setFocus();
272 myEditCurrentArgument = GroupPoints->LineEdit1;
277 //=================================================================================
278 // function : ValueChangedInSpinBox()
280 //=================================================================================
281 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
288 //=================================================================================
289 // function : getHeight()
291 //=================================================================================
292 double GenerationGUI_PrismDlg::getHeight() const
294 return GroupPoints->SpinBox_DX->GetValue();
297 //=================================================================================
298 // function : createOperation
300 //=================================================================================
301 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
303 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
306 //=================================================================================
307 // function : isValid
309 //=================================================================================
310 bool GenerationGUI_PrismDlg::isValid( QString& )
312 return myOkBase && myOkVec;
315 //=================================================================================
316 // function : execute
318 //=================================================================================
319 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
321 GEOM::GEOM_Object_var anObj;
323 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation() )->MakePrismVecH ( myBase, myVec, getHeight() );
325 if ( !anObj->_is_nil() )
326 objects.push_back( anObj._retn() );
332 //=================================================================================
333 // function : onReverse()
335 //=================================================================================
336 void GenerationGUI_PrismDlg::onReverse()
338 double anOldValue = GroupPoints->SpinBox_DX->GetValue();
339 GroupPoints->SpinBox_DX->SetValue( -anOldValue );