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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : RepairGUI_SuppressFacesDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "RepairGUI_SuppressFacesDlg.h"
32 #include "DisplayGUI.h"
33 #include "QAD_RightFrame.h"
34 #include "OCCViewer_Viewer3d.h"
36 //=================================================================================
37 // class : RepairGUI_SuppressFacesDlg()
38 // purpose : Constructs a RepairGUI_SuppressFacesDlg which is a child of 'parent', with the
39 // name 'name' and widget flags set to 'f'.
40 // The dialog will by default be modeless, unless you set 'modal' to
41 // TRUE to construct a modal dialog.
42 //=================================================================================
43 RepairGUI_SuppressFacesDlg::RepairGUI_SuppressFacesDlg(QWidget* parent, const char* name, RepairGUI* theRepairGUI, SALOME_Selection* Sel, Handle(AIS_InteractiveContext) ic, bool modal, WFlags fl)
44 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
46 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SUPRESS_FACE")));
47 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
49 setCaption(tr("GEOM_SUPRESSFACE_TITLE"));
51 /***************************************************************/
52 GroupConstructors->setTitle(tr("GEOM_SUPRESSFACE"));
53 RadioButton1->setPixmap(image0);
54 RadioButton2->close(TRUE);
55 RadioButton3->close(TRUE);
57 GroupPoints = new DlgRef_1Sel1Check_QTD(this, "GroupPoints");
58 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
59 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
60 GroupPoints->CheckButton1->setText(tr("GEOM_SUPRESSFACE_SELECT"));
61 GroupPoints->PushButton1->setPixmap(image1);
63 Layout1->addWidget(GroupPoints, 1, 0);
64 /***************************************************************/
67 myRepairGUI = theRepairGUI;
72 //=================================================================================
73 // function : ~RepairGUI_SuppressFacesDlg()
74 // purpose : Destroys the object and frees any allocated resources
75 //=================================================================================
76 RepairGUI_SuppressFacesDlg::~RepairGUI_SuppressFacesDlg()
78 // no need to delete child widgets, Qt does it all for us
82 //=================================================================================
85 //=================================================================================
86 void RepairGUI_SuppressFacesDlg::Init(Handle(AIS_InteractiveContext) ic)
89 myEditCurrentArgument = GroupPoints->LineEdit1;
91 myOkSelectSubMode = false;
92 myOkShape = myUseLocalContext = false;
94 myLocalContextId = -1;
96 /* signals and slots connections */
97 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
98 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
99 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
101 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
102 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
104 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
105 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
107 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ActivateUserSelection()));
109 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
111 /* displays Dialog */
119 //=================================================================================
120 // function : ClickOnOk()
121 // purpose : Same than click on apply but close this dialog.
122 //=================================================================================
123 void RepairGUI_SuppressFacesDlg::ClickOnOk()
125 this->ClickOnApply();
126 this->ClickOnCancel();
132 //=================================================================================
133 // function : ClickOnApply()
135 //=================================================================================
136 void RepairGUI_SuppressFacesDlg::ClickOnApply()
138 QAD_Application::getDesktop()->putInfo(tr(""));
139 bool testResult = false;
141 if(myOkShape && myOkSelectSubMode)
142 testResult = myRepairGUI->OnSuppressFaces(myShape, myShapeIOR, myLocalContextId, myUseLocalContext);
145 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
147 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
149 /* Reset arguments to allow a new selection */
150 this->ResetStateOfDialog();
155 //=================================================================================
156 // function : ClickOnCancel()
158 //=================================================================================
159 void RepairGUI_SuppressFacesDlg::ClickOnCancel()
161 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
162 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
163 myIC = v3d->getAISContext();
164 if(myUseLocalContext) {
165 myIC->CloseLocalContext(myLocalContextId);
166 myUseLocalContext = false;
168 DisplayGUI* myDisplayGUI = new DisplayGUI();
169 myDisplayGUI->OnDisplayAll(true);
171 GEOMBase_Skeleton::ClickOnCancel();
176 //=================================================================================
177 // function : SelectionIntoArgument()
178 // purpose : Called when selection as changed or other case
179 // : used only by SelectButtonC1A1 (LineEditC1A1)
180 //=================================================================================
181 void RepairGUI_SuppressFacesDlg::SelectionIntoArgument()
183 myEditCurrentArgument->setText("");
184 this->ResetStateOfDialog();
185 QString aString = ""; /* name of selection */
187 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
195 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
196 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
199 if(!IO->hasEntry()) {
200 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
204 /* Test the exact type of topology to suppress faces into */
205 if(!S.IsNull() && (S.ShapeType() == TopAbs_SOLID || S.ShapeType() == TopAbs_SHELL || S.ShapeType() == TopAbs_COMPOUND)) {
206 if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
207 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO);
208 myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
209 myEditCurrentArgument->setText(aString);
216 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
217 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
218 SALOMEDS::GenericAttribute_var anAttr;
219 SALOMEDS::AttributeIOR_var anIOR;
220 if(!obj->_is_nil()) {
221 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
222 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
223 myShapeIOR = anIOR->Value();
226 myEditCurrentArgument->setText(aString);
237 //=================================================================================
238 // function : SetEditCurrentArgument()
240 //=================================================================================
241 void RepairGUI_SuppressFacesDlg::SetEditCurrentArgument()
243 QPushButton* send = (QPushButton*)sender();
245 if(send == GroupPoints->PushButton1) {
246 GroupPoints->LineEdit1->setFocus();
247 myEditCurrentArgument = GroupPoints->LineEdit1;
249 this->SelectionIntoArgument();
255 //=================================================================================
256 // function : LineEditReturnPressed()
258 //=================================================================================
259 void RepairGUI_SuppressFacesDlg::LineEditReturnPressed()
261 QLineEdit* send = (QLineEdit*)sender();
262 if(send == GroupPoints->LineEdit1)
263 myEditCurrentArgument = GroupPoints->LineEdit1;
267 GEOMBase_Skeleton::LineEditReturnPressed();
272 //=================================================================================
273 // function : DeactivateActiveDialog()
275 //=================================================================================
276 void RepairGUI_SuppressFacesDlg::DeactivateActiveDialog()
278 if(GroupConstructors->isEnabled()) {
279 this->ResetStateOfDialog();
280 GEOMBase_Skeleton::DeactivateActiveDialog();
286 //=================================================================================
287 // function : ActivateThisDialog()
289 //=================================================================================
290 void RepairGUI_SuppressFacesDlg::ActivateThisDialog()
292 GEOMBase_Skeleton::ActivateThisDialog();
293 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
298 //=================================================================================
299 // function : enterEvent()
300 // purpose : Mouse enter onto the dialog to activate it
301 //=================================================================================
302 void RepairGUI_SuppressFacesDlg::enterEvent(QEvent* e)
304 if(GroupConstructors->isEnabled())
306 this->ActivateThisDialog();
311 //=================================================================================
312 // function : closeEvent()
314 //=================================================================================
315 void RepairGUI_SuppressFacesDlg::closeEvent(QCloseEvent* e)
317 /* same than click on cancel button */
318 this->ClickOnCancel();
323 //=================================================================================
324 // function : ActivateUserSelection()
325 // purpose : Activate selection of faces when CheckBox1->isChecked()...
326 //=================================================================================
327 void RepairGUI_SuppressFacesDlg::ActivateUserSelection()
329 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
331 this->ResetStateOfDialog();
332 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SELECT_FIRST"));
336 myOkSelectSubMode = GroupPoints->CheckButton1->isChecked();
338 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
339 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
340 myIC = v3d->getAISContext();
341 if(myUseLocalContext) {
342 myIC->CloseLocalContext(myLocalContextId);
343 myUseLocalContext = false;
345 DisplayGUI* myDisplayGUI = new DisplayGUI();
346 myDisplayGUI->OnDisplayAll(true);
349 if(myOkShape && myOkSelectSubMode) {
350 /* local context is defined into the method : 4 = FACES sub selection */
351 DisplayGUI* myDisplayGUI = new DisplayGUI();
352 myDisplayGUI->PrepareSubShapeSelection(int(TopAbs_FACE), myLocalContextId);
353 myUseLocalContext = true;
354 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SELECT_FACE"));
358 GroupPoints->CheckButton1->setChecked(false);
364 //=================================================================================
365 // function : ResetStateOfDialog()
366 // purpose : Completely reset the state of method including local context
367 //=================================================================================
368 void RepairGUI_SuppressFacesDlg::ResetStateOfDialog()
371 myEditCurrentArgument->setText("");
373 /* Select sub shapes mode not checked */
374 myOkSelectSubMode = false;
375 GroupPoints->CheckButton1->setChecked(FALSE);
377 /* Close its local contact if opened */
378 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
379 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
380 myIC = v3d->getAISContext();
381 if(myUseLocalContext) {
382 myIC->CloseLocalContext(myLocalContextId);
383 myUseLocalContext = false;
385 DisplayGUI* myDisplayGUI = new DisplayGUI();
386 myDisplayGUI->OnDisplayAll(true);