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");
79 case OperationGUI::CUT:
80 image0 = QPixmap( aResMgr->loadPixmap("GEOM", tr("ICO_EXTRUDED_CUT")));
81 aTitle = tr("GEOM_EXTRUDED_CUT");
85 setWindowTitle(aTitle);
86 mainFrame()->GroupConstructors->setTitle(aTitle);
87 mainFrame()->RadioButton1->setIcon(image0);
88 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
89 mainFrame()->RadioButton2->close();
90 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
91 mainFrame()->RadioButton3->close();
93 mainFrame()->RadioButton1->setChecked(true);
95 myGroup = new DlgRef_2Sel2Spin1Push(centralWidget());
96 myGroup->PushButton1->setIcon(image1);
97 myGroup->PushButton2->setIcon(image1);
98 myGroup->PushButton3->setIcon(image2);
99 myGroup->LineEdit1->setReadOnly(true);
100 myGroup->LineEdit2->setReadOnly(true);
101 myGroup->TextLabel1->setText(tr("GEOM_INIT_SHAPE"));
102 myGroup->TextLabel2->setText(tr("GEOM_SKETCH"));
103 myGroup->TextLabel3->setText(tr("GEOM_HEIGHT"));
106 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
107 layout->setMargin(0);
108 layout->setSpacing(6);
109 layout->addWidget(myGroup);
115 //=================================================================================
116 // function : ~OperationGUI_ExtrudedFeatureDlg()
117 // purpose : Destroys the object and frees any allocated resources
118 //=================================================================================
119 OperationGUI_ExtrudedFeatureDlg::~OperationGUI_ExtrudedFeatureDlg()
123 //=================================================================================
126 //=================================================================================
127 void OperationGUI_ExtrudedFeatureDlg::Init()
130 myEditCurrentArgument = myGroup->LineEdit1;
132 // Get setting of step value from file configuration
133 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
134 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
136 initSpinBox(myGroup->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
137 initSpinBox(myGroup->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
139 myGroup->LineEdit1->setText("");
140 myGroup->LineEdit2->setText("");
141 myGroup->SpinBox_DX->setValue(10.0);
142 myGroup->SpinBox_DY->setValue(10.0);
143 myGroup->SpinBox_DY->setEnabled(false);
147 // signals and slots connections
148 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
149 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
151 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
153 connect(myGroup->PushButton3, SIGNAL(clicked(bool)), this, SLOT(ButtonClicked(bool)));
154 connect(myGroup->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
155 connect(myGroup->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
158 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
159 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
161 initName(mainFrame()->GroupConstructors->title());
163 mainFrame()->RadioButton1->setFocus();
165 globalSelection(GEOM_ALLSHAPES); //TODO à changer
167 myGroup->PushButton1->click();
168 SelectionIntoArgument();
170 resize(minimumSizeHint());
173 //=================================================================================
174 // function : ClickOnOk()
176 //=================================================================================
177 void OperationGUI_ExtrudedFeatureDlg::ClickOnOk()
179 setIsApplyAndClose( true );
184 //=================================================================================
185 // function : ClickOnApply()
187 //=================================================================================
188 bool OperationGUI_ExtrudedFeatureDlg::ClickOnApply()
194 // activate selection and connect selection manager
195 myGroup->PushButton1->click();
199 //=================================================================================
200 // function : SetEditCurrentArgument()
202 //=================================================================================
203 void OperationGUI_ExtrudedFeatureDlg::SetEditCurrentArgument()
205 QPushButton* send = (QPushButton*)sender();
207 if (send == myGroup->PushButton1) {
208 myEditCurrentArgument = myGroup->LineEdit1;
210 myGroup->PushButton2->setDown(false);
211 myGroup->LineEdit2->setEnabled(false);
213 else if (send == myGroup->PushButton2) {
214 myEditCurrentArgument = myGroup->LineEdit2;
216 myGroup->PushButton1->setDown(false);
217 myGroup->LineEdit1->setEnabled(false);
221 myEditCurrentArgument->setEnabled(true);
222 myEditCurrentArgument->setFocus();
223 // after setFocus(), because it will be setDown(false) when loses focus
228 //=================================================================================
229 // function : SelectionIntoArgument()
230 // purpose : Called when selection is changed or on dialog initialization or activation
231 //=================================================================================
232 void OperationGUI_ExtrudedFeatureDlg::SelectionIntoArgument()
234 myEditCurrentArgument->setText("");
236 QList<TopAbs_ShapeEnum> types;
239 if (myEditCurrentArgument == myGroup->LineEdit1)
242 types<<TopAbs_COMPOUND<<TopAbs_SOLID;
244 if (myEditCurrentArgument == myGroup->LineEdit2)
247 types << TopAbs_EDGE << TopAbs_WIRE;
250 GEOM::GeomObjPtr aSelectedObject = getSelected( types );
252 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
253 QString aName = GEOMBase::GetName( aSelectedObject.get() );
254 myEditCurrentArgument->setText( aName );
257 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
258 myGeomGUI->getApp()->selectionMgr()->clearSelected();
259 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
260 this, SLOT(SelectionIntoArgument()));
262 if (myEditCurrentArgument == myGroup->LineEdit1) {
263 myObject1 = aSelectedObject;
265 myGroup->PushButton2->click();
267 else if (myEditCurrentArgument == myGroup->LineEdit2) {
268 myObject2 = aSelectedObject;
270 myGroup->PushButton1->click();
273 displayPreview(true);
276 if (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
277 else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify();
281 //=================================================================================
282 // function : ActivateThisDialog()
284 //=================================================================================
285 void OperationGUI_ExtrudedFeatureDlg::ActivateThisDialog()
287 GEOMBase_Skeleton::ActivateThisDialog();
289 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
290 this, SLOT( SelectionIntoArgument() ) );
295 //=================================================================================
296 // function : enterEvent()
297 // purpose : when mouse enter onto the QWidget
298 //=================================================================================
299 void OperationGUI_ExtrudedFeatureDlg::enterEvent (QEvent*)
301 if (!mainFrame()->GroupConstructors->isEnabled())
302 ActivateThisDialog();
305 //=================================================================================
306 // function : ValueChangedInSpinBox()
308 //=================================================================================
309 void OperationGUI_ExtrudedFeatureDlg::ValueChangedInSpinBox()
311 displayPreview(true);
314 //=================================================================================
315 // function : ButtonClicked(bool checked)
317 //=================================================================================
318 void OperationGUI_ExtrudedFeatureDlg::ButtonClicked(bool checked)
320 myGroup->SpinBox_DY->setEnabled(checked);
321 displayPreview(true);
324 //=================================================================================
325 // function : createOperation
327 //=================================================================================
328 GEOM::GEOM_IOperations_ptr OperationGUI_ExtrudedFeatureDlg::createOperation()
330 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
333 //=================================================================================
334 // function : isValid
336 //=================================================================================
337 bool OperationGUI_ExtrudedFeatureDlg::isValid (QString&)
339 return myObject1 && myObject2;
342 //=================================================================================
343 // function : execute
345 //=================================================================================
346 bool OperationGUI_ExtrudedFeatureDlg::execute (ObjectList& objects)
348 // GEOM::GEOM_Object_var anObj;
350 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
353 if (myGroup->PushButton3->isChecked())
354 angle=myGroup->SpinBox_DY->value();
356 bool isProtrusion = (myOperation == OperationGUI::BOSS);
358 GEOM::GEOM_Object_var anObj = anOper->MakeDraftPrism(myObject1.get(), myObject2.get(),
359 myGroup->SpinBox_DX->value(),
362 // switch (myOperation)
364 // case OperationGUI::BOSS:
365 // anObj = anOper->MakeDraftPrism(myObject1.get(), myObject2.get(),myGroup->SpinBox_DX->value(),angle, true);
367 // case OperationGUI::CUT:
368 // anObj = anOper->MakeDraftPrism(myObject1.get(), myObject2.get(),myGroup->SpinBox_DX->value(),angle, false);
371 if (!anObj->_is_nil())
372 objects.push_back(anObj._retn());