-// GEOM GEOMGUI : GUI for Geometry component
+// Copyright (C) 2007-2012 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 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// Copyright (C) 2003-2007 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 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
//
-// File : MeasureGUI_MaxToleranceDlg.cxx
-// Author : Nicolas REJNERI
-// Module : GEOM
-// $Header$
+// GEOM GEOMGUI : GUI for Geometry component
+// File : MeasureGUI_MaxToleranceDlg.cxx
+// Author : Nicolas REJNERI, Open CASCADE S.A.S.
+//
#include "MeasureGUI_MaxToleranceDlg.h"
+#include "MeasureGUI_Widgets.h"
+#include "DlgRef.h"
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopExp_Explorer.hxx>
-#include <BRep_Tool.hxx>
-
-#include "utilities.h"
-
-using namespace std;
+#include <SUIT_Session.h>
+#include <SUIT_ResourceMgr.h>
+#include <SalomeApp_Tools.h>
//=================================================================================
// class : MeasureGUI_MaxToleranceDlg()
-// purpose : Constructs a MeasureGUI_MaxToleranceDlg which is a child of 'parent', with the
+// purpose : Constructs a MeasureGUI_MaxToleranceDlg 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.
+// true to construct a modal dialog.
//=================================================================================
-MeasureGUI_MaxToleranceDlg::MeasureGUI_MaxToleranceDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
- :MeasureGUI_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
+MeasureGUI_MaxToleranceDlg::MeasureGUI_MaxToleranceDlg( GeometryGUI* GUI, QWidget* parent )
+ : MeasureGUI_Skeleton( GUI, parent )
{
- QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_TOLERANCE")));
- QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
+ QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
+ "GEOM", tr( "ICON_DLG_TOLERANCE" ) ) );
+ QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
+ "GEOM", tr( "ICON_SELECT" ) ) );
- setCaption(tr("GEOM_TOLERANCE_TITLE"));
+ setWindowTitle( tr( "GEOM_TOLERANCE_TITLE" ) );
/***************************************************************/
- GroupConstructors->setTitle(tr("GEOM_TOLERANCE"));
- RadioButton1->setPixmap(image0);
-
- GroupC1 = new MeasureGUI_1Sel6LineEdit_QTD(this, "GroupC1");
- GroupC1->GroupBox1->setTitle(tr("GEOM_TOLERANCE_CONSTR"));
- GroupC1->TextLabel1->setText(tr("GEOM_OBJECT"));
- GroupC1->TextLabel2->setText(tr("GEOM_MIN"));
- GroupC1->TextLabel3->setText(tr("GEOM_MAX"));
- GroupC1->TextLabel4->setText(tr("GEOM_TOLERANCE_FACE"));
- GroupC1->TextLabel5->setText(tr("GEOM_TOLERANCE_EDGE"));
- GroupC1->TextLabel6->setText(tr("GEOM_TOLERANCE_VERTEX"));
- GroupC1->LineEdit11->setReadOnly(TRUE);
- GroupC1->LineEdit12->setReadOnly(TRUE);
- GroupC1->LineEdit21->setReadOnly(TRUE);
- GroupC1->LineEdit22->setReadOnly(TRUE);
- GroupC1->LineEdit31->setReadOnly(TRUE);
- GroupC1->LineEdit32->setReadOnly(TRUE);
- GroupC1->PushButton1->setPixmap(image1);
-
- Layout1->addWidget(GroupC1, 1, 0);
+
+ mainFrame()->GroupConstructors->setTitle( tr( "GEOM_TOLERANCE" ) );
+ mainFrame()->RadioButton1->setIcon( image0 );
+
+ myGrp = new MeasureGUI_1Sel6LineEdit( centralWidget() );
+ myGrp->GroupBox1->setTitle( tr( "GEOM_TOLERANCE_CONSTR" ) );
+ myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
+ myGrp->TextLabel2->setText( tr( "GEOM_MIN" ) );
+ myGrp->TextLabel3->setText( tr( "GEOM_MAX" ) );
+ myGrp->TextLabel4->setText( tr( "GEOM_TOLERANCE_FACE" ) );
+ myGrp->TextLabel5->setText( tr( "GEOM_TOLERANCE_EDGE" ) );
+ myGrp->TextLabel6->setText( tr( "GEOM_TOLERANCE_VERTEX" ) );
+ myGrp->LineEdit11->setReadOnly( true );
+ myGrp->LineEdit12->setReadOnly( true );
+ myGrp->LineEdit21->setReadOnly( true );
+ myGrp->LineEdit22->setReadOnly( true );
+ myGrp->LineEdit31->setReadOnly( true );
+ myGrp->LineEdit32->setReadOnly( true );
+ myGrp->PushButton1->setIcon( image1 );
+ myGrp->LineEdit1->setReadOnly( true );
+
+ QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
+ layout->setMargin( 0 ); layout->setSpacing( 6 );
+ layout->addWidget( myGrp );
+
/***************************************************************/
+ myHelpFileName = "using_measurement_tools_page.html#tolerance_anchor";
+
/* Initialisation */
Init();
}
//=================================================================================
MeasureGUI_MaxToleranceDlg::~MeasureGUI_MaxToleranceDlg()
{
- // no need to delete child widgets, Qt does it all for us
}
//=================================================================================
void MeasureGUI_MaxToleranceDlg::Init()
{
- /* init variables */
- myEditCurrentArgument = GroupC1->LineEdit1;
-
- /* signals and slots connections */
- connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
- connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
-
- connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
-
- /* displays Dialog */
- GroupC1->show();
- this->show();
-
- return;
-}
-
-
-//=================================================================================
-// function : SelectionIntoArgument()
-// purpose : Called when selection as changed or other case
-//=================================================================================
-void MeasureGUI_MaxToleranceDlg::SelectionIntoArgument()
-{
- myEditCurrentArgument->setText("");
- QString aString = "";
-
- GroupC1->LineEdit11->setText("");
- GroupC1->LineEdit12->setText("");
- GroupC1->LineEdit21->setText("");
- GroupC1->LineEdit22->setText("");
- GroupC1->LineEdit31->setText("");
- GroupC1->LineEdit32->setText("");
-
- int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
- if(nbSel != 1)
- return;
-
- /* nbSel == 1 */
- TopoDS_Shape S;
- if(!myGeomBase->GetTopoFromSelection(mySelection, S) || S.IsNull())
- return;
-
- if(S.IsNull())
- return;
-
- GroupC1->LineEdit1->setText(aString);
-
- this->CalculateMaxTolerance(S);
- return;
+ mySelBtn = myGrp->PushButton1;
+ mySelEdit = myGrp->LineEdit1;
+ MeasureGUI_Skeleton::Init();
}
-
//=================================================================================
-// function : SetEditCurrentArgument()
+// function : processObject
// purpose :
//=================================================================================
-void MeasureGUI_MaxToleranceDlg::SetEditCurrentArgument()
+void MeasureGUI_MaxToleranceDlg::processObject()
{
- QPushButton* send = (QPushButton*)sender();
+ double aMinFaceToler, aMaxFaceToler;
+ double aMinEdgeToler, aMaxEdgeToler;
+ double aMinVertexToler, aMaxVertexToler;
+
+ if ( !getParameters( aMinFaceToler, aMaxFaceToler,
+ aMinEdgeToler, aMaxEdgeToler,
+ aMinVertexToler, aMaxVertexToler ) ) {
+ myGrp->LineEdit11->setText( "" );
+ myGrp->LineEdit12->setText( "" );
+
+ myGrp->LineEdit21->setText( "" );
+ myGrp->LineEdit22->setText( "" );
+
+ myGrp->LineEdit31->setText( "" );
+ myGrp->LineEdit32->setText( "" );
- if(send == GroupC1->PushButton1) {
- GroupC1->LineEdit1->setFocus();
- myEditCurrentArgument = GroupC1->LineEdit1;
- }
-
- this->SelectionIntoArgument();
- return;
-}
-
-
-//=================================================================================
-// function : LineEditReturnPressed()
-// purpose :
-//=================================================================================
-void MeasureGUI_MaxToleranceDlg::LineEditReturnPressed()
-{
- QLineEdit* send = (QLineEdit*)sender();
- if(send == GroupC1->LineEdit1)
- myEditCurrentArgument = GroupC1->LineEdit1;
- else
return;
+ }
- MeasureGUI_Skeleton::LineEditReturnPressed();
- return;
-}
+ double invalidMin = RealLast();
+ double invalidMax = -RealLast();
+ SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+ int aPrecision = resMgr->integerValue( "Geometry", "len_tol_precision", -9);
-//=================================================================================
-// function : ActivateThisDialog()
-// purpose :
-//=================================================================================
-void MeasureGUI_MaxToleranceDlg::ActivateThisDialog()
-{
- MeasureGUI_Skeleton::ActivateThisDialog();
- connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
- return;
-}
+ myGrp->LineEdit11->setText( aMinFaceToler != invalidMin ? DlgRef::PrintDoubleValue( aMinFaceToler, aPrecision ) : QString("") );
+ myGrp->LineEdit12->setText( aMaxFaceToler != invalidMax ? DlgRef::PrintDoubleValue( aMaxFaceToler, aPrecision ) : QString("") );
+ myGrp->LineEdit21->setText( aMinEdgeToler != invalidMin ? DlgRef::PrintDoubleValue( aMinEdgeToler, aPrecision ) : QString("") );
+ myGrp->LineEdit22->setText( aMaxEdgeToler != invalidMax ? DlgRef::PrintDoubleValue( aMaxEdgeToler, aPrecision ) : QString("") );
-//=================================================================================
-// function : enterEvent()
-// purpose :
-//=================================================================================
-void MeasureGUI_MaxToleranceDlg::enterEvent(QEvent* e)
-{
- if(GroupConstructors->isEnabled())
- return;
- this->ActivateThisDialog();
- return;
+ myGrp->LineEdit31->setText( aMinVertexToler != invalidMin ? DlgRef::PrintDoubleValue( aMinVertexToler, aPrecision ) : QString("") );
+ myGrp->LineEdit32->setText( aMaxVertexToler != invalidMax ? DlgRef::PrintDoubleValue( aMaxVertexToler, aPrecision ) : QString("") );
}
-
//=================================================================================
-// function : CalculateMaxTolerance()
-// purpose :
+// function : getParameters
+// purpose : Get tolerances. Returns false is myObj is nill. If there is no a
+// type of entity ( face, edge or vertex ) in selected object then corresponding
+// tolerances is less than 0
//=================================================================================
-void MeasureGUI_MaxToleranceDlg::CalculateMaxTolerance(const TopoDS_Shape& S)
+bool MeasureGUI_MaxToleranceDlg::getParameters( double& theMinFaceToler,
+ double& theMaxFaceToler,
+ double& theMinEdgeToler,
+ double& theMaxEdgeToler,
+ double& theMinVertexToler,
+ double& theMaxVertexToler )
{
- GroupC1->LineEdit11->setText("");
- GroupC1->LineEdit12->setText("");
- GroupC1->LineEdit21->setText("");
- GroupC1->LineEdit22->setText("");
- GroupC1->LineEdit31->setText("");
- GroupC1->LineEdit32->setText("");
-
- if(S.IsNull())
- return;
-
- Standard_Real T, TMF, TME, TMV, TmF, TmE, TmV;
- Standard_Integer nbF, nbE, nbV;
- bool m_isFace, m_isEdge, m_isVertex;
-
- TMF = TME = TMV = -RealLast();
- TmF = TmE = TmV = RealLast();
- nbF = nbE = nbV = 0;
- m_isFace = m_isEdge = m_isVertex = false;
-
- try {
- for(TopExp_Explorer ExF(S,TopAbs_FACE); ExF.More(); ExF.Next()) {
- m_isFace = true;
- TopoDS_Face Face=TopoDS::Face(ExF.Current());
- T=BRep_Tool::Tolerance(Face);
- if(T>TMF)
- TMF=T;
- if(T<TmF)
- TmF=T;
- nbF++;
- }
- for(TopExp_Explorer ExE(S,TopAbs_EDGE); ExE.More(); ExE.Next()) {
- m_isEdge = true;
- TopoDS_Edge Edge=TopoDS::Edge(ExE.Current());
- T=BRep_Tool::Tolerance(Edge);
- if(T>TME)
- TME=T;
- if(T<TmE)
- TmE=T;
- nbE++;
+ if ( myObj->_is_nil() )
+ return false;
+ else {
+ GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
+ try {
+ anOper->GetTolerance( myObj,
+ theMinFaceToler, theMaxFaceToler, theMinEdgeToler,
+ theMaxEdgeToler, theMinVertexToler, theMaxVertexToler );
}
- for(TopExp_Explorer ExV(S,TopAbs_VERTEX); ExV.More(); ExV.Next()) {
- m_isVertex = true;
- TopoDS_Vertex Vertex=TopoDS::Vertex(ExV.Current());
- T=BRep_Tool::Tolerance(Vertex);
- if(T>TMV)
- TMV=T;
- if(T<TmV)
- TmV=T;
- nbV++;
+ catch( const SALOME::SALOME_Exception& e ) {
+ SalomeApp_Tools::QtCatchCorbaException( e );
+ return false;
}
- if(m_isFace) {
- GroupC1->LineEdit11->setText(tr("%1").arg(TmF, 5, 'e', 8));
- GroupC1->LineEdit12->setText(tr("%1").arg(TMF, 5, 'e', 8));
- }
- if(m_isEdge) {
- GroupC1->LineEdit21->setText(tr("%1").arg(TmE, 5, 'e', 8));
- GroupC1->LineEdit22->setText(tr("%1").arg(TME, 5, 'e', 8));
- }
- if(m_isVertex) {
- GroupC1->LineEdit31->setText(tr("%1").arg(TmV, 5, 'e', 8));
- GroupC1->LineEdit32->setText(tr("%1").arg(TMV, 5, 'e', 8));
- }
+ return anOper->IsDone();
}
- catch(Standard_Failure)
- {
- MESSAGE("Catch intercepted in CalculateMaxTolerance()");
- }
- return;
}