2009-02-13 17:16:39 +05:00
|
|
|
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
|
2008-03-07 12:45:34 +05:00
|
|
|
//
|
2009-02-13 17:16:39 +05:00
|
|
|
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
|
2008-03-07 12:45:34 +05:00
|
|
|
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
2009-02-13 17:16:39 +05:00
|
|
|
// GEOM GEOMGUI : GUI for Geometry component
|
|
|
|
// File : MeasureGUI_NormaleDlg.cxx
|
|
|
|
// Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
|
2008-03-07 12:45:34 +05:00
|
|
|
//
|
|
|
|
#include "MeasureGUI_NormaleDlg.h"
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
#include <DlgRef.h>
|
|
|
|
#include <GEOMBase.h>
|
|
|
|
#include <GeometryGUI.h>
|
2008-03-07 12:45:34 +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>
|
2008-03-07 12:45:34 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
// OCCT Includes
|
|
|
|
#include <TopoDS_Shape.hxx>
|
|
|
|
#include <TopoDS.hxx>
|
|
|
|
#include <TopExp.hxx>
|
|
|
|
#include <TColStd_IndexedMapOfInteger.hxx>
|
|
|
|
#include <TopTools_IndexedMapOfShape.hxx>
|
2008-03-07 12:45:34 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
#include <GEOMImpl_Types.hxx>
|
2008-03-07 12:45:34 +05:00
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// class : MeasureGUI_NormaleDlg()
|
|
|
|
// purpose : Constructs a MeasureGUI_NormaleDlg 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
|
|
|
MeasureGUI_NormaleDlg::MeasureGUI_NormaleDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
|
|
|
|
: GEOMBase_Skeleton(theGeometryGUI, parent, false)
|
2008-03-07 12:45:34 +05:00
|
|
|
{
|
|
|
|
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
|
|
|
|
QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_NORMALE")));
|
|
|
|
QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
setWindowTitle(tr("GEOM_NORMALE_TITLE"));
|
2008-03-07 12:45:34 +05:00
|
|
|
|
|
|
|
/***************************************************************/
|
2009-02-13 17:16:39 +05:00
|
|
|
mainFrame()->GroupConstructors->setTitle(tr("GEOM_NORMALE"));
|
|
|
|
mainFrame()->RadioButton1->setIcon(image0);
|
|
|
|
mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
mainFrame()->RadioButton2->close();
|
|
|
|
mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
mainFrame()->RadioButton3->close();
|
|
|
|
|
|
|
|
GroupArgs = new DlgRef_2Sel (centralWidget());
|
2008-03-07 12:45:34 +05:00
|
|
|
GroupArgs->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
|
|
|
|
|
|
|
|
GroupArgs->TextLabel1->setText(tr("GEOM_FACE"));
|
|
|
|
GroupArgs->TextLabel2->setText(tr("GEOM_POINT"));
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
GroupArgs->PushButton1->setIcon(image1);
|
|
|
|
GroupArgs->PushButton2->setIcon(image1);
|
2008-03-07 12:45:34 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
QVBoxLayout* layout = new QVBoxLayout(centralWidget());
|
|
|
|
layout->setMargin(0); layout->setSpacing(6);
|
|
|
|
layout->addWidget(GroupArgs);
|
2008-03-07 12:45:34 +05:00
|
|
|
/***************************************************************/
|
|
|
|
|
|
|
|
setHelpFileName("using_measurement_tools_page.html#normale_anchor");
|
|
|
|
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ~MeasureGUI_NormaleDlg()
|
|
|
|
// purpose : Destroys the object and frees any allocated resources
|
|
|
|
//=================================================================================
|
|
|
|
MeasureGUI_NormaleDlg::~MeasureGUI_NormaleDlg()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : Init()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void MeasureGUI_NormaleDlg::Init()
|
|
|
|
{
|
2009-02-13 17:16:39 +05:00
|
|
|
// init variables
|
2008-03-07 12:45:34 +05:00
|
|
|
GroupArgs->LineEdit1->setReadOnly(true);
|
|
|
|
GroupArgs->LineEdit2->setReadOnly(true);
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
GroupArgs->LineEdit1->setText("");
|
|
|
|
GroupArgs->LineEdit2->setText("");
|
|
|
|
myFace = myPoint = GEOM::GEOM_Object::_nil();
|
2008-03-07 12:45:34 +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()));
|
2008-03-07 12:45:34 +05:00
|
|
|
|
|
|
|
connect(GroupArgs->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
|
|
|
|
connect(GroupArgs->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
connect(GroupArgs->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
|
|
|
|
connect(GroupArgs->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
|
2008-03-07 12:45:34 +05:00
|
|
|
|
|
|
|
initName(tr("GEOM_VECTOR_NORMALE"));
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
GroupArgs->PushButton1->click();
|
2008-03-07 12:45:34 +05:00
|
|
|
SelectionIntoArgument();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ClickOnOk()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void MeasureGUI_NormaleDlg::ClickOnOk()
|
|
|
|
{
|
|
|
|
if (ClickOnApply())
|
|
|
|
ClickOnCancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ClickOnApply()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
bool MeasureGUI_NormaleDlg::ClickOnApply()
|
|
|
|
{
|
|
|
|
if (!onAccept())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
initName();
|
2009-02-13 17:16:39 +05:00
|
|
|
// activate first line edit
|
|
|
|
GroupArgs->PushButton1->click();
|
2008-03-07 12:45:34 +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
|
2008-03-07 12:45:34 +05:00
|
|
|
//=================================================================================
|
|
|
|
void MeasureGUI_NormaleDlg::SelectionIntoArgument()
|
|
|
|
{
|
|
|
|
erasePreview();
|
|
|
|
myEditCurrentArgument->setText("");
|
|
|
|
|
|
|
|
if (myEditCurrentArgument == GroupArgs->LineEdit1) {
|
|
|
|
myFace = GEOM::GEOM_Object::_nil();
|
|
|
|
}
|
|
|
|
else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
|
|
|
|
myPoint = GEOM::GEOM_Object::_nil();
|
|
|
|
}
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
|
|
|
|
SALOME_ListIO aSelList;
|
|
|
|
aSelMgr->selectedObjects(aSelList);
|
|
|
|
|
|
|
|
if (aSelList.Extent() != 1)
|
2008-03-07 12:45:34 +05:00
|
|
|
return;
|
|
|
|
|
|
|
|
// nbSel == 1
|
|
|
|
Standard_Boolean testResult = Standard_False;
|
|
|
|
GEOM::GEOM_Object_var aSelectedObject =
|
2009-02-13 17:16:39 +05:00
|
|
|
GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
|
2008-03-07 12:45:34 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
if (!testResult || CORBA::is_nil(aSelectedObject))
|
2008-03-07 12:45:34 +05:00
|
|
|
return;
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
QString aName = GEOMBase::GetName(aSelectedObject);
|
|
|
|
|
2008-03-07 12:45:34 +05:00
|
|
|
if (myEditCurrentArgument == GroupArgs->LineEdit1) {
|
2009-02-13 17:16:39 +05:00
|
|
|
TopoDS_Shape aShape;
|
|
|
|
if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
|
|
|
|
{
|
|
|
|
TColStd_IndexedMapOfInteger aMap;
|
|
|
|
aSelMgr->GetIndexes(aSelList.First(), aMap);
|
|
|
|
if (aMap.Extent() == 1) // Local Selection
|
|
|
|
{
|
|
|
|
GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
|
|
|
|
int anIndex = aMap(1);
|
|
|
|
aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
|
|
|
|
aName += QString(":face_%1").arg(anIndex);
|
|
|
|
}
|
|
|
|
else // Global Selection
|
|
|
|
{
|
|
|
|
if (aShape.ShapeType() != TopAbs_FACE) {
|
|
|
|
aSelectedObject = GEOM::GEOM_Object::_nil();
|
|
|
|
aName = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-07 12:45:34 +05:00
|
|
|
myFace = aSelectedObject;
|
2009-02-13 17:16:39 +05:00
|
|
|
myEditCurrentArgument->setText(aName);
|
|
|
|
|
|
|
|
// clear selection
|
|
|
|
disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
|
|
|
|
myGeomGUI->getApp()->selectionMgr()->clearSelected();
|
|
|
|
connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
|
|
|
|
this, SLOT(SelectionIntoArgument()));
|
|
|
|
|
|
|
|
if (!myFace->_is_nil() && myPoint->_is_nil())
|
|
|
|
GroupArgs->PushButton2->click();
|
2008-03-07 12:45:34 +05:00
|
|
|
}
|
|
|
|
else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
|
2009-02-13 17:16:39 +05:00
|
|
|
TopoDS_Shape aShape;
|
|
|
|
if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
|
|
|
|
{
|
|
|
|
TColStd_IndexedMapOfInteger aMap;
|
|
|
|
aSelMgr->GetIndexes(aSelList.First(), aMap);
|
|
|
|
if (aMap.Extent() == 1) // Local Selection
|
|
|
|
{
|
|
|
|
GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
|
|
|
|
int anIndex = aMap(1);
|
|
|
|
aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
|
|
|
|
aName += QString(":vertex_%1").arg(anIndex);
|
|
|
|
}
|
|
|
|
else // Global Selection
|
|
|
|
{
|
|
|
|
if (aShape.ShapeType() != TopAbs_VERTEX) {
|
|
|
|
aSelectedObject = GEOM::GEOM_Object::_nil();
|
|
|
|
aName = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-07 12:45:34 +05:00
|
|
|
myPoint = aSelectedObject;
|
2009-02-13 17:16:39 +05:00
|
|
|
myEditCurrentArgument->setText(aName);
|
2008-03-07 12:45:34 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
// clear selection
|
|
|
|
disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
|
|
|
|
myGeomGUI->getApp()->selectionMgr()->clearSelected();
|
|
|
|
connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
|
|
|
|
this, SLOT(SelectionIntoArgument()));
|
2008-03-07 12:45:34 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
if (!myPoint->_is_nil() && myFace->_is_nil())
|
|
|
|
GroupArgs->PushButton1->click();
|
2008-03-07 12:45:34 +05:00
|
|
|
}
|
2009-02-13 17:16:39 +05:00
|
|
|
|
|
|
|
displayPreview();
|
2008-03-07 12:45:34 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : SetEditCurrentArgument()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void MeasureGUI_NormaleDlg::SetEditCurrentArgument()
|
|
|
|
{
|
|
|
|
QPushButton* send = (QPushButton*)sender();
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
|
|
|
|
globalSelection(GEOM_FACE);
|
|
|
|
|
2008-03-07 12:45:34 +05:00
|
|
|
if (send == GroupArgs->PushButton1) {
|
|
|
|
myEditCurrentArgument = GroupArgs->LineEdit1;
|
2009-02-13 17:16:39 +05:00
|
|
|
|
|
|
|
GroupArgs->PushButton2->setDown(false);
|
|
|
|
GroupArgs->LineEdit2->setEnabled(false);
|
|
|
|
|
|
|
|
localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE);
|
2008-03-07 12:45:34 +05:00
|
|
|
}
|
|
|
|
else if (send == GroupArgs->PushButton2) {
|
|
|
|
myEditCurrentArgument = GroupArgs->LineEdit2;
|
2009-02-13 17:16:39 +05:00
|
|
|
|
|
|
|
GroupArgs->PushButton1->setDown(false);
|
|
|
|
GroupArgs->LineEdit1->setEnabled(false);
|
|
|
|
|
|
|
|
localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
|
2008-03-07 12:45:34 +05:00
|
|
|
}
|
2009-02-13 17:16:39 +05:00
|
|
|
connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
|
|
|
|
this, SLOT(SelectionIntoArgument()));
|
2008-03-07 12:45:34 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
// enable line edit
|
|
|
|
myEditCurrentArgument->setEnabled(true);
|
2008-03-07 12:45:34 +05:00
|
|
|
myEditCurrentArgument->setFocus();
|
2009-02-13 17:16:39 +05:00
|
|
|
// after setFocus(), because it will be setDown(false) when loses focus
|
|
|
|
send->setDown(true);
|
|
|
|
|
|
|
|
// seems we need it only to avoid preview disappearing, caused by selection mode change
|
|
|
|
displayPreview();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : LineEditReturnPressed()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void MeasureGUI_NormaleDlg::LineEditReturnPressed()
|
|
|
|
{
|
|
|
|
QLineEdit* send = (QLineEdit*)sender();
|
|
|
|
if (send == GroupArgs->LineEdit1 ||
|
|
|
|
send == GroupArgs->LineEdit2) {
|
|
|
|
myEditCurrentArgument = send;
|
|
|
|
GEOMBase_Skeleton::LineEditReturnPressed();
|
|
|
|
}
|
2008-03-07 12:45:34 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ActivateThisDialog()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void MeasureGUI_NormaleDlg::ActivateThisDialog()
|
|
|
|
{
|
|
|
|
GEOMBase_Skeleton::ActivateThisDialog();
|
2009-02-13 17:16:39 +05:00
|
|
|
connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
|
|
|
|
this, SLOT( SelectionIntoArgument() ) );
|
2008-03-07 12:45:34 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
displayPreview();
|
2008-03-07 12:45:34 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : enterEvent()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2009-02-13 17:16:39 +05:00
|
|
|
void MeasureGUI_NormaleDlg::enterEvent (QEvent*)
|
2008-03-07 12:45:34 +05:00
|
|
|
{
|
2009-02-13 17:16:39 +05:00
|
|
|
if (!mainFrame()->GroupConstructors->isEnabled())
|
2008-03-07 12:45:34 +05:00
|
|
|
ActivateThisDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : createOperation
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
GEOM::GEOM_IOperations_ptr MeasureGUI_NormaleDlg::createOperation()
|
|
|
|
{
|
|
|
|
return getGeomEngine()->GetIMeasureOperations(getStudyId());
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : isValid
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
bool MeasureGUI_NormaleDlg::isValid (QString&)
|
|
|
|
{
|
|
|
|
//return !CORBA::is_nil(myFace) && !CORBA::is_nil(myPoint);
|
|
|
|
return !CORBA::is_nil(myFace);
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : execute
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
bool MeasureGUI_NormaleDlg::execute (ObjectList& objects)
|
|
|
|
{
|
|
|
|
GEOM::GEOM_Object_var anObj =
|
|
|
|
GEOM::GEOM_IMeasureOperations::_narrow(getOperation())->GetNormal(myFace, myPoint);
|
|
|
|
|
|
|
|
if (!anObj->_is_nil())
|
|
|
|
objects.push_back(anObj._retn());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|