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 : RepairGUI_RemoveIntWiresDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "RepairGUI_RemoveIntWiresDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
39 #include <TColStd_MapOfInteger.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <GEOMImpl_Types.hxx>
44 //=================================================================================
45 // class : RepairGUI_RemoveIntWiresDlg()
46 // purpose : Constructs a RepairGUI_RemoveIntWiresDlg 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 RepairGUI_RemoveIntWiresDlg::RepairGUI_RemoveIntWiresDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
53 : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
55 QPixmap image0 (myGeomGUI->getApp()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SUPPRESS_INT_WIRES")));
56 QPixmap image1 (myGeomGUI->getApp()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
58 setWindowTitle(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
60 /***************************************************************/
61 mainFrame()->GroupConstructors->setTitle(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
62 mainFrame()->RadioButton1->setIcon(image0);
63 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
64 mainFrame()->RadioButton2->close();
65 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
66 mainFrame()->RadioButton3->close();
68 GroupPoints = new DlgRef_1Sel1Check1Sel(centralWidget());
69 GroupPoints->GroupBox1->setTitle(tr("GEOM_INTERNAL_WIRES"));
70 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_FACE"));
71 GroupPoints->PushButton1->setIcon(image1);
72 GroupPoints->LineEdit1->setReadOnly(true);
73 GroupPoints->CheckButton1->setText(tr("GEOM_REMOVE_ALL_INT_WIRES"));
74 GroupPoints->TextLabel2->setText(tr("GEOM_WIRES_TO_REMOVE"));
75 GroupPoints->PushButton2->setIcon(image1);
76 GroupPoints->LineEdit2->setReadOnly(true);
78 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
79 layout->setMargin(0); layout->setSpacing(6);
80 layout->addWidget(GroupPoints);
81 /***************************************************************/
83 setHelpFileName("suppress_internal_wires_operation_page.html");
88 //=================================================================================
89 // function : ~RepairGUI_RemoveIntWiresDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 RepairGUI_RemoveIntWiresDlg::~RepairGUI_RemoveIntWiresDlg()
96 //=================================================================================
99 //=================================================================================
100 void RepairGUI_RemoveIntWiresDlg::Init()
103 GroupPoints->LineEdit1->clear();
104 GroupPoints->LineEdit2->clear();
105 myObject = GEOM::GEOM_Object::_nil();
106 myWiresInd = new GEOM::short_array();
107 myWiresInd->length(0);
109 // signals and slots connections
110 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
111 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
113 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
114 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
116 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
117 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
119 connect(GroupPoints->CheckButton1, SIGNAL(clicked()), this, SLOT(onRemoveAllClicked()));
121 initName(tr("REMOVE_INT_WIRES_NEW_OBJ_NAME"));
123 GroupPoints->PushButton1->click();
124 SelectionIntoArgument();
127 //=================================================================================
128 // function : ClickOnOk()
129 // purpose : Same than click on apply but close this dialog.
130 //=================================================================================
131 void RepairGUI_RemoveIntWiresDlg::ClickOnOk()
137 //=================================================================================
138 // function : ClickOnApply()
140 //=================================================================================
141 bool RepairGUI_RemoveIntWiresDlg::ClickOnApply()
147 // activate first line edit
148 GroupPoints->PushButton1->click();
152 //=================================================================================
153 // function : SelectionIntoArgument()
154 // purpose : Called when selection is changed or on dialog initialization or activation
155 //=================================================================================
156 void RepairGUI_RemoveIntWiresDlg::SelectionIntoArgument()
158 myEditCurrentArgument->setText("");
159 // the second argument depends on the first one
160 GroupPoints->LineEdit2->setText("");
161 myWiresInd->length(0);
163 if (myEditCurrentArgument == GroupPoints->LineEdit1)
164 myObject = GEOM::GEOM_Object::_nil();
166 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
167 SALOME_ListIO aSelList;
168 aSelMgr->selectedObjects(aSelList);
170 if (aSelList.Extent() == 1) {
171 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
173 if (myEditCurrentArgument == GroupPoints->LineEdit1) { // face selection
174 Standard_Boolean aRes;
175 myObject = GEOMBase::ConvertIOinGEOMObject(anIO, aRes);
176 if (aRes && GEOMBase::IsShape(myObject)) {
177 myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
180 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
181 myGeomGUI->getApp()->selectionMgr()->clearSelected();
182 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
183 this, SLOT(SelectionIntoArgument()));
185 if (!GroupPoints->CheckButton1->isChecked())
186 GroupPoints->PushButton2->click();
189 myObject = GEOM::GEOM_Object::_nil();
191 else if (myEditCurrentArgument == GroupPoints->LineEdit2 &&
192 !GroupPoints->CheckButton1->isChecked()) {
193 TColStd_IndexedMapOfInteger aMap;
194 aSelMgr->GetIndexes(anIO, aMap);
195 const int n = aMap.Extent();
196 myWiresInd->length(n);
197 for (int i = 1; i <= n; i++)
198 myWiresInd[i-1] = aMap(i);
200 myEditCurrentArgument->setText(QString::number(n) + "_" + tr("GEOM_WIRE") + tr("_S_"));
205 //=================================================================================
206 // function : SetEditCurrentArgument()
208 //=================================================================================
209 void RepairGUI_RemoveIntWiresDlg::SetEditCurrentArgument()
211 QPushButton* send = (QPushButton*)sender();
213 bool isEffective = false;
215 if (send == GroupPoints->PushButton1) {
217 myEditCurrentArgument = GroupPoints->LineEdit1;
219 GroupPoints->PushButton2->setDown(false);
220 GroupPoints->LineEdit2->setEnabled(false);
222 else if (send == GroupPoints->PushButton2 && !myObject->_is_nil()) {
224 myEditCurrentArgument = GroupPoints->LineEdit2;
226 GroupPoints->PushButton1->setDown(false);
227 GroupPoints->LineEdit1->setEnabled(false);
234 myEditCurrentArgument->setEnabled(true);
235 myEditCurrentArgument->setFocus();
236 // after setFocus(), because it will be setDown(false) when loses focus
241 //=================================================================================
242 // function : LineEditReturnPressed()
244 //=================================================================================
245 void RepairGUI_RemoveIntWiresDlg::LineEditReturnPressed()
247 const QObject* send = sender();
248 if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2) {
249 myEditCurrentArgument = (QLineEdit*)send;
250 GEOMBase_Skeleton::LineEditReturnPressed();
254 //=================================================================================
255 // function : ActivateThisDialog()
257 //=================================================================================
258 void RepairGUI_RemoveIntWiresDlg::ActivateThisDialog()
260 GEOMBase_Skeleton::ActivateThisDialog();
261 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
262 this, SLOT( SelectionIntoArgument() ) );
264 myEditCurrentArgument = GroupPoints->LineEdit1;
265 myEditCurrentArgument->setText( "" );
266 GroupPoints->LineEdit2->setText( "" );
267 myObject = GEOM::GEOM_Object::_nil();
268 myWiresInd->length( 0 );
270 //myGeomGUI->SetState( 0 );
274 //=================================================================================
275 // function : enterEvent()
276 // purpose : Mouse enter onto the dialog to activate it
277 //=================================================================================
278 void RepairGUI_RemoveIntWiresDlg::enterEvent (QEvent*)
280 if (!mainFrame()->GroupConstructors->isEnabled())
281 ActivateThisDialog();
284 //=================================================================================
285 // function : createOperation
287 //=================================================================================
288 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveIntWiresDlg::createOperation()
290 return getGeomEngine()->GetIHealingOperations(getStudyId());
293 //=================================================================================
294 // function : isValid
296 //=================================================================================
297 bool RepairGUI_RemoveIntWiresDlg::isValid (QString&)
299 return !myObject->_is_nil() && (GroupPoints->CheckButton1->isChecked() || myWiresInd->length());
302 //=================================================================================
303 // function : execute
305 //=================================================================================
306 bool RepairGUI_RemoveIntWiresDlg::execute (ObjectList& objects)
308 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow(getOperation())->
309 RemoveIntWires(myObject, myWiresInd);
311 bool aResult = !anObj->_is_nil();
313 objects.push_back(anObj._retn());
318 //=================================================================================
319 // function : onRemoveAllClicked
321 //=================================================================================
322 void RepairGUI_RemoveIntWiresDlg::onRemoveAllClicked()
324 bool b = GroupPoints->CheckButton1->isChecked();
325 GroupPoints->TextLabel2->setEnabled(!b);
326 GroupPoints->PushButton2->setEnabled(!b);
327 GroupPoints->LineEdit2->setEnabled(!b);
329 GroupPoints->LineEdit2->setText("");
330 myWiresInd->length(0);
334 //=================================================================================
335 // function : initSelection
337 //=================================================================================
338 void RepairGUI_RemoveIntWiresDlg::initSelection()
340 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
342 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
343 TColStd_MapOfInteger aTypes;
344 aTypes.Add(GEOM_COMPOUND);
345 aTypes.Add(GEOM_SOLID);
346 aTypes.Add(GEOM_SHELL);
347 aTypes.Add(GEOM_FACE);
349 globalSelection(aTypes);
351 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
352 //localSelection(myObject, TopAbs_EDGE);
353 localSelection(myObject, TopAbs_WIRE);
356 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
357 this, SLOT(SelectionIntoArgument()));