geom/src/RepairGUI/RepairGUI_FuseEdgesDlg.cxx

349 lines
12 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
2009-02-13 17:16:39 +05: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.
//
// 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.
//
// 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
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2013-04-01 18:25:01 +06:00
//
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
#include "RepairGUI_FuseEdgesDlg.h"
2009-02-13 17:16:39 +05:00
#include <DlgRef.h>
#include <GeometryGUI.h>
#include <GEOMBase.h>
#include <SUIT_Desktop.h>
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
#include <SUIT_ViewWindow.h>
#include <SUIT_ViewManager.h>
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
#include <OCCViewer_ViewModel.h>
// OCCT Includes
#include <TColStd_MapOfInteger.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
#include <GEOMImpl_Types.hxx>
//=================================================================================
2012-08-09 13:58:02 +06:00
// class : RepairGUI_FuseEdgesDlg()
// purpose : Constructs a RepairGUI_FuseEdgesDlg which is a child of 'parent', with the
2009-02-13 17:16:39 +05:00
// 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
RepairGUI_FuseEdgesDlg::RepairGUI_FuseEdgesDlg (GeometryGUI* theGeometryGUI,
QWidget* parent)
2009-02-13 17:16:39 +05:00
: GEOMBase_Skeleton(theGeometryGUI, parent, false)
{
SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
2012-08-09 13:58:02 +06:00
QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_FUSE_EDGES")));
2009-02-13 17:16:39 +05:00
QPixmap iconSelect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
2012-08-09 13:58:02 +06:00
setWindowTitle(tr("GEOM_FUSE_EDGES_TITLE"));
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
mainFrame()->GroupConstructors->setTitle(tr("GEOM_FUSE_EDGES"));
2009-02-13 17:16:39 +05:00
mainFrame()->RadioButton1->setIcon(image0);
mainFrame()->RadioButton2->close();
mainFrame()->RadioButton3->close();
2012-08-09 13:58:02 +06:00
GroupVertexes = new DlgRef_2Sel1Spin (centralWidget());
GroupVertexes->GroupBox1->setTitle(tr("GEOM_FUSE_EDGES"));
GroupVertexes->TextLabel1->setText(tr("GEOM_WIRE"));
2009-02-13 17:16:39 +05:00
GroupVertexes->TextLabel2->setText(tr("GEOM_VERTEXES"));
GroupVertexes->PushButton1->setIcon(iconSelect);
GroupVertexes->PushButton2->setIcon(iconSelect);
GroupVertexes->LineEdit1->setReadOnly(true);
GroupVertexes->LineEdit2->setReadOnly(true);
2012-08-09 13:58:02 +06:00
GroupVertexes->TextLabel3->setShown(false);
GroupVertexes->SpinBox_DX->setShown(false);
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
QVBoxLayout* layout = new QVBoxLayout (centralWidget());
layout->setMargin(0);
layout->setSpacing(6);
layout->addWidget(GroupVertexes);
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
setHelpFileName("fuse_edges_operation_page.html");
2009-02-13 17:16:39 +05:00
// Initialisation
Init();
2012-08-09 13:58:02 +06:00
resize(100,100);
2009-02-13 17:16:39 +05:00
}
//=================================================================================
2012-08-09 13:58:02 +06:00
// function : ~RepairGUI_FuseEdgesDlg()
2009-02-13 17:16:39 +05:00
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
2012-08-09 13:58:02 +06:00
RepairGUI_FuseEdgesDlg::~RepairGUI_FuseEdgesDlg()
2009-02-13 17:16:39 +05:00
{
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
2012-08-09 13:58:02 +06:00
void RepairGUI_FuseEdgesDlg::Init()
2009-02-13 17:16:39 +05:00
{
// Clear line edits
GroupVertexes->LineEdit1->setText("");
GroupVertexes->LineEdit2->setText("");
myShape = GEOM::GEOM_Object::_nil();
2012-08-09 13:58:02 +06:00
myPoints.clear();
2009-02-13 17:16:39 +05:00
// signals and slots connections
2012-08-09 13:58:02 +06:00
connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
2009-02-13 17:16:39 +05:00
connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
connect(GroupVertexes->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
connect(GroupVertexes->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
connect(GroupVertexes->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
connect(GroupVertexes->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
2012-08-09 13:58:02 +06:00
initName(tr("FUSE_EDGES_NEW_OBJ_NAME"));
2009-02-13 17:16:39 +05:00
GroupVertexes->PushButton1->click();
2012-08-09 13:58:02 +06:00
SelectionIntoArgument();
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : ClickOnOk()
// purpose :
//=================================================================================
2012-08-09 13:58:02 +06:00
void RepairGUI_FuseEdgesDlg::ClickOnOk()
2009-02-13 17:16:39 +05:00
{
2012-08-09 13:58:02 +06:00
setIsApplyAndClose(true);
2009-02-13 17:16:39 +05:00
if (ClickOnApply())
ClickOnCancel();
}
//=================================================================================
// function : ClickOnApply()
// purpose :
//=================================================================================
2012-08-09 13:58:02 +06:00
bool RepairGUI_FuseEdgesDlg::ClickOnApply()
2009-02-13 17:16:39 +05:00
{
if (!onAccept())
return false;
initName();
// Reset dialog state
GroupVertexes->LineEdit1->setText("");
GroupVertexes->LineEdit2->setText("");
myShape = GEOM::GEOM_Object::_nil();
2012-08-09 13:58:02 +06:00
myPoints.clear();
2009-02-13 17:16:39 +05:00
GroupVertexes->PushButton1->click();
return true;
}
//=================================================================================
// function : SelectionIntoArgument()
// purpose : Called when selection is changed or on dialog initialization or activation
//=================================================================================
2012-08-09 13:58:02 +06:00
void RepairGUI_FuseEdgesDlg::SelectionIntoArgument()
2009-02-13 17:16:39 +05:00
{
myEditCurrentArgument->setText("");
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList);
// If selection of main object is activated
if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
myShape = GEOM::GEOM_Object::_nil();
if (aSelList.Extent() == 1) {
GEOM::GEOM_Object_var anObj =
2012-08-09 13:58:02 +06:00
GEOMBase::ConvertIOinGEOMObject(aSelList.First());
if (!anObj->_is_nil()) {
QString aName = GEOMBase::GetName(anObj);
TopoDS_Shape aShape;
if (GEOMBase::GetShape(anObj, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
TColStd_IndexedMapOfInteger aMap;
aSelMgr->GetIndexes(aSelList.First(), aMap);
if (aMap.Extent() == 1) { // Local Selection
int anIndex = aMap(1);
aName += QString(":wire_%1").arg(anIndex);
//Find SubShape Object in Father
GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(anObj, aName);
if (aFindedObject->_is_nil()) { // Object not found in study
GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
anObj = aShapesOp->GetSubShape(anObj, anIndex);
}
else
anObj = aFindedObject; // get Object from study
}
else { // Global Selection
if (aShape.ShapeType() != TopAbs_WIRE) {
anObj = GEOM::GEOM_Object::_nil();
aName = "";
}
2009-02-13 17:16:39 +05:00
}
}
2012-08-09 13:58:02 +06:00
myShape = anObj;
myEditCurrentArgument->setText(aName);
2009-02-13 17:16:39 +05:00
}
}
2012-08-09 13:58:02 +06:00
if (!myShape->_is_nil() && myPoints.isEmpty())
2009-02-13 17:16:39 +05:00
GroupVertexes->PushButton2->click();
}
2012-08-09 13:58:02 +06:00
else if (myEditCurrentArgument == GroupVertexes->LineEdit2) {
myPoints = getSelected(TopAbs_VERTEX, -1);
if (!myPoints.isEmpty())
myEditCurrentArgument->setText(QString::number(myPoints.count()) + "_" + tr("GEOM_POINT") + tr("_S_"));
else
myEditCurrentArgument->setText("");
}
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
2012-08-09 13:58:02 +06:00
void RepairGUI_FuseEdgesDlg::SetEditCurrentArgument()
2009-02-13 17:16:39 +05:00
{
QPushButton* send = (QPushButton*)sender();
if (send == GroupVertexes->PushButton1) {
myEditCurrentArgument = GroupVertexes->LineEdit1;
GroupVertexes->PushButton2->setDown(false);
GroupVertexes->LineEdit2->setEnabled(false);
}
else if (send == GroupVertexes->PushButton2) {
myEditCurrentArgument = GroupVertexes->LineEdit2;
GroupVertexes->PushButton1->setDown(false);
GroupVertexes->LineEdit1->setEnabled(false);
}
// enable line edit
myEditCurrentArgument->setEnabled(true);
myEditCurrentArgument->setFocus();
// after setFocus(), because it will be setDown(false) when loses focus
send->setDown(true);
activateSelection();
}
//=================================================================================
// function : LineEditReturnPressed()
// purpose :
//=================================================================================
2012-08-09 13:58:02 +06:00
void RepairGUI_FuseEdgesDlg::LineEditReturnPressed()
2009-02-13 17:16:39 +05:00
{
QLineEdit* send = (QLineEdit*)sender();
if (send == GroupVertexes->LineEdit1)
myEditCurrentArgument = GroupVertexes->LineEdit1;
else if (send == GroupVertexes->LineEdit2)
myEditCurrentArgument = GroupVertexes->LineEdit2;
else
return;
GEOMBase_Skeleton::LineEditReturnPressed();
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
2012-08-09 13:58:02 +06:00
void RepairGUI_FuseEdgesDlg::ActivateThisDialog()
2009-02-13 17:16:39 +05:00
{
GEOMBase_Skeleton::ActivateThisDialog();
}
//=================================================================================
// function : enterEvent()
// purpose :
//=================================================================================
2012-08-09 13:58:02 +06:00
void RepairGUI_FuseEdgesDlg::enterEvent (QEvent*)
2009-02-13 17:16:39 +05:00
{
if (!mainFrame()->GroupConstructors->isEnabled())
this->ActivateThisDialog();
}
//=================================================================================
// function : activateSelection
// purpose : Activate selection in accordance with myEditCurrentArgument
//=================================================================================
2012-08-09 13:58:02 +06:00
void RepairGUI_FuseEdgesDlg::activateSelection()
2009-02-13 17:16:39 +05:00
{
disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
globalSelection();
if (myEditCurrentArgument == GroupVertexes->LineEdit1)
2012-08-09 13:58:02 +06:00
globalSelection(GEOM_WIRE);
2009-02-13 17:16:39 +05:00
else if (!myShape->_is_nil() && myEditCurrentArgument == GroupVertexes->LineEdit2)
localSelection(myShape, TopAbs_VERTEX);
connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
this, SLOT(SelectionIntoArgument()));
}
//=================================================================================
// function : createOperation
// purpose :
//=================================================================================
2012-08-09 13:58:02 +06:00
GEOM::GEOM_IOperations_ptr RepairGUI_FuseEdgesDlg::createOperation()
2009-02-13 17:16:39 +05:00
{
2012-08-09 13:58:02 +06:00
return getGeomEngine()->GetIHealingOperations(getStudyId());
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : isValid()
// purpose : Verify validity of input data
//=================================================================================
2012-08-09 13:58:02 +06:00
bool RepairGUI_FuseEdgesDlg::isValid (QString& msg)
2009-02-13 17:16:39 +05:00
{
2012-08-09 13:58:02 +06:00
return (!myShape->_is_nil());
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : execute
// purpose :
//=================================================================================
2012-08-09 13:58:02 +06:00
bool RepairGUI_FuseEdgesDlg::execute (ObjectList& objects)
2009-02-13 17:16:39 +05:00
{
2012-08-09 13:58:02 +06:00
GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
GEOM::ListOfGO_var points = new GEOM::ListOfGO();
points->length(myPoints.count());
for (int i = 0; i < myPoints.count(); i++)
points[i] = myPoints[i].copy();
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
GEOM::GEOM_Object_var anObj = anOper->FuseCollinearEdgesWithinWire(myShape, points.in());
2009-02-13 17:16:39 +05:00
if (!anObj->_is_nil())
objects.push_back(anObj._retn());
return true;
}
//=================================================================================
2012-08-09 13:58:02 +06:00
// function : addSubshapeToStudy
// purpose : virtual method to add new SubObjects if local selection
2009-02-13 17:16:39 +05:00
//=================================================================================
2012-08-09 13:58:02 +06:00
void RepairGUI_FuseEdgesDlg::addSubshapesToStudy()
2009-02-13 17:16:39 +05:00
{
2012-08-09 13:58:02 +06:00
for (int i = 0; i < myPoints.count(); i++)
GEOMBase::PublishSubObject(myPoints[i].get());
2009-02-13 17:16:39 +05:00
}