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_Fillet1d2dDlg.cxx
26 #include "OperationGUI_Fillet1d2dDlg.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_Fillet1d2dDlg()
49 // purpose : Constructs a OperationGUI_Fillet1d2dDlg 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_Fillet1d2dDlg::OperationGUI_Fillet1d2dDlg (GeometryGUI* theGeometryGUI,
57 : GEOMBase_Skeleton(theGeometryGUI, parent, false),
60 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
61 QPixmap image0 (aResMgr->loadPixmap("GEOM", myIs1D ? tr("ICON_DLG_FILLET_1D")
62 : tr("ICON_DLG_FILLET_2D")));
63 QPixmap iconSelect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
65 setWindowTitle(myIs1D ? tr("GEOM_FILLET_1D_TITLE") : tr("GEOM_FILLET_2D_TITLE"));
67 /***************************************************************/
68 mainFrame()->GroupConstructors->setTitle(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
69 mainFrame()->RadioButton1->setIcon(image0);
70 mainFrame()->RadioButton2->close();
71 mainFrame()->RadioButton3->close();
73 GroupVertexes = new DlgRef_2Sel1Spin(centralWidget());
74 GroupVertexes->GroupBox1->setTitle(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
75 GroupVertexes->TextLabel1->setText(myIs1D ? tr("GEOM_PLANAR_EDGE_WIRE") : tr("GEOM_PLANAR_FACE"));
76 GroupVertexes->TextLabel2->setText(tr("GEOM_VERTEXES"));
77 GroupVertexes->TextLabel3->setText(tr("GEOM_RADIUS"));
78 GroupVertexes->PushButton1->setIcon(iconSelect);
79 GroupVertexes->PushButton2->setIcon(iconSelect);
80 GroupVertexes->LineEdit1->setReadOnly(true);
81 GroupVertexes->LineEdit2->setReadOnly(true);
83 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
84 layout->setMargin(0); layout->setSpacing(6);
85 layout->addWidget(GroupVertexes);
87 /***************************************************************/
89 // Set range of spinboxes
90 double SpecificStep = 10.0;
91 initSpinBox(GroupVertexes->SpinBox_DX, 0.00001, COORD_MAX, SpecificStep, "length_precision" );
93 setHelpFileName(myIs1D ? "fillet1d_operation_page.html" : "fillet2d_operation_page.html");
100 //=================================================================================
101 // function : ~OperationGUI_Fillet1d2dDlg()
102 // purpose : Destroys the object and frees any allocated resources
103 //=================================================================================
104 OperationGUI_Fillet1d2dDlg::~OperationGUI_Fillet1d2dDlg()
108 //=================================================================================
111 //=================================================================================
112 void OperationGUI_Fillet1d2dDlg::Init()
114 // Set Initial values of spinboxes
115 GroupVertexes->SpinBox_DX->setValue(5);
118 GroupVertexes->LineEdit1->setText("");
119 GroupVertexes->LineEdit2->setText("");
121 myShape = GEOM::GEOM_Object::_nil();
125 // signals and slots connections
127 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk() ));
128 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
130 // connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
132 connect(GroupVertexes->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupVertexes->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(GroupVertexes->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(GroupVertexes->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(GroupVertexes->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
140 initName(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
141 GroupVertexes->PushButton1->click();
143 SelectionIntoArgument();
146 //=================================================================================
147 // function : ClickOnOk()
149 //=================================================================================
150 void OperationGUI_Fillet1d2dDlg::ClickOnOk()
156 //=================================================================================
157 // function : ClickOnApply()
159 //=================================================================================
160 bool OperationGUI_Fillet1d2dDlg::ClickOnApply()
166 // Reset dialog state
167 GroupVertexes->LineEdit1->setText("");
168 GroupVertexes->LineEdit2->setText("");
169 myShape = GEOM::GEOM_Object::_nil();
171 GroupVertexes->PushButton1->click();
176 //=================================================================================
177 // function : SelectionIntoArgument()
178 // purpose : Called when selection is changed or on dialog initialization or activation
179 //=================================================================================
180 void OperationGUI_Fillet1d2dDlg::SelectionIntoArgument()
183 myEditCurrentArgument->setText("");
185 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
186 SALOME_ListIO aSelList;
187 aSelMgr->selectedObjects(aSelList);
189 // If selection of main object is activated
190 if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
191 myShape = GEOM::GEOM_Object::_nil();
192 if (aSelList.Extent() == 1) {
193 Standard_Boolean aResult = Standard_False;
194 GEOM::GEOM_Object_var anObj =
195 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
197 if (aResult && !anObj->_is_nil()) {
198 QString aName = GEOMBase::GetName( anObj );
200 if ( GEOMBase::GetShape( anObj, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
201 TColStd_IndexedMapOfInteger aMap;
202 aSelMgr->GetIndexes(aSelList.First(), aMap);
203 if ( aMap.Extent() == 1 ) { // Local Selection
204 int anIndex = aMap( 1 );
205 aName += QString( myIs1D ? ":wire_%1" : ":face_%1" ).arg( anIndex );
207 //Find SubShape Object in Father
208 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( anObj, aName );
210 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
211 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
212 anObj = aShapesOp->GetSubShape( anObj, anIndex );
215 anObj = aFindedObject; // get Object from study
217 else { // Global Selection
218 if ( aShape.ShapeType() != (myIs1D ? TopAbs_WIRE : TopAbs_FACE) ) {
219 anObj = GEOM::GEOM_Object::_nil();
225 myEditCurrentArgument->setText(aName
230 } else if (myEditCurrentArgument == GroupVertexes->LineEdit2) {
232 bool isPreview = myIs1D;
233 if (aSelList.Extent() == 1) {
234 Standard_Boolean aResult = Standard_False;
235 GEOM::GEOM_Object_var anObj =
236 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
238 if (aResult && !anObj->_is_nil()) {
239 TColStd_IndexedMapOfInteger anIndexes;
240 aSelMgr->GetIndexes(aSelList.First(), anIndexes);
242 if (anIndexes.Extent() > 0) {
244 if (anIndexes.Extent() == 1) {
245 int anIndex = anIndexes(1);
246 aName = QString(GEOMBase::GetName(anObj)) + QString(":vertex_%1").arg(anIndex);
249 aName = tr("GEOM_MEN_POPUP_NAME").arg(anIndexes.Extent());
252 myEditCurrentArgument->setText(aName);
253 myVertexes = anIndexes;
261 if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
262 if (!myShape->_is_nil() && myVertexes.Extent() == 0)
263 GroupVertexes->PushButton2->click();
267 //=================================================================================
268 // function : SetEditCurrentArgument()
270 //=================================================================================
271 void OperationGUI_Fillet1d2dDlg::SetEditCurrentArgument()
273 QPushButton* send = (QPushButton*)sender();
275 if (send == GroupVertexes->PushButton1) {
276 myEditCurrentArgument = GroupVertexes->LineEdit1;
277 GroupVertexes->PushButton2->setDown(false);
278 GroupVertexes->LineEdit2->setEnabled(false);
280 else if (send == GroupVertexes->PushButton2) {
281 myEditCurrentArgument = GroupVertexes->LineEdit2;
282 GroupVertexes->PushButton1->setDown(false);
283 GroupVertexes->LineEdit1->setEnabled(false);
287 myEditCurrentArgument->setEnabled(true);
288 myEditCurrentArgument->setFocus();
289 // after setFocus(), because it will be setDown(false) when loses focus
294 // seems we need it only to avoid preview disappearing, caused by selection mode change
298 //=================================================================================
299 // function : LineEditReturnPressed()
301 //=================================================================================
302 void OperationGUI_Fillet1d2dDlg::LineEditReturnPressed()
304 QLineEdit* send = (QLineEdit*)sender();
306 if (send == GroupVertexes->LineEdit1)
307 myEditCurrentArgument = GroupVertexes->LineEdit1;
308 else if (send == GroupVertexes->LineEdit2)
309 myEditCurrentArgument = GroupVertexes->LineEdit2;
313 GEOMBase_Skeleton::LineEditReturnPressed();
316 //=================================================================================
317 // function : ActivateThisDialog()
319 //=================================================================================
320 void OperationGUI_Fillet1d2dDlg::ActivateThisDialog()
322 GEOMBase_Skeleton::ActivateThisDialog();
325 //=================================================================================
326 // function : enterEvent()
328 //=================================================================================
329 void OperationGUI_Fillet1d2dDlg::enterEvent (QEvent*)
331 if (!mainFrame()->GroupConstructors->isEnabled())
332 this->ActivateThisDialog();
335 //=================================================================================
336 // function : ValueChangedInSpinBox()
338 //=================================================================================
339 void OperationGUI_Fillet1d2dDlg::ValueChangedInSpinBox (double)
344 //=================================================================================
345 // function : activateSelection
346 // purpose : Activate selection in accordance with myEditCurrentArgument
347 //=================================================================================
348 void OperationGUI_Fillet1d2dDlg::activateSelection()
350 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
352 if (myEditCurrentArgument == GroupVertexes->LineEdit1)
353 globalSelection( myIs1D ? GEOM_WIRE : GEOM_FACE ); // localSelection(myShape, myIs1D ? TopAbs_WIRE
355 else if (!myShape->_is_nil() && myEditCurrentArgument == GroupVertexes->LineEdit2)
356 localSelection(myShape, TopAbs_VERTEX);
358 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
359 this, SLOT(SelectionIntoArgument()));
362 //=================================================================================
363 // function : createOperation
365 //=================================================================================
366 GEOM::GEOM_IOperations_ptr OperationGUI_Fillet1d2dDlg::createOperation()
368 return getGeomEngine()->GetILocalOperations(getStudyId());
371 //=================================================================================
372 // function : isValid()
373 // purpose : Verify validity of input data
374 //=================================================================================
375 bool OperationGUI_Fillet1d2dDlg::isValid (QString&)
377 return !myShape->_is_nil() && (myIs1D || myVertexes.Extent() > 0);
380 //=================================================================================
381 // function : execute
383 //=================================================================================
384 bool OperationGUI_Fillet1d2dDlg::execute (ObjectList& objects)
386 GEOM::ListOfLong_var aListOfIndexes = new GEOM::ListOfLong;
387 aListOfIndexes->length(myVertexes.Extent());
389 for (int i = 1, n = myVertexes.Extent(); i <= n; i++)
390 aListOfIndexes[ i - 1 ] = myVertexes(i);
392 GEOM::GEOM_ILocalOperations_var anOper = GEOM::GEOM_ILocalOperations::_narrow(getOperation());
393 GEOM::GEOM_Object_var anObj = myIs1D ?
394 anOper->MakeFillet1D(myShape, getRadius(), aListOfIndexes) :
395 anOper->MakeFillet2D(myShape, getRadius(), aListOfIndexes);
397 if (!anObj->_is_nil())
398 objects.push_back(anObj._retn());
403 //=================================================================================
404 // function : getRadius
405 // purpose : Get radius
406 //=================================================================================
407 double OperationGUI_Fillet1d2dDlg::getRadius() const
409 return GroupVertexes ->SpinBox_DX->value();