Back to index

salome-geom  6.5.0
BasicGUI_PointDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  GEOM GEOMGUI : GUI for Geometry component
00024 //  File   : BasicGUI_PointDlg.cxx
00025 //  Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 
00027 #include "BasicGUI_PointDlg.h"
00028 
00029 #include <SUIT_ResourceMgr.h>
00030 #include <SUIT_Session.h>
00031 #include <SalomeApp_Application.h>
00032 #include <LightApp_SelectionMgr.h>
00033 
00034 #include <GeometryGUI.h>
00035 #include <GEOMBase.h>
00036 
00037 #include <DlgRef.h>
00038 
00039 #include <GEOMImpl_Types.hxx>
00040 
00041 #include <QApplication>
00042 #include <QButtonGroup>
00043 #include <QHBoxLayout>
00044 #include <QLabel>
00045 #include <QRadioButton>
00046 #include <QMenu>
00047 #include <QTimer>
00048 
00049 #include <gp_Pnt.hxx>
00050 #include <TopoDS_Shape.hxx>
00051 #include <TopAbs_ShapeEnum.hxx>
00052 #include <TopoDS.hxx>
00053 #include <BRep_Tool.hxx>
00054 #include <TopExp.hxx>
00055 #include <TColStd_IndexedMapOfInteger.hxx>
00056 #include <TopTools_IndexedMapOfShape.hxx>
00057 
00058 #define PARAM_VALUE 0
00059 #define COORD_VALUE 1
00060 #define LENGTH_VALUE 2
00061 
00062 #define GEOM_POINT_XYZ    0
00063 #define GEOM_POINT_REF    1
00064 #define GEOM_POINT_EDGE   2
00065 #define GEOM_POINT_INTINT 3
00066 #define GEOM_POINT_SURF   4
00067 
00068 #define SPACING 6
00069 #define MARGIN  9
00070 
00071 enum { SelectEdge, SelectWire };
00072 
00073 //=================================================================================
00074 // class    : BasicGUI_PointDlg()
00075 // purpose  : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the
00076 //            name 'name' and widget flags set to 'f'.
00077 //            The dialog will by default be modeless, unless you set 'modal' to
00078 //            TRUE to construct a modal dialog.
00079 //=================================================================================
00080 BasicGUI_PointDlg::BasicGUI_PointDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
00081                                       bool modal, Qt::WindowFlags fl)
00082   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
00083     myBusy (false)
00084 {
00085   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
00086   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT")));
00087   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_EDGE")));
00088   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
00089   QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_REF")));
00090   QPixmap image4 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_LINES")));
00091   QPixmap image5 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_FACE")));
00092   QPixmap image6 (aResMgr->loadPixmap("GEOM", tr("ICO_LINE")));
00093   QPixmap image7 (aResMgr->loadPixmap("GEOM", tr("ICO_WIRE")));
00094 
00095   setWindowTitle(tr("GEOM_POINT_TITLE"));
00096 
00097   /***************************************************************/
00098   mainFrame()->GroupConstructors->setTitle(tr("GEOM_POINTS"));
00099   mainFrame()->RadioButton1->setIcon(image0);
00100   mainFrame()->RadioButton2->setIcon(image3);
00101   mainFrame()->RadioButton3->setIcon(image1);
00102   mainFrame()->RadioButton4->show();
00103   mainFrame()->RadioButton4->setIcon(image4);
00104   mainFrame()->RadioButton5->show();
00105   mainFrame()->RadioButton5->setIcon(image5);
00106 
00107   myParamGroup = new QGroupBox(centralWidget());
00108   myParamCoord = new QButtonGroup(myParamGroup);
00109   QHBoxLayout* boxLayout = new QHBoxLayout(myParamGroup);
00110   boxLayout->setMargin(MARGIN); boxLayout->setSpacing(SPACING);
00111   QRadioButton* btn = new QRadioButton(tr("GEOM_PARAM_VALUE"), myParamGroup);
00112   myParamCoord->addButton(btn, PARAM_VALUE);
00113   boxLayout->addWidget(btn);
00114   btn = new QRadioButton(tr("GEOM_LENGTH_VALUE"), myParamGroup);
00115   myParamCoord->addButton(btn, LENGTH_VALUE);
00116   boxLayout->addWidget(btn);
00117   btn = new QRadioButton(tr("GEOM_COORD_VALUE"), myParamGroup);
00118   myParamCoord->addButton(btn, COORD_VALUE);
00119   boxLayout->addWidget(btn);
00120   myParamCoord->setExclusive(true);
00121   myParamCoord->button(PARAM_VALUE)->setChecked(true);
00122 
00123   GroupXYZ = new DlgRef_3Spin(centralWidget());
00124   GroupXYZ->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
00125   GroupXYZ->TextLabel1->setText(tr("GEOM_X"));
00126   GroupXYZ->TextLabel2->setText(tr("GEOM_Y"));
00127   GroupXYZ->TextLabel3->setText(tr("GEOM_Z"));
00128 
00129   GroupOnCurve = new DlgRef_2Sel1Spin(centralWidget());
00130   GroupOnCurve->GroupBox1->setTitle(tr("GEOM_POINT_ON_EDGE"));
00131   GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
00132   GroupOnCurve->TextLabel2->setText(tr("GEOM_START_POINT"));
00133   GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
00134   GroupOnCurve->PushButton1->setIcon(image2);
00135   GroupOnCurve->PushButton2->setIcon(image2);
00136 
00137   GroupOnSurface = new DlgRef_1Sel2Spin(centralWidget());
00138   GroupOnSurface->GroupBox1->setTitle(tr("GEOM_POINT_ON_FACE"));
00139   GroupOnSurface->TextLabel1->setText(tr("GEOM_FACE"));
00140   GroupOnSurface->TextLabel2->setText(tr("GEOM_UPARAMETER"));
00141   GroupOnSurface->TextLabel3->setText(tr("GEOM_VPARAMETER"));
00142   GroupOnSurface->PushButton1->setIcon(image2);
00143 
00144   GroupRefPoint = new DlgRef_1Sel3Spin(centralWidget());
00145   GroupRefPoint->GroupBox1->setTitle(tr("GEOM_REF_POINT"));
00146   GroupRefPoint->TextLabel1->setText(tr("GEOM_POINT"));
00147   GroupRefPoint->PushButton1->setIcon(image2);
00148   GroupRefPoint->TextLabel2->setText(tr("GEOM_DX"));
00149   GroupRefPoint->TextLabel3->setText(tr("GEOM_DY"));
00150   GroupRefPoint->TextLabel4->setText(tr("GEOM_DZ"));
00151 
00152   /* popup menu for line intersect buttons */
00153   myBtnPopup = new QMenu(this);
00154   QIcon ico_line = QIcon(image6);
00155   QIcon ico_wire = QIcon(image7);
00156   myActions[myBtnPopup->addAction(ico_line, tr("GEOM_EDGE"))] = SelectEdge;
00157   myActions[myBtnPopup->addAction(ico_wire, tr("GEOM_WIRE"))] = SelectWire;
00158 
00159   GroupLineIntersection = new DlgRef_2Sel(centralWidget());
00160   GroupLineIntersection->GroupBox1->setTitle(tr("GEOM_LINE_INTERSECTION"));
00161   GroupLineIntersection->TextLabel1->setText(tr("GEOM_LINE1"));
00162   GroupLineIntersection->TextLabel2->setText(tr("GEOM_LINE2"));
00163   GroupLineIntersection->PushButton1->setIcon(image2);
00164   GroupLineIntersection->PushButton1->setMenu(myBtnPopup);
00165   GroupLineIntersection->PushButton2->setIcon(image2);
00166   GroupLineIntersection->PushButton2->setMenu(myBtnPopup);
00167   GroupLineIntersection->LineEdit2->setEnabled(false);
00168 
00169   myCoordGrp = new QGroupBox(tr("GEOM_COORDINATES_RES"), centralWidget());
00170   QGridLayout* myCoordGrpLayout = new QGridLayout(myCoordGrp);
00171   myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_X"), myCoordGrp), 0, 0);
00172   myX = new QLineEdit(myCoordGrp);
00173   myCoordGrpLayout->addWidget(myX, 0, 1);
00174   myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Y"), myCoordGrp), 1, 0);
00175   myY = new QLineEdit(myCoordGrp);
00176   myCoordGrpLayout->addWidget(myY, 1, 1);
00177   myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Z"), myCoordGrp), 2, 0);
00178   myZ = new QLineEdit(myCoordGrp);
00179   myCoordGrpLayout->addWidget(myZ, 2, 1);
00180 
00181   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00182   layout->setMargin(0); layout->setSpacing(6);
00183   layout->addWidget(myParamGroup);
00184   layout->addWidget(GroupXYZ);
00185   layout->addWidget(GroupOnCurve);
00186   layout->addWidget(GroupOnSurface);
00187   layout->addWidget(GroupRefPoint);
00188   layout->addWidget(GroupLineIntersection);
00189   layout->addWidget(myCoordGrp);
00190 
00191   myX->setReadOnly(true);
00192   myY->setReadOnly(true);
00193   myZ->setReadOnly(true);
00194 
00195   myX->setEnabled(false);
00196   myY->setEnabled(false);
00197   myZ->setEnabled(false);
00198 
00199   QPalette aPal = myX->palette();
00200   aPal.setColor(QPalette::Disabled, QPalette::Text, QColor(0, 0, 0));
00201   myX->setPalette(aPal);
00202   myY->setPalette(aPal);
00203   myZ->setPalette(aPal);
00204 
00205   setHelpFileName("create_point_page.html");
00206 
00207   Init();
00208 }
00209 
00210 
00211 //=================================================================================
00212 // function : ~BasicGUI_PointDlg()
00213 // purpose  : Destructor
00214 //=================================================================================
00215 BasicGUI_PointDlg::~BasicGUI_PointDlg()
00216 {
00217 }
00218 
00219 
00220 //=================================================================================
00221 // function : Init()
00222 // purpose  :
00223 //=================================================================================
00224 void BasicGUI_PointDlg::Init()
00225 {
00226   GroupOnCurve->LineEdit1->setReadOnly(true);
00227   GroupOnCurve->LineEdit2->setReadOnly(true);
00228   GroupOnSurface->LineEdit1->setReadOnly(true);
00229   GroupRefPoint->LineEdit1->setReadOnly(true);
00230   GroupLineIntersection->LineEdit1->setReadOnly(true);
00231   GroupLineIntersection->LineEdit2->setReadOnly(true);
00232   GroupLineIntersection->LineEdit1->setEnabled(true);
00233   GroupLineIntersection->LineEdit2->setEnabled(false);
00234 
00235   myEdge.nullify();
00236   myFace.nullify();
00237   myRefPoint.nullify();
00238   myLine1.nullify();
00239   myLine2.nullify();
00240   myNeedType = TopAbs_VERTEX;
00241 
00242   myEditCurrentArgument = 0;
00243 
00244   /* Get setting of step value from file configuration */
00245   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00246   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
00247 
00248   /* min, max, step and decimals for spin boxes */
00249   initSpinBox(GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
00250   initSpinBox(GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision");
00251   initSpinBox(GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision");
00252   GroupXYZ->SpinBox_DX->setValue(0.0);
00253   GroupXYZ->SpinBox_DY->setValue(0.0);
00254   GroupXYZ->SpinBox_DZ->setValue(0.0);
00255 
00256   initSpinBox(GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
00257   initSpinBox(GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision");
00258   initSpinBox(GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision");
00259   GroupRefPoint->SpinBox_DX->setValue(0.0);
00260   GroupRefPoint->SpinBox_DY->setValue(0.0);
00261   GroupRefPoint->SpinBox_DZ->setValue(0.0);
00262 
00263   step = 0.1;
00264 
00265   initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1., step, "parametric_precision");
00266   GroupOnCurve->SpinBox_DX->setValue(0.5);
00267 
00268   initSpinBox(GroupOnSurface->SpinBox_DX, 0., 1., step, "parametric_precision");
00269   GroupOnSurface->SpinBox_DX->setValue(0.5);
00270   initSpinBox(GroupOnSurface->SpinBox_DY, 0., 1., step, "parametric_precision");
00271   GroupOnSurface->SpinBox_DY->setValue(0.5);
00272 
00273   /* signals and slots connections */
00274   connect(myGeomGUI,      SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
00275   connect(myGeomGUI,      SIGNAL(SignalCloseAllDialogs()),        this, SLOT(ClickOnCancel()));
00276 
00277   connect(buttonOk(),     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00278   connect(buttonApply(),  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00279 
00280   connect(this,           SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
00281 
00282   connect(myParamCoord,   SIGNAL(buttonClicked(int)), this, SLOT(ClickParamCoord(int)));
00283 
00284   connect(GroupOnCurve->PushButton1,          SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00285   connect(GroupOnCurve->PushButton2,          SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00286   connect(GroupOnSurface->PushButton1,        SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00287   connect(GroupLineIntersection->PushButton1, SIGNAL(pressed()), this, SLOT(SetEditCurrentArgument()));
00288   connect(GroupLineIntersection->PushButton2, SIGNAL(pressed()), this, SLOT(SetEditCurrentArgument()));
00289 
00290   connect(myBtnPopup, SIGNAL(triggered(QAction*)), this, SLOT(onBtnPopup(QAction*)));
00291 
00292   connect(GroupOnCurve->SpinBox_DX,   SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
00293   connect(GroupOnSurface->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
00294   connect(GroupOnSurface->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
00295   connect(GroupXYZ->SpinBox_DX,       SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
00296   connect(GroupXYZ->SpinBox_DY,       SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
00297   connect(GroupXYZ->SpinBox_DZ,       SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
00298   connect(GroupRefPoint->SpinBox_DX,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
00299   connect(GroupRefPoint->SpinBox_DY,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
00300   connect(GroupRefPoint->SpinBox_DZ,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
00301 
00302   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this,  SLOT(SetDoubleSpinBoxStep(double)));
00303 
00304   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00305            this,  SLOT(SelectionIntoArgument()));
00306 
00307   initName(tr("GEOM_VERTEX"));
00308 
00309   ConstructorsClicked(0);
00310 }
00311 
00312 //=================================================================================
00313 // function : SetDoubleSpinBoxStep()
00314 // purpose  : Double spin box management
00315 //=================================================================================
00316 void BasicGUI_PointDlg::SetDoubleSpinBoxStep(double step)
00317 {
00318   GroupOnCurve->SpinBox_DX->setSingleStep(step);
00319   GroupXYZ->SpinBox_DX->setSingleStep(step);
00320   GroupXYZ->SpinBox_DY->setSingleStep(step);
00321   GroupXYZ->SpinBox_DZ->setSingleStep(step);
00322   GroupRefPoint->SpinBox_DX->setSingleStep(step);
00323   GroupRefPoint->SpinBox_DY->setSingleStep(step);
00324   GroupRefPoint->SpinBox_DZ->setSingleStep(step);
00325 }
00326 
00327 
00328 //=================================================================================
00329 // function : ConstructorsClicked()
00330 // purpose  : Radio button management
00331 //=================================================================================
00332 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
00333 {
00334   switch (constructorId) {
00335   case GEOM_POINT_XYZ:
00336     {
00337       globalSelection(); // close local contexts, if any
00338       myNeedType = TopAbs_VERTEX;
00339       localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
00340 
00341       GroupRefPoint->hide();
00342       GroupOnCurve->hide();
00343       GroupLineIntersection->hide();
00344       GroupOnSurface->hide();
00345       myCoordGrp->hide();
00346       myParamGroup->hide();
00347       GroupXYZ->show();
00348       break;
00349     }
00350   case GEOM_POINT_REF:
00351     {
00352       globalSelection(); // close local contexts, if any
00353       myNeedType = TopAbs_VERTEX;
00354       localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
00355 
00356       myEditCurrentArgument = GroupRefPoint->LineEdit1;
00357       myEditCurrentArgument->setText("");
00358       myRefPoint.nullify();
00359       GroupRefPoint->PushButton1->setDown(true);
00360       myParamGroup->hide();
00361       GroupXYZ->hide();
00362       GroupOnCurve->hide();
00363       GroupLineIntersection->hide();
00364       GroupOnSurface->hide();
00365       GroupRefPoint->show();
00366       myCoordGrp->show();
00367       break;
00368     }
00369   case GEOM_POINT_EDGE:
00370     {
00371       globalSelection(); // close local contexts, if any
00372       myNeedType = TopAbs_EDGE;
00373       localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
00374 
00375       myEditCurrentArgument = GroupOnCurve->LineEdit1;
00376       myEditCurrentArgument->setText("");
00377       myEdge.nullify();
00378       myRefPoint.nullify();
00379       GroupOnCurve->PushButton1->setDown(true);
00380       GroupRefPoint->hide();
00381       GroupLineIntersection->hide();
00382       GroupOnSurface->hide();
00383       myParamGroup->show();
00384       myParamCoord->button(LENGTH_VALUE)->show();
00385       myParamCoord->button(PARAM_VALUE)->setChecked(true);
00386       GroupOnCurve->show();
00387       myCoordGrp->show();
00388       updateParamCoord(false);
00389       break;
00390     }
00391   case GEOM_POINT_INTINT:
00392     {
00393       globalSelection(); // close local contexts, if any
00394       myNeedType = TopAbs_EDGE;
00395       localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
00396 
00397       myEditCurrentArgument = GroupLineIntersection->LineEdit1;
00398       GroupLineIntersection->LineEdit1->setText("");
00399       GroupLineIntersection->LineEdit2->setText("");
00400       GroupLineIntersection->LineEdit1->setEnabled(true);
00401       GroupLineIntersection->LineEdit2->setEnabled(false);
00402       myLine1.nullify();
00403       myLine2.nullify();
00404       GroupLineIntersection->PushButton1->setDown(true);
00405       GroupLineIntersection->PushButton2->setDown(false);
00406       myParamGroup->hide();
00407       GroupXYZ->hide();
00408       GroupRefPoint->hide();
00409       GroupOnCurve->hide();
00410       GroupOnSurface->hide();
00411       myCoordGrp->hide();
00412       GroupLineIntersection->show();
00413       break;
00414     }
00415   case GEOM_POINT_SURF:
00416     {
00417       globalSelection(); // close local contexts, if any
00418       myNeedType = TopAbs_FACE;
00419       localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
00420 
00421       myEditCurrentArgument = GroupOnSurface->LineEdit1;
00422       myEditCurrentArgument->setText("");
00423       myFace.nullify();
00424       GroupOnSurface->PushButton1->setDown(true);
00425       GroupRefPoint->hide();
00426       GroupOnCurve->hide();
00427       GroupLineIntersection->hide();
00428       myParamGroup->show();
00429       myParamCoord->button(LENGTH_VALUE)->hide();
00430       myParamCoord->button(PARAM_VALUE)->setChecked(true);
00431       GroupOnSurface->show();
00432       myCoordGrp->show();
00433       updateParamCoord(false);
00434       break;
00435     }
00436   }
00437 
00438   myX->setText("");
00439   myY->setText("");
00440   myZ->setText("");
00441 
00442   QTimer::singleShot(50, this, SLOT(updateSize()));
00443 
00444   SelectionIntoArgument();
00445 }
00446 
00447 //=================================================================================
00448 // function : ClickOnOk()
00449 // purpose  :
00450 //=================================================================================
00451 void BasicGUI_PointDlg::ClickOnOk()
00452 {
00453   setIsApplyAndClose(true);
00454   if (onAccept())
00455     ClickOnCancel();
00456 }
00457 
00458 //=================================================================================
00459 // function : ClickOnApply()
00460 // purpose  :
00461 //=================================================================================
00462 bool BasicGUI_PointDlg::ClickOnApply()
00463 {
00464   if (!onAccept())
00465     return false;
00466 
00467   initName();
00468   ConstructorsClicked(getConstructorId());
00469   return true;
00470 }
00471 
00472 
00473 //=================================================================================
00474 // function : SelectionIntoArgument()
00475 // purpose  : Called when selection as changed (for constructors not using local context)
00476 //=================================================================================
00477 void BasicGUI_PointDlg::SelectionIntoArgument()
00478 {
00479   erasePreview();
00480   const int id = getConstructorId();
00481 
00482   if ((id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF)
00483        && myEditCurrentArgument != 0)
00484   {
00485     myEditCurrentArgument->setText("");
00486     myX->setText("");
00487     myY->setText("");
00488     myZ->setText("");
00489     myFace.nullify();
00490     if (myEditCurrentArgument == GroupOnCurve->LineEdit1)
00491       myEdge.nullify();
00492     else if (myEditCurrentArgument == GroupOnCurve->LineEdit2)
00493       myRefPoint.nullify();
00494   }
00495   else if (id == GEOM_POINT_INTINT) {
00496     myEditCurrentArgument->setText("");
00497     if (myEditCurrentArgument == GroupLineIntersection->LineEdit1)
00498       myLine1.nullify();
00499     else if (myEditCurrentArgument == GroupLineIntersection->LineEdit2)
00500       myLine2.nullify();
00501   }
00502 
00503   GEOM::GeomObjPtr aSelectedObject = getSelected(myNeedType);
00504   TopoDS_Shape aShape;
00505   if (aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) && !aShape.IsNull()) {
00506     QString aName = GEOMBase::GetName(aSelectedObject.get());
00507     myBusy = true;
00508     if (id == GEOM_POINT_XYZ) {
00509       gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
00510       GroupXYZ->SpinBox_DX->setValue(aPnt.X());
00511       GroupXYZ->SpinBox_DY->setValue(aPnt.Y());
00512       GroupXYZ->SpinBox_DZ->setValue(aPnt.Z());
00513     }
00514     else if (id == GEOM_POINT_REF) {
00515       myRefPoint = aSelectedObject;
00516       GroupRefPoint->LineEdit1->setText(aName);
00517     }
00518     else if (id == GEOM_POINT_EDGE) {
00519       myEditCurrentArgument->setText(aName);
00520       if (myEditCurrentArgument == GroupOnCurve->LineEdit1) {
00521         myEdge = aSelectedObject;
00522         if (myEdge && !myRefPoint) {
00523           GroupOnCurve->PushButton2->click();
00524         }
00525       }
00526       else if (myEditCurrentArgument == GroupOnCurve->LineEdit2) {
00527         myRefPoint = aSelectedObject;
00528         if (myRefPoint && !myEdge) {
00529           GroupOnCurve->PushButton1->click();
00530         }
00531       }
00532     }
00533     else if (id == GEOM_POINT_INTINT) {
00534       myEditCurrentArgument->setText(aName);
00535       if (myEditCurrentArgument == GroupLineIntersection->LineEdit1) {
00536         myLine1 = aSelectedObject;
00537         if (myLine1 && !myLine2) {
00538           GroupLineIntersection->PushButton2->setMenu(0);
00539           GroupLineIntersection->PushButton2->click();
00540           GroupLineIntersection->PushButton2->setDown(true);
00541           GroupLineIntersection->PushButton2->setMenu(myBtnPopup);
00542         }
00543       }
00544       else if (myEditCurrentArgument == GroupLineIntersection->LineEdit2) {
00545         myLine2 = aSelectedObject;
00546         if (myLine2 && !myLine1) {
00547           GroupLineIntersection->PushButton1->setMenu(0);
00548           GroupLineIntersection->PushButton1->click();
00549           GroupLineIntersection->PushButton1->setDown(true);
00550           GroupLineIntersection->PushButton1->setMenu(myBtnPopup);
00551         }
00552       }
00553     }
00554     else if (id == GEOM_POINT_SURF) {
00555       myFace = aSelectedObject;
00556       GroupOnSurface->LineEdit1->setText(aName);
00557     }
00558     myBusy = false;
00559   }
00560 
00561   displayPreview(true);
00562 }
00563 
00564 
00565 //=================================================================================
00566 // function : SetEditCurrentArgument()
00567 // purpose  :
00568 //=================================================================================
00569 void BasicGUI_PointDlg::SetEditCurrentArgument()
00570 {
00571   QPushButton* send = (QPushButton*)sender();
00572 
00573   if (send == GroupRefPoint->PushButton1) {
00574     GroupRefPoint->LineEdit1->setFocus();
00575     myEditCurrentArgument = GroupRefPoint->LineEdit1;
00576     globalSelection(); // close local contexts, if any
00577     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
00578   }
00579   else if (send == GroupOnCurve->PushButton1) {
00580     GroupOnCurve->LineEdit1->setFocus();
00581     myEditCurrentArgument = GroupOnCurve->LineEdit1;
00582     globalSelection(); // close local contexts, if any
00583     myNeedType = TopAbs_EDGE;
00584     localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
00585     GroupOnCurve->PushButton2->setDown(false);
00586     GroupOnCurve->LineEdit1->setEnabled(true);
00587     GroupOnCurve->LineEdit2->setEnabled(false);
00588   }
00589   else if (send == GroupOnCurve->PushButton2) {
00590     GroupOnCurve->LineEdit2->setFocus();
00591     myEditCurrentArgument = GroupOnCurve->LineEdit2;
00592     globalSelection(); // close local contexts, if any
00593     myNeedType = TopAbs_VERTEX;
00594     localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
00595     GroupOnCurve->PushButton1->setDown(false);
00596     GroupOnCurve->LineEdit2->setEnabled(true);
00597     GroupOnCurve->LineEdit1->setEnabled(false);
00598   }
00599   else if (send == GroupOnSurface->PushButton1)
00600   {
00601     GroupOnSurface->LineEdit1->setFocus();
00602     myEditCurrentArgument = GroupOnSurface->LineEdit1;
00603     globalSelection(); // close local contexts, if any
00604     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE);
00605   }
00606   else if (send == GroupLineIntersection->PushButton1) {
00607     GroupLineIntersection->LineEdit1->setFocus();
00608     myEditCurrentArgument = GroupLineIntersection->LineEdit1;
00609     GroupLineIntersection->PushButton2->setDown(false);
00610     GroupLineIntersection->LineEdit1->setEnabled(true);
00611     GroupLineIntersection->LineEdit2->setEnabled(false);
00612   }
00613   else if (send == GroupLineIntersection->PushButton2) {
00614     GroupLineIntersection->LineEdit2->setFocus();
00615     myEditCurrentArgument = GroupLineIntersection->LineEdit2;
00616     GroupLineIntersection->PushButton1->setDown(false);
00617     GroupLineIntersection->LineEdit1->setEnabled(false);
00618     GroupLineIntersection->LineEdit2->setEnabled(true);
00619   }
00620   send->setDown(true);
00621 
00622   if ((send == GroupLineIntersection->PushButton1 ||
00623          send == GroupLineIntersection->PushButton2) && !myBusy)
00624     SelectionIntoArgument();
00625 }
00626 
00627 
00628 //=================================================================================
00629 // function : enterEvent()
00630 // purpose  : to reactivate this dialog box when mouse enter onto the window
00631 //=================================================================================
00632 void BasicGUI_PointDlg::enterEvent(QEvent*)
00633 {
00634   if (!mainFrame()->GroupConstructors->isEnabled())
00635     ActivateThisDialog();
00636 }
00637 
00638 
00639 //=================================================================================
00640 // function : ActivateThisDialog()
00641 // purpose  :
00642 //=================================================================================
00643 void BasicGUI_PointDlg::ActivateThisDialog()
00644 {
00645   GEOMBase_Skeleton::ActivateThisDialog();
00646 
00647   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00648            this, SLOT(SelectionIntoArgument()));
00649 
00650   ConstructorsClicked(getConstructorId());
00651 }
00652 
00653 
00654 //=================================================================================
00655 // function : DeactivateActiveDialog()
00656 // purpose  : public slot to deactivate if active
00657 //=================================================================================
00658 void BasicGUI_PointDlg::DeactivateActiveDialog()
00659 {
00660   // myGeomGUI->SetState(-1);
00661   GEOMBase_Skeleton::DeactivateActiveDialog();
00662 }
00663 
00664 
00665 //=================================================================================
00666 // function : ValueChangedInSpinBox()
00667 // purpose  :
00668 //=================================================================================
00669 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
00670 {
00671   displayPreview(true);
00672 }
00673 
00674 //=================================================================================
00675 // function : CheckBoxClicked()
00676 // purpose  : Check Boxes Management
00677 //=================================================================================
00678 void BasicGUI_PointDlg::CheckBoxClicked(int  State)
00679 {
00680   displayPreview(true);
00681 }
00682 
00683 
00684 //=================================================================================
00685 // funcion  : getParameter()
00686 // purpose  :
00687 //=================================================================================
00688 double BasicGUI_PointDlg::getParameter() const
00689 {
00690   return GroupOnCurve->SpinBox_DX->value();
00691 }
00692 
00693 
00694 //=================================================================================
00695 // funcion  : getUParameter()
00696 // purpose  :
00697 //=================================================================================
00698 double BasicGUI_PointDlg::getUParameter() const
00699 {
00700   return GroupOnSurface->SpinBox_DX->value();
00701 }
00702 
00703 
00704 //=================================================================================
00705 // funcion  : getVParameter()
00706 // purpose  :
00707 //=================================================================================
00708 double BasicGUI_PointDlg::getVParameter() const
00709 {
00710   return GroupOnSurface->SpinBox_DY->value();
00711 }
00712 
00713 
00714 //=================================================================================
00715 // function : OnPointSelected
00716 // purpose  :
00717 //=================================================================================
00718 void BasicGUI_PointDlg::OnPointSelected(const gp_Pnt& thePnt)
00719 {
00720   if (getConstructorId() == GEOM_POINT_XYZ) {
00721     GroupXYZ->SpinBox_DX->setValue(thePnt.X());
00722     GroupXYZ->SpinBox_DY->setValue(thePnt.Y());
00723     GroupXYZ->SpinBox_DZ->setValue(thePnt.Z());
00724 
00725     displayPreview(true);
00726   }
00727 }
00728 
00729 //=================================================================================
00730 // function : createOperation
00731 // purpose  :
00732 //=================================================================================
00733 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
00734 {
00735   return myGeomGUI->GetGeomGen()->GetIBasicOperations(getStudyId());
00736 }
00737 
00738 //=================================================================================
00739 // function : isValid
00740 // purpose  :
00741 //=================================================================================
00742 bool BasicGUI_PointDlg::isValid(QString& msg)
00743 {
00744   bool ok = false;
00745   switch (getConstructorId()) {
00746   case GEOM_POINT_XYZ :
00747     ok = GroupXYZ->SpinBox_DX->isValid(msg, !IsPreview()) &&
00748          GroupXYZ->SpinBox_DY->isValid(msg, !IsPreview()) &&
00749          GroupXYZ->SpinBox_DZ->isValid(msg, !IsPreview());
00750     break;
00751   case GEOM_POINT_REF:
00752     ok = GroupRefPoint->SpinBox_DX->isValid(msg, !IsPreview()) &&
00753          GroupRefPoint->SpinBox_DY->isValid(msg, !IsPreview()) &&
00754          GroupRefPoint->SpinBox_DZ->isValid(msg, !IsPreview()) &&
00755          myRefPoint;
00756     break;
00757   case GEOM_POINT_EDGE:
00758     if (myParamCoord->checkedId() == PARAM_VALUE || myParamCoord->checkedId() == LENGTH_VALUE)
00759       ok = GroupOnCurve->SpinBox_DX->isValid(msg, !IsPreview());
00760     else
00761       ok = GroupXYZ->SpinBox_DX->isValid(msg, !IsPreview()) &&
00762            GroupXYZ->SpinBox_DY->isValid(msg, !IsPreview()) &&
00763            GroupXYZ->SpinBox_DZ->isValid(msg, !IsPreview());
00764     ok = myEdge && ok;
00765     break;
00766   case GEOM_POINT_INTINT:
00767     ok = myLine1 && myLine2;
00768     break;
00769   case GEOM_POINT_SURF:
00770     if (myParamCoord->checkedId() == PARAM_VALUE)
00771       ok = GroupOnSurface->SpinBox_DX->isValid(msg, !IsPreview()) &&
00772            GroupOnSurface->SpinBox_DY->isValid(msg, !IsPreview());
00773     else
00774       ok = GroupXYZ->SpinBox_DX->isValid(msg, !IsPreview()) &&
00775            GroupXYZ->SpinBox_DY->isValid(msg, !IsPreview()) &&
00776            GroupXYZ->SpinBox_DZ->isValid(msg, !IsPreview());
00777     ok = myFace && ok;
00778     break;
00779   default:
00780     break;
00781   }
00782   return ok;
00783 }
00784 
00785 //=================================================================================
00786 // function : execute
00787 // purpose  :
00788 //=================================================================================
00789 bool BasicGUI_PointDlg::execute(ObjectList& objects)
00790 {
00791   bool res = false;
00792 
00793   GEOM::GEOM_Object_var anObj;
00794   QStringList aParameters;
00795 
00796   GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow(getOperation());
00797 
00798   switch (getConstructorId()) {
00799   case GEOM_POINT_XYZ :
00800     {
00801       double x = GroupXYZ->SpinBox_DX->value();
00802       double y = GroupXYZ->SpinBox_DY->value();
00803       double z = GroupXYZ->SpinBox_DZ->value();
00804 
00805       aParameters << GroupXYZ->SpinBox_DX->text();
00806       aParameters << GroupXYZ->SpinBox_DY->text();
00807       aParameters << GroupXYZ->SpinBox_DZ->text();
00808 
00809       anObj = anOper->MakePointXYZ(x, y, z);
00810       res = true;
00811       break;
00812     }
00813   case GEOM_POINT_REF :
00814     {
00815       double dx = GroupRefPoint->SpinBox_DX->value();
00816       double dy = GroupRefPoint->SpinBox_DY->value();
00817       double dz = GroupRefPoint->SpinBox_DZ->value();
00818 
00819       aParameters << GroupRefPoint->SpinBox_DX->text();
00820       aParameters << GroupRefPoint->SpinBox_DY->text();
00821       aParameters << GroupRefPoint->SpinBox_DZ->text();
00822 
00823       anObj = anOper->MakePointWithReference(myRefPoint.get(), dx, dy, dz);
00824       res = true;
00825       break;
00826     }
00827   case GEOM_POINT_EDGE :
00828     {
00829       if (myParamCoord->checkedId() == PARAM_VALUE) {
00830         anObj = anOper->MakePointOnCurve(myEdge.get(), getParameter());
00831         aParameters<<GroupOnCurve->SpinBox_DX->text();
00832       }
00833       else if (myParamCoord->checkedId() == LENGTH_VALUE) {
00834         anObj = anOper->MakePointOnCurveByLength(myEdge.get(), getParameter(), myRefPoint.get());
00835         aParameters<<GroupOnCurve->SpinBox_DX->text();
00836       }
00837       else if (myParamCoord->checkedId() == COORD_VALUE) {
00838         double x = GroupXYZ->SpinBox_DX->value();
00839         double y = GroupXYZ->SpinBox_DY->value();
00840         double z = GroupXYZ->SpinBox_DZ->value();
00841 
00842         aParameters << GroupXYZ->SpinBox_DX->text();
00843         aParameters << GroupXYZ->SpinBox_DY->text();
00844         aParameters << GroupXYZ->SpinBox_DZ->text();
00845 
00846         anObj = anOper->MakePointOnCurveByCoord(myEdge.get(), x, y, z);
00847       }
00848       res = true;
00849       break;
00850     }
00851   case GEOM_POINT_INTINT :
00852     anObj = anOper->MakePointOnLinesIntersection(myLine1.get(), myLine2.get());
00853     if (!anObj->_is_nil()) {
00854       QString aName = getNewObjectName();
00855       if (anObj->GetShapeType() == GEOM::COMPOUND && aName.startsWith("Vertex"))
00856         initName(tr("GEOM_COMPOUND"));
00857       else if (anObj->GetShapeType() == GEOM::VERTEX && aName.startsWith("Compound"))
00858         initName(tr("GEOM_VERTEX"));
00859     }
00860     res = true;
00861     break;
00862   case GEOM_POINT_SURF :
00863     {
00864       if (myParamCoord->checkedId() == PARAM_VALUE) {
00865         anObj = anOper->MakePointOnSurface(myFace.get(), getUParameter(), getVParameter());
00866         aParameters<<GroupOnSurface->SpinBox_DX->text();
00867         aParameters<<GroupOnSurface->SpinBox_DY->text();
00868       } else {
00869         double x = GroupXYZ->SpinBox_DX->value();
00870         double y = GroupXYZ->SpinBox_DY->value();
00871         double z = GroupXYZ->SpinBox_DZ->value();
00872 
00873         aParameters << GroupXYZ->SpinBox_DX->text();
00874         aParameters << GroupXYZ->SpinBox_DY->text();
00875         aParameters << GroupXYZ->SpinBox_DZ->text();
00876 
00877         anObj = anOper->MakePointOnSurfaceByCoord(myFace.get(), x, y, z);
00878       }
00879       res = true;
00880       break;
00881     }
00882   }
00883 
00884   const int id = getConstructorId();
00885   if(!anObj->_is_nil() && !IsPreview() && (id == GEOM_POINT_XYZ ||
00886                                            id == GEOM_POINT_REF ||
00887                                            id == GEOM_POINT_EDGE ||
00888                                            id == GEOM_POINT_SURF)) {
00889       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00890   }
00891 
00892   if (id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF) {
00893     TopoDS_Shape aShape;
00894     if (GEOMBase::GetShape(anObj, aShape) && !aShape.IsNull() &&
00895          aShape.ShapeType() == TopAbs_VERTEX) {
00896       gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
00897       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00898       int aPrecision = resMgr->integerValue("Geometry", "length_precision", 6);
00899       myX->setText(DlgRef::PrintDoubleValue(aPnt.X(), aPrecision));
00900       myY->setText(DlgRef::PrintDoubleValue(aPnt.Y(), aPrecision));
00901       myZ->setText(DlgRef::PrintDoubleValue(aPnt.Z(), aPrecision));
00902     }
00903     else {
00904       myX->setText("");
00905       myY->setText("");
00906       myZ->setText("");
00907     }
00908   }
00909 
00910   if (!anObj->_is_nil()) {
00911     objects.push_back(anObj._retn());
00912   }
00913 
00914   return res;
00915 }
00916 
00917 //=================================================================================
00918 // function : addSubshapeToStudy
00919 // purpose  : virtual method to add new SubObjects if local selection
00920 //=================================================================================
00921 void BasicGUI_PointDlg::addSubshapesToStudy()
00922 {
00923   switch (getConstructorId()) {
00924   case GEOM_POINT_REF:
00925     GEOMBase::PublishSubObject(myRefPoint.get());
00926     break;
00927   case GEOM_POINT_EDGE:
00928     GEOMBase::PublishSubObject(myEdge.get());
00929     break;
00930   case GEOM_POINT_INTINT:
00931     GEOMBase::PublishSubObject(myLine1.get());
00932     GEOMBase::PublishSubObject(myLine2.get());
00933     break;
00934   case GEOM_POINT_SURF:
00935     GEOMBase::PublishSubObject(myFace.get());
00936     break;
00937   default:
00938     break;
00939   }
00940 }
00941 
00942 //=================================================================================
00943 // function : ClickParamCoord()
00944 // purpose  :
00945 //=================================================================================
00946 void BasicGUI_PointDlg::ClickParamCoord(int id)
00947 {
00948   updateParamCoord(true);
00949   displayPreview(true);
00950 }
00951 
00952 //=================================================================================
00953 // function : updateParamCoord
00954 // purpose  :
00955 //=================================================================================
00956 void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
00957 {
00958   bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
00959   bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
00960 
00961   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00962   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
00963 
00964   const int id = getConstructorId();
00965   if (id == GEOM_POINT_EDGE) {
00966     GroupOnCurve->TextLabel2->setVisible(isLength);
00967     GroupOnCurve->PushButton2->setVisible(isLength);
00968     GroupOnCurve->LineEdit2->setVisible(isLength);
00969     GroupOnCurve->TextLabel3->setVisible(isParam || isLength);
00970     GroupOnCurve->SpinBox_DX->setVisible(isParam || isLength);
00971     if (isParam){
00972       initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1., 0.1, "parametric_precision");
00973       GroupOnCurve->SpinBox_DX->setValue(0.5);
00974       GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
00975     }
00976     else if (isLength){
00977       initSpinBox(GroupOnCurve->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
00978       GroupOnCurve->SpinBox_DX->setValue(0.0);
00979       GroupOnCurve->TextLabel3->setText(tr("GEOM_LENGTH"));
00980     }
00981   }
00982   else if (id == GEOM_POINT_SURF) {
00983     GroupOnSurface->TextLabel2->setShown(isParam);
00984     GroupOnSurface->TextLabel3->setShown(isParam);
00985     GroupOnSurface->SpinBox_DX->setShown(isParam);
00986     GroupOnSurface->SpinBox_DY->setShown(isParam);
00987   }
00988 
00989   GroupXYZ->setShown(!isParam && !isLength);
00990 
00991   if (theIsUpdate)
00992     QTimer::singleShot(50, this, SLOT(updateSize()));
00993 }
00994 
00995 //=================================================================================
00996 // function : onBtnPopup()
00997 // purpose  :
00998 //=================================================================================
00999 void BasicGUI_PointDlg::onBtnPopup(QAction* a)
01000 {
01001   globalSelection(); // close local contexts, if any
01002   myNeedType = myActions[a] == SelectEdge ? TopAbs_EDGE : TopAbs_WIRE;
01003   localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
01004 }
01005 
01006 //=================================================================================
01007 // function : updateSize
01008 // purpose  : adjust dialog size to minimum
01009 //=================================================================================
01010 void BasicGUI_PointDlg::updateSize()
01011 {
01012   qApp->processEvents();
01013   updateGeometry();
01014   resize(minimumSizeHint());
01015 }