geom/src/RepairGUI/RepairGUI_RemoveIntWiresDlg.cxx

361 lines
13 KiB
C++
Raw Normal View History

2014-02-18 12:44:41 +06:00
// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
2004-12-01 15:39:14 +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-12-01 15:39:14 +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
2014-02-18 12:44:41 +06:00
// version 2.1 of the License, or (at your option) any later version.
2004-12-01 15:39:14 +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 : RepairGUI_RemoveIntWiresDlg.cxx
// Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
2004-12-01 15:39:14 +05:00
//
#include "RepairGUI_RemoveIntWiresDlg.h"
2009-02-13 17:16:39 +05:00
#include <DlgRef.h>
#include <GeometryGUI.h>
#include <GEOMBase.h>
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
// OCCT Includes
2004-12-01 15:39:14 +05:00
#include <TopAbs.hxx>
#include <TColStd_MapOfInteger.hxx>
2009-02-13 17:16:39 +05:00
#include <TColStd_IndexedMapOfInteger.hxx>
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
#include <GEOMImpl_Types.hxx>
2004-12-01 15:39:14 +05:00
//=================================================================================
// class : RepairGUI_RemoveIntWiresDlg()
// purpose : Constructs a RepairGUI_RemoveIntWiresDlg 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.
//=================================================================================
2009-02-13 17:16:39 +05:00
RepairGUI_RemoveIntWiresDlg::RepairGUI_RemoveIntWiresDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
bool modal)
: GEOMBase_Skeleton(theGeometryGUI, parent, modal)
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
QPixmap image0 (myGeomGUI->getApp()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SUPPRESS_INT_WIRES")));
QPixmap image1 (myGeomGUI->getApp()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
setWindowTitle(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
2004-12-01 15:39:14 +05:00
/***************************************************************/
2009-02-13 17:16:39 +05:00
mainFrame()->GroupConstructors->setTitle(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
mainFrame()->RadioButton1->setIcon(image0);
mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
mainFrame()->RadioButton2->close();
mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
mainFrame()->RadioButton3->close();
GroupPoints = new DlgRef_1Sel1Check1Sel(centralWidget());
2004-12-01 15:39:14 +05:00
GroupPoints->GroupBox1->setTitle(tr("GEOM_INTERNAL_WIRES"));
GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_FACE"));
2009-02-13 17:16:39 +05:00
GroupPoints->PushButton1->setIcon(image1);
GroupPoints->LineEdit1->setReadOnly(true);
GroupPoints->CheckButton1->setText(tr("GEOM_REMOVE_ALL_INT_WIRES"));
GroupPoints->TextLabel2->setText(tr("GEOM_WIRES_TO_REMOVE"));
GroupPoints->PushButton2->setIcon(image1);
GroupPoints->LineEdit2->setReadOnly(true);
QVBoxLayout* layout = new QVBoxLayout(centralWidget());
layout->setMargin(0); layout->setSpacing(6);
layout->addWidget(GroupPoints);
2004-12-01 15:39:14 +05:00
/***************************************************************/
setHelpFileName("suppress_internal_wires_operation_page.html");
2004-12-01 15:39:14 +05:00
Init();
}
//=================================================================================
// function : ~RepairGUI_RemoveIntWiresDlg()
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
RepairGUI_RemoveIntWiresDlg::~RepairGUI_RemoveIntWiresDlg()
{
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void RepairGUI_RemoveIntWiresDlg::Init()
{
2009-02-13 17:16:39 +05:00
// init variables
GroupPoints->LineEdit1->clear();
GroupPoints->LineEdit2->clear();
2004-12-01 15:39:14 +05:00
myObject = GEOM::GEOM_Object::_nil();
2009-02-13 17:16:39 +05:00
myWiresInd = new GEOM::short_array();
myWiresInd->length(0);
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
// signals and slots connections
connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
connect(GroupPoints->CheckButton1, SIGNAL(clicked()), this, SLOT(onRemoveAllClicked()));
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
initName(tr("REMOVE_INT_WIRES_NEW_OBJ_NAME"));
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
GroupPoints->PushButton1->click();
SelectionIntoArgument();
2012-08-09 13:58:02 +06:00
resize(100,100);
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : ClickOnOk()
// purpose : Same than click on apply but close this dialog.
//=================================================================================
void RepairGUI_RemoveIntWiresDlg::ClickOnOk()
{
2012-08-09 13:58:02 +06:00
setIsApplyAndClose( true );
2009-02-13 17:16:39 +05:00
if (ClickOnApply())
2004-12-01 15:39:14 +05:00
ClickOnCancel();
}
//=================================================================================
// function : ClickOnApply()
// purpose :
//=================================================================================
bool RepairGUI_RemoveIntWiresDlg::ClickOnApply()
{
2009-02-13 17:16:39 +05:00
if (!onAccept())
return false;
2004-12-01 15:39:14 +05:00
initName();
2009-02-13 17:16:39 +05:00
// activate first line edit
GroupPoints->PushButton1->click();
2004-12-01 15:39:14 +05:00
return true;
}
//=================================================================================
// function : SelectionIntoArgument()
2009-02-13 17:16:39 +05:00
// purpose : Called when selection is changed or on dialog initialization or activation
2004-12-01 15:39:14 +05:00
//=================================================================================
void RepairGUI_RemoveIntWiresDlg::SelectionIntoArgument()
{
myEditCurrentArgument->setText("");
2009-02-13 17:16:39 +05:00
// the second argument depends on the first one
GroupPoints->LineEdit2->setText("");
myWiresInd->length(0);
if (myEditCurrentArgument == GroupPoints->LineEdit1)
myObject = GEOM::GEOM_Object::_nil();
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList);
if (aSelList.Extent() == 1) {
Handle(SALOME_InteractiveObject) anIO = aSelList.First();
if (myEditCurrentArgument == GroupPoints->LineEdit1) { // face selection
2012-08-09 13:58:02 +06:00
myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
if ( GEOMBase::IsShape(myObject) ) {
2009-02-13 17:16:39 +05:00
myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
// clear selection
disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
myGeomGUI->getApp()->selectionMgr()->clearSelected();
connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
this, SLOT(SelectionIntoArgument()));
if (!GroupPoints->CheckButton1->isChecked())
GroupPoints->PushButton2->click();
}
else
myObject = GEOM::GEOM_Object::_nil();
}
2009-02-13 17:16:39 +05:00
else if (myEditCurrentArgument == GroupPoints->LineEdit2 &&
!GroupPoints->CheckButton1->isChecked()) {
TColStd_IndexedMapOfInteger aMap;
aSelMgr->GetIndexes(anIO, aMap);
const int n = aMap.Extent();
myWiresInd->length(n);
for (int i = 1; i <= n; i++)
myWiresInd[i-1] = aMap(i);
if (n)
myEditCurrentArgument->setText(QString::number(n) + "_" + tr("GEOM_WIRE") + tr("_S_"));
}
}
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
void RepairGUI_RemoveIntWiresDlg::SetEditCurrentArgument()
{
2009-02-13 17:16:39 +05:00
QPushButton* send = (QPushButton*)sender();
bool isEffective = false;
if (send == GroupPoints->PushButton1) {
isEffective = true;
myEditCurrentArgument = GroupPoints->LineEdit1;
GroupPoints->PushButton2->setDown(false);
GroupPoints->LineEdit2->setEnabled(false);
2004-12-01 15:39:14 +05:00
}
2009-02-13 17:16:39 +05:00
else if (send == GroupPoints->PushButton2 && !myObject->_is_nil()) {
isEffective = true;
myEditCurrentArgument = GroupPoints->LineEdit2;
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
GroupPoints->PushButton1->setDown(false);
GroupPoints->LineEdit1->setEnabled(false);
}
if (isEffective) {
initSelection();
// enable line edit
myEditCurrentArgument->setEnabled(true);
myEditCurrentArgument->setFocus();
// after setFocus(), because it will be setDown(false) when loses focus
send->setDown(true);
}
}
2004-12-01 15:39:14 +05:00
//=================================================================================
// function : LineEditReturnPressed()
// purpose :
//=================================================================================
void RepairGUI_RemoveIntWiresDlg::LineEditReturnPressed()
{
2009-02-13 17:16:39 +05:00
const QObject* send = sender();
if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2) {
2004-12-01 15:39:14 +05:00
myEditCurrentArgument = (QLineEdit*)send;
2009-02-13 17:16:39 +05:00
GEOMBase_Skeleton::LineEditReturnPressed();
}
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
void RepairGUI_RemoveIntWiresDlg::ActivateThisDialog()
{
GEOMBase_Skeleton::ActivateThisDialog();
2009-02-13 17:16:39 +05:00
connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
2012-08-09 13:58:02 +06:00
this, SLOT( SelectionIntoArgument() ) );
2004-12-01 15:39:14 +05:00
myEditCurrentArgument = GroupPoints->LineEdit1;
2009-02-13 17:16:39 +05:00
myEditCurrentArgument->setText( "" );
GroupPoints->LineEdit2->setText( "" );
2004-12-01 15:39:14 +05:00
myObject = GEOM::GEOM_Object::_nil();
myWiresInd->length( 0 );
//myGeomGUI->SetState( 0 );
initSelection();
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : enterEvent()
// purpose : Mouse enter onto the dialog to activate it
//=================================================================================
2009-02-13 17:16:39 +05:00
void RepairGUI_RemoveIntWiresDlg::enterEvent (QEvent*)
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
if (!mainFrame()->GroupConstructors->isEnabled())
2004-12-01 15:39:14 +05:00
ActivateThisDialog();
}
//=================================================================================
// function : createOperation
// purpose :
//=================================================================================
GEOM::GEOM_IOperations_ptr RepairGUI_RemoveIntWiresDlg::createOperation()
{
2009-02-13 17:16:39 +05:00
return getGeomEngine()->GetIHealingOperations(getStudyId());
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : isValid
// purpose :
//=================================================================================
2009-02-13 17:16:39 +05:00
bool RepairGUI_RemoveIntWiresDlg::isValid (QString&)
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
return !myObject->_is_nil() && (GroupPoints->CheckButton1->isChecked() || myWiresInd->length());
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : execute
// purpose :
//=================================================================================
2009-02-13 17:16:39 +05:00
bool RepairGUI_RemoveIntWiresDlg::execute (ObjectList& objects)
2004-12-01 15:39:14 +05:00
{
2012-08-09 13:58:02 +06:00
GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
GEOM::GEOM_Object_var anObj = anOper->RemoveIntWires(myObject, myWiresInd);
2009-02-13 17:16:39 +05:00
bool aResult = !anObj->_is_nil();
2009-02-13 17:16:39 +05:00
if (aResult)
objects.push_back(anObj._retn());
2004-12-01 15:39:14 +05:00
return aResult;
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : onRemoveAllClicked
// purpose :
//=================================================================================
void RepairGUI_RemoveIntWiresDlg::onRemoveAllClicked()
{
2009-02-13 17:16:39 +05:00
bool b = GroupPoints->CheckButton1->isChecked();
GroupPoints->TextLabel2->setEnabled(!b);
GroupPoints->PushButton2->setEnabled(!b);
GroupPoints->LineEdit2->setEnabled(!b);
if (b) {
GroupPoints->LineEdit2->setText("");
myWiresInd->length(0);
2004-12-01 15:39:14 +05:00
}
}
//=================================================================================
// function : initSelection
// purpose :
//=================================================================================
void RepairGUI_RemoveIntWiresDlg::initSelection()
{
2009-02-13 17:16:39 +05:00
disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
if (myEditCurrentArgument == GroupPoints->LineEdit1) {
TColStd_MapOfInteger aTypes;
aTypes.Add(GEOM_COMPOUND);
aTypes.Add(GEOM_SOLID);
aTypes.Add(GEOM_SHELL);
aTypes.Add(GEOM_FACE);
globalSelection(aTypes);
2004-12-01 15:39:14 +05:00
}
2009-02-13 17:16:39 +05:00
else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
//localSelection(myObject, TopAbs_EDGE);
localSelection(myObject, TopAbs_WIRE);
2004-12-01 15:39:14 +05:00
}
2009-02-13 17:16:39 +05:00
connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
this, SLOT(SelectionIntoArgument()));
2004-12-01 15:39:14 +05:00
}