1 // Copyright (C) 2007-2012 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
19 // GEOM GEOMGUI : GUI for Geometry component
20 // File : OperationGUI_Fillet1d2dDlg.cxx
23 #include "OperationGUI_Fillet1d2dDlg.h"
26 #include <GeometryGUI.h>
29 #include <SUIT_Desktop.h>
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_ViewWindow.h>
33 #include <SUIT_ViewManager.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36 #include <OCCViewer_ViewModel.h>
39 #include <TColStd_MapOfInteger.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <GEOMImpl_Types.hxx>
44 //=================================================================================
45 // class : OperationGUI_Fillet1d2dDlg()
46 // purpose : Constructs a OperationGUI_Fillet1d2dDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 OperationGUI_Fillet1d2dDlg::OperationGUI_Fillet1d2dDlg (GeometryGUI* theGeometryGUI,
54 : GEOMBase_Skeleton(theGeometryGUI, parent, false),
57 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
58 QPixmap image0 (aResMgr->loadPixmap("GEOM", myIs1D ? tr("ICON_DLG_FILLET_1D")
59 : tr("ICON_DLG_FILLET_2D")));
60 QPixmap iconSelect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
62 setWindowTitle(myIs1D ? tr("GEOM_FILLET_1D_TITLE") : tr("GEOM_FILLET_2D_TITLE"));
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
66 mainFrame()->RadioButton1->setIcon(image0);
67 mainFrame()->RadioButton2->close();
68 mainFrame()->RadioButton3->close();
70 GroupVertexes = new DlgRef_2Sel1Spin2Check (centralWidget());
71 GroupVertexes->GroupBox1->setTitle(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
72 GroupVertexes->TextLabel1->setText(myIs1D ? tr("GEOM_PLANAR_EDGE_WIRE") : tr("GEOM_PLANAR_FACE"));
73 GroupVertexes->TextLabel2->setText(tr("GEOM_VERTEXES"));
74 GroupVertexes->TextLabel3->setText(tr("GEOM_RADIUS"));
75 GroupVertexes->PushButton1->setIcon(iconSelect);
76 GroupVertexes->PushButton2->setIcon(iconSelect);
77 GroupVertexes->LineEdit1->setReadOnly(true);
78 GroupVertexes->LineEdit2->setReadOnly(true);
80 GroupVertexes->CheckButton1->setText(tr("GEOM_FILLET_1D_IGNORE_SECANT"));
81 GroupVertexes->CheckButton1->setChecked(true);
84 GroupVertexes->CheckButton1->close();
85 GroupVertexes->CheckButton2->close();
87 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
88 layout->setMargin(0); layout->setSpacing(6);
89 layout->addWidget(GroupVertexes);
91 /***************************************************************/
93 // Set range of spinboxes
94 double SpecificStep = 10.0;
95 initSpinBox(GroupVertexes->SpinBox_DX, 0.00001, COORD_MAX, SpecificStep, "length_precision" );
97 setHelpFileName(myIs1D ? "fillet1d_operation_page.html" : "fillet2d_operation_page.html");
104 //=================================================================================
105 // function : ~OperationGUI_Fillet1d2dDlg()
106 // purpose : Destroys the object and frees any allocated resources
107 //=================================================================================
108 OperationGUI_Fillet1d2dDlg::~OperationGUI_Fillet1d2dDlg()
112 //=================================================================================
115 //=================================================================================
116 void OperationGUI_Fillet1d2dDlg::Init()
118 // Set Initial values of spinboxes
119 GroupVertexes->SpinBox_DX->setValue(5);
122 GroupVertexes->LineEdit1->setText("");
123 GroupVertexes->LineEdit2->setText("");
125 myShape = GEOM::GEOM_Object::_nil();
129 showOnlyPreviewControl();
131 // signals and slots connections
133 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk() ));
134 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
136 connect(GroupVertexes->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137 connect(GroupVertexes->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 connect(GroupVertexes->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
140 connect(GroupVertexes->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142 connect(GroupVertexes->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
144 connect(GroupVertexes->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(processPreview()));
146 initName(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
147 GroupVertexes->PushButton1->click();
149 SelectionIntoArgument();
152 //=================================================================================
153 // function : ClickOnOk()
155 //=================================================================================
156 void OperationGUI_Fillet1d2dDlg::ClickOnOk()
158 setIsApplyAndClose( true );
163 //=================================================================================
164 // function : ClickOnApply()
166 //=================================================================================
167 bool OperationGUI_Fillet1d2dDlg::ClickOnApply()
173 // Reset dialog state
174 GroupVertexes->LineEdit1->setText("");
175 GroupVertexes->LineEdit2->setText("");
176 myShape = GEOM::GEOM_Object::_nil();
178 GroupVertexes->PushButton1->click();
183 //=================================================================================
184 // function : SelectionIntoArgument()
185 // purpose : Called when selection is changed or on dialog initialization or activation
186 //=================================================================================
187 void OperationGUI_Fillet1d2dDlg::SelectionIntoArgument()
190 myEditCurrentArgument->setText("");
192 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
193 SALOME_ListIO aSelList;
194 aSelMgr->selectedObjects(aSelList);
196 // If selection of main object is activated
197 if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
198 myShape = GEOM::GEOM_Object::_nil();
199 if (aSelList.Extent() == 1) {
200 GEOM::GEOM_Object_var anObj =
201 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
203 if ( !anObj->_is_nil() ) {
204 QString aName = GEOMBase::GetName( anObj );
206 if ( GEOMBase::GetShape( anObj, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
207 TColStd_IndexedMapOfInteger aMap;
208 aSelMgr->GetIndexes(aSelList.First(), aMap);
209 if ( aMap.Extent() == 1 ) { // Local Selection
210 int anIndex = aMap( 1 );
211 aName += QString( myIs1D ? ":wire_%1" : ":face_%1" ).arg( anIndex );
213 //Find SubShape Object in Father
214 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( anObj, aName );
216 if ( aFindedObject->_is_nil()) { // Object not found in study
217 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
218 anObj = aShapesOp->GetSubShape( anObj, anIndex );
221 anObj = aFindedObject; // get Object from study
223 else { // Global Selection
224 if ((myIs1D && aShape.ShapeType() != TopAbs_WIRE) ||
225 (!myIs1D && aShape.ShapeType() != TopAbs_FACE && aShape.ShapeType() != TopAbs_SHELL)) {
226 anObj = GEOM::GEOM_Object::_nil();
232 myEditCurrentArgument->setText(aName
237 } else if (myEditCurrentArgument == GroupVertexes->LineEdit2) {
239 bool isPreview = myIs1D;
240 if (aSelList.Extent() == 1) {
241 GEOM::GEOM_Object_var anObj =
242 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
244 if ( !anObj->_is_nil() ) {
245 TColStd_IndexedMapOfInteger anIndexes;
246 aSelMgr->GetIndexes(aSelList.First(), anIndexes);
248 if (anIndexes.Extent() > 0) {
250 if (anIndexes.Extent() == 1) {
251 int anIndex = anIndexes(1);
252 aName = QString(GEOMBase::GetName(anObj)) + QString(":vertex_%1").arg(anIndex);
255 aName = tr("GEOM_MEN_POPUP_NAME").arg(anIndexes.Extent());
258 myEditCurrentArgument->setText(aName);
259 myVertexes = anIndexes;
267 if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
268 if (!myShape->_is_nil() && myVertexes.Extent() == 0)
269 GroupVertexes->PushButton2->click();
273 //=================================================================================
274 // function : SetEditCurrentArgument()
276 //=================================================================================
277 void OperationGUI_Fillet1d2dDlg::SetEditCurrentArgument()
279 QPushButton* send = (QPushButton*)sender();
281 if (send == GroupVertexes->PushButton1) {
282 myEditCurrentArgument = GroupVertexes->LineEdit1;
283 GroupVertexes->PushButton2->setDown(false);
284 GroupVertexes->LineEdit2->setEnabled(false);
286 else if (send == GroupVertexes->PushButton2) {
287 myEditCurrentArgument = GroupVertexes->LineEdit2;
288 GroupVertexes->PushButton1->setDown(false);
289 GroupVertexes->LineEdit1->setEnabled(false);
293 myEditCurrentArgument->setEnabled(true);
294 myEditCurrentArgument->setFocus();
295 // after setFocus(), because it will be setDown(false) when loses focus
300 // seems we need it only to avoid preview disappearing, caused by selection mode change
304 //=================================================================================
305 // function : LineEditReturnPressed()
307 //=================================================================================
308 void OperationGUI_Fillet1d2dDlg::LineEditReturnPressed()
310 QLineEdit* send = (QLineEdit*)sender();
312 if (send == GroupVertexes->LineEdit1)
313 myEditCurrentArgument = GroupVertexes->LineEdit1;
314 else if (send == GroupVertexes->LineEdit2)
315 myEditCurrentArgument = GroupVertexes->LineEdit2;
319 GEOMBase_Skeleton::LineEditReturnPressed();
322 //=================================================================================
323 // function : ActivateThisDialog()
325 //=================================================================================
326 void OperationGUI_Fillet1d2dDlg::ActivateThisDialog()
328 GEOMBase_Skeleton::ActivateThisDialog();
331 //=================================================================================
332 // function : enterEvent()
334 //=================================================================================
335 void OperationGUI_Fillet1d2dDlg::enterEvent (QEvent*)
337 if (!mainFrame()->GroupConstructors->isEnabled())
338 this->ActivateThisDialog();
341 //=================================================================================
342 // function : ValueChangedInSpinBox()
344 //=================================================================================
345 void OperationGUI_Fillet1d2dDlg::ValueChangedInSpinBox (double)
350 //=================================================================================
351 // function : activateSelection
352 // purpose : Activate selection in accordance with myEditCurrentArgument
353 //=================================================================================
354 void OperationGUI_Fillet1d2dDlg::activateSelection()
356 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
358 if (myEditCurrentArgument == GroupVertexes->LineEdit1)
359 //localSelection(myShape, myIs1D ? TopAbs_WIRE : TopAbs_FACE);
361 globalSelection(GEOM_WIRE);
363 TColStd_MapOfInteger aMap;
365 aMap.Add(GEOM_SHELL);
366 globalSelection(aMap);
368 else if (!myShape->_is_nil() && myEditCurrentArgument == GroupVertexes->LineEdit2)
369 localSelection(myShape, TopAbs_VERTEX);
371 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
372 this, SLOT(SelectionIntoArgument()));
375 //=================================================================================
376 // function : createOperation
378 //=================================================================================
379 GEOM::GEOM_IOperations_ptr OperationGUI_Fillet1d2dDlg::createOperation()
381 return getGeomEngine()->GetILocalOperations(getStudyId());
384 //=================================================================================
385 // function : isValid()
386 // purpose : Verify validity of input data
387 //=================================================================================
388 bool OperationGUI_Fillet1d2dDlg::isValid (QString& msg)
390 bool ok = !myShape->_is_nil();
391 ok = GroupVertexes->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
392 ok = (myIs1D || myVertexes.Extent() > 0) && ok;
396 //=================================================================================
397 // function : execute
399 //=================================================================================
400 bool OperationGUI_Fillet1d2dDlg::execute (ObjectList& objects)
402 GEOM::ListOfLong_var aListOfIndexes = new GEOM::ListOfLong;
403 aListOfIndexes->length(myVertexes.Extent());
405 for (int i = 1, n = myVertexes.Extent(); i <= n; i++)
406 aListOfIndexes[ i - 1 ] = myVertexes(i);
408 GEOM::GEOM_ILocalOperations_var anOper = GEOM::GEOM_ILocalOperations::_narrow(getOperation());
409 GEOM::GEOM_Object_var anObj = myIs1D ?
410 anOper->MakeFillet1D(myShape, getRadius(), aListOfIndexes, GroupVertexes->CheckButton1->isChecked()) :
411 anOper->MakeFillet2D(myShape, getRadius(), aListOfIndexes);
413 if (!anObj->_is_nil())
414 objects.push_back(anObj._retn());
419 //=================================================================================
420 // function : getRadius
421 // purpose : Get radius
422 //=================================================================================
423 double OperationGUI_Fillet1d2dDlg::getRadius() const
425 return GroupVertexes->SpinBox_DX->value();