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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : OperationGUI_Fillet2dDlg.cxx
26 #include "OperationGUI_Fillet2dDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_ViewWindow.h>
36 #include <SUIT_ViewManager.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
39 #include <OCCViewer_ViewModel.h>
42 #include <TColStd_MapOfInteger.hxx>
43 #include <TColStd_IndexedMapOfInteger.hxx>
45 #include <GEOMImpl_Types.hxx>
47 //=================================================================================
48 // class : OperationGUI_Fillet2dDlg()
49 // purpose : Constructs a OperationGUI_Fillet2dDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 OperationGUI_Fillet2dDlg::OperationGUI_Fillet2dDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
55 : GEOMBase_Skeleton(theGeometryGUI, parent, false)
57 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
58 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_FILLET_2D")));
59 QPixmap iconSelect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
61 setWindowTitle(tr("GEOM_FILLET_2D_TITLE"));
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle(tr("GEOM_FILLET_2D"));
65 mainFrame()->RadioButton1->setIcon(image0);
66 mainFrame()->RadioButton2->close();
67 mainFrame()->RadioButton3->close();
69 GroupVertexes = new DlgRef_2Sel1Spin(centralWidget());
70 GroupVertexes->GroupBox1->setTitle(tr("GEOM_FILLET_2D"));
71 GroupVertexes->TextLabel1->setText(tr("GEOM_PLANAR_FACE"));
72 GroupVertexes->TextLabel2->setText(tr("GEOM_VERTEXES"));
73 GroupVertexes->TextLabel3->setText(tr("GEOM_RADIUS"));
74 GroupVertexes->PushButton1->setIcon(iconSelect);
75 GroupVertexes->PushButton2->setIcon(iconSelect);
76 GroupVertexes->LineEdit1->setReadOnly(true);
77 GroupVertexes->LineEdit2->setReadOnly(true);
79 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
80 layout->setMargin(0); layout->setSpacing(6);
81 layout->addWidget(GroupVertexes);
83 /***************************************************************/
85 // Set range of spinboxes
86 double SpecificStep = 10.0;
87 initSpinBox(GroupVertexes->SpinBox_DX, 0.00001, COORD_MAX, SpecificStep, 5); // VSR: TODO: DBL_DIGITS_DISPLAY
89 setHelpFileName("fillet2d_operation_page.html");
96 //=================================================================================
97 // function : ~OperationGUI_Fillet2dDlg()
98 // purpose : Destroys the object and frees any allocated resources
99 //=================================================================================
100 OperationGUI_Fillet2dDlg::~OperationGUI_Fillet2dDlg()
104 //=================================================================================
107 //=================================================================================
108 void OperationGUI_Fillet2dDlg::Init()
110 // Set Initial values of spinboxes
111 GroupVertexes->SpinBox_DX->setValue(5);
114 GroupVertexes->LineEdit1->setText("");
115 GroupVertexes->LineEdit2->setText("");
117 myShape = GEOM::GEOM_Object::_nil();
121 // signals and slots connections
123 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk() ));
124 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
126 // connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
128 connect(GroupVertexes->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(GroupVertexes->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(GroupVertexes->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132 connect(GroupVertexes->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(GroupVertexes->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
136 initName(tr("GEOM_FILLET_2D"));
137 GroupVertexes->PushButton1->click();
140 //=================================================================================
141 // function : ClickOnOk()
143 //=================================================================================
144 void OperationGUI_Fillet2dDlg::ClickOnOk()
150 //=================================================================================
151 // function : ClickOnApply()
153 //=================================================================================
154 bool OperationGUI_Fillet2dDlg::ClickOnApply()
160 // Reset dialog state
161 GroupVertexes->LineEdit1->setText("");
162 GroupVertexes->LineEdit2->setText("");
163 myShape = GEOM::GEOM_Object::_nil();
165 GroupVertexes->PushButton1->click();
170 //=================================================================================
171 // function : SelectionIntoArgument()
172 // purpose : Called when selection is changed or on dialog initialization or activation
173 //=================================================================================
174 void OperationGUI_Fillet2dDlg::SelectionIntoArgument()
177 myEditCurrentArgument->setText("");
179 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
180 SALOME_ListIO aSelList;
181 aSelMgr->selectedObjects(aSelList);
183 // If selection of main object is activated
184 if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
185 myShape = GEOM::GEOM_Object::_nil();
186 if (aSelList.Extent() == 1) {
187 Standard_Boolean aResult = Standard_False;
188 GEOM::GEOM_Object_var anObj =
189 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
191 if (aResult && !anObj->_is_nil()) {
192 QString aName = GEOMBase::GetName( anObj );
194 if ( GEOMBase::GetShape( anObj, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
195 TColStd_IndexedMapOfInteger aMap;
196 aSelMgr->GetIndexes(aSelList.First(), aMap);
197 if ( aMap.Extent() == 1 ) { // Local Selection
198 int anIndex = aMap( 1 );
199 aName += QString( ":face_%1" ).arg( anIndex );
201 //Find SubShape Object in Father
202 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( anObj, aName );
204 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
205 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
206 anObj = aShapesOp->GetSubShape( anObj, anIndex );
209 anObj = aFindedObject; // get Object from study
211 else { // Global Selection
212 if ( aShape.ShapeType() != TopAbs_FACE ) {
213 anObj = GEOM::GEOM_Object::_nil();
219 myEditCurrentArgument->setText(aName
224 } else if (myEditCurrentArgument == GroupVertexes->LineEdit2) {
226 if (aSelList.Extent() == 1) {
227 Standard_Boolean aResult = Standard_False;
228 GEOM::GEOM_Object_var anObj =
229 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
231 if (aResult && !anObj->_is_nil()) {
232 TColStd_IndexedMapOfInteger anIndexes;
233 aSelMgr->GetIndexes(aSelList.First(), anIndexes);
235 if (anIndexes.Extent() > 0) {
237 if (anIndexes.Extent() == 1) {
238 int anIndex = anIndexes(1);
239 aName = QString(GEOMBase::GetName(anObj)) + QString(":vertex_%1").arg(anIndex);
242 aName = tr("GEOM_MEN_POPUP_NAME").arg(anIndexes.Extent());
244 myEditCurrentArgument->setText(aName);
245 myVertexes = anIndexes;
252 if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
253 if (!myShape->_is_nil() && myVertexes.Extent() == 0)
254 GroupVertexes->PushButton2->click();
258 //=================================================================================
259 // function : SetEditCurrentArgument()
261 //=================================================================================
262 void OperationGUI_Fillet2dDlg::SetEditCurrentArgument()
264 QPushButton* send = (QPushButton*)sender();
266 if (send == GroupVertexes->PushButton1) {
267 myEditCurrentArgument = GroupVertexes->LineEdit1;
268 GroupVertexes->PushButton2->setDown(false);
269 GroupVertexes->LineEdit2->setEnabled(false);
271 else if (send == GroupVertexes->PushButton2) {
272 myEditCurrentArgument = GroupVertexes->LineEdit2;
273 GroupVertexes->PushButton1->setDown(false);
274 GroupVertexes->LineEdit1->setEnabled(false);
278 myEditCurrentArgument->setEnabled(true);
279 myEditCurrentArgument->setFocus();
280 // after setFocus(), because it will be setDown(false) when loses focus
285 // seems we need it only to avoid preview disappearing, caused by selection mode change
289 //=================================================================================
290 // function : LineEditReturnPressed()
292 //=================================================================================
293 void OperationGUI_Fillet2dDlg::LineEditReturnPressed()
295 QLineEdit* send = (QLineEdit*)sender();
297 if (send == GroupVertexes->LineEdit1)
298 myEditCurrentArgument = GroupVertexes->LineEdit1;
299 else if (send == GroupVertexes->LineEdit2)
300 myEditCurrentArgument = GroupVertexes->LineEdit2;
304 GEOMBase_Skeleton::LineEditReturnPressed();
307 //=================================================================================
308 // function : ActivateThisDialog()
310 //=================================================================================
311 void OperationGUI_Fillet2dDlg::ActivateThisDialog()
313 GEOMBase_Skeleton::ActivateThisDialog();
316 //=================================================================================
317 // function : enterEvent()
319 //=================================================================================
320 void OperationGUI_Fillet2dDlg::enterEvent (QEvent*)
322 if (!mainFrame()->GroupConstructors->isEnabled())
323 this->ActivateThisDialog();
326 //=================================================================================
327 // function : ValueChangedInSpinBox()
329 //=================================================================================
330 void OperationGUI_Fillet2dDlg::ValueChangedInSpinBox (double)
335 //=================================================================================
336 // function : activateSelection
337 // purpose : Activate selection in accordance with myEditCurrentArgument
338 //=================================================================================
339 void OperationGUI_Fillet2dDlg::activateSelection()
341 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
343 if (myEditCurrentArgument == GroupVertexes->LineEdit1)
344 globalSelection( GEOM_FACE ); // localSelection(myShape, TopAbs_FACE);
345 else if (!myShape->_is_nil() && myEditCurrentArgument == GroupVertexes->LineEdit2)
346 localSelection(myShape, TopAbs_VERTEX);
348 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
349 this, SLOT(SelectionIntoArgument()));
352 //=================================================================================
353 // function : createOperation
355 //=================================================================================
356 GEOM::GEOM_IOperations_ptr OperationGUI_Fillet2dDlg::createOperation()
358 return getGeomEngine()->GetILocalOperations(getStudyId());
361 //=================================================================================
362 // function : isValid()
363 // purpose : Verify validity of input data
364 //=================================================================================
365 bool OperationGUI_Fillet2dDlg::isValid (QString&)
367 return !myShape->_is_nil() && myVertexes.Extent() > 0;
370 //=================================================================================
371 // function : execute
373 //=================================================================================
374 bool OperationGUI_Fillet2dDlg::execute (ObjectList& objects)
376 GEOM::GEOM_Object_var anObj;
378 GEOM::ListOfLong_var aListOfIndexes = new GEOM::ListOfLong;
379 aListOfIndexes->length(myVertexes.Extent());
381 for (int i = 1, n = myVertexes.Extent(); i <= n; i++)
382 aListOfIndexes[ i - 1 ] = myVertexes(i);
384 anObj = GEOM::GEOM_ILocalOperations::_narrow(getOperation())->
385 MakeFillet2D(myShape, getRadius(), aListOfIndexes);
387 if (!anObj->_is_nil())
388 objects.push_back(anObj._retn());
393 //=================================================================================
394 // function : getRadius
395 // purpose : Get radius
396 //=================================================================================
397 double OperationGUI_Fillet2dDlg::getRadius() const
399 return GroupVertexes ->SpinBox_DX->value();