1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : EntityGUI_SubShapeDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "EntityGUI_SubShapeDlg.h"
30 #include <GeometryGUI.h>
32 #include <GEOMUtils.hxx>
33 #include <MeasureGUI_ShapeStatisticsDlg.h>
35 #include <OCCViewer_ViewModel.h>
36 #include <SVTK_ViewModel.h>
37 #include <SalomeApp_Study.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
40 #include <SALOME_ListIO.hxx>
41 #include <SUIT_MessageBox.h>
43 #include <SUIT_Desktop.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_ViewManager.h>
47 #include <SUIT_ViewWindow.h>
50 #include <TopExp_Explorer.hxx>
51 #include <TopoDS_Iterator.hxx>
52 #include <TopTools_MapOfShape.hxx>
53 #include <TopTools_IndexedMapOfShape.hxx>
55 #include <TColStd_IndexedMapOfInteger.hxx>
57 #include <GEOMImpl_Types.hxx>
61 const char* const ShapeTypes [] = {
74 enum { Filter_LT, Filter_LE, Filter_GT, Filter_GE };
76 unsigned int NumberOfSubShapes(const TopoDS_Shape& S, const int shapeType, TopTools_MapOfShape& M)
78 unsigned int index = 0;
81 if (S.ShapeType() == TopAbs_COMPOUND &&
82 (shapeType == TopAbs_SHAPE || shapeType == TopAbs_FLAT || shapeType == TopAbs_COMPOUND)) {
83 TopoDS_Iterator It(S, Standard_True, Standard_True);
84 for (; It.More(); It.Next()) {
85 TopoDS_Shape SS = It.Value();
87 if (shapeType == TopAbs_FLAT) {
88 if (SS.ShapeType() != TopAbs_COMPOUND)
91 index += NumberOfSubShapes(SS, shapeType, M);
93 else if (shapeType == TopAbs_SHAPE || shapeType == SS.ShapeType()) {
100 TopExp_Explorer Exp (S, TopAbs_ShapeEnum(shapeType));
101 for (; Exp.More(); Exp.Next()) {
102 if (M.Add(Exp.Current())) {
110 unsigned int NumberOfSubShapes(const TopoDS_Shape& S, const int shapeType)
112 TopTools_MapOfShape M;
113 return NumberOfSubShapes(S, shapeType, M);
117 //=================================================================================
118 // class : EntityGUI_SubShapeDlg
119 // purpose : Constructs a EntityGUI_SubShapeDlg which is a child of 'parent', with the
120 // name 'name' and widget flags set to 'f'.
121 // The dialog will by default be modeless, unless you set 'modal' to
122 // TRUE to construct a modal dialog.
123 //=================================================================================
124 EntityGUI_SubShapeDlg::EntityGUI_SubShapeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
125 bool modal, Qt::WindowFlags fl)
126 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
128 myIsHiddenMain(false)
130 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SUBSHAPE")));
131 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
133 setWindowTitle(tr("GEOM_SUBSHAPE_TITLE"));
135 /***************************************************************/
136 mainFrame()->GroupConstructors->setTitle(tr("GEOM_SUB_SHAPE"));
137 mainFrame()->RadioButton1->setIcon(image0);
138 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
139 mainFrame()->RadioButton2->close();
140 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
141 mainFrame()->RadioButton3->close();
143 GroupPoints = new DlgRef_1Sel1List1Check3Btn(centralWidget());
145 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
146 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
147 GroupPoints->TextLabel2->setText(tr("GEOM_SUBSHAPE_TYPE"));
148 GroupPoints->CheckButton1->setText(tr("GEOM_SUBSHAPE_SELECT"));
149 GroupPoints->PushButton1->setIcon(image1);
150 GroupPoints->PushButton2->setText(tr("SHOW_ONLY_SELECTED"));
151 GroupPoints->PushButton3->setText(tr("HIDE_SELECTED"));
152 GroupPoints->PushButton4->setText(tr("SHOW_ALL_SUB_SHAPES"));
153 GroupPoints->LineEdit1->setReadOnly(true);
157 myFilterGrp = new QGroupBox(tr("GEOM_FILTER"), centralWidget());
158 myLessFilterCheck = new QCheckBox(myFilterGrp);
159 myLessFilterCombo = new QComboBox(myFilterGrp);
160 myLessFilterCombo->addItem( tr("GEOM_LESS_THAN"), Filter_LT );
161 myLessFilterCombo->addItem( tr("GEOM_LESSOREQUAL_THAN"), Filter_LE );
162 myGreaterFilterCheck = new QCheckBox(myFilterGrp);
163 myGreaterFilterCombo = new QComboBox(myFilterGrp);
164 myGreaterFilterCombo->addItem( tr("GEOM_GREAT_THAN"), Filter_GT );
165 myGreaterFilterCombo->addItem( tr("GEOM_GREATOREQUAL_THAN"), Filter_GE );
166 myLessFilterSpin = new SalomeApp_DoubleSpinBox(myFilterGrp);
167 myGreaterFilterSpin = new SalomeApp_DoubleSpinBox(myFilterGrp);
168 myApplyFilterButton = new QPushButton(tr("GEOM_BUT_APPLY"), myFilterGrp);
169 myPlotDistributionButton = new QPushButton(tr("GEOM_PLOT_DISTRIBUTION"), myFilterGrp);
171 QGridLayout* filterLayout = new QGridLayout(myFilterGrp);
172 filterLayout->addWidget(myLessFilterCheck, 0, 0);
173 filterLayout->addWidget(myLessFilterCombo, 0, 1);
174 filterLayout->addWidget(myLessFilterSpin, 0, 2);
175 filterLayout->addWidget(myGreaterFilterCheck, 1, 0);
176 filterLayout->addWidget(myGreaterFilterCombo, 1, 1);
177 filterLayout->addWidget(myGreaterFilterSpin, 1, 2);
178 filterLayout->addWidget(myApplyFilterButton, 0, 3);
179 filterLayout->addWidget(myPlotDistributionButton, 1, 3);
181 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
182 layout->setMargin(0); layout->setSpacing(6);
183 layout->addWidget(GroupPoints);
184 layout->addWidget(myFilterGrp);
185 /***************************************************************/
187 setIsOptimizedBrowsing(true);
189 setHelpFileName("create_explode_page.html");
191 mainFrame()->GroupBoxName->hide();
196 //=================================================================================
197 // function : ~EntityGUI_SubShapeDlg()
198 // purpose : Destroys the object and frees any allocated resources
199 //=================================================================================
200 EntityGUI_SubShapeDlg::~EntityGUI_SubShapeDlg()
202 if (myIsHiddenMain) {
203 GEOM_Displayer* aDisplayer = getDisplayer();
204 aDisplayer->Display(myObject);
205 myIsHiddenMain = false;
210 //=================================================================================
213 //=================================================================================
214 void EntityGUI_SubShapeDlg::Init()
216 // Get setting of step value from file configuration
217 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
218 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
220 // min, max, step and decimals for spin boxes
221 initSpinBox(myLessFilterSpin, 0., COORD_MAX, step, "length_precision" );
222 initSpinBox(myGreaterFilterSpin, 0., COORD_MAX, step, "length_precision" );
223 myLessFilterSpin->setValue( 0. );
224 myGreaterFilterSpin->setValue( 0. );
228 myEditCurrentArgument = GroupPoints->LineEdit1;
229 myObject = GEOM::GEOM_Object::_nil();
231 /* type for sub-shape selection */
232 for ( int i = 0; i <= (int)GEOM::FLAT; i++ )
233 GroupPoints->ComboBox1->addItem(ShapeTypes[i], i);
235 if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
236 != OCCViewer_Viewer::Type())
237 GroupPoints->CheckButton1->setEnabled(false);
239 /* signals and slots connections */
240 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
242 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
243 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
245 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
246 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
248 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
249 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(SubShapeToggled()));
251 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
252 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
253 connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
255 connect(myApplyFilterButton, SIGNAL(clicked()), this, SLOT(ClickOnOkFilter()));
256 connect(myPlotDistributionButton, SIGNAL(clicked()), this, SLOT(ClickOnPlot()));
257 connect(myLessFilterCheck, SIGNAL(stateChanged(int)), this, SLOT(MeasureToggled()));
258 connect(myGreaterFilterCheck, SIGNAL(stateChanged(int)), this, SLOT(MeasureToggled()));
260 connect(myGeomGUI->getApp()->selectionMgr(),
261 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
265 SelectionIntoArgument();
270 //=================================================================================
271 // function : enterEvent()
273 //=================================================================================
274 void EntityGUI_SubShapeDlg::enterEvent(QEvent*)
276 if (!mainFrame()->GroupConstructors->isEnabled())
277 ActivateThisDialog();
280 //=================================================================================
281 // function : ActivateThisDialog()
283 //=================================================================================
284 void EntityGUI_SubShapeDlg::ActivateThisDialog()
286 GEOMBase_Skeleton::ActivateThisDialog();
287 connect(myGeomGUI->getApp()->selectionMgr(),
288 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
293 //=================================================================================
294 //function : closeEvent
295 //purpose : remove temporary geom object
296 //=================================================================================
297 void EntityGUI_SubShapeDlg::closeEvent(QCloseEvent* e)
300 GEOMBase_Skeleton::closeEvent(e);
303 //=================================================================================
304 // function : ClickOnOk()
306 //=================================================================================
307 void EntityGUI_SubShapeDlg::ClickOnOk()
309 setIsApplyAndClose(true);
311 SUIT_Session::session()->activeApplication()->putInfo("");
313 /* Explode all sub-shapes */
315 if (isAllSubShapes()) {
316 /* More than 30 sub-shapes : ask confirmation */
317 unsigned int nb = NumberOfSubShapes(myShape, shapeType());
319 if (SUIT_MessageBox::question( this,
321 tr("GEOM_CONFIRM_INFO").arg(nb),
322 tr("GEOM_BUT_EXPLODE"),
323 tr("GEOM_BUT_CANCEL") ) != 0 )
324 isOk = false; /* aborted */
335 //=================================================================================
336 // function : ClickOnApply()
338 //=================================================================================
339 bool EntityGUI_SubShapeDlg::ClickOnApply()
341 SUIT_Session::session()->activeApplication()->putInfo("");
343 /* Explode all sub-shapes */
344 if (isAllSubShapes()) {
345 /* More than 30 sub-shapes : ask confirmation */
346 unsigned int nb = NumberOfSubShapes(myShape, shapeType());
348 if (SUIT_MessageBox::question( this,
350 tr("GEOM_CONFIRM_INFO").arg(nb),
351 tr("GEOM_BUT_EXPLODE"),
352 tr("GEOM_BUT_CANCEL") ) != 0 )
353 return false; /* aborted */
357 setIsDisableBrowsing( true );
358 bool isOk = onAccept( true, true, false );
359 setIsDisableBrowsing( false );
361 // restore selection, corresponding to current selection mode
367 //=================================================================================
368 // function : SelectionIntoArgument()
369 // purpose : Called when selection has changed or other case
370 //=================================================================================
371 void EntityGUI_SubShapeDlg::SelectionIntoArgument()
373 if (!isAllSubShapes())
376 int currentType = GroupPoints->ComboBox1->itemData( GroupPoints->ComboBox1->currentIndex() ).toInt();
378 ResetStateOfDialog();
380 QString aString = ""; /* name of selection */
382 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
383 SALOME_ListIO aSelList;
384 aSelMgr->selectedObjects(aSelList);
386 int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
388 Handle(SALOME_InteractiveObject) IO = aSelList.First();
389 if (!IO->hasEntry()) {
390 SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
393 TopoDS_Shape S = GEOMBase::GetTopoFromSelection(aSelList);
394 if (S.IsNull() || S.ShapeType() == TopAbs_VERTEX) {
395 myObject = GEOM::GEOM_Object::_nil();
398 myObject = GEOMBase::ConvertIOinGEOMObject(IO);
399 if (!CORBA::is_nil(myObject)) {
401 GroupPoints->LineEdit1->setText(aString);
404 if (myShape.ShapeType() == TopAbs_COMPOUND) {
405 unsigned int nb = NumberOfSubShapes(myShape, TopAbs_COMPOUND);
409 while (i <= myShape.ShapeType()) {
410 GroupPoints->ComboBox1->removeItem(0);
413 // remove Shape and Flat types for non-compound shapes
414 if (myShape.ShapeType() != TopAbs_COMPOUND) {
415 int idx = GroupPoints->ComboBox1->findData( (int)GEOM::SHAPE );
416 if ( idx != -1 ) GroupPoints->ComboBox1->removeItem( idx );
417 idx = GroupPoints->ComboBox1->findData( (int)GEOM::FLAT );
418 if ( idx != -1 ) GroupPoints->ComboBox1->removeItem( idx );
419 } // if (myShape.ShapeType() != TopAbs_COMPOUND)
420 } // if (!CORBA::is_nil(myObject))
421 } // if (S.IsNull() || S.ShapeType() == TopAbs_VERTEX)
422 } // if (!IO->hasEntry()) ... else
425 int idx = GroupPoints->ComboBox1->findData( currentType );
427 GroupPoints->ComboBox1->setCurrentIndex( idx );
432 //=================================================================================
433 // function : SetEditCurrentArgument()
435 //=================================================================================
436 void EntityGUI_SubShapeDlg::SetEditCurrentArgument()
438 GroupPoints->LineEdit1->setFocus();
439 myEditCurrentArgument = GroupPoints->LineEdit1;
441 GroupPoints->CheckButton1->setChecked(false);
443 SelectionIntoArgument();
446 //=================================================================================
447 // function : LineEditReturnPressed()
449 //=================================================================================
450 void EntityGUI_SubShapeDlg::LineEditReturnPressed()
452 QLineEdit* send = (QLineEdit*)sender();
453 if (send == GroupPoints->LineEdit1)
454 SetEditCurrentArgument();
458 GEOMBase_Skeleton::LineEditReturnPressed();
461 //=================================================================================
462 // function : ResetStateOfDialog()
463 // purpose : Completely reset the state of method including local context
464 //=================================================================================
465 void EntityGUI_SubShapeDlg::ResetStateOfDialog()
467 if (myIsHiddenMain) {
468 GEOM_Displayer* aDisplayer = getDisplayer();
469 aDisplayer->Display(myObject);
470 myIsHiddenMain = false;
472 myObject = GEOM::GEOM_Object::_nil();
474 myEditCurrentArgument->setText("");
476 /* type for sub-shape selection */
477 GroupPoints->ComboBox1->clear();
478 for ( int i = 0; i <= (int)GEOM::FLAT; i++ )
479 GroupPoints->ComboBox1->addItem(ShapeTypes[i], i);
484 //=================================================================================
485 // function : SubShapeToggled()
486 // purpose : Allow user selection of all or only selected sub-shapes
487 // : Called when 'CheckButton1' state change
488 //=================================================================================
489 void EntityGUI_SubShapeDlg::SubShapeToggled()
491 GroupPoints->PushButton2->setEnabled(!isAllSubShapes());
492 GroupPoints->PushButton3->setEnabled(!isAllSubShapes());
493 GroupPoints->PushButton4->setEnabled(!isAllSubShapes());
494 myFilterGrp->setEnabled(GroupPoints->CheckButton1->isEnabled() &&
495 GroupPoints->CheckButton1->isChecked() &&
496 shapeType() < GEOM::VERTEX);
498 myPlotDistributionButton->setEnabled( myFilterGrp->isEnabled() &&
499 ( shapeType() == TopAbs_EDGE ||
500 shapeType() == TopAbs_FACE ||
501 shapeType() == TopAbs_SOLID ) );
506 //=================================================================================
507 // function : ComboTextChanged()
509 //=================================================================================
510 void EntityGUI_SubShapeDlg::ComboTextChanged()
512 /* Select sub-shapes mode not checked */
517 //=================================================================================
518 // function : updateButtonState
520 //=================================================================================
521 void EntityGUI_SubShapeDlg::updateButtonState()
523 bool viewOk = SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() == OCCViewer_Viewer::Type();
524 bool shapeTypeOk = shapeType() != TopAbs_SHAPE && shapeType() != TopAbs_FLAT && shapeType() != TopAbs_COMPOUND;
525 bool objectOK = !CORBA::is_nil( myObject );
527 if ( viewOk && objectOK && shapeTypeOk ) {
528 GroupPoints->CheckButton1->setEnabled( true );
531 GroupPoints->CheckButton1->setChecked( false );
532 GroupPoints->CheckButton1->setEnabled( false );
534 myFilterGrp->setEnabled(GroupPoints->CheckButton1->isEnabled() && GroupPoints->CheckButton1->isChecked());
537 //=================================================================================
538 // function : isAllSubShapes
540 //=================================================================================
541 bool EntityGUI_SubShapeDlg::isAllSubShapes() const
543 return !GroupPoints->CheckButton1->isEnabled() || !GroupPoints->CheckButton1->isChecked();
546 //=================================================================================
547 // function : shapeType
549 //=================================================================================
550 int EntityGUI_SubShapeDlg::shapeType() const
552 return GroupPoints->ComboBox1->itemData(GroupPoints->ComboBox1->currentIndex()).toInt();
555 //=================================================================================
556 // function : showOnlySelected
558 //=================================================================================
559 void EntityGUI_SubShapeDlg::showOnlySelected()
561 if (CORBA::is_nil(myObject) || isAllSubShapes())
564 QPushButton* send = (QPushButton*)sender();
565 if (send == GroupPoints->PushButton4) {
570 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
571 SALOME_ListIO aSelList;
572 aSelMgr->selectedObjects(aSelList);
574 GEOM_Displayer* aDisplayer = getDisplayer();
576 if (send == GroupPoints->PushButton3) {
577 aDisplayer->Erase(aSelList, /*forced=*/false, /*updateViewer=*/true);
580 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
581 SALOME_View* view = GEOM_Displayer::GetActiveView();
583 CORBA::String_var aMainEntry = myObject->GetStudyEntry();
584 Handle(SALOME_InteractiveObject) io =
585 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
586 if (view->isVisible(io)) myIsHiddenMain = true;
588 //keep the selected entry and IO in the map for checking
589 std::map<QString, Handle(SALOME_InteractiveObject)> aSelEntriesMap;
590 SALOME_ListIteratorOfListIO aSelIt(aSelList);
591 for ( ; aSelIt.More(); aSelIt.Next() ) {
592 //fill map <entry, io>
593 Handle(SALOME_InteractiveObject) anSelIO = aSelIt.Value();
594 aSelEntriesMap[anSelIO->getEntry()] = anSelIO;
596 //get the displayed sub-shapes
597 SALOME_ListIO displayed;
598 view->GetVisible(displayed);
599 // Erase all, except the selected shapes
600 std::map<QString, Handle(SALOME_InteractiveObject)>::iterator
601 aSelDispIter = aSelEntriesMap.end();
602 SALOME_ListIteratorOfListIO aDispIt( displayed );
603 for ( ; aDispIt.More(); aDispIt.Next() ) {
604 Handle(SALOME_InteractiveObject) anIO = aDispIt.Value();
605 aSelDispIter = aSelEntriesMap.find( anIO->getEntry() );
606 if ( aSelDispIter != aSelEntriesMap.end() ) {
607 //sub-shape is selected, so erase it's record from map to keep in it not displayed, but selected sub-shapes only
608 aSelEntriesMap.erase(aSelDispIter);
610 //sub-shape is not in the map of selected, then erase it from view
611 aDisplayer->Erase( anIO, /*forced = */false, /*updateViewer = */false );
615 if ( !aSelEntriesMap.empty() ) {
616 // Build a presentation of the selected, but not displayed sub-shapes
617 TopTools_IndexedMapOfShape aSubShapesMap;
618 TopExp::MapShapes(myShape, aSubShapesMap);
619 QString anEntryBase = aMainEntry.in();
621 TopExp_Explorer anExp (myShape, (TopAbs_ShapeEnum)shapeType());
622 for (; anExp.More(); anExp.Next())
624 TopoDS_Shape aSubShape = anExp.Current();
625 int index = aSubShapesMap.FindIndex(aSubShape);
626 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
627 if ( aSelEntriesMap.find( anEntry ) == aSelEntriesMap.end() ) {
628 //skip not selected sub-shapes
631 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, view);
633 displayPreview(aPrs, true, false); // append, do not update
637 aDisplayer->UpdateViewer();
640 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
641 if ((TopAbs_ShapeEnum)shapeType() == TopAbs_VERTEX && myIsHiddenMain) {
642 aDisplayer->Display(myObject);
647 //=================================================================================
648 // function : getSelectedSubshapes
650 //=================================================================================
651 int EntityGUI_SubShapeDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
655 SalomeApp_Application* app = myGeomGUI->getApp();
656 if (!app || myObject->_is_nil())
659 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
660 SALOME_ListIO aSelList;
661 aSelMgr->selectedObjects(aSelList);
663 // try to find out and process the global selection
664 // (of not published objects and of published sub-shapes)
666 SALOME_ListIteratorOfListIO anIter (aSelList);
667 for (int i = 0; anIter.More(); anIter.Next(), i++)
669 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
670 QString anEntry = anIObj->getEntry();
672 int index = anEntry.lastIndexOf(str);
673 if (index > 0) // selection among special preview
675 anEntry.remove(0, index+1);
676 int anIndex = anEntry.toInt();
678 theMapIndex.Add(anIndex);
680 else // selection among published shapes
682 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
683 if (!appStudy) return 0;
684 _PTR(Study) aStudy = appStudy->studyDS();
686 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
687 GEOM::GEOM_Object_var aGeomObj =
688 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
690 if (GEOMBase::GetShape(aGeomObj, aShape)) {
691 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == (TopAbs_ShapeEnum)shapeType()) {
692 TopTools_IndexedMapOfShape aMainMap;
693 TopExp::MapShapes(myShape, aMainMap);
695 TopExp_Explorer anExp (aShape, (TopAbs_ShapeEnum)shapeType());
696 for (; anExp.More(); anExp.Next()) {
697 TopoDS_Shape aSubShape = anExp.Current();
698 int anIndex = aMainMap.FindIndex(aSubShape);
700 theMapIndex.Add(anIndex);
709 return theMapIndex.Extent();
712 //=================================================================================
713 // function : activateSelection
714 // purpose : Activate selection in accordance with myEditCurrentArgument
715 //=================================================================================
716 void EntityGUI_SubShapeDlg::activateSelection()
718 bool isApply = ((QPushButton*)sender() == buttonApply());
724 if (!myObject->_is_nil() && !isAllSubShapes())
726 GEOM_Displayer* aDisplayer = getDisplayer();
728 //display mode for main shape
729 if ( myDmMode == -1 ) {
730 SALOME_View* view = GEOM_Displayer::GetActiveView();
732 CORBA::String_var aMainEntry = myObject->GetStudyEntry();
733 Handle(SALOME_InteractiveObject) io =
734 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
735 if ( view->isVisible( io ) ) {
736 Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIOinGEOMAISShape( io, true );
738 myDmMode = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
741 myDmMode = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "display_mode" );
744 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
745 if (shapeType() != TopAbs_VERTEX) {
746 aDisplayer->Erase(myObject, false, false);
747 myIsHiddenMain = true;
750 aDisplayer->Display(myObject);
752 aDisplayer->SetDisplayMode(myDmMode);
755 SUIT_ViewWindow* aViewWindow = 0;
756 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
758 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
759 if (aViewWindow == 0) return;
761 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
762 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
763 aViewManager->getType() != SVTK_Viewer::Type())
766 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
767 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
768 if (aView == 0) return;
770 //TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myObject);
772 TopTools_IndexedMapOfShape aSubShapesMap;
773 TopExp::MapShapes(myShape, aSubShapesMap);
774 CORBA::String_var aMainEntry = myObject->GetStudyEntry();
775 QString anEntryBase = aMainEntry.in();
777 TopExp_Explorer anExp (myShape, (TopAbs_ShapeEnum)shapeType());
778 for (; anExp.More(); anExp.Next())
780 TopoDS_Shape aSubShape = anExp.Current();
781 int index = aSubShapesMap.FindIndex(aSubShape);
782 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
784 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
786 displayPreview(aPrs, true, false); // append, do not update
789 aDisplayer->UnsetDisplayMode();
790 aDisplayer->UpdateViewer();
794 globalSelection(GEOM_ALLSHAPES);
797 //=================================================================================
798 // function : createOperation
800 //=================================================================================
801 GEOM::GEOM_IOperations_ptr EntityGUI_SubShapeDlg::createOperation()
803 return getGeomEngine()->GetIShapesOperations(getStudyId());
806 //=================================================================================
807 // function : isValid
809 //=================================================================================
810 bool EntityGUI_SubShapeDlg::isValid (QString& msg)
814 if (myObject->_is_nil()) {
819 if (isAllSubShapes())
822 TColStd_IndexedMapOfInteger aMapIndex;
823 int nbSel = getSelectedSubshapes(aMapIndex);
827 msg += tr("NO_SUBSHAPES_SELECTED");
833 //=================================================================================
834 // function : execute
836 //=================================================================================
837 bool EntityGUI_SubShapeDlg::execute (ObjectList& objects)
839 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
841 if (!isAllSubShapes()) {
843 TColStd_IndexedMapOfInteger aMapIndex;
844 int nbSel = getSelectedSubshapes(aMapIndex);
849 GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
850 anArray->length(nbSel);
852 for (i = 1; i <= nbSel; i++)
853 anArray[i - 1] = aMapIndex.FindKey(i);
855 GEOM::ListOfGO_var aList = anOper->MakeSubShapes(myObject, anArray);
856 int n = aList->length();
857 for (i = 0; i < n; i++)
858 objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
862 GEOM::ListOfGO_var aList = anOper->ExtractSubShapes(myObject, shapeType(), true);
863 if (!aList->length())
865 for (int i = 0, n = aList->length(); i < n; i++)
866 objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
869 return objects.size();
872 //================================================================
873 // Function : getFather
874 // Purpose : Get father object for object to be added in study
875 // (called with addInStudy method)
876 //================================================================
877 GEOM::GEOM_Object_ptr EntityGUI_SubShapeDlg::getFather(GEOM::GEOM_Object_ptr)
882 //================================================================
883 // Function : getNewObjectName
885 //================================================================
886 QString EntityGUI_SubShapeDlg::getNewObjectName (int) const
888 return QString::null;
891 //=================================================================================
892 // function : ClickOnOkFilter()
893 // purpose : highlight and select entities which parameters (length, area or volume) are less than the value specified by the user
894 //=================================================================================
895 void EntityGUI_SubShapeDlg::ClickOnOkFilter()
897 if (CORBA::is_nil(myObject) || isAllSubShapes() || shapeType() >= GEOM::VERTEX)
900 TopTools_IndexedMapOfShape aSubShapesMap;
901 TopExp::MapShapes(myShape, aSubShapesMap);
902 SALOME_View* view = GEOM_Displayer::GetActiveView();
903 getDisplayer()->Erase(myObject, false, false);
904 CORBA::String_var aMainEntry = myObject->GetStudyEntry();
905 QString anEntryBase = aMainEntry.in();
907 SALOME_ListIO toSelect;
909 TopExp_Explorer anExp (myShape, (TopAbs_ShapeEnum)shapeType());
910 for (; anExp.More(); anExp.Next())
912 TopoDS_Shape aSubShape = anExp.Current();
913 int index = aSubShapesMap.FindIndex(aSubShape);
914 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
915 if ( !getDisplayer()->IsDisplayed( anEntry ) )
918 double factor = GEOMUtils::ShapeToDouble(aSubShape).second;
919 double v1 = myLessFilterSpin->value();
920 double v2 = myGreaterFilterSpin->value();
921 bool isLess = myLessFilterCombo->itemData(myLessFilterCombo->currentIndex()).toInt() == Filter_LT ? factor < v1 : factor <= v1;
922 bool isGreater = myGreaterFilterCombo->itemData(myGreaterFilterCombo->currentIndex()).toInt() == Filter_GT ? factor > v2 : factor >= v2;
923 if ( ( myLessFilterCheck->isChecked() && myGreaterFilterCheck->isChecked() && isLess && isGreater ) ||
924 ( myLessFilterCheck->isChecked() && !myGreaterFilterCheck->isChecked() && isLess ) ||
925 ( myGreaterFilterCheck->isChecked() && !myLessFilterCheck->isChecked() && isGreater ) ) {
926 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject();
927 io->setEntry( anEntry.toLatin1().constData() );
928 io->setName( myObject->GetName() );
932 if ( toSelect.Extent() > 0 ) {
933 myGeomGUI->getApp()->selectionMgr()->setSelectedObjects(toSelect);
934 SUIT_MessageBox::information( this,
936 tr( "GEOM_SOME_SHAPES_SELECTED").arg( toSelect.Extent() ),
940 SUIT_MessageBox::information( this,
942 tr( "GEOM_NO_SHAPES_SELECTED" ),
948 //=================================================================================
949 // function : ClickOnPlot()
950 // purpose : opens "Shape Statistics" dialog box in order to plot sub-shapes distribution.
951 //=================================================================================
952 void EntityGUI_SubShapeDlg::ClickOnPlot()
954 QDialog* dlg = new MeasureGUI_ShapeStatisticsDlg( this, myShape, (TopAbs_ShapeEnum)shapeType() );
960 //=================================================================================
961 // function : MeasureToggled()
963 // : Called when 'myLessFilterCheck' or 'myGreaterFilterCheck' state change
964 //=================================================================================
965 void EntityGUI_SubShapeDlg::MeasureToggled()
967 myLessFilterSpin->setEnabled(myLessFilterCheck->isChecked());
968 myLessFilterCombo->setEnabled(myLessFilterCheck->isChecked());
969 myGreaterFilterSpin->setEnabled(myGreaterFilterCheck->isChecked());
970 myGreaterFilterCombo->setEnabled(myGreaterFilterCheck->isChecked());
971 myApplyFilterButton->setEnabled(myLessFilterCheck->isChecked() || myGreaterFilterCheck->isChecked());
974 //=================================================================================
975 // function : getSourceObjects
976 // purpose : virtual method to get source objects
977 //=================================================================================
978 QList<GEOM::GeomObjPtr> EntityGUI_SubShapeDlg::getSourceObjects()
980 QList<GEOM::GeomObjPtr> res;
981 GEOM::GeomObjPtr aGeomObjPtr(myObject);