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 : EntityGUI_SubShapeDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "EntityGUI_SubShapeDlg.h"
32 #include "DisplayGUI.h"
33 #include "QAD_RightFrame.h"
34 #include "OCCViewer_Viewer3d.h"
36 #include <TopExp_Explorer.hxx>
37 #include <TopTools_MapOfShape.hxx>
39 #include <qmessagebox.h>
41 //=================================================================================
42 // class : EntityGUI_SubShapeDlg()
43 // purpose : Constructs a EntityGUI_SubShapeDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 EntityGUI_SubShapeDlg::EntityGUI_SubShapeDlg(QWidget* parent, const char* name, EntityGUI* theEntityGUI, SALOME_Selection* Sel, Handle(AIS_InteractiveContext) ic, bool modal, WFlags fl)
49 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SUBSHAPE")));
52 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
54 setCaption(tr("GEOM_SUBSHAPE_TITLE"));
56 /***************************************************************/
57 GroupConstructors->setTitle(tr("GEOM_SUB_SHAPE"));
58 RadioButton1->setPixmap(image0);
59 RadioButton2->close(TRUE);
60 RadioButton3->close(TRUE);
62 GroupPoints = new DlgRef_1Sel1Check1List_QTD(this, "GroupPoints");
63 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
64 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
65 GroupPoints->TextLabel2->setText(tr("GEOM_SUBSHAPE_TYPE"));
66 GroupPoints->CheckButton1->setText(tr("GEOM_SUBSHAPE_SELECT"));
67 GroupPoints->PushButton1->setPixmap(image1);
69 Layout1->addWidget(GroupPoints, 1, 0);
70 /***************************************************************/
73 myEntityGUI = theEntityGUI;
78 //=================================================================================
79 // function : ~EntityGUI_SubShapeDlg()
80 // purpose : Destroys the object and frees any allocated resources
81 //=================================================================================
82 EntityGUI_SubShapeDlg::~EntityGUI_SubShapeDlg()
84 // no need to delete child widgets, Qt does it all for us
88 //=================================================================================
91 //=================================================================================
92 void EntityGUI_SubShapeDlg::Init(Handle(AIS_InteractiveContext) ic)
95 myEditCurrentArgument = GroupPoints->LineEdit1;
98 myAbort = myOkShape = myUseLocalContext = false;
100 myLocalContextId = -1;
102 /* type for sub shape selection */
103 GroupPoints->ComboBox1->insertItem("Compound");
104 GroupPoints->ComboBox1->insertItem("Compsolid");
105 GroupPoints->ComboBox1->insertItem("Solid");
106 GroupPoints->ComboBox1->insertItem("Shell");
107 GroupPoints->ComboBox1->insertItem("Face");
108 GroupPoints->ComboBox1->insertItem("Wire");
109 GroupPoints->ComboBox1->insertItem("Edge");
110 GroupPoints->ComboBox1->insertItem("Vertex");
111 GroupPoints->ComboBox1->insertItem("Shape");
113 myShapeType = GroupPoints->ComboBox1->currentItem();
114 myOkSelectSubMode = GroupPoints->CheckButton1->isChecked();
116 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC)
117 GroupPoints->CheckButton1->setEnabled(false);
119 /* signals and slots connections */
120 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
121 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
122 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
124 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
125 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
127 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
131 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(AllOrNotAll()));
133 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
135 /* displays Dialog */
143 //=================================================================================
144 // function : ClickOnOk()
146 //=================================================================================
147 void EntityGUI_SubShapeDlg::ClickOnOk()
149 this->ClickOnApply();
151 /* User has aborted or not operation of explode all with many sub shapes */
153 this->ClickOnCancel();
161 //=================================================================================
162 // function : ClickOnApply()
164 //=================================================================================
165 void EntityGUI_SubShapeDlg::ClickOnApply()
167 QAD_Application::getDesktop()->putInfo(tr(""));
168 bool testResult = false;
169 myAbort = false; /* Not aborted by default */
171 /* Explode all sub shapes */
172 if(myOkShape && !myOkSelectSubMode) {
173 /* More than 30 subshapes : ask confirmation */
174 unsigned int nb = NumberOfSubShapes(myShape, myShapeType);
176 const QString caption = tr("GEOM_CONFIRM");
177 const QString text = tr("GEOM_CONFIRM_INFO").arg(nb);
178 const QString button0 = tr("GEOM_BUT_EXPLODE");
179 const QString button1 = tr("GEOM_BUT_CANCEL");
181 if(QMessageBox::warning(this, caption, text, button0, button1) == 0)
182 testResult = myEntityGUI->OnSubShapeGetAll(myShape, myShapeIOR, myShapeType);
184 myAbort = true; /* aborted */
187 testResult = myEntityGUI->OnSubShapeGetAll(myShape, myShapeIOR, myShapeType);
189 /* explode only selected sub shapes */
190 else if(myOkShape && myOkSelectSubMode)
191 testResult = myEntityGUI->OnSubShapeGetSelected(myShape, myShapeIOR, myShapeType, myLocalContextId, myUseLocalContext);
194 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
198 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
200 /* Reset all arguments and local context to allow user a new selection ...*/
201 this->ResetStateOfDialog();
206 //=================================================================================
207 // function : ClickOnCancel()
209 //=================================================================================
210 void EntityGUI_SubShapeDlg::ClickOnCancel()
212 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
213 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
214 myIC = v3d->getAISContext();
215 if(myUseLocalContext) {
216 myIC->CloseLocalContext(myLocalContextId);
217 myUseLocalContext = false;
219 DisplayGUI* myDisplayGUI = new DisplayGUI();
220 myDisplayGUI->OnDisplayAll(true);
222 GEOMBase_Skeleton::ClickOnCancel();
227 //=================================================================================
228 // function : SelectionIntoArgument()
229 // purpose : Called when selection as changed or other case
230 // : used only by SelectButtonC1A1 (LineEditC1A1)
231 //=================================================================================
232 void EntityGUI_SubShapeDlg::SelectionIntoArgument()
234 myEditCurrentArgument->setText("");
235 this->ResetStateOfDialog();
236 QString aString = ""; /* name of selection */
238 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
246 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
247 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
250 if(!IO->hasEntry()) {
251 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
255 if(!S.IsNull() && S.ShapeType() != TopAbs_VERTEX) {
256 if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
257 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO );
258 myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
259 myEditCurrentArgument->setText(aString);
264 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
265 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
266 SALOMEDS::GenericAttribute_var anAttr;
267 SALOMEDS::AttributeIOR_var anIOR;
268 if(!obj->_is_nil()) {
269 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
270 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
271 myShapeIOR = anIOR->Value();
274 GroupPoints->LineEdit1->setText(aString);
279 int SelectedShapeType = GroupPoints->ComboBox1->currentItem();
280 int count = GroupPoints->ComboBox1->count();
286 while(i <= myShape.ShapeType()) {
287 GroupPoints->ComboBox1->removeItem(0);
291 if(myShape.ShapeType()==TopAbs_COMPOUND) {
292 if(myWithShape == false) {
293 GroupPoints->ComboBox1->insertItem("Shape");
298 if(myWithShape == true) {
299 GroupPoints->ComboBox1->removeItem(GroupPoints->ComboBox1->count() - 1);
304 int count1 = GroupPoints->ComboBox1->count();
308 if(SelectedShapeType > myShape.ShapeType()) {
309 if(SelectedShapeType == 8) {
310 if(myShape.ShapeType() != TopAbs_COMPOUND) {
311 GroupPoints->ComboBox1->setCurrentItem(0);
312 myShapeType = 8 - count1;
316 GroupPoints->ComboBox1->setCurrentItem(count1 - count + SelectedShapeType);
317 myShapeType = 8 - count1 + GroupPoints->ComboBox1->currentItem();
321 GroupPoints->ComboBox1->setCurrentItem(0);
322 myShapeType = 8 - count1;
329 //=================================================================================
330 // function : SetEditCurrentArgument()
332 //=================================================================================
333 void EntityGUI_SubShapeDlg::SetEditCurrentArgument()
335 QPushButton* send = (QPushButton*)sender();
337 if(send == GroupPoints->PushButton1) {
338 GroupPoints->LineEdit1->setFocus();
339 myEditCurrentArgument = GroupPoints->LineEdit1;
341 this->SelectionIntoArgument();
347 //=================================================================================
348 // function : LineEditReturnPressed()
350 //=================================================================================
351 void EntityGUI_SubShapeDlg::LineEditReturnPressed()
353 QLineEdit* send = (QLineEdit*)sender();
354 if(send == GroupPoints->LineEdit1)
355 myEditCurrentArgument = GroupPoints->LineEdit1;
359 GEOMBase_Skeleton::LineEditReturnPressed();
364 //=================================================================================
365 // function : DeactivateActiveDialog()
367 //=================================================================================
368 void EntityGUI_SubShapeDlg::DeactivateActiveDialog()
370 if(GroupConstructors->isEnabled()) {
371 this->ResetStateOfDialog();
372 GEOMBase_Skeleton::DeactivateActiveDialog();
378 //=================================================================================
379 // function : ActivateThisDialog()
381 //=================================================================================
382 void EntityGUI_SubShapeDlg::ActivateThisDialog()
384 GEOMBase_Skeleton::ActivateThisDialog();
385 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
386 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC)
387 GroupPoints->CheckButton1->setEnabled(true);
389 GroupPoints->CheckButton1->setEnabled(false);
394 //=================================================================================
395 // function : enterEvent()
397 //=================================================================================
398 void EntityGUI_SubShapeDlg::enterEvent(QEvent* e)
400 if(GroupConstructors->isEnabled())
402 this->ActivateThisDialog();
407 //=================================================================================
408 // function : closeEvent()
410 //=================================================================================
411 void EntityGUI_SubShapeDlg::closeEvent(QCloseEvent* e)
413 /* same than click on cancel button */
414 this->ClickOnCancel();
419 //=================================================================================
420 // function : ResetStateOfDialog()
421 // purpose : Completely reset the state of method including local context
422 //=================================================================================
423 void EntityGUI_SubShapeDlg::ResetStateOfDialog()
425 if(myAbort == true) {
427 myEditCurrentArgument->setText("");
430 int SelectedShapeType = GroupPoints->ComboBox1->currentItem();
431 int count = GroupPoints->ComboBox1->count();
435 /* type for sub shape selection */
436 GroupPoints->ComboBox1->clear();
437 GroupPoints->ComboBox1->insertItem("Compound");
438 GroupPoints->ComboBox1->insertItem("Compsolid");
439 GroupPoints->ComboBox1->insertItem("Solid");
440 GroupPoints->ComboBox1->insertItem("Shell");
441 GroupPoints->ComboBox1->insertItem("Face");
442 GroupPoints->ComboBox1->insertItem("Wire");
443 GroupPoints->ComboBox1->insertItem("Edge");
444 GroupPoints->ComboBox1->insertItem("Vertex");
445 GroupPoints->ComboBox1->insertItem("Shape");
447 GroupPoints->ComboBox1->setCurrentItem(8 - count + SelectedShapeType);
448 myOkSelectSubMode = false;
450 /* unpress buttons : due to abort box*/
451 buttonApply->setDown(FALSE);
452 buttonOk->setDown(FALSE);
453 GroupPoints->CheckButton1->setChecked(FALSE);
455 /* Close its local contact if opened */
456 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
457 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
458 myIC = v3d->getAISContext();
459 if(myUseLocalContext) {
460 myIC->CloseLocalContext(myLocalContextId);
461 myUseLocalContext = false;
463 DisplayGUI* myDisplayGUI = new DisplayGUI();
464 myDisplayGUI->OnDisplayAll(true);
470 //=================================================================================
471 // function : AllOrNotAll()
472 // purpose : Allow user selection of all or only selected sub shapes
473 // : Called when 'CheckButton1' state change
474 //=================================================================================
475 void EntityGUI_SubShapeDlg::AllOrNotAll()
477 /* No sub shape selection if main shape not selected */
479 this->ResetStateOfDialog();
480 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SELECT_FIRST"));
484 if(myShapeType ==TopAbs_SHAPE && myShape.ShapeType()==TopAbs_COMPOUND) {
485 /* Select sub shapes mode not checked */
486 myOkSelectSubMode = false;
487 GroupPoints->CheckButton1->setChecked( FALSE );
488 //no meaning to allow user selection for type = shape
489 //TODO - add another message
490 //QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SELECT_FIRST")) ;
494 myOkSelectSubMode = GroupPoints->CheckButton1->isChecked();
496 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
497 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
498 myIC = v3d->getAISContext();
500 if(myUseLocalContext) {
501 myIC->CloseLocalContext(myLocalContextId);
502 myUseLocalContext = false;
504 DisplayGUI* myDisplayGUI = new DisplayGUI();
505 myDisplayGUI->OnDisplayAll(true);
508 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NOT_FOR_VTK_VIEWER"));
512 if(myOkShape && myOkSelectSubMode) {
513 /* local context is defined into the method */
514 DisplayGUI* myDisplayGUI = new DisplayGUI();
515 myDisplayGUI->PrepareSubShapeSelection(myShapeType, myLocalContextId);
516 myUseLocalContext = true;
517 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SELECT_FACE"));
523 //=================================================================================
524 // function : ComboTextChanged()
526 //=================================================================================
527 void EntityGUI_SubShapeDlg::ComboTextChanged()
530 myShapeType = GroupPoints->ComboBox1->currentItem() + myShape.ShapeType() + 1;
532 myShapeType = GroupPoints->ComboBox1->currentItem();
534 /* Select sub shapes mode not checked */
535 GroupPoints->CheckButton1->setChecked(FALSE);
536 myOkSelectSubMode = FALSE;
538 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
539 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
540 myIC = v3d->getAISContext();
542 if(myUseLocalContext) {
543 myIC->CloseLocalContext(myLocalContextId);
544 myUseLocalContext = false;
546 DisplayGUI* myDisplayGUI = new DisplayGUI();
547 myDisplayGUI->OnDisplayAll(true);
553 //=================================================================================
554 // function : NumberOfSubShapes()
556 //=================================================================================
557 unsigned int EntityGUI_SubShapeDlg::NumberOfSubShapes(const TopoDS_Shape& S, const int shapeType)
562 unsigned int index = 0;
563 TopExp_Explorer Exp(S, TopAbs_ShapeEnum(shapeType));
564 TopTools_MapOfShape M;
566 if(M.Add(Exp.Current()))