1 // Copyright (C) 2007-2010 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_2Sel1Spin(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 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
82 layout->setMargin(0); layout->setSpacing(6);
83 layout->addWidget(GroupVertexes);
85 /***************************************************************/
87 // Set range of spinboxes
88 double SpecificStep = 10.0;
89 initSpinBox(GroupVertexes->SpinBox_DX, 0.00001, COORD_MAX, SpecificStep, "length_precision" );
91 setHelpFileName(myIs1D ? "fillet1d_operation_page.html" : "fillet2d_operation_page.html");
98 //=================================================================================
99 // function : ~OperationGUI_Fillet1d2dDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 OperationGUI_Fillet1d2dDlg::~OperationGUI_Fillet1d2dDlg()
106 //=================================================================================
109 //=================================================================================
110 void OperationGUI_Fillet1d2dDlg::Init()
112 // Set Initial values of spinboxes
113 GroupVertexes->SpinBox_DX->setValue(5);
116 GroupVertexes->LineEdit1->setText("");
117 GroupVertexes->LineEdit2->setText("");
119 myShape = GEOM::GEOM_Object::_nil();
123 // signals and slots connections
125 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk() ));
126 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
128 // connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
130 connect(GroupVertexes->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(GroupVertexes->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupVertexes->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(GroupVertexes->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(GroupVertexes->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
138 initName(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
139 GroupVertexes->PushButton1->click();
141 SelectionIntoArgument();
144 //=================================================================================
145 // function : ClickOnOk()
147 //=================================================================================
148 void OperationGUI_Fillet1d2dDlg::ClickOnOk()
154 //=================================================================================
155 // function : ClickOnApply()
157 //=================================================================================
158 bool OperationGUI_Fillet1d2dDlg::ClickOnApply()
164 // Reset dialog state
165 GroupVertexes->LineEdit1->setText("");
166 GroupVertexes->LineEdit2->setText("");
167 myShape = GEOM::GEOM_Object::_nil();
169 GroupVertexes->PushButton1->click();
174 //=================================================================================
175 // function : SelectionIntoArgument()
176 // purpose : Called when selection is changed or on dialog initialization or activation
177 //=================================================================================
178 void OperationGUI_Fillet1d2dDlg::SelectionIntoArgument()
181 myEditCurrentArgument->setText("");
183 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
184 SALOME_ListIO aSelList;
185 aSelMgr->selectedObjects(aSelList);
187 // If selection of main object is activated
188 if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
189 myShape = GEOM::GEOM_Object::_nil();
190 if (aSelList.Extent() == 1) {
191 GEOM::GEOM_Object_var anObj =
192 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
194 if ( !anObj->_is_nil() ) {
195 QString aName = GEOMBase::GetName( anObj );
197 if ( GEOMBase::GetShape( anObj, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
198 TColStd_IndexedMapOfInteger aMap;
199 aSelMgr->GetIndexes(aSelList.First(), aMap);
200 if ( aMap.Extent() == 1 ) { // Local Selection
201 int anIndex = aMap( 1 );
202 aName += QString( myIs1D ? ":wire_%1" : ":face_%1" ).arg( anIndex );
204 //Find SubShape Object in Father
205 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( anObj, aName );
207 if ( aFindedObject->_is_nil()) { // Object not found in study
208 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
209 anObj = aShapesOp->GetSubShape( anObj, anIndex );
212 anObj = aFindedObject; // get Object from study
214 else { // Global Selection
215 if ( aShape.ShapeType() != (myIs1D ? TopAbs_WIRE : TopAbs_FACE) ) {
216 anObj = GEOM::GEOM_Object::_nil();
222 myEditCurrentArgument->setText(aName
227 } else if (myEditCurrentArgument == GroupVertexes->LineEdit2) {
229 bool isPreview = myIs1D;
230 if (aSelList.Extent() == 1) {
231 GEOM::GEOM_Object_var anObj =
232 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
234 if ( !anObj->_is_nil() ) {
235 TColStd_IndexedMapOfInteger anIndexes;
236 aSelMgr->GetIndexes(aSelList.First(), anIndexes);
238 if (anIndexes.Extent() > 0) {
240 if (anIndexes.Extent() == 1) {
241 int anIndex = anIndexes(1);
242 aName = QString(GEOMBase::GetName(anObj)) + QString(":vertex_%1").arg(anIndex);
245 aName = tr("GEOM_MEN_POPUP_NAME").arg(anIndexes.Extent());
248 myEditCurrentArgument->setText(aName);
249 myVertexes = anIndexes;
257 if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
258 if (!myShape->_is_nil() && myVertexes.Extent() == 0)
259 GroupVertexes->PushButton2->click();
263 //=================================================================================
264 // function : SetEditCurrentArgument()
266 //=================================================================================
267 void OperationGUI_Fillet1d2dDlg::SetEditCurrentArgument()
269 QPushButton* send = (QPushButton*)sender();
271 if (send == GroupVertexes->PushButton1) {
272 myEditCurrentArgument = GroupVertexes->LineEdit1;
273 GroupVertexes->PushButton2->setDown(false);
274 GroupVertexes->LineEdit2->setEnabled(false);
276 else if (send == GroupVertexes->PushButton2) {
277 myEditCurrentArgument = GroupVertexes->LineEdit2;
278 GroupVertexes->PushButton1->setDown(false);
279 GroupVertexes->LineEdit1->setEnabled(false);
283 myEditCurrentArgument->setEnabled(true);
284 myEditCurrentArgument->setFocus();
285 // after setFocus(), because it will be setDown(false) when loses focus
290 // seems we need it only to avoid preview disappearing, caused by selection mode change
294 //=================================================================================
295 // function : LineEditReturnPressed()
297 //=================================================================================
298 void OperationGUI_Fillet1d2dDlg::LineEditReturnPressed()
300 QLineEdit* send = (QLineEdit*)sender();
302 if (send == GroupVertexes->LineEdit1)
303 myEditCurrentArgument = GroupVertexes->LineEdit1;
304 else if (send == GroupVertexes->LineEdit2)
305 myEditCurrentArgument = GroupVertexes->LineEdit2;
309 GEOMBase_Skeleton::LineEditReturnPressed();
312 //=================================================================================
313 // function : ActivateThisDialog()
315 //=================================================================================
316 void OperationGUI_Fillet1d2dDlg::ActivateThisDialog()
318 GEOMBase_Skeleton::ActivateThisDialog();
321 //=================================================================================
322 // function : enterEvent()
324 //=================================================================================
325 void OperationGUI_Fillet1d2dDlg::enterEvent (QEvent*)
327 if (!mainFrame()->GroupConstructors->isEnabled())
328 this->ActivateThisDialog();
331 //=================================================================================
332 // function : ValueChangedInSpinBox()
334 //=================================================================================
335 void OperationGUI_Fillet1d2dDlg::ValueChangedInSpinBox (double)
340 //=================================================================================
341 // function : activateSelection
342 // purpose : Activate selection in accordance with myEditCurrentArgument
343 //=================================================================================
344 void OperationGUI_Fillet1d2dDlg::activateSelection()
346 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
348 if (myEditCurrentArgument == GroupVertexes->LineEdit1)
349 globalSelection( myIs1D ? GEOM_WIRE : GEOM_FACE ); // localSelection(myShape, myIs1D ? TopAbs_WIRE
351 else if (!myShape->_is_nil() && myEditCurrentArgument == GroupVertexes->LineEdit2)
352 localSelection(myShape, TopAbs_VERTEX);
354 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
355 this, SLOT(SelectionIntoArgument()));
358 //=================================================================================
359 // function : createOperation
361 //=================================================================================
362 GEOM::GEOM_IOperations_ptr OperationGUI_Fillet1d2dDlg::createOperation()
364 return getGeomEngine()->GetILocalOperations(getStudyId());
367 //=================================================================================
368 // function : isValid()
369 // purpose : Verify validity of input data
370 //=================================================================================
371 bool OperationGUI_Fillet1d2dDlg::isValid (QString& msg)
373 bool ok = !myShape->_is_nil();
374 ok = GroupVertexes->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
375 ok = (myIs1D || myVertexes.Extent() > 0) && ok;
379 //=================================================================================
380 // function : execute
382 //=================================================================================
383 bool OperationGUI_Fillet1d2dDlg::execute (ObjectList& objects)
385 GEOM::ListOfLong_var aListOfIndexes = new GEOM::ListOfLong;
386 aListOfIndexes->length(myVertexes.Extent());
388 for (int i = 1, n = myVertexes.Extent(); i <= n; i++)
389 aListOfIndexes[ i - 1 ] = myVertexes(i);
391 GEOM::GEOM_ILocalOperations_var anOper = GEOM::GEOM_ILocalOperations::_narrow(getOperation());
392 GEOM::GEOM_Object_var anObj = myIs1D ?
393 anOper->MakeFillet1D(myShape, getRadius(), aListOfIndexes) :
394 anOper->MakeFillet2D(myShape, getRadius(), aListOfIndexes);
396 if (!anObj->_is_nil())
397 objects.push_back(anObj._retn());
402 //=================================================================================
403 // function : getRadius
404 // purpose : Get radius
405 //=================================================================================
406 double OperationGUI_Fillet1d2dDlg::getRadius() const
408 return GroupVertexes ->SpinBox_DX->value();