1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // GEOM GEOMGUI : GUI for Geometry component
21 // File : OperationGUI_Fillet1d2dDlg.cxx
24 #include "OperationGUI_Fillet1d2dDlg.h"
27 #include <GeometryGUI.h>
30 #include <SUIT_Desktop.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_ViewWindow.h>
34 #include <SUIT_ViewManager.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
37 #include <OCCViewer_ViewModel.h>
40 #include <TColStd_MapOfInteger.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <GEOMImpl_Types.hxx>
45 //=================================================================================
46 // class : OperationGUI_Fillet1d2dDlg()
47 // purpose : Constructs a OperationGUI_Fillet1d2dDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 OperationGUI_Fillet1d2dDlg::OperationGUI_Fillet1d2dDlg (GeometryGUI* theGeometryGUI,
55 : GEOMBase_Skeleton(theGeometryGUI, parent, false),
58 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
59 QPixmap image0 (aResMgr->loadPixmap("GEOM", myIs1D ? tr("ICON_DLG_FILLET_1D")
60 : tr("ICON_DLG_FILLET_2D")));
61 QPixmap iconSelect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
63 setWindowTitle(myIs1D ? tr("GEOM_FILLET_1D_TITLE") : tr("GEOM_FILLET_2D_TITLE"));
65 /***************************************************************/
66 mainFrame()->GroupConstructors->setTitle(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
67 mainFrame()->RadioButton1->setIcon(image0);
68 mainFrame()->RadioButton2->close();
69 mainFrame()->RadioButton3->close();
71 GroupVertexes = new DlgRef_2Sel1Spin2Check (centralWidget());
72 GroupVertexes->GroupBox1->setTitle(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
73 GroupVertexes->TextLabel1->setText(myIs1D ? tr("GEOM_PLANAR_EDGE_WIRE") : tr("GEOM_PLANAR_FACE"));
74 GroupVertexes->TextLabel2->setText(tr("GEOM_VERTEXES"));
75 GroupVertexes->TextLabel3->setText(tr("GEOM_RADIUS"));
76 GroupVertexes->PushButton1->setIcon(iconSelect);
77 GroupVertexes->PushButton2->setIcon(iconSelect);
78 GroupVertexes->LineEdit1->setReadOnly(true);
79 GroupVertexes->LineEdit2->setReadOnly(true);
81 GroupVertexes->CheckButton1->setText(tr("GEOM_FILLET_1D_IGNORE_SECANT"));
82 GroupVertexes->CheckButton1->setChecked(true);
85 GroupVertexes->CheckButton1->close();
86 GroupVertexes->CheckButton2->close();
88 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
89 layout->setMargin(0); layout->setSpacing(6);
90 layout->addWidget(GroupVertexes);
92 /***************************************************************/
94 // Set range of spinboxes
95 double SpecificStep = 10.0;
96 initSpinBox(GroupVertexes->SpinBox_DX, 0.00001, COORD_MAX, SpecificStep, "length_precision" );
98 setHelpFileName(myIs1D ? "fillet1d_operation_page.html" : "fillet2d_operation_page.html");
105 //=================================================================================
106 // function : ~OperationGUI_Fillet1d2dDlg()
107 // purpose : Destroys the object and frees any allocated resources
108 //=================================================================================
109 OperationGUI_Fillet1d2dDlg::~OperationGUI_Fillet1d2dDlg()
113 //=================================================================================
116 //=================================================================================
117 void OperationGUI_Fillet1d2dDlg::Init()
119 // Set Initial values of spinboxes
120 GroupVertexes->SpinBox_DX->setValue(5);
123 GroupVertexes->LineEdit1->setText("");
124 GroupVertexes->LineEdit2->setText("");
126 myShape = GEOM::GEOM_Object::_nil();
130 showOnlyPreviewControl();
132 // signals and slots connections
134 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk() ));
135 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
137 connect(GroupVertexes->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(GroupVertexes->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(GroupVertexes->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
141 connect(GroupVertexes->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143 connect(GroupVertexes->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
145 connect(GroupVertexes->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(processPreview()));
147 initName(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
148 GroupVertexes->PushButton1->click();
150 SelectionIntoArgument();
153 //=================================================================================
154 // function : ClickOnOk()
156 //=================================================================================
157 void OperationGUI_Fillet1d2dDlg::ClickOnOk()
159 setIsApplyAndClose( true );
164 //=================================================================================
165 // function : ClickOnApply()
167 //=================================================================================
168 bool OperationGUI_Fillet1d2dDlg::ClickOnApply()
174 // Reset dialog state
175 GroupVertexes->LineEdit1->setText("");
176 GroupVertexes->LineEdit2->setText("");
177 myShape = GEOM::GEOM_Object::_nil();
179 GroupVertexes->PushButton1->click();
184 //=================================================================================
185 // function : SelectionIntoArgument()
186 // purpose : Called when selection is changed or on dialog initialization or activation
187 //=================================================================================
188 void OperationGUI_Fillet1d2dDlg::SelectionIntoArgument()
191 myEditCurrentArgument->setText("");
193 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
194 SALOME_ListIO aSelList;
195 aSelMgr->selectedObjects(aSelList);
197 // If selection of main object is activated
198 if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
199 myShape = GEOM::GEOM_Object::_nil();
200 if (aSelList.Extent() == 1) {
201 GEOM::GEOM_Object_var anObj =
202 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
204 if ( !anObj->_is_nil() ) {
205 QString aName = GEOMBase::GetName( anObj );
207 if ( GEOMBase::GetShape( anObj, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
208 TColStd_IndexedMapOfInteger aMap;
209 aSelMgr->GetIndexes(aSelList.First(), aMap);
210 if ( aMap.Extent() == 1 ) { // Local Selection
211 int anIndex = aMap( 1 );
212 aName += QString( myIs1D ? ":wire_%1" : ":face_%1" ).arg( anIndex );
214 //Find SubShape Object in Father
215 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( anObj, aName );
217 if ( aFindedObject->_is_nil()) { // Object not found in study
218 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
219 anObj = aShapesOp->GetSubShape( anObj, anIndex );
222 anObj = aFindedObject; // get Object from study
224 else { // Global Selection
225 if ((myIs1D && aShape.ShapeType() != TopAbs_WIRE) ||
226 (!myIs1D && aShape.ShapeType() != TopAbs_FACE && aShape.ShapeType() != TopAbs_SHELL)) {
227 anObj = GEOM::GEOM_Object::_nil();
233 myEditCurrentArgument->setText(aName
238 } else if (myEditCurrentArgument == GroupVertexes->LineEdit2) {
240 bool isPreview = myIs1D;
241 if (aSelList.Extent() == 1) {
242 GEOM::GEOM_Object_var anObj =
243 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
245 if ( !anObj->_is_nil() ) {
246 TColStd_IndexedMapOfInteger anIndexes;
247 aSelMgr->GetIndexes(aSelList.First(), anIndexes);
249 if (anIndexes.Extent() > 0) {
251 if (anIndexes.Extent() == 1) {
252 int anIndex = anIndexes(1);
253 aName = QString(GEOMBase::GetName(anObj)) + QString(":vertex_%1").arg(anIndex);
256 aName = tr("GEOM_MEN_POPUP_NAME").arg(anIndexes.Extent());
259 myEditCurrentArgument->setText(aName);
260 myVertexes = anIndexes;
268 if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
269 if (!myShape->_is_nil() && myVertexes.Extent() == 0)
270 GroupVertexes->PushButton2->click();
274 //=================================================================================
275 // function : SetEditCurrentArgument()
277 //=================================================================================
278 void OperationGUI_Fillet1d2dDlg::SetEditCurrentArgument()
280 QPushButton* send = (QPushButton*)sender();
282 if (send == GroupVertexes->PushButton1) {
283 myEditCurrentArgument = GroupVertexes->LineEdit1;
284 GroupVertexes->PushButton2->setDown(false);
285 GroupVertexes->LineEdit2->setEnabled(false);
287 else if (send == GroupVertexes->PushButton2) {
288 myEditCurrentArgument = GroupVertexes->LineEdit2;
289 GroupVertexes->PushButton1->setDown(false);
290 GroupVertexes->LineEdit1->setEnabled(false);
294 myEditCurrentArgument->setEnabled(true);
295 myEditCurrentArgument->setFocus();
296 // after setFocus(), because it will be setDown(false) when loses focus
301 // seems we need it only to avoid preview disappearing, caused by selection mode change
305 //=================================================================================
306 // function : LineEditReturnPressed()
308 //=================================================================================
309 void OperationGUI_Fillet1d2dDlg::LineEditReturnPressed()
311 QLineEdit* send = (QLineEdit*)sender();
313 if (send == GroupVertexes->LineEdit1)
314 myEditCurrentArgument = GroupVertexes->LineEdit1;
315 else if (send == GroupVertexes->LineEdit2)
316 myEditCurrentArgument = GroupVertexes->LineEdit2;
320 GEOMBase_Skeleton::LineEditReturnPressed();
323 //=================================================================================
324 // function : ActivateThisDialog()
326 //=================================================================================
327 void OperationGUI_Fillet1d2dDlg::ActivateThisDialog()
329 GEOMBase_Skeleton::ActivateThisDialog();
332 //=================================================================================
333 // function : enterEvent()
335 //=================================================================================
336 void OperationGUI_Fillet1d2dDlg::enterEvent (QEvent*)
338 if (!mainFrame()->GroupConstructors->isEnabled())
339 this->ActivateThisDialog();
342 //=================================================================================
343 // function : ValueChangedInSpinBox()
345 //=================================================================================
346 void OperationGUI_Fillet1d2dDlg::ValueChangedInSpinBox (double)
351 //=================================================================================
352 // function : activateSelection
353 // purpose : Activate selection in accordance with myEditCurrentArgument
354 //=================================================================================
355 void OperationGUI_Fillet1d2dDlg::activateSelection()
357 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
359 if (myEditCurrentArgument == GroupVertexes->LineEdit1)
360 //localSelection(myShape, myIs1D ? TopAbs_WIRE : TopAbs_FACE);
362 globalSelection(GEOM_WIRE);
364 TColStd_MapOfInteger aMap;
366 aMap.Add(GEOM_SHELL);
367 globalSelection(aMap);
369 else if (!myShape->_is_nil() && myEditCurrentArgument == GroupVertexes->LineEdit2)
370 localSelection(myShape, TopAbs_VERTEX);
372 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
373 this, SLOT(SelectionIntoArgument()));
376 //=================================================================================
377 // function : createOperation
379 //=================================================================================
380 GEOM::GEOM_IOperations_ptr OperationGUI_Fillet1d2dDlg::createOperation()
382 return getGeomEngine()->GetILocalOperations(getStudyId());
385 //=================================================================================
386 // function : isValid()
387 // purpose : Verify validity of input data
388 //=================================================================================
389 bool OperationGUI_Fillet1d2dDlg::isValid (QString& msg)
391 bool ok = !myShape->_is_nil();
392 ok = GroupVertexes->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
393 ok = (myIs1D || myVertexes.Extent() > 0) && ok;
397 //=================================================================================
398 // function : execute
400 //=================================================================================
401 bool OperationGUI_Fillet1d2dDlg::execute (ObjectList& objects)
403 GEOM::ListOfLong_var aListOfIndexes = new GEOM::ListOfLong;
404 aListOfIndexes->length(myVertexes.Extent());
406 for (int i = 1, n = myVertexes.Extent(); i <= n; i++)
407 aListOfIndexes[ i - 1 ] = myVertexes(i);
409 GEOM::GEOM_ILocalOperations_var anOper = GEOM::GEOM_ILocalOperations::_narrow(getOperation());
410 GEOM::GEOM_Object_var anObj = myIs1D ?
411 anOper->MakeFillet1D(myShape, getRadius(), aListOfIndexes, GroupVertexes->CheckButton1->isChecked()) :
412 anOper->MakeFillet2D(myShape, getRadius(), aListOfIndexes);
414 if (!anObj->_is_nil())
415 objects.push_back(anObj._retn());
420 //=================================================================================
421 // function : getRadius
422 // purpose : Get radius
423 //=================================================================================
424 double OperationGUI_Fillet1d2dDlg::getRadius() const
426 return GroupVertexes->SpinBox_DX->value();