1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GenerationGUI_PrismDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "GenerationGUI_PrismDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Edge.hxx>
43 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <GEOMImpl_Types.hxx>
48 //=================================================================================
49 // class : GenerationGUI_PrismDlg()
50 // purpose : Constructs a GenerationGUI_PrismDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 GenerationGUI_PrismDlg::GenerationGUI_PrismDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
56 bool modal, Qt::WindowFlags fl)
57 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
59 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
60 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PRISM")));
61 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
62 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PRISM_2P")));
63 QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PRISM_DXDYDZ")));
65 setWindowTitle(tr("GEOM_EXTRUSION_TITLE"));
67 /***************************************************************/
68 mainFrame()->GroupConstructors->setTitle(tr("GEOM_EXTRUSION"));
69 mainFrame()->RadioButton1->setIcon(image0);
70 mainFrame()->RadioButton2->setIcon(image2);
71 mainFrame()->RadioButton3->setIcon(image3);
73 mainFrame()->RadioButton1->setChecked(true);
75 GroupPoints = new DlgRef_2Sel1Spin2Check(centralWidget());
76 GroupPoints->GroupBox1->setTitle(tr("GEOM_EXTRUSION_BSV"));
77 GroupPoints->TextLabel1->setText(tr("GEOM_BASE"));
78 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
79 GroupPoints->TextLabel3->setText(tr("GEOM_HEIGHT"));
80 GroupPoints->PushButton1->setIcon(image1);
81 GroupPoints->PushButton2->setIcon(image1);
82 GroupPoints->LineEdit1->setReadOnly(true);
83 GroupPoints->LineEdit2->setReadOnly(true);
84 GroupPoints->CheckButton1->setText(tr("GEOM_BOTHWAY"));
85 GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
87 GroupPoints2 = new DlgRef_3Sel1Check(centralWidget());
88 GroupPoints2->GroupBox1->setTitle(tr("GEOM_EXTRUSION_BSV_2P"));
89 GroupPoints2->TextLabel1->setText(tr("GEOM_BASE"));
90 GroupPoints2->TextLabel2->setText(tr("GEOM_POINT_I").arg(1));
91 GroupPoints2->TextLabel3->setText(tr("GEOM_POINT_I").arg(2));
92 GroupPoints2->PushButton1->setIcon(image1);
93 GroupPoints2->PushButton2->setIcon(image1);
94 GroupPoints2->PushButton3->setIcon(image1);
95 GroupPoints2->CheckButton1->setText(tr("GEOM_BOTHWAY"));
97 GroupPoints3 = new DlgRef_1Sel3Spin1Check(centralWidget());
98 GroupPoints3->GroupBox1->setTitle(tr("GEOM_EXTRUSION_DXDYDZ"));
99 GroupPoints3->TextLabel1->setText(tr("GEOM_BASE"));
100 GroupPoints3->PushButton1->setIcon(image1);
101 GroupPoints3->TextLabel2->setText(tr("GEOM_DX"));
102 GroupPoints3->TextLabel3->setText(tr("GEOM_DY"));
103 GroupPoints3->TextLabel4->setText(tr("GEOM_DZ"));
104 GroupPoints3->CheckButton1->setText(tr("GEOM_BOTHWAY"));
106 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
107 layout->setMargin(0); layout->setSpacing(6);
108 layout->addWidget(GroupPoints);
109 layout->addWidget(GroupPoints2);
110 layout->addWidget(GroupPoints3);
111 /***************************************************************/
113 setHelpFileName("create_extrusion_page.html");
118 //=================================================================================
119 // function : ~GenerationGUI_PrismDlg()
120 // purpose : Destroys the object and frees any allocated resources
121 //=================================================================================
122 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
124 // no need to delete child widgets, Qt does it all for us
127 //=================================================================================
130 //=================================================================================
131 void GenerationGUI_PrismDlg::Init()
133 // Get setting of step value from file configuration
134 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
135 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
137 // min, max, step and decimals for spin boxes & initial values
138 initSpinBox(GroupPoints3->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
139 initSpinBox(GroupPoints3->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
140 initSpinBox(GroupPoints3->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
141 GroupPoints3->SpinBox_DX->setValue(0.0);
142 GroupPoints3->SpinBox_DY->setValue(0.0);
143 GroupPoints3->SpinBox_DZ->setValue(0.0);
145 initSpinBox(GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
146 GroupPoints->SpinBox_DX->setValue(100.0);
149 myEditCurrentArgument = GroupPoints->LineEdit1;
150 GroupPoints->LineEdit1->setReadOnly(true);
151 GroupPoints->LineEdit2->setReadOnly(true);
153 GroupPoints2->LineEdit1->setReadOnly(true);
154 GroupPoints2->LineEdit2->setReadOnly(true);
155 GroupPoints2->LineEdit3->setReadOnly(true);
157 GroupPoints3->LineEdit1->setReadOnly(true);
159 GroupPoints->LineEdit1->setText("");
160 GroupPoints->LineEdit2->setText("");
162 GroupPoints2->LineEdit1->setText("");
163 GroupPoints2->LineEdit2->setText("");
164 GroupPoints2->LineEdit3->setText("");
166 GroupPoints3->LineEdit1->setText("");
168 myBaseObjects.clear();
173 // signals and slots connections
174 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
175 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
177 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
179 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
180 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
182 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
183 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
185 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(onBothway()));
186 connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
188 connect(GroupPoints2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
189 connect(GroupPoints2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
190 connect(GroupPoints2->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
191 connect(GroupPoints2->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(onBothway()));
193 connect(GroupPoints3->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
194 connect(GroupPoints3->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
195 connect(GroupPoints3->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
196 connect(GroupPoints3->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
197 connect(GroupPoints3->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(onBothway()));
199 initName(tr("GEOM_EXTRUSION"));
201 ConstructorsClicked(0);
204 //=================================================================================
205 // function : SetDoubleSpinBoxStep()
206 // purpose : Double spin box management
207 //=================================================================================
208 void GenerationGUI_PrismDlg::SetDoubleSpinBoxStep (double step)
210 GroupPoints->SpinBox_DX->setSingleStep(step);
211 GroupPoints3->SpinBox_DX->setSingleStep(step);
212 GroupPoints3->SpinBox_DY->setSingleStep(step);
213 GroupPoints3->SpinBox_DZ->setSingleStep(step);
216 //=================================================================================
217 // function : ConstructorsClicked()
218 // purpose : Radio button management
219 //=================================================================================
220 void GenerationGUI_PrismDlg::ConstructorsClicked (int constructorId)
222 switch (constructorId) {
224 GroupPoints2->hide();
225 GroupPoints3->hide();
228 GroupPoints->LineEdit2->setText("");
231 GroupPoints->PushButton1->click();
235 GroupPoints2->show();
236 GroupPoints3->hide();
238 GroupPoints2->LineEdit2->setText("");
239 GroupPoints2->LineEdit3->setText("");
243 GroupPoints2->PushButton1->click();
247 GroupPoints2->hide();
248 GroupPoints3->show();
250 GroupPoints3->PushButton1->click();
256 qApp->processEvents();
258 resize(minimumSizeHint());
260 SelectionIntoArgument();
264 //=================================================================================
265 // function : ClickOnOk()
267 //=================================================================================
268 void GenerationGUI_PrismDlg::ClickOnOk()
274 //=================================================================================
275 // function : ClickOnApply()
277 //=================================================================================
278 bool GenerationGUI_PrismDlg::ClickOnApply()
284 // activate selection and connect selection manager
285 ConstructorsClicked(getConstructorId());
289 //=================================================================================
290 // function : SelectionIntoArgument()
291 // purpose : Called when selection is changed or on dialog initialization or activation
292 //=================================================================================
293 void GenerationGUI_PrismDlg::SelectionIntoArgument()
296 myEditCurrentArgument->setText("");
298 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ||
299 myEditCurrentArgument == GroupPoints2->LineEdit1 ||
300 myEditCurrentArgument == GroupPoints3->LineEdit1 ) {
301 myBaseObjects.clear();
302 QList<GEOM::GeomObjPtr> objects = getSelected( TopAbs_SHAPE, -1 );
303 for ( int i = 0; i < objects.count(); i++ ) {
304 GEOM::shape_type stype = objects[i]->GetMaxShapeType();
305 if ( stype < GEOM::SHELL || stype > GEOM::VERTEX )
307 myBaseObjects << objects[i];
309 if ( !myBaseObjects.isEmpty() ) {
310 QString aName = myBaseObjects.count() > 1 ? QString( "%1_objects").arg( myBaseObjects.count() ) : GEOMBase::GetName( myBaseObjects[0].get() );
311 GroupPoints->LineEdit1->setText( aName );
312 GroupPoints2->LineEdit1->setText( aName );
313 GroupPoints3->LineEdit1->setText( aName );
316 GroupPoints->LineEdit1->setText( "" );
317 GroupPoints2->LineEdit1->setText( "" );
318 GroupPoints3->LineEdit1->setText( "" );
321 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
322 myVec = getSelected( TopAbs_EDGE );
324 QString aName = GEOMBase::GetName( myVec.get() );
325 myEditCurrentArgument->setText( aName );
326 if ( myBaseObjects.isEmpty() )
327 GroupPoints->PushButton1->click();
330 if ( myEditCurrentArgument == GroupPoints2->LineEdit2 ) {
331 myPoint1 = getSelected( TopAbs_VERTEX );
333 QString aName = GEOMBase::GetName( myPoint1.get() );
334 myEditCurrentArgument->setText( aName );
336 GroupPoints2->PushButton3->click();
337 else if ( myBaseObjects.isEmpty() )
338 GroupPoints2->PushButton1->click();
341 if ( myEditCurrentArgument == GroupPoints2->LineEdit3 ) {
342 myPoint2 = getSelected( TopAbs_VERTEX );
344 QString aName = GEOMBase::GetName( myPoint2.get() );
345 myEditCurrentArgument->setText( aName );
346 if ( myBaseObjects.isEmpty() )
347 GroupPoints2->PushButton1->click();
348 else if ( !myPoint1 )
349 GroupPoints2->PushButton2->click();
356 //=================================================================================
357 // function : SetEditCurrentArgument()
359 //=================================================================================
360 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
362 QPushButton* send = (QPushButton*)sender();
364 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
365 globalSelection(GEOM_ALLSHAPES);
366 if (send == GroupPoints->PushButton1) {
367 myEditCurrentArgument = GroupPoints->LineEdit1;
368 GroupPoints->PushButton2->setDown(false);
369 GroupPoints->LineEdit2->setEnabled(false);
371 else if (send == GroupPoints->PushButton2) {
372 myEditCurrentArgument = GroupPoints->LineEdit2;
373 GroupPoints->PushButton1->setDown(false);
374 GroupPoints->LineEdit1->setEnabled(false);
375 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
377 else if (send == GroupPoints2->PushButton1) {
378 myEditCurrentArgument = GroupPoints2->LineEdit1;
379 GroupPoints2->PushButton2->setDown(false);
380 GroupPoints2->PushButton3->setDown(false);
381 GroupPoints2->LineEdit2->setEnabled(false);
382 GroupPoints2->LineEdit3->setEnabled(false);
384 else if (send == GroupPoints2->PushButton2) {
385 myEditCurrentArgument = GroupPoints2->LineEdit2;
386 GroupPoints2->PushButton1->setDown(false);
387 GroupPoints2->PushButton3->setDown(false);
388 GroupPoints2->LineEdit1->setEnabled(false);
389 GroupPoints2->LineEdit3->setEnabled(false);
390 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
392 else if (send == GroupPoints2->PushButton3) {
393 myEditCurrentArgument = GroupPoints2->LineEdit3;
394 GroupPoints2->PushButton1->setDown(false);
395 GroupPoints2->PushButton2->setDown(false);
396 GroupPoints2->LineEdit1->setEnabled(false);
397 GroupPoints2->LineEdit2->setEnabled(false);
398 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
400 else if (send == GroupPoints3->PushButton1) {
401 myEditCurrentArgument = GroupPoints3->LineEdit1;
403 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
404 this, SLOT(SelectionIntoArgument()));
407 myEditCurrentArgument->setEnabled(true);
408 myEditCurrentArgument->setFocus();
409 // after setFocus(), because it will be setDown(false) when loses focus
412 // seems we need it only to avoid preview disappearing, caused by selection mode change
416 //=================================================================================
417 // function : ActivateThisDialog()
419 //=================================================================================
420 void GenerationGUI_PrismDlg::ActivateThisDialog()
422 GEOMBase_Skeleton::ActivateThisDialog();
424 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
425 this, SLOT( SelectionIntoArgument() ) );
427 ConstructorsClicked( getConstructorId() );
430 //=================================================================================
431 // function : enterEvent()
432 // purpose : when mouse enter onto the QWidget
433 //=================================================================================
434 void GenerationGUI_PrismDlg::enterEvent (QEvent*)
436 if (!mainFrame()->GroupConstructors->isEnabled())
437 ActivateThisDialog();
440 //=================================================================================
441 // function : ValueChangedInSpinBox()
443 //=================================================================================
444 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
449 //=================================================================================
450 // function : getHeight()
452 //=================================================================================
453 double GenerationGUI_PrismDlg::getHeight() const
455 return GroupPoints->SpinBox_DX->value();
458 //=================================================================================
459 // function : createOperation
461 //=================================================================================
462 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
464 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
467 //=================================================================================
468 // function : isValid
470 //=================================================================================
471 bool GenerationGUI_PrismDlg::isValid (QString& msg)
474 switch ( getConstructorId() ) {
476 ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) &&
477 !myBaseObjects.isEmpty() && myVec;
480 ok = !myBaseObjects.isEmpty() && myPoint1 && myPoint2;
483 ok = GroupPoints3->SpinBox_DX->isValid( msg, !IsPreview() ) &&
484 GroupPoints3->SpinBox_DY->isValid( msg, !IsPreview() ) &&
485 GroupPoints3->SpinBox_DZ->isValid( msg, !IsPreview() ) &&
486 !myBaseObjects.isEmpty();
495 //=================================================================================
496 // function : execute
498 //=================================================================================
499 bool GenerationGUI_PrismDlg::execute (ObjectList& objects)
501 QStringList aParameters;
502 GEOM::GEOM_Object_var anObj;
504 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
506 for (int i = 0; i < myBaseObjects.count(); i++) {
507 switch (getConstructorId()) {
509 if (!GroupPoints->CheckButton1->isChecked())
510 anObj = anOper->MakePrismVecH(myBaseObjects[i].get(), myVec.get(), getHeight());
512 anObj = anOper->MakePrismVecH2Ways(myBaseObjects[i].get(), myVec.get(), getHeight());
514 if (!anObj->_is_nil() && !IsPreview()) {
515 aParameters << GroupPoints->SpinBox_DX->text();
516 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
520 if (!GroupPoints2->CheckButton1->isChecked())
521 anObj = anOper->MakePrismTwoPnt(myBaseObjects[i].get(), myPoint1.get(), myPoint2.get());
523 anObj = anOper->MakePrismTwoPnt2Ways(myBaseObjects[i].get(), myPoint1.get(), myPoint2.get());
526 double dx = GroupPoints3->SpinBox_DX->value();
527 double dy = GroupPoints3->SpinBox_DY->value();
528 double dz = GroupPoints3->SpinBox_DZ->value();
530 if (!GroupPoints3->CheckButton1->isChecked())
531 anObj = anOper->MakePrismDXDYDZ(myBaseObjects[i].get(), dx, dy, dz);
533 anObj = anOper->MakePrismDXDYDZ2Ways(myBaseObjects[i].get(), dx, dy, dz);
535 if (!anObj->_is_nil() && !IsPreview()) {
536 aParameters << GroupPoints3->SpinBox_DX->text();
537 aParameters << GroupPoints3->SpinBox_DY->text();
538 aParameters << GroupPoints3->SpinBox_DZ->text();
539 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
544 if (!anObj->_is_nil())
545 objects.push_back(anObj._retn());
551 //=================================================================================
552 // function : onReverse()
554 //=================================================================================
555 void GenerationGUI_PrismDlg::onReverse()
557 double anOldValue = GroupPoints->SpinBox_DX->value();
558 GroupPoints->SpinBox_DX->setValue(-anOldValue);
561 //=================================================================================
562 // function : onBothway()
564 //=================================================================================
565 void GenerationGUI_PrismDlg::onBothway()
567 GroupPoints->CheckButton2->setEnabled(!GroupPoints->CheckButton1->isChecked());
571 //=================================================================================
572 // function : addSubshapeToStudy
573 // purpose : virtual method to add new SubObjects if local selection
574 //=================================================================================
575 void GenerationGUI_PrismDlg::addSubshapesToStudy()
577 switch (getConstructorId()) {
579 GEOMBase::PublishSubObject( myVec.get() );
582 GEOMBase::PublishSubObject( myPoint1.get() );
583 GEOMBase::PublishSubObject( myPoint2.get() );
590 //=================================================================================
591 // function : extractPrefix
592 // purpose : redefined from GEOMBase_Helper class
593 //=================================================================================
594 bool GenerationGUI_PrismDlg::extractPrefix() const
596 return myBaseObjects.count() > 1;