X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMeasureGUI%2FMeasureGUI_AngleDlg.cxx;h=c473dd78d4a87c335242f31b17266bf543674e8f;hb=b37488eb20416962c252fc96ee0a0d1bb9963da5;hp=de13dd70b45305e71bb6b080a39e325d4e1ef369;hpb=239f8109c64fa0c5a2e1d87a420bad5529b57f48;p=modules%2Fgeom.git diff --git a/src/MeasureGUI/MeasureGUI_AngleDlg.cxx b/src/MeasureGUI/MeasureGUI_AngleDlg.cxx index de13dd70b..c473dd78d 100644 --- a/src/MeasureGUI/MeasureGUI_AngleDlg.cxx +++ b/src/MeasureGUI/MeasureGUI_AngleDlg.cxx @@ -1,47 +1,45 @@ -// GEOM GEOMGUI : GUI for Geometry component +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// 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 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. // -// 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 // -// 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 -// -// -// -// File : MeasureGUI_AngleDlg.cxx -// Author : Julia DOROVSKIKH -// Module : GEOM -// $Header$ - -#include "MeasureGUI_AngleDlg.h" - -#include "MeasureGUI_2Sel1LineEdit_QTD.h" +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -#include "GEOMBase.h" -#include "GEOM_Displayer.h" -#include "DlgRef_SpinBox.h" -#include "GeometryGUI.h" +// GEOM GEOMGUI : GUI for Geometry component +// File : MeasureGUI_AngleDlg.cxx +// Author : Julia DOROVSKIKH, Open CASCADE S.A.S. -#include "SUIT_Session.h" -#include "SUIT_ViewWindow.h" -#include "SUIT_MessageBox.h" -#include "SOCC_Prs.h" -#include "SOCC_ViewModel.h" -#include "SalomeApp_Tools.h" -#include "SalomeApp_Application.h" +#include "MeasureGUI_AngleDlg.h" +#include "MeasureGUI_Widgets.h" + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // OCCT Includes #include @@ -55,6 +53,10 @@ #include #include #include +#include +#include +#include +#include // QT Includes #include @@ -79,30 +81,33 @@ // TRUE to construct a modal dialog. //================================================================================= MeasureGUI_AngleDlg::MeasureGUI_AngleDlg (GeometryGUI* GUI, QWidget* parent) - : MeasureGUI_Skeleton(GUI, parent, "MeasureGUI_AngleDlg") + : MeasureGUI_Skeleton(GUI, parent) { - QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_ANGLE"))); - QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT"))); - - setCaption(tr("GEOM_MEASURE_ANGLE_TITLE")); + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_ANGLE"))); + QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); - // Widgets + setWindowTitle(tr("GEOM_MEASURE_ANGLE_TITLE")); - GroupConstructors->setTitle(tr("GEOM_MEASURE_ANGLE_ANGLE")); - RadioButton1->setPixmap(image0); + /***************************************************************/ + mainFrame()->GroupConstructors->setTitle(tr("GEOM_MEASURE_ANGLE_ANGLE")); + mainFrame()->RadioButton1->setIcon(image0); - myGrp = new MeasureGUI_2Sel1LineEdit_QTD(this, "myGrp"); + myGrp = new MeasureGUI_2Sel1LineEdit(centralWidget()); myGrp->GroupBox1->setTitle(tr("GEOM_MEASURE_ANGLE_OBJ")); myGrp->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1")); myGrp->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2")); myGrp->TextLabel3->setText(tr("GEOM_MEASURE_ANGLE_IS")); - myGrp->LineEdit3->setReadOnly(TRUE); - myGrp->PushButton1->setPixmap(image1); - myGrp->PushButton2->setPixmap(image1); + myGrp->LineEdit3->setReadOnly(true); + myGrp->PushButton1->setIcon(image1); + myGrp->PushButton2->setIcon(image1); myGrp->LineEdit1->setReadOnly(true); myGrp->LineEdit2->setReadOnly(true); - Layout1->addWidget(myGrp, 1, 0); + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); layout->setSpacing(6); + layout->addWidget(myGrp); + /***************************************************************/ // Help page reference myHelpFileName = "using_measurement_tools_page.html#angle_anchor"; @@ -125,6 +130,11 @@ MeasureGUI_AngleDlg::~MeasureGUI_AngleDlg() //================================================================================= void MeasureGUI_AngleDlg::Init() { + // init variables + myGrp->LineEdit1->setText(""); + myGrp->LineEdit2->setText(""); + myObj = myObj2 = GEOM::GEOM_Object::_nil(); + mySelBtn = myGrp->PushButton1; mySelEdit = myGrp->LineEdit1; mySelBtn2 = myGrp->PushButton2; @@ -132,31 +142,46 @@ void MeasureGUI_AngleDlg::Init() myEditCurrentArgument = mySelEdit; + // signals and slots connections connect(mySelEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); - connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); globalSelection(GEOM_LINE); MeasureGUI_Skeleton::Init(); } - //================================================================================= // function : SelectionIntoArgument() // purpose : Called when selection has changed //================================================================================= void MeasureGUI_AngleDlg::SelectionIntoArgument() { - Standard_Boolean testResult = Standard_False; - GEOM::GEOM_Object_var aSelectedObject = - GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult); + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); + + GEOM::GEOM_Object_var aSelectedObject = GEOM::GEOM_Object::_nil(); + + if (aSelList.Extent() > 0) { + aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() ); + } - if (!testResult) - aSelectedObject = GEOM::GEOM_Object::_nil(); + // clear selection + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + myGeomGUI->getApp()->selectionMgr()->clearSelected(); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); - if (myEditCurrentArgument == mySelEdit) + if (myEditCurrentArgument == mySelEdit) { myObj = aSelectedObject; - else + if (!myObj->_is_nil() && myObj2->_is_nil()) + myGrp->PushButton2->click(); + } + else { myObj2 = aSelectedObject; + if (!myObj2->_is_nil() && myObj->_is_nil()) + myGrp->PushButton1->click(); + } processObject(); } @@ -171,13 +196,13 @@ void MeasureGUI_AngleDlg::processObject() myGrp->LineEdit2->setText(!myObj2->_is_nil() ? GEOMBase::GetName(myObj2) : ""); double anAngle = 0.; - if (getParameters(anAngle)) - { - myGrp->LineEdit3->setText(DlgRef_SpinBox::PrintDoubleValue(anAngle)); + if (getParameters(anAngle)) { + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + int aPrecision = resMgr->integerValue( "Geometry", "angle_precision", 6 ); + myGrp->LineEdit3->setText(DlgRef::PrintDoubleValue(anAngle, aPrecision)); redisplayPreview(); } - else - { + else { myGrp->LineEdit3->setText(""); erasePreview(); } @@ -191,21 +216,21 @@ bool MeasureGUI_AngleDlg::getParameters (double& theAngle) { QString msg; if (isValid(msg)) { + GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() ); try { - theAngle = GEOM::GEOM_IMeasureOperations::_narrow(getOperation())->GetAngle(myObj, myObj2); + theAngle = anOper->GetAngle(myObj, myObj2); } catch(const SALOME::SALOME_Exception& e) { SalomeApp_Tools::QtCatchCorbaException(e); return false; } - bool isDone = getOperation()->IsDone(); + bool isDone = anOper->IsDone(); if (!isDone) { - CORBA::String_var aMsg = getOperation()->GetErrorCode(); - SUIT_MessageBox::warn1((QWidget*)myGeomGUI->getApp()->desktop(), - QObject::tr("WRN_WARNING"), - QObject::tr(aMsg.in()), - QObject::tr("BUT_OK")); + CORBA::String_var aMsg = anOper->GetErrorCode(); + SUIT_MessageBox::warning(this, + QObject::tr("WRN_WARNING"), + QObject::tr(aMsg.in())); } return isDone; } @@ -221,17 +246,32 @@ void MeasureGUI_AngleDlg::SetEditCurrentArgument() { QPushButton* send = (QPushButton*)sender(); - if (send == mySelBtn) { - mySelEdit->setFocus(); - myEditCurrentArgument = mySelEdit; + if (send == myGrp->PushButton1) { + myEditCurrentArgument = myGrp->LineEdit1; + + myGrp->PushButton2->setDown(false); + myGrp->LineEdit2->setEnabled(false); } else { - mySelEdit2->setFocus(); - myEditCurrentArgument = mySelEdit2; + myEditCurrentArgument = myGrp->LineEdit2; + + myGrp->PushButton1->setDown(false); + myGrp->LineEdit1->setEnabled(false); } + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); globalSelection(GEOM_LINE); - SelectionIntoArgument(); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + // enable line edit + myEditCurrentArgument->setEnabled(true); + myEditCurrentArgument->setFocus(); + // 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 + redisplayPreview(); } //================================================================================= @@ -247,7 +287,11 @@ void MeasureGUI_AngleDlg::LineEditReturnPressed() else myEditCurrentArgument = mySelEdit2; - if (GEOMBase::SelectionByNameInDialogs(this, mySelEdit->text(), selectedIO())) + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); + + if (GEOMBase::SelectionByNameInDialogs(this, mySelEdit->text(), aSelList)) mySelEdit->setText(mySelEdit->text()); } @@ -262,20 +306,17 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs() SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); if (myObj->_is_nil() || myObj2->_is_nil() || !getParameters(anAngle) || - vw->getViewManager()->getType() != OCCViewer_Viewer::Type()) + vw->getViewManager()->getType() != OCCViewer_Viewer::Type()) return 0; - if (anAngle > Precision::Angular()) - { - try - { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + if (anAngle > Precision::Angular()) { + try { +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif TopoDS_Shape S1, S2; if (GEOMBase::GetShape(myObj , S1, TopAbs_EDGE) && - GEOMBase::GetShape(myObj2, S2, TopAbs_EDGE)) - { + GEOMBase::GetShape(myObj2, S2, TopAbs_EDGE)) { TopoDS_Edge anEdge1 = TopoDS::Edge(S1); TopoDS_Edge anEdge2 = TopoDS::Edge(S2); @@ -303,7 +344,7 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs() // *P21 gp_Pnt aP3 (aP22.XYZ() + aP11.XYZ() - aP21.XYZ()); - gce_MakePln gce_MP (aP11, aP12, aP3); + gce_MakePln gce_MP(aP11, aP12, aP3); Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP.Value()); // Build the angle dimension presentation @@ -311,8 +352,39 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs() aLabel.sprintf("%.1f", anAngle); Handle(AIS_AngleDimension) anIO = new AIS_AngleDimension - (anEdge1, anEdge2, aPlane, anAngle * PI180, - TCollection_ExtendedString((Standard_CString)aLabel.latin1())); + (anEdge1, anEdge2, aPlane, anAngle * M_PI / 180., + TCollection_ExtendedString((Standard_CString)aLabel.toLatin1().data())); + Handle(Geom_Line) geom_lin1,geom_lin2; + gp_Pnt ptat11,ptat12,ptat21,ptat22; + Standard_Boolean isInfinite1,isInfinite2; + Handle(Geom_Curve) extCurv; + Standard_Integer extShape; + if (AIS::ComputeGeometry(anEdge1, + anEdge2, + extShape, + geom_lin1, + geom_lin2, + ptat11, + ptat12, + ptat21, + ptat22, + extCurv, + isInfinite1, + isInfinite2, + aPlane)) { + Standard_Real arrSize1 = anIO->ArrowSize(); + Standard_Real arrSize2 = anIO->ArrowSize(); + if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/10.; + if (!isInfinite2) arrSize2 = ptat21.Distance(ptat22)/10.; + Standard_Real arrowSize = Max(arrSize1,arrSize2); + anIO->SetArrowSize(arrowSize); + } + + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + int w = resMgr->integerValue("Geometry", "measures_line_width", 1); + Handle(Prs3d_AngleAspect) asp = new Prs3d_AngleAspect(); + asp->LineAspect()->SetWidth(w); + anIO->Attributes()->SetAngleAspect(asp); SOCC_Prs* aPrs = dynamic_cast(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0)); @@ -323,8 +395,7 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs() return aPrs; } } - catch(Standard_Failure) - { + catch(Standard_Failure) { } } @@ -335,7 +406,7 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs() // function : isValid() // purpose : //================================================================================= -bool MeasureGUI_AngleDlg::isValid(QString& msg) +bool MeasureGUI_AngleDlg::isValid (QString& msg) { return MeasureGUI_Skeleton::isValid(msg) && !myObj2->_is_nil(); }