1 // Copyright (C) 2007-2011 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 : OperationGUI_ExtrudedFeatureDlg.cxx
25 // Author : Renaud NEDELEC, Open CASCADE S.A.S.
27 #include "OperationGUI.h"
28 #include "OperationGUI_ExtrudedFeatureDlg.h"
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
35 #include <GeometryGUI.h>
39 #include <GEOM_Object.hxx>
42 // #include <TopoDS_Shape.hxx>
43 // #include <TopoDS_Edge.hxx>
44 // #include <TopoDS.hxx>
45 // #include <TopExp.hxx>
46 // #include <TColStd_IndexedMapOfInteger.hxx>
47 // #include <TopTools_IndexedMapOfShape.hxx>
48 // #include <Precision.hxx>
49 #include <TColStd_HSequenceOfTransient.hxx>
51 #include <GEOMImpl_Types.hxx>
53 //=================================================================================
54 // class : OperationGUI_ExtrudedFeatureDlg()
55 // purpose : Constructs a OperationGUI_ExtrudedCutDlg which is a child of 'parent',
56 // with the name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
61 OperationGUI_ExtrudedFeatureDlg::OperationGUI_ExtrudedFeatureDlg(const int theOperation,
62 GeometryGUI* theGeometryGUI,
63 QWidget* parent,bool modal,
65 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
66 myOperation(theOperation)
68 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
70 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
71 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICO_DRAFT")));
75 case OperationGUI::BOSS:
76 image0 = QPixmap(aResMgr->loadPixmap("GEOM", tr("ICO_EXTRUDED_BOSS")));
77 aTitle = tr("GEOM_EXTRUDED_BOSS");
78 setHelpFileName("extruded_boss_operation_page.html");
80 case OperationGUI::CUT:
81 image0 = QPixmap( aResMgr->loadPixmap("GEOM", tr("ICO_EXTRUDED_CUT")));
82 aTitle = tr("GEOM_EXTRUDED_CUT");
83 setHelpFileName("extruded_cut_operation_page.html");
87 setWindowTitle(aTitle);
88 mainFrame()->GroupConstructors->setTitle(aTitle);
89 mainFrame()->RadioButton1->setIcon(image0);
90 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
91 mainFrame()->RadioButton2->close();
92 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
93 mainFrame()->RadioButton3->close();
95 mainFrame()->RadioButton1->setChecked(true);
97 myGroup = new DlgRef_2Sel2Spin1Push(centralWidget());
98 myGroup->PushButton1->setIcon(image1);
99 myGroup->PushButton2->setIcon(image1);
100 myGroup->PushButton3->setIcon(image2);
101 myGroup->LineEdit1->setReadOnly(true);
102 myGroup->LineEdit2->setReadOnly(true);
103 myGroup->TextLabel1->setText(tr("GEOM_INIT_SHAPE"));
104 myGroup->TextLabel2->setText(tr("GEOM_SKETCH"));
105 myGroup->TextLabel3->setText(tr("GEOM_HEIGHT"));
108 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
109 layout->setMargin(0);
110 layout->setSpacing(6);
111 layout->addWidget(myGroup);
117 //=================================================================================
118 // function : ~OperationGUI_ExtrudedFeatureDlg()
119 // purpose : Destroys the object and frees any allocated resources
120 //=================================================================================
121 OperationGUI_ExtrudedFeatureDlg::~OperationGUI_ExtrudedFeatureDlg()
125 //=================================================================================
128 //=================================================================================
129 void OperationGUI_ExtrudedFeatureDlg::Init()
132 myEditCurrentArgument = myGroup->LineEdit1;
134 // Get setting of step value from file configuration
135 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
136 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
138 initSpinBox(myGroup->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
139 initSpinBox(myGroup->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
141 myGroup->LineEdit1->setText("");
142 myGroup->LineEdit2->setText("");
143 myGroup->SpinBox_DX->setValue(10.0);
144 myGroup->SpinBox_DY->setValue(10.0);
145 myGroup->SpinBox_DY->setEnabled(false);
149 // signals and slots connections
150 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
151 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
153 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
155 connect(myGroup->PushButton3, SIGNAL(clicked(bool)), this, SLOT(ButtonClicked(bool)));
156 connect(myGroup->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
157 connect(myGroup->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
160 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
161 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
163 initName(mainFrame()->GroupConstructors->title());
165 mainFrame()->RadioButton1->setFocus();
167 globalSelection(GEOM_ALLSHAPES); //TODO à changer
169 myGroup->PushButton1->click();
170 SelectionIntoArgument();
172 resize(minimumSizeHint());
175 //=================================================================================
176 // function : ClickOnOk()
178 //=================================================================================
179 void OperationGUI_ExtrudedFeatureDlg::ClickOnOk()
181 setIsApplyAndClose( true );
186 //=================================================================================
187 // function : ClickOnApply()
189 //=================================================================================
190 bool OperationGUI_ExtrudedFeatureDlg::ClickOnApply()
196 // activate selection and connect selection manager
197 myGroup->PushButton1->click();
201 //=================================================================================
202 // function : SetEditCurrentArgument()
204 //=================================================================================
205 void OperationGUI_ExtrudedFeatureDlg::SetEditCurrentArgument()
207 QPushButton* send = (QPushButton*)sender();
209 if (send == myGroup->PushButton1) {
210 myEditCurrentArgument = myGroup->LineEdit1;
212 myGroup->PushButton2->setDown(false);
213 myGroup->LineEdit2->setEnabled(false);
215 // globalSelection(); // close local selection
217 else if (send == myGroup->PushButton2) {
218 myEditCurrentArgument = myGroup->LineEdit2;
220 myGroup->PushButton1->setDown(false);
221 myGroup->LineEdit1->setEnabled(false);
223 // globalSelection(); // close local selection to clear it
225 // // localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
228 // localSelection( myObject1.get(), TopAbs_FACE );
229 // // localSelection( myObject1.get(), TopAbs_EDGE );
231 // /* localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE ); */
235 myEditCurrentArgument->setEnabled(true);
236 myEditCurrentArgument->setFocus();
237 // after setFocus(), because it will be setDown(false) when loses focus
242 //=================================================================================
243 // function : SelectionIntoArgument()
244 // purpose : Called when selection is changed or on dialog initialization or activation
245 //=================================================================================
246 void OperationGUI_ExtrudedFeatureDlg::SelectionIntoArgument()
248 myEditCurrentArgument->setText("");
250 QList<TopAbs_ShapeEnum> types;
253 if (myEditCurrentArgument == myGroup->LineEdit1)
256 types<<TopAbs_COMPOUND<<TopAbs_SOLID;
258 if (myEditCurrentArgument == myGroup->LineEdit2)
261 types << TopAbs_EDGE << TopAbs_WIRE << TopAbs_FACE;
264 GEOM::GeomObjPtr aSelectedObject = getSelected( types );
266 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
267 QString aName = GEOMBase::GetName( aSelectedObject.get() );
268 myEditCurrentArgument->setText( aName );
271 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
272 myGeomGUI->getApp()->selectionMgr()->clearSelected();
273 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
274 this, SLOT(SelectionIntoArgument()));
276 if (myEditCurrentArgument == myGroup->LineEdit1) {
277 myObject1 = aSelectedObject;
279 myGroup->PushButton2->click();
281 else if (myEditCurrentArgument == myGroup->LineEdit2) {
282 myObject2 = aSelectedObject;
284 myGroup->PushButton1->click();
287 displayPreview(true);
290 if (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
291 else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify();
295 //=================================================================================
296 // function : ActivateThisDialog()
298 //=================================================================================
299 void OperationGUI_ExtrudedFeatureDlg::ActivateThisDialog()
301 GEOMBase_Skeleton::ActivateThisDialog();
303 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
304 this, SLOT( SelectionIntoArgument() ) );
309 //=================================================================================
310 // function : enterEvent()
311 // purpose : when mouse enter onto the QWidget
312 //=================================================================================
313 void OperationGUI_ExtrudedFeatureDlg::enterEvent (QEvent*)
315 if (!mainFrame()->GroupConstructors->isEnabled())
316 ActivateThisDialog();
319 //=================================================================================
320 // function : ValueChangedInSpinBox()
322 //=================================================================================
323 void OperationGUI_ExtrudedFeatureDlg::ValueChangedInSpinBox()
325 displayPreview(true);
328 //=================================================================================
329 // function : ButtonClicked(bool checked)
331 //=================================================================================
332 void OperationGUI_ExtrudedFeatureDlg::ButtonClicked(bool checked)
334 myGroup->SpinBox_DY->setEnabled(checked);
335 displayPreview(true);
338 //=================================================================================
339 // function : createOperation
341 //=================================================================================
342 GEOM::GEOM_IOperations_ptr OperationGUI_ExtrudedFeatureDlg::createOperation()
344 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
347 //=================================================================================
348 // function : isValid
350 //=================================================================================
351 bool OperationGUI_ExtrudedFeatureDlg::isValid (QString&)
353 return myObject1 && myObject2;
356 //=================================================================================
357 // function : execute
359 //=================================================================================
360 bool OperationGUI_ExtrudedFeatureDlg::execute (ObjectList& objects)
362 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
365 if (myGroup->PushButton3->isChecked())
366 angle=myGroup->SpinBox_DY->value();
368 bool isProtrusion = (myOperation == OperationGUI::BOSS);
370 // Hide the initial shape in order to see the modifications on the preview
371 erase(myObject1.get(),false);
373 GEOM::GEOM_Object_var anObj = anOper->MakeDraftPrism(myObject1.get(), myObject2.get(),
374 myGroup->SpinBox_DX->value(),
377 if (!anObj->_is_nil())
378 objects.push_back(anObj._retn());
383 // //=================================================================================
384 // // function : addSubshapeToStudy
385 // // purpose : virtual method to add new SubObjects if local selection
386 // //=================================================================================
387 // void OperationGUI_ExtrudedFeatureDlg::addSubshapesToStudy()
389 // GEOMBase::PublishSubObject( myObject2.get() );