geom/src/EntityGUI/EntityGUI_SubShapeDlg.cxx

850 lines
29 KiB
C++
Raw Normal View History

2013-04-01 18:25:01 +06:00
// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
2004-01-07 20:46:21 +05:00
//
2012-08-09 13:58:02 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
2004-01-07 20:46:21 +05:00
//
2012-08-09 13:58:02 +06:00
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
2004-01-07 20:46:21 +05:00
//
2012-08-09 13:58:02 +06:00
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
2009-02-13 17:16:39 +05:00
// GEOM GEOMGUI : GUI for Geometry component
// File : EntityGUI_SubShapeDlg.cxx
// Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
2012-08-09 13:58:02 +06:00
2004-01-07 20:46:21 +05:00
#include "EntityGUI_SubShapeDlg.h"
2009-02-13 17:16:39 +05:00
#include <DlgRef.h>
#include <GeometryGUI.h>
#include <GEOMBase.h>
2012-08-09 13:58:02 +06:00
#include <OCCViewer_ViewModel.h>
#include <SVTK_ViewModel.h>
#include <SalomeApp_Study.h>
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
#include <SALOME_ListIteratorOfListIO.hxx>
2009-02-13 17:16:39 +05:00
#include <SUIT_Desktop.h>
#include <SUIT_ResourceMgr.h>
#include <SUIT_Session.h>
#include <SUIT_ViewManager.h>
#include <SUIT_ViewWindow.h>
2004-01-07 20:46:21 +05:00
2012-08-09 13:58:02 +06:00
#include <TopExp.hxx>
2004-01-07 20:46:21 +05:00
#include <TopExp_Explorer.hxx>
2012-08-09 13:58:02 +06:00
#include <TopoDS_Iterator.hxx>
2004-01-07 20:46:21 +05:00
#include <TopTools_MapOfShape.hxx>
2012-08-09 13:58:02 +06:00
#include <TopTools_IndexedMapOfShape.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
#include <QMessageBox>
2004-01-07 20:46:21 +05:00
2012-08-09 13:58:02 +06:00
#include <GEOMImpl_Types.hxx>
2004-01-07 20:46:21 +05:00
//=================================================================================
2004-12-01 15:39:14 +05:00
// class : EntityGUI_SubShapeDlg
2004-01-07 20:46:21 +05:00
// purpose : Constructs a EntityGUI_SubShapeDlg which is a child of 'parent', with the
// name 'name' and widget flags set to 'f'.
// The dialog will by default be modeless, unless you set 'modal' to
// TRUE to construct a modal dialog.
//=================================================================================
2012-08-09 13:58:02 +06:00
EntityGUI_SubShapeDlg::EntityGUI_SubShapeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
bool modal, Qt::WindowFlags fl)
: GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
myDmMode( -1 ),
2012-08-09 13:58:02 +06:00
myWithShape(true),
myIsHiddenMain(false)
2004-01-07 20:46:21 +05:00
{
2012-08-09 13:58:02 +06:00
QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SUBSHAPE")));
QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
2004-01-07 20:46:21 +05:00
2012-08-09 13:58:02 +06:00
setWindowTitle(tr("GEOM_SUBSHAPE_TITLE"));
2004-01-07 20:46:21 +05:00
/***************************************************************/
2012-08-09 13:58:02 +06:00
mainFrame()->GroupConstructors->setTitle(tr("GEOM_SUB_SHAPE"));
mainFrame()->RadioButton1->setIcon(image0);
mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
2009-02-13 17:16:39 +05:00
mainFrame()->RadioButton2->close();
2012-08-09 13:58:02 +06:00
mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
2009-02-13 17:16:39 +05:00
mainFrame()->RadioButton3->close();
2012-08-09 13:58:02 +06:00
GroupPoints = new DlgRef_1Sel1List1Check3Btn(centralWidget());
GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
GroupPoints->TextLabel2->setText(tr("GEOM_SUBSHAPE_TYPE"));
GroupPoints->CheckButton1->setText(tr("GEOM_SUBSHAPE_SELECT"));
GroupPoints->PushButton1->setIcon(image1);
GroupPoints->PushButton2->setText(tr("SHOW_ONLY_SELECTED"));
GroupPoints->PushButton3->setText(tr("HIDE_SELECTED"));
GroupPoints->PushButton4->setText(tr("SHOW_ALL_SUB_SHAPES"));
GroupPoints->LineEdit1->setReadOnly(true);
QVBoxLayout* layout = new QVBoxLayout(centralWidget());
layout->setMargin(0); layout->setSpacing(6);
layout->addWidget(GroupPoints);
2004-01-07 20:46:21 +05:00
/***************************************************************/
2012-08-09 13:58:02 +06:00
setIsOptimizedBrowsing(true);
setHelpFileName("create_explode_page.html");
2009-02-13 17:16:39 +05:00
mainFrame()->GroupBoxName->hide();
2004-12-01 15:39:14 +05:00
Init();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : ~EntityGUI_SubShapeDlg()
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
EntityGUI_SubShapeDlg::~EntityGUI_SubShapeDlg()
{
2012-08-09 13:58:02 +06:00
if (myIsHiddenMain) {
GEOM_Displayer* aDisplayer = getDisplayer();
aDisplayer->Display(myObject);
myIsHiddenMain = false;
}
myDmMode = -1;
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
2004-12-01 15:39:14 +05:00
void EntityGUI_SubShapeDlg::Init()
2004-01-07 20:46:21 +05:00
{
/* init variables */
myDmMode = -1;
2004-01-07 20:46:21 +05:00
myEditCurrentArgument = GroupPoints->LineEdit1;
2004-12-01 15:39:14 +05:00
myObject = GEOM::GEOM_Object::_nil();
2004-01-07 20:46:21 +05:00
myWithShape = true;
2012-08-09 13:58:02 +06:00
/* type for sub-shape selection */
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compound");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compsolid");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Solid");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shell");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Face");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Wire");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Edge");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Vertex");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
!= OCCViewer_Viewer::Type())
GroupPoints->CheckButton1->setEnabled(false);
2004-01-07 20:46:21 +05:00
/* signals and slots connections */
2012-08-09 13:58:02 +06:00
connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
2004-01-07 20:46:21 +05:00
2012-08-09 13:58:02 +06:00
connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
2004-01-07 20:46:21 +05:00
2012-08-09 13:58:02 +06:00
connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
2004-01-07 20:46:21 +05:00
2012-08-09 13:58:02 +06:00
connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(SubShapeToggled()));
2012-08-09 13:58:02 +06:00
connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
2012-08-09 13:58:02 +06:00
connect(myGeomGUI->getApp()->selectionMgr(),
SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
2004-01-07 20:46:21 +05:00
2012-08-09 13:58:02 +06:00
updateButtonState();
resize(100,100);
2004-12-01 15:39:14 +05:00
SelectionIntoArgument();
2004-01-07 20:46:21 +05:00
}
2012-08-09 13:58:02 +06:00
//=================================================================================
// function : enterEvent()
// purpose :
//=================================================================================
void EntityGUI_SubShapeDlg::enterEvent(QEvent*)
{
if (!mainFrame()->GroupConstructors->isEnabled())
ActivateThisDialog();
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
void EntityGUI_SubShapeDlg::ActivateThisDialog()
{
GEOMBase_Skeleton::ActivateThisDialog();
connect(myGeomGUI->getApp()->selectionMgr(),
SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
SubShapeToggled();
updateButtonState();
}
//=================================================================================
//function : closeEvent
//purpose : remove temporary geom object
//=================================================================================
void EntityGUI_SubShapeDlg::closeEvent(QCloseEvent* e)
{
erasePreview(true);
GEOMBase_Skeleton::closeEvent(e);
}
2004-01-07 20:46:21 +05:00
//=================================================================================
// function : ClickOnOk()
// purpose :
//=================================================================================
void EntityGUI_SubShapeDlg::ClickOnOk()
{
2012-08-09 13:58:02 +06:00
setIsApplyAndClose(true);
SUIT_Session::session()->activeApplication()->putInfo("");
/* Explode all sub-shapes */
bool isOk = true;
if (isAllSubShapes()) {
/* More than 30 sub-shapes : ask confirmation */
unsigned int nb = NumberOfSubShapes(myShape, shapeType());
if (nb > 30) {
const QString caption = tr("GEOM_CONFIRM");
const QString text = tr("GEOM_CONFIRM_INFO").arg(nb);
const QString button0 = tr("GEOM_BUT_EXPLODE");
const QString button1 = tr("GEOM_BUT_CANCEL");
if (QMessageBox::warning(this, caption, text, button0, button1) != 0)
isOk = false; /* aborted */
}
}
if (isOk)
isOk = onAccept();
if (isOk)
2004-12-01 15:39:14 +05:00
ClickOnCancel();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : ClickOnApply()
// purpose :
//=================================================================================
2004-12-01 15:39:14 +05:00
bool EntityGUI_SubShapeDlg::ClickOnApply()
2004-01-07 20:46:21 +05:00
{
2012-08-09 13:58:02 +06:00
SUIT_Session::session()->activeApplication()->putInfo("");
/* Explode all sub-shapes */
if (isAllSubShapes()) {
/* More than 30 sub-shapes : ask confirmation */
unsigned int nb = NumberOfSubShapes(myShape, shapeType());
if (nb > 30) {
const QString caption = tr("GEOM_CONFIRM");
const QString text = tr("GEOM_CONFIRM_INFO").arg(nb);
const QString button0 = tr("GEOM_BUT_EXPLODE");
const QString button1 = tr("GEOM_BUT_CANCEL");
if (QMessageBox::warning(this, caption, text, button0, button1) != 0)
2004-12-01 15:39:14 +05:00
return false; /* aborted */
2004-01-07 20:46:21 +05:00
}
}
2012-08-09 13:58:02 +06:00
setIsDisableBrowsing( true );
bool isOk = onAccept( true, true, false );
setIsDisableBrowsing( false );
// restore selection, corresponding to current selection mode
SubShapeToggled();
return isOk;
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : SelectionIntoArgument()
2012-08-09 13:58:02 +06:00
// purpose : Called when selection has changed or other case
2004-01-07 20:46:21 +05:00
//=================================================================================
void EntityGUI_SubShapeDlg::SelectionIntoArgument()
{
2009-02-13 17:16:39 +05:00
if (!isAllSubShapes())
2004-12-01 15:39:14 +05:00
return;
ResetStateOfDialog();
2004-01-07 20:46:21 +05:00
QString aString = ""; /* name of selection */
2009-02-13 17:16:39 +05:00
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList);
int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
if (nbSel != 1)
2004-01-07 20:46:21 +05:00
return;
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
Handle(SALOME_InteractiveObject) IO = aSelList.First();
2012-08-09 13:58:02 +06:00
if (!IO->hasEntry()) {
SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
2004-12-01 15:39:14 +05:00
updateButtonState();
2004-01-07 20:46:21 +05:00
return;
2004-12-01 15:39:14 +05:00
}
2012-08-09 13:58:02 +06:00
if (myIsHiddenMain) {
GEOM_Displayer* aDisplayer = getDisplayer();
aDisplayer->Display(myObject);
myIsHiddenMain = false;
}
TopoDS_Shape S = GEOMBase::GetTopoFromSelection(aSelList);
if (S.IsNull() || S.ShapeType() == TopAbs_VERTEX) {
2009-02-13 17:16:39 +05:00
myObject = GEOM::GEOM_Object::_nil();
2004-12-01 15:39:14 +05:00
updateButtonState();
2004-01-07 20:46:21 +05:00
return;
}
2012-08-09 13:58:02 +06:00
myObject = GEOMBase::ConvertIOinGEOMObject(IO);
if (myObject->_is_nil()) {
2004-12-01 15:39:14 +05:00
updateButtonState();
return;
}
myShape = S;
2009-02-13 17:16:39 +05:00
GroupPoints->LineEdit1->setText(aString);
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
2004-12-01 15:39:14 +05:00
int count = GroupPoints->ComboBox1->count();
2009-02-13 17:16:39 +05:00
if (myWithShape)
2004-12-01 15:39:14 +05:00
count = count - 1;
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
int i = 0;
// Solving PAL5590
2009-02-13 17:16:39 +05:00
if (myShape.ShapeType() == TopAbs_COMPOUND) {
2004-12-01 15:39:14 +05:00
unsigned int nb = NumberOfSubShapes(myShape, TopAbs_COMPOUND);
2012-08-09 13:58:02 +06:00
if (nb > 0)
2004-01-07 20:46:21 +05:00
i++;
2004-12-01 15:39:14 +05:00
}
2009-02-13 17:16:39 +05:00
while (i <= myShape.ShapeType()) {
GroupPoints->ComboBox1->removeItem(0);
2004-12-01 15:39:14 +05:00
i++;
}
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
if (myShape.ShapeType() == TopAbs_COMPOUND) {
if (myWithShape == false) {
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
2004-12-01 15:39:14 +05:00
myWithShape = true;
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
}
2009-02-13 17:16:39 +05:00
else {
2012-08-09 13:58:02 +06:00
if (myWithShape == true) {
GroupPoints->ComboBox1->removeItem(GroupPoints->ComboBox1->count() - 1);
2004-12-01 15:39:14 +05:00
myWithShape = false;
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
}
int count1 = GroupPoints->ComboBox1->count();
2012-08-09 13:58:02 +06:00
if (myWithShape)
2004-12-01 15:39:14 +05:00
count1 = count1 - 1;
2012-08-09 13:58:02 +06:00
if (SelectedShapeType > myShape.ShapeType()) {
if (SelectedShapeType == 8) {
if (myShape.ShapeType() != TopAbs_COMPOUND) {
GroupPoints->ComboBox1->setCurrentIndex(0);
2004-12-01 15:39:14 +05:00
ComboTextChanged();
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
}
else
2012-08-09 13:58:02 +06:00
GroupPoints->ComboBox1->setCurrentIndex(count1 - count + SelectedShapeType);
2004-12-01 15:39:14 +05:00
}
2009-02-13 17:16:39 +05:00
else {
2012-08-09 13:58:02 +06:00
GroupPoints->ComboBox1->setCurrentIndex(0);
2004-12-01 15:39:14 +05:00
ComboTextChanged();
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
updateButtonState();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
void EntityGUI_SubShapeDlg::SetEditCurrentArgument()
{
2004-12-01 15:39:14 +05:00
GroupPoints->LineEdit1->setFocus();
myEditCurrentArgument = GroupPoints->LineEdit1;
2012-08-09 13:58:02 +06:00
GroupPoints->CheckButton1->setChecked(false);
2004-12-01 15:39:14 +05:00
SubShapeToggled();
SelectionIntoArgument();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
// function : LineEditReturnPressed()
// purpose :
//=================================================================================
void EntityGUI_SubShapeDlg::LineEditReturnPressed()
2012-08-09 13:58:02 +06:00
{
2004-01-07 20:46:21 +05:00
QLineEdit* send = (QLineEdit*)sender();
2012-08-09 13:58:02 +06:00
if (send == GroupPoints->LineEdit1)
2004-12-01 15:39:14 +05:00
SetEditCurrentArgument();
2004-01-07 20:46:21 +05:00
else
return;
GEOMBase_Skeleton::LineEditReturnPressed();
}
//=================================================================================
// function : ResetStateOfDialog()
// purpose : Completely reset the state of method including local context
//=================================================================================
void EntityGUI_SubShapeDlg::ResetStateOfDialog()
{
2012-08-09 13:58:02 +06:00
if (myIsHiddenMain) {
GEOM_Displayer* aDisplayer = getDisplayer();
aDisplayer->Display(myObject);
myIsHiddenMain = false;
}
2004-12-01 15:39:14 +05:00
myObject = GEOM::GEOM_Object::_nil();
myShape.Nullify();
2012-08-09 13:58:02 +06:00
myEditCurrentArgument->setText("");
2004-01-07 20:46:21 +05:00
2009-02-13 17:16:39 +05:00
int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
2004-01-07 20:46:21 +05:00
int count = GroupPoints->ComboBox1->count();
2012-08-09 13:58:02 +06:00
if (myWithShape)
2004-01-07 20:46:21 +05:00
count = count - 1;
2012-08-09 13:58:02 +06:00
/* type for sub-shape selection */
2004-01-07 20:46:21 +05:00
GroupPoints->ComboBox1->clear();
2012-08-09 13:58:02 +06:00
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compound");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compsolid");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Solid");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shell");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Face");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Wire");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Edge");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Vertex");
GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
2004-12-01 15:39:14 +05:00
myWithShape = true;
2012-08-09 13:58:02 +06:00
GroupPoints->ComboBox1->setCurrentIndex(8 - count + SelectedShapeType);
// to avoid recursion: SelectionIntoArgument->ResetStateOfDialog->ComboTextChanged->SubShapeToggled->activateSelection->(currentSelectionChanged)->SelectionIntoArgument
//ComboTextChanged();
2004-12-01 15:39:14 +05:00
updateButtonState();
2004-01-07 20:46:21 +05:00
}
//=================================================================================
2004-12-01 15:39:14 +05:00
// function : SubShapeToggled()
2012-08-09 13:58:02 +06:00
// purpose : Allow user selection of all or only selected sub-shapes
2004-01-07 20:46:21 +05:00
// : Called when 'CheckButton1' state change
//=================================================================================
2004-12-01 15:39:14 +05:00
void EntityGUI_SubShapeDlg::SubShapeToggled()
2004-01-07 20:46:21 +05:00
{
2012-08-09 13:58:02 +06:00
GroupPoints->PushButton2->setEnabled(!isAllSubShapes());
GroupPoints->PushButton3->setEnabled(!isAllSubShapes());
GroupPoints->PushButton4->setEnabled(!isAllSubShapes());
2012-08-09 13:58:02 +06:00
activateSelection();
2004-12-01 15:39:14 +05:00
}
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
//=================================================================================
// function : ComboTextChanged()
2012-08-09 13:58:02 +06:00
// purpose :
2004-12-01 15:39:14 +05:00
//=================================================================================
void EntityGUI_SubShapeDlg::ComboTextChanged()
{
2012-08-09 13:58:02 +06:00
/* Select sub-shapes mode not checked */
2004-12-01 15:39:14 +05:00
updateButtonState();
2012-08-09 13:58:02 +06:00
SubShapeToggled();
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : NumberOfSubShapes()
// purpose :
//=================================================================================
2012-08-09 13:58:02 +06:00
unsigned int EntityGUI_SubShapeDlg::NumberOfSubShapes(const TopoDS_Shape& S,
const int shapeType) const
2004-12-01 15:39:14 +05:00
{
2012-08-09 13:58:02 +06:00
if (S.IsNull())
2004-12-01 15:39:14 +05:00
return 0;
unsigned int index = 0;
TopTools_MapOfShape M;
2012-08-09 13:58:02 +06:00
if (S.ShapeType() == TopAbs_COMPOUND &&
(TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
TopAbs_ShapeEnum(shapeType) == TopAbs_COMPSOLID ||
TopAbs_ShapeEnum(shapeType) == TopAbs_COMPOUND)) {
TopoDS_Iterator It(S, Standard_True, Standard_True);
for (; It.More(); It.Next()) {
if (M.Add(It.Value())) {
if (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
TopAbs_ShapeEnum(shapeType) == It.Value().ShapeType()) {
2004-12-01 15:39:14 +05:00
index++;
}
}
}
2012-08-09 13:58:02 +06:00
}
2009-02-13 17:16:39 +05:00
else {
2012-08-09 13:58:02 +06:00
TopExp_Explorer Exp (S, TopAbs_ShapeEnum(shapeType));
for (; Exp.More(); Exp.Next()) {
if (M.Add(Exp.Current())) {
2004-12-01 15:39:14 +05:00
index++;
}
2004-01-07 20:46:21 +05:00
}
}
2004-12-01 15:39:14 +05:00
M.Clear();
return index;
}
//=================================================================================
// function : updateButtonState
// purpose :
//=================================================================================
void EntityGUI_SubShapeDlg::updateButtonState()
{
2012-08-09 13:58:02 +06:00
if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() != OCCViewer_Viewer::Type() ||
myObject->_is_nil() || shapeType() == TopAbs_SHAPE || shapeType() == TopAbs_COMPOUND) {
GroupPoints->CheckButton1->setChecked(false);
GroupPoints->CheckButton1->setEnabled(false);
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
else
2012-08-09 13:58:02 +06:00
GroupPoints->CheckButton1->setEnabled(true);
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
//=================================================================================
// function : isAllSubShapes
// purpose :
//=================================================================================
bool EntityGUI_SubShapeDlg::isAllSubShapes() const
{
return !GroupPoints->CheckButton1->isChecked() || !GroupPoints->CheckButton1->isEnabled();
}
2004-01-07 20:46:21 +05:00
//=================================================================================
2004-12-01 15:39:14 +05:00
// function : shapeType
// purpose :
2004-01-07 20:46:21 +05:00
//=================================================================================
2004-12-01 15:39:14 +05:00
int EntityGUI_SubShapeDlg::shapeType() const
2004-01-07 20:46:21 +05:00
{
2009-02-13 17:16:39 +05:00
int type = GroupPoints->ComboBox1->currentIndex();
2004-01-07 20:46:21 +05:00
2012-08-09 13:58:02 +06:00
if (myObject->_is_nil())
2004-12-01 15:39:14 +05:00
return type;
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
// Solving PAL5590
type += myShape.ShapeType() + 1;
2012-08-09 13:58:02 +06:00
if (myShape.ShapeType() == TopAbs_COMPOUND &&
NumberOfSubShapes(myShape, TopAbs_COMPOUND) > 0) {
2004-12-01 15:39:14 +05:00
type--;
}
return type;
}
2012-08-09 13:58:02 +06:00
//=================================================================================
// function : showOnlySelected
// purpose :
//=================================================================================
void EntityGUI_SubShapeDlg::showOnlySelected()
{
if (CORBA::is_nil(myObject) || isAllSubShapes())
return;
QPushButton* send = (QPushButton*)sender();
if (send == GroupPoints->PushButton4) {
activateSelection();
return;
}
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList);
GEOM_Displayer* aDisplayer = getDisplayer();
if (send == GroupPoints->PushButton3) {
aDisplayer->Erase(aSelList, /*forced=*/false, /*updateViewer=*/true);
}
else {
// Mantis issue 0021421: do not hide main shape, if explode on VERTEX
SALOME_View* view = GEOM_Displayer::GetActiveView();
if (view) {
CORBA::String_var aMainEntry = myObject->GetStudyEntry();
Handle(SALOME_InteractiveObject) io =
new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
if (view->isVisible(io)) myIsHiddenMain = true;
}
aDisplayer->EraseAll(/*forced = false, updateViewer = true*/);
aDisplayer->Display(aSelList, true);
// Mantis issue 0021421: do not hide main shape, if explode on VERTEX
if ((TopAbs_ShapeEnum)shapeType() == TopAbs_VERTEX && myIsHiddenMain) {
aDisplayer->Display(myObject);
}
}
}
//=================================================================================
// function : getSelectedSubshapes
// purpose :
//=================================================================================
int EntityGUI_SubShapeDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
{
theMapIndex.Clear();
SalomeApp_Application* app = myGeomGUI->getApp();
if (!app || myObject->_is_nil())
return 0;
LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList);
// try to find out and process the global selection
// (of not published objects and of published sub-shapes)
{
SALOME_ListIteratorOfListIO anIter (aSelList);
for (int i = 0; anIter.More(); anIter.Next(), i++)
{
Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
QString anEntry = anIObj->getEntry();
QString str = "_";
int index = anEntry.lastIndexOf(str);
if (index > 0) // selection among special preview
{
anEntry.remove(0, index+1);
int anIndex = anEntry.toInt();
if (anIndex)
theMapIndex.Add(anIndex);
}
else // selection among published shapes
{
SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
if (!appStudy) return 0;
_PTR(Study) aStudy = appStudy->studyDS();
_PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
GEOM::GEOM_Object_var aGeomObj =
GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
TopoDS_Shape aShape;
if (GEOMBase::GetShape(aGeomObj, aShape)) {
if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == (TopAbs_ShapeEnum)shapeType()) {
TopTools_IndexedMapOfShape aMainMap;
TopExp::MapShapes(myShape, aMainMap);
TopExp_Explorer anExp (aShape, (TopAbs_ShapeEnum)shapeType());
for (; anExp.More(); anExp.Next()) {
TopoDS_Shape aSubShape = anExp.Current();
int anIndex = aMainMap.FindIndex(aSubShape);
if (anIndex >= 0) {
theMapIndex.Add(anIndex);
}
}
}
}
}
} // for aSelList
}
return theMapIndex.Extent();
}
//=================================================================================
// function : activateSelection
// purpose : Activate selection in accordance with myEditCurrentArgument
//=================================================================================
void EntityGUI_SubShapeDlg::activateSelection()
{
bool isApply = ((QPushButton*)sender() == buttonApply());
if(!isApply)
erasePreview(false);
// local selection
if (!myObject->_is_nil() && !isAllSubShapes())
{
GEOM_Displayer* aDisplayer = getDisplayer();
//display mode for main shape
if ( myDmMode == -1 ) {
2012-08-09 13:58:02 +06:00
SALOME_View* view = GEOM_Displayer::GetActiveView();
if (view) {
CORBA::String_var aMainEntry = myObject->GetStudyEntry();
Handle(SALOME_InteractiveObject) io =
new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
if ( view->isVisible( io ) ) {
Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIOinGEOMAISShape( io, true );
if(!aSh.IsNull()) {
myDmMode = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
}
// Hide main shape, if explode on VERTEX
if (shapeType() != TopAbs_VERTEX) {
aDisplayer->Erase(myObject, false, false);
myIsHiddenMain = true;
}
2012-08-09 13:58:02 +06:00
}
else
myDmMode = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "display_mode" );
2012-08-09 13:58:02 +06:00
}
}
// Mantis issue 0021421: do not hide main shape, if explode on VERTEX
if (shapeType() == TopAbs_VERTEX) {
if (myIsHiddenMain)
aDisplayer->Display(myObject);
}
aDisplayer->SetDisplayMode(myDmMode);
2012-08-09 13:58:02 +06:00
if(!isApply) {
SUIT_ViewWindow* aViewWindow = 0;
SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
if (activeStudy)
aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
if (aViewWindow == 0) return;
SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
aViewManager->getType() != SVTK_Viewer::Type())
return;
SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
if (aView == 0) return;
//TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myObject);
TopTools_IndexedMapOfShape aSubShapesMap;
TopExp::MapShapes(myShape, aSubShapesMap);
CORBA::String_var aMainEntry = myObject->GetStudyEntry();
QString anEntryBase = aMainEntry.in();
TopExp_Explorer anExp (myShape, (TopAbs_ShapeEnum)shapeType());
for (; anExp.More(); anExp.Next())
{
TopoDS_Shape aSubShape = anExp.Current();
int index = aSubShapesMap.FindIndex(aSubShape);
2013-06-17 18:15:50 +06:00
QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
2012-08-09 13:58:02 +06:00
SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
if (aPrs) {
displayPreview(aPrs, true, false); // append, do not update
}
}
aDisplayer->UnsetDisplayMode();
2012-08-09 13:58:02 +06:00
aDisplayer->UpdateViewer();
}
}
globalSelection(GEOM_ALLSHAPES);
}
2004-12-01 15:39:14 +05:00
//=================================================================================
// function : createOperation
// purpose :
//=================================================================================
GEOM::GEOM_IOperations_ptr EntityGUI_SubShapeDlg::createOperation()
{
2012-08-09 13:58:02 +06:00
return getGeomEngine()->GetIShapesOperations(getStudyId());
2004-12-01 15:39:14 +05:00
}
2004-01-07 20:46:21 +05:00
2004-12-01 15:39:14 +05:00
//=================================================================================
// function : isValid
// purpose :
//=================================================================================
2009-02-13 17:16:39 +05:00
bool EntityGUI_SubShapeDlg::isValid (QString& msg)
2004-12-01 15:39:14 +05:00
{
bool isOk = false;
2009-02-13 17:16:39 +05:00
if (myObject->_is_nil()) {
updateButtonState();
return isOk;
}
2009-02-13 17:16:39 +05:00
if (isAllSubShapes())
isOk = true;
else {
2012-08-09 13:58:02 +06:00
TColStd_IndexedMapOfInteger aMapIndex;
int nbSel = getSelectedSubshapes(aMapIndex);
isOk = nbSel > 0;
if (!isOk)
msg += tr("NO_SUBSHAPES_SELECTED");
2004-01-07 20:46:21 +05:00
}
2009-02-13 17:16:39 +05:00
2004-12-01 15:39:14 +05:00
return isOk;
2004-01-07 20:46:21 +05:00
}
//=================================================================================
2004-12-01 15:39:14 +05:00
// function : execute
2004-01-07 20:46:21 +05:00
// purpose :
//=================================================================================
2009-02-13 17:16:39 +05:00
bool EntityGUI_SubShapeDlg::execute (ObjectList& objects)
2004-01-07 20:46:21 +05:00
{
2012-08-09 13:58:02 +06:00
GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
2009-02-13 17:16:39 +05:00
if (!isAllSubShapes()) {
2012-08-09 13:58:02 +06:00
// manual selection
TColStd_IndexedMapOfInteger aMapIndex;
int nbSel = getSelectedSubshapes(aMapIndex);
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
if (nbSel > 0) {
int i;
2004-12-01 15:39:14 +05:00
2012-08-09 13:58:02 +06:00
GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
anArray->length(nbSel);
2004-12-01 15:39:14 +05:00
2012-08-09 13:58:02 +06:00
for (i = 1; i <= nbSel; i++)
anArray[i - 1] = aMapIndex.FindKey(i);
2004-12-01 15:39:14 +05:00
2012-08-09 13:58:02 +06:00
GEOM::ListOfGO_var aList = anOper->MakeSubShapes(myObject, anArray);
int n = aList->length();
for (i = 0; i < n; i++)
objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
2004-12-01 15:39:14 +05:00
}
2004-01-07 20:46:21 +05:00
}
2012-08-09 13:58:02 +06:00
else {
GEOM::ListOfGO_var aList = anOper->ExtractSubShapes(myObject, shapeType(), true);
if (!aList->length())
return false;
2009-02-13 17:16:39 +05:00
for (int i = 0, n = aList->length(); i < n; i++)
objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
2012-08-09 13:58:02 +06:00
}
2004-12-01 15:39:14 +05:00
return objects.size();
2004-01-07 20:46:21 +05:00
}
2004-12-01 15:39:14 +05:00
//================================================================
// Function : getFather
// Purpose : Get father object for object to be added in study
2012-08-09 13:58:02 +06:00
// (called with addInStudy method)
2004-12-01 15:39:14 +05:00
//================================================================
2012-08-09 13:58:02 +06:00
GEOM::GEOM_Object_ptr EntityGUI_SubShapeDlg::getFather(GEOM::GEOM_Object_ptr)
2004-12-01 15:39:14 +05:00
{
return myObject;
}
2012-08-09 13:58:02 +06:00
//================================================================
// Function : getNewObjectName
// Purpose :
//================================================================
2013-02-12 17:35:16 +06:00
QString EntityGUI_SubShapeDlg::getNewObjectName (int) const
{
2009-02-13 17:16:39 +05:00
return QString::null;
}