-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 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 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
// GEOM GEOMGUI : GUI for Geometry component
// File : BuildGUI_EdgeDlg.cxx
// Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
-//
+
#include "BuildGUI_EdgeDlg.h"
#include <DlgRef.h>
#include <LightApp_SelectionMgr.h>
#include <GEOMImpl_Types.hxx>
+#include <TColStd_IndexedMapOfInteger.hxx>
//=================================================================================
// class : BuildGUI_EdgeDlg()
BuildGUI_EdgeDlg::BuildGUI_EdgeDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
: GEOMBase_Skeleton(theGeometryGUI, parent)
{
- QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BUILD_EDGE")));
- QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
+ SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+ QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
+ QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_BUILD_EDGE")));
+ QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_BUILD_EDGE_WIRE")));
+ QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_BUILD_EDGE_CURVE")));
setWindowTitle(tr("GEOM_EDGE_TITLE"));
/***************************************************************/
mainFrame()->GroupConstructors->setTitle(tr("GEOM_EDGE"));
- mainFrame()->RadioButton1->setIcon(image0);
- mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
- mainFrame()->RadioButton2->close();
- mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
- mainFrame()->RadioButton3->close();
+ mainFrame()->RadioButton1->setIcon(image1);
+ mainFrame()->RadioButton2->setIcon(image2);
+ mainFrame()->RadioButton3->setIcon(image3);
- GroupPoints = new DlgRef_2Sel(centralWidget());
+ // two points
+ GroupPoints = new DlgRef_2Sel(centralWidget());
GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg(1));
GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg(2));
- GroupPoints->PushButton1->setIcon(image1);
- GroupPoints->PushButton2->setIcon(image1);
-
+ GroupPoints->PushButton1->setIcon(image0);
+ GroupPoints->PushButton2->setIcon(image0);
GroupPoints->LineEdit1->setReadOnly(true);
GroupPoints->LineEdit2->setReadOnly(true);
+ // wire
+
+ GroupWire = new DlgRef_1Sel2Spin(centralWidget());
+ GroupWire->GroupBox1->setTitle(tr("GEOM_WIRE"));
+ GroupWire->TextLabel1->setText(tr("GEOM_WIRE"));
+ GroupWire->PushButton1->setIcon(image0);
+ GroupWire->LineEdit1->setReadOnly(true);
+ GroupWire->TextLabel2->setText(tr("GEOM_LINEAR_TOLERANCE"));
+ GroupWire->TextLabel3->setText(tr("GEOM_ANGULAR_TOLERANCE"));
+ double SpecificStep = 0.0001;
+ double prec1 = Precision::Confusion();
+ double prec2 = Precision::Angular();
+ initSpinBox(GroupWire->SpinBox_DX, prec1, MAX_NUMBER, SpecificStep, "len_tol_precision");
+ initSpinBox(GroupWire->SpinBox_DY, prec2, MAX_NUMBER, SpecificStep, "ang_tol_precision");
+ GroupWire->SpinBox_DX->setValue(prec1);
+ GroupWire->SpinBox_DY->setValue(prec2);
+
+ // on curve
+
+ GroupOnCurve = new DlgRef_2Sel1Spin(centralWidget());
+ GroupOnCurve->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
+ GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
+ GroupOnCurve->PushButton1->setIcon(image0);
+ GroupOnCurve->LineEdit1->setReadOnly(true);
+ GroupOnCurve->TextLabel2->setText(tr("GEOM_START_POINT"));
+ GroupOnCurve->PushButton2->setIcon(image0);
+ GroupOnCurve->LineEdit2->setReadOnly(true);
+ GroupOnCurve->TextLabel3->setText(tr("GEOM_LENGTH"));
+ double step = aResMgr->doubleValue("Geometry", "SettingsGeomStep", 100.0);
+ initSpinBox(GroupOnCurve->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
+ GroupOnCurve->SpinBox_DX->setValue(step);
+
+ // layout
+
QVBoxLayout* layout = new QVBoxLayout(centralWidget());
layout->setMargin(0); layout->setSpacing(6);
layout->addWidget(GroupPoints);
+ layout->addWidget(GroupWire);
+ layout->addWidget(GroupOnCurve);
/***************************************************************/
setHelpFileName("create_edge_page.html");
- // Initialisation
+ // initialisation
Init();
}
void BuildGUI_EdgeDlg::Init()
{
// init variables
- GroupPoints->LineEdit1->setReadOnly(true);
- GroupPoints->LineEdit2->setReadOnly(true);
+ myPoint1.nullify();
+ myPoint2.nullify();
+ myWire.nullify();
+ myCurve.nullify();
+ myStartPoint.nullify();
- GroupPoints->LineEdit1->setText("");
- GroupPoints->LineEdit2->setText("");
- myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
- myOkPoint1 = myOkPoint2 = false;
+ myEditCurrentArgument = GroupPoints->LineEdit1;
+ GroupPoints->PushButton1->setDown(true);
+ globalSelection(); // close local contexts, if any
+ localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
// signals and slots connections
+ connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
+ connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
+
+ connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
+
connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
- connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
- connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+ connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+ connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+ connect(GroupWire->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+ connect(GroupOnCurve->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+ connect(GroupOnCurve->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+
+ connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
- connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
- connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
+ connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
+ this, SLOT(SelectionIntoArgument()));
initName(tr("GEOM_EDGE"));
- GroupPoints->PushButton1->click();
- SelectionIntoArgument();
+ ConstructorsClicked(0);
}
//=================================================================================
//=================================================================================
void BuildGUI_EdgeDlg::ClickOnOk()
{
+ setIsApplyAndClose( true );
if (ClickOnApply())
ClickOnCancel();
}
return false;
initName();
- // activate selection and connect selection manager
- GroupPoints->PushButton1->click();
+
+ myEditCurrentArgument->setText("");
+ ConstructorsClicked(getConstructorId());
+
return true;
}
+//=================================================================================
+// function : ConstructorsClicked()
+// purpose : Radio button management
+//=================================================================================
+void BuildGUI_EdgeDlg::ConstructorsClicked(int constructorId)
+{
+ switch (constructorId) {
+ case 0:
+ {
+ globalSelection(); // close local contexts, if any
+ localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
+
+ myEditCurrentArgument = GroupPoints->LineEdit1;
+ GroupPoints->LineEdit1->setText("");
+ GroupPoints->LineEdit2->setText("");
+ myPoint1.nullify();
+ myPoint2.nullify();
+ GroupPoints->PushButton1->setDown(true);
+ GroupPoints->PushButton2->setDown(false);
+ GroupPoints->LineEdit1->setEnabled(true);
+ GroupPoints->LineEdit2->setEnabled(false);
+ GroupPoints->show();
+ GroupWire->hide();
+ GroupOnCurve->hide();
+ break;
+ }
+ case 1:
+ {
+ globalSelection(); // close local contexts, if any
+ localSelection(GEOM::GEOM_Object::_nil(), TopAbs_WIRE);
+
+ myEditCurrentArgument = GroupWire->LineEdit1;
+ GroupWire->LineEdit1->setText("");
+ myWire.nullify();
+ GroupWire->PushButton1->setDown(true);
+ GroupWire->LineEdit1->setEnabled(true);
+ GroupPoints->hide();
+ GroupOnCurve->hide();
+ GroupWire->show();
+ break;
+ }
+ case 2:
+ {
+ globalSelection(); // close local contexts, if any
+ localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
+
+ myEditCurrentArgument = GroupOnCurve->LineEdit1;
+ GroupOnCurve->LineEdit1->setText("");
+ GroupOnCurve->LineEdit2->setText("");
+ myCurve.nullify();
+ myStartPoint.nullify();
+ GroupOnCurve->PushButton1->setDown(true);
+ GroupOnCurve->PushButton2->setDown(false);
+ GroupOnCurve->LineEdit1->setEnabled(true);
+ GroupOnCurve->LineEdit2->setEnabled(false);
+ GroupPoints->hide();
+ GroupWire->hide();
+ GroupOnCurve->show();
+ break;
+ }
+ }
+
+ qApp->processEvents();
+ updateGeometry();
+ resize(minimumSizeHint());
+ SelectionIntoArgument();
+}
+
//=================================================================================
// function : SelectionIntoArgument()
// purpose : Called when selection is changed or on dialog initialization or activation
aSelMgr->selectedObjects(aSelList);
if (aSelList.Extent() != 1) {
- if (myEditCurrentArgument == GroupPoints->LineEdit1)
- myOkPoint1 = false;
- else if (myEditCurrentArgument == GroupPoints->LineEdit2)
- myOkPoint2 = false;
+ if (myEditCurrentArgument == GroupPoints->LineEdit1) myPoint1.nullify();
+ else if (myEditCurrentArgument == GroupPoints->LineEdit2) myPoint2.nullify();
+ else if (myEditCurrentArgument == GroupWire->LineEdit1) myWire.nullify();
+ else if (myEditCurrentArgument == GroupOnCurve->LineEdit1) myCurve.nullify();
+ else if (myEditCurrentArgument == GroupOnCurve->LineEdit2) myStartPoint.nullify();
+ displayPreview(true);
return;
}
- // nbSel == 1
- Standard_Boolean testResult = Standard_False;
- GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
- if (!testResult || aSelectedObject->_is_nil())
- return;
-
- myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
-
- // clear selection
- disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
- myGeomGUI->getApp()->selectionMgr()->clearSelected();
- connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
- this, SLOT(SelectionIntoArgument()));
-
- if (myEditCurrentArgument == GroupPoints->LineEdit1) {
- myPoint1 = aSelectedObject;
- myOkPoint1 = true;
- if (!myOkPoint2)
- GroupPoints->PushButton2->click();
- }
- else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
- myPoint2 = aSelectedObject;
- myOkPoint2 = true;
- if (!myOkPoint1)
- GroupPoints->PushButton1->click();
+ TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
+ if (myEditCurrentArgument == GroupWire->LineEdit1) aNeedType = TopAbs_WIRE;
+ else if (myEditCurrentArgument == GroupOnCurve->LineEdit1) aNeedType = TopAbs_EDGE;
+ GEOM::GeomObjPtr aSelectedObject = getSelected(aNeedType);
+
+ TopoDS_Shape aShape;
+ if (aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) && !aShape.IsNull()) {
+ QString aName = GEOMBase::GetName(aSelectedObject.get());
+ myEditCurrentArgument->setText(aName);
+
+ globalSelection();
+ localSelection(GEOM::GEOM_Object::_nil(), aNeedType);
+
+ if (myEditCurrentArgument == GroupPoints->LineEdit1) {
+ myPoint1 = aSelectedObject;
+ if (myPoint1 && !myPoint2)
+ GroupPoints->PushButton2->click();
+ }
+ else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
+ myPoint2 = aSelectedObject;
+ if (myPoint2 && !myPoint1)
+ GroupPoints->PushButton1->click();
+ }
+ else if (myEditCurrentArgument == GroupWire->LineEdit1) {
+ myWire = aSelectedObject;
+ }
+ else if (myEditCurrentArgument == GroupOnCurve->LineEdit1) {
+ myCurve = aSelectedObject;
+ if (myCurve && !myStartPoint)
+ GroupOnCurve->PushButton2->click();
+ }
+ else if (myEditCurrentArgument == GroupOnCurve->LineEdit2) {
+ myStartPoint = aSelectedObject;
+ if (myStartPoint && !myCurve)
+ GroupOnCurve->PushButton1->click();
+ }
}
- displayPreview();
+ displayPreview(true);
}
//=================================================================================
void BuildGUI_EdgeDlg::SetEditCurrentArgument()
{
QPushButton* send = (QPushButton*)sender();
- //globalSelection();//??
if (send == GroupPoints->PushButton1) {
myEditCurrentArgument = GroupPoints->LineEdit1;
GroupPoints->PushButton1->setDown(false);
GroupPoints->LineEdit1->setEnabled(false);
}
+ else if (send == GroupWire->PushButton1) {
+ myEditCurrentArgument = GroupWire->LineEdit1;
+ }
+ else if (send == GroupOnCurve->PushButton1) {
+ myEditCurrentArgument = GroupOnCurve->LineEdit1;
+ GroupOnCurve->PushButton2->setDown(false);
+ GroupOnCurve->LineEdit2->setEnabled(false);
+
+ globalSelection(); // close local contexts, if any
+ localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
+ }
+ else if (send == GroupOnCurve->PushButton2) {
+ myEditCurrentArgument = GroupOnCurve->LineEdit2;
+ GroupOnCurve->PushButton1->setDown(false);
+ GroupOnCurve->LineEdit1->setEnabled(false);
+
+ globalSelection(); // close local contexts, if any
+ localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
+ }
// enable line edit
myEditCurrentArgument->setEnabled(true);
myEditCurrentArgument->setFocus();
- // after setFocus(), because it will be setDown(false) when loses focus
send->setDown(true);
-
- disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
- globalSelection(GEOM_POINT);
- connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
- this, SLOT(SelectionIntoArgument()));
-
- // seems we need it only to avoid preview disappearing, caused by selection mode change
- displayPreview();
-}
-
-//=================================================================================
-// function : LineEditReturnPressed()
-// purpose :
-//=================================================================================
-void BuildGUI_EdgeDlg::LineEditReturnPressed()
-{
- QLineEdit* send = (QLineEdit*)sender();
- if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2) {
- myEditCurrentArgument = send;
- GEOMBase_Skeleton::LineEditReturnPressed();
- }
+ displayPreview(true);
}
//=================================================================================
{
GEOMBase_Skeleton::ActivateThisDialog();
- connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
- this, SLOT( SelectionIntoArgument() ) );
+ connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
+ this, SLOT(SelectionIntoArgument()));
- displayPreview();
+ ConstructorsClicked(getConstructorId());
}
//=================================================================================
ActivateThisDialog();
}
+//=================================================================================
+// function : ValueChangedInSpinBox()
+// purpose :
+//=================================================================================
+void BuildGUI_EdgeDlg::ValueChangedInSpinBox(double newValue)
+{
+ displayPreview(true);
+}
+
//=================================================================================
// function : createOperation
// purpose :
// function : isValid
// purpose :
//=================================================================================
-bool BuildGUI_EdgeDlg::isValid (QString&)
+bool BuildGUI_EdgeDlg::isValid (QString& msg)
{
- return myOkPoint1 && myOkPoint2;
+ bool ok = false;
+ switch (getConstructorId()) {
+ case 0:
+ ok = myPoint1 && myPoint2;
+ break;
+ case 1:
+ ok = GroupWire->SpinBox_DX->isValid(msg, !IsPreview()) &&
+ GroupWire->SpinBox_DY->isValid(msg, !IsPreview()) &&
+ myWire;
+ break;
+ case 2:
+ ok = GroupOnCurve->SpinBox_DX->isValid(msg, !IsPreview()) &&
+ myCurve;
+ break;
+ default:
+ break;
+ }
+ return ok;
}
//=================================================================================
//=================================================================================
bool BuildGUI_EdgeDlg::execute (ObjectList& objects)
{
+ bool res = false;
GEOM::GEOM_Object_var anObj;
- anObj = GEOM::GEOM_IShapesOperations::_narrow(getOperation())->MakeEdge(myPoint1, myPoint2);
+ GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
- if (!anObj->_is_nil())
- objects.push_back(anObj._retn());
+ switch (getConstructorId()) {
+ case 0:
+ {
+ anObj = anOper->MakeEdge(myPoint1.get(), myPoint2.get());
+ res = true;
+ break;
+ }
+ case 1:
+ {
+ double aLinearTolerance = GroupWire->SpinBox_DX->value();
+ double anAngularTolerance = GroupWire->SpinBox_DY->value();
- return true;
+ QStringList aParameters;
+ aParameters << GroupWire->SpinBox_DX->text();
+ aParameters << GroupWire->SpinBox_DY->text();
+
+ anObj = anOper->MakeEdgeWire(myWire.get(), aLinearTolerance, anAngularTolerance);
+
+ if (!anObj->_is_nil() && !IsPreview())
+ anObj->SetParameters(aParameters.join(":").toLatin1().constData());
+
+ res = true;
+ break;
+ }
+ case 2:
+ {
+ double aLength = GroupOnCurve->SpinBox_DX->value();
+
+ anObj = anOper->MakeEdgeOnCurveByLength(myCurve.get(), aLength, myStartPoint.get());
+
+ if (!anObj->_is_nil() && !IsPreview())
+ anObj->SetParameters(GroupOnCurve->SpinBox_DX->text().toLatin1().constData());
+
+ res = true;
+ break;
+ }
+ }
+
+ if (!anObj->_is_nil()) objects.push_back(anObj._retn());
+
+ return res;
+}
+
+//=================================================================================
+// function : addSubshapeToStudy
+// purpose : virtual method to add new SubObjects if local selection
+//=================================================================================
+void BuildGUI_EdgeDlg::addSubshapesToStudy()
+{
+ switch (getConstructorId()) {
+ case 0:
+ GEOMBase::PublishSubObject(myPoint1.get());
+ GEOMBase::PublishSubObject(myPoint2.get());
+ break;
+ case 1:
+ GEOMBase::PublishSubObject(myWire.get());
+ break;
+ case 2:
+ GEOMBase::PublishSubObject(myCurve.get());
+ GEOMBase::PublishSubObject(myStartPoint.get());
+ break;
+ default:
+ break;
+ }
}