Back to index

salome-geom  6.5.0
BuildGUI_EdgeDlg.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   : BuildGUI_EdgeDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 
00027 #include "BuildGUI_EdgeDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 
00033 #include <SUIT_Session.h>
00034 #include <SUIT_ResourceMgr.h>
00035 #include <SalomeApp_Application.h>
00036 #include <LightApp_SelectionMgr.h>
00037 
00038 #include <GEOMImpl_Types.hxx>
00039 #include <TColStd_IndexedMapOfInteger.hxx>
00040 
00041 //=================================================================================
00042 // class    : BuildGUI_EdgeDlg()
00043 // purpose  : Constructs a BuildGUI_EdgeDlg which is a child of 'parent', with the
00044 //            name 'name' and widget flags set to 'f'.
00045 //            The dialog will by default be modeless, unless you set 'modal' to
00046 //            TRUE to construct a modal dialog.
00047 //=================================================================================
00048 BuildGUI_EdgeDlg::BuildGUI_EdgeDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
00049   : GEOMBase_Skeleton(theGeometryGUI, parent)
00050 {
00051   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
00052   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
00053   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_BUILD_EDGE")));
00054   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_BUILD_EDGE_WIRE")));
00055   QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_BUILD_EDGE_CURVE")));
00056 
00057   setWindowTitle(tr("GEOM_EDGE_TITLE"));
00058 
00059   /***************************************************************/
00060   mainFrame()->GroupConstructors->setTitle(tr("GEOM_EDGE"));
00061   mainFrame()->RadioButton1->setIcon(image1);
00062   mainFrame()->RadioButton2->setIcon(image2);
00063   mainFrame()->RadioButton3->setIcon(image3);
00064 
00065   // two points
00066 
00067   GroupPoints = new DlgRef_2Sel(centralWidget());
00068   GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
00069   GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg(1));
00070   GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg(2));
00071   GroupPoints->PushButton1->setIcon(image0);
00072   GroupPoints->PushButton2->setIcon(image0);
00073   GroupPoints->LineEdit1->setReadOnly(true);
00074   GroupPoints->LineEdit2->setReadOnly(true);
00075 
00076   // wire
00077 
00078   GroupWire = new DlgRef_1Sel2Spin(centralWidget());
00079   GroupWire->GroupBox1->setTitle(tr("GEOM_WIRE"));
00080   GroupWire->TextLabel1->setText(tr("GEOM_WIRE"));
00081   GroupWire->PushButton1->setIcon(image0);
00082   GroupWire->LineEdit1->setReadOnly(true);
00083   GroupWire->TextLabel2->setText(tr("GEOM_LINEAR_TOLERANCE"));
00084   GroupWire->TextLabel3->setText(tr("GEOM_ANGULAR_TOLERANCE"));
00085   double SpecificStep = 0.0001;
00086   double prec1 = Precision::Confusion();
00087   double prec2 = Precision::Angular();
00088   initSpinBox(GroupWire->SpinBox_DX, prec1, MAX_NUMBER, SpecificStep, "len_tol_precision");
00089   initSpinBox(GroupWire->SpinBox_DY, prec2, MAX_NUMBER, SpecificStep, "ang_tol_precision");
00090   GroupWire->SpinBox_DX->setValue(prec1);
00091   GroupWire->SpinBox_DY->setValue(prec2);
00092 
00093   // on curve
00094 
00095   GroupOnCurve = new DlgRef_2Sel1Spin(centralWidget());
00096   GroupOnCurve->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
00097   GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
00098   GroupOnCurve->PushButton1->setIcon(image0);
00099   GroupOnCurve->LineEdit1->setReadOnly(true);
00100   GroupOnCurve->TextLabel2->setText(tr("GEOM_START_POINT"));
00101   GroupOnCurve->PushButton2->setIcon(image0);
00102   GroupOnCurve->LineEdit2->setReadOnly(true);
00103   GroupOnCurve->TextLabel3->setText(tr("GEOM_LENGTH"));
00104   double step = aResMgr->doubleValue("Geometry", "SettingsGeomStep", 100.0);
00105   initSpinBox(GroupOnCurve->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
00106   GroupOnCurve->SpinBox_DX->setValue(step);
00107 
00108   // layout
00109 
00110   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00111   layout->setMargin(0); layout->setSpacing(6);
00112   layout->addWidget(GroupPoints);
00113   layout->addWidget(GroupWire);
00114   layout->addWidget(GroupOnCurve);
00115   /***************************************************************/
00116 
00117   setHelpFileName("create_edge_page.html");
00118 
00119   // initialisation
00120   Init();
00121 }
00122 
00123 //=================================================================================
00124 // function : ~BuildGUI_EdgeDlg()
00125 // purpose  : Destroys the object and frees any allocated resources
00126 //=================================================================================
00127 BuildGUI_EdgeDlg::~BuildGUI_EdgeDlg()
00128 {
00129   // no need to delete child widgets, Qt does it all for us
00130 }
00131 
00132 //=================================================================================
00133 // function : Init()
00134 // purpose  :
00135 //=================================================================================
00136 void BuildGUI_EdgeDlg::Init()
00137 {
00138   // init variables
00139   myPoint1.nullify();
00140   myPoint2.nullify();
00141   myWire.nullify();
00142   myCurve.nullify();
00143   myStartPoint.nullify();
00144 
00145   myEditCurrentArgument = GroupPoints->LineEdit1;
00146   GroupPoints->PushButton1->setDown(true);
00147   globalSelection(); // close local contexts, if any
00148   localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
00149 
00150   // signals and slots connections
00151   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
00152   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(ClickOnCancel()));
00153 
00154   connect(this,      SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
00155 
00156   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00157   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00158 
00159   connect(GroupPoints->PushButton1,  SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00160   connect(GroupPoints->PushButton2,  SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00161   connect(GroupWire->PushButton1,    SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00162   connect(GroupOnCurve->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00163   connect(GroupOnCurve->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00164 
00165   connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
00166 
00167   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00168            this, SLOT(SelectionIntoArgument()));
00169 
00170   initName(tr("GEOM_EDGE"));
00171 
00172   ConstructorsClicked(0);
00173 }
00174 
00175 //=================================================================================
00176 // function : ClickOnOk()
00177 // purpose  :
00178 //=================================================================================
00179 void BuildGUI_EdgeDlg::ClickOnOk()
00180 {
00181   setIsApplyAndClose( true );
00182   if (ClickOnApply())
00183     ClickOnCancel();
00184 }
00185 
00186 //=================================================================================
00187 // function : ClickOnApply()
00188 // purpose  :
00189 //=================================================================================
00190 bool BuildGUI_EdgeDlg::ClickOnApply()
00191 {
00192   if (!onAccept())
00193     return false;
00194 
00195   initName();
00196 
00197   myEditCurrentArgument->setText("");
00198   ConstructorsClicked(getConstructorId());
00199 
00200   return true;
00201 }
00202 
00203 //=================================================================================
00204 // function : ConstructorsClicked()
00205 // purpose  : Radio button management
00206 //=================================================================================
00207 void BuildGUI_EdgeDlg::ConstructorsClicked(int constructorId)
00208 {
00209   switch (constructorId) {
00210   case 0:
00211     {
00212       globalSelection(); // close local contexts, if any
00213       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
00214 
00215       myEditCurrentArgument = GroupPoints->LineEdit1;
00216       GroupPoints->LineEdit1->setText("");
00217       GroupPoints->LineEdit2->setText("");
00218       myPoint1.nullify();
00219       myPoint2.nullify();
00220       GroupPoints->PushButton1->setDown(true);
00221       GroupPoints->PushButton2->setDown(false);
00222       GroupPoints->LineEdit1->setEnabled(true);
00223       GroupPoints->LineEdit2->setEnabled(false);
00224       GroupPoints->show();
00225       GroupWire->hide();
00226       GroupOnCurve->hide();
00227       break;
00228     }
00229   case 1:
00230     {
00231       globalSelection(); // close local contexts, if any
00232       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_WIRE);
00233 
00234       myEditCurrentArgument = GroupWire->LineEdit1;
00235       GroupWire->LineEdit1->setText("");
00236       myWire.nullify();
00237       GroupWire->PushButton1->setDown(true);
00238       GroupWire->LineEdit1->setEnabled(true);
00239       GroupPoints->hide();
00240       GroupOnCurve->hide();
00241       GroupWire->show();
00242       break;
00243     }
00244   case 2:
00245     {
00246       globalSelection(); // close local contexts, if any
00247       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
00248 
00249       myEditCurrentArgument = GroupOnCurve->LineEdit1;
00250       GroupOnCurve->LineEdit1->setText("");
00251       GroupOnCurve->LineEdit2->setText("");
00252       myCurve.nullify();
00253       myStartPoint.nullify();
00254       GroupOnCurve->PushButton1->setDown(true);
00255       GroupOnCurve->PushButton2->setDown(false);
00256       GroupOnCurve->LineEdit1->setEnabled(true);
00257       GroupOnCurve->LineEdit2->setEnabled(false);
00258       GroupPoints->hide();
00259       GroupWire->hide();
00260       GroupOnCurve->show();
00261       break;
00262     }
00263   }
00264 
00265   qApp->processEvents();
00266   updateGeometry();
00267   resize(minimumSizeHint());
00268   SelectionIntoArgument();
00269 }
00270 
00271 //=================================================================================
00272 // function : SelectionIntoArgument()
00273 // purpose  : Called when selection is changed or on dialog initialization or activation
00274 //=================================================================================
00275 void BuildGUI_EdgeDlg::SelectionIntoArgument()
00276 {
00277   erasePreview();
00278   myEditCurrentArgument->setText("");
00279 
00280   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00281   SALOME_ListIO aSelList;
00282   aSelMgr->selectedObjects(aSelList);
00283 
00284   if (aSelList.Extent() != 1) {
00285     if      (myEditCurrentArgument == GroupPoints->LineEdit1)  myPoint1.nullify();
00286     else if (myEditCurrentArgument == GroupPoints->LineEdit2)  myPoint2.nullify();
00287     else if (myEditCurrentArgument == GroupWire->LineEdit1)    myWire.nullify();
00288     else if (myEditCurrentArgument == GroupOnCurve->LineEdit1) myCurve.nullify();
00289     else if (myEditCurrentArgument == GroupOnCurve->LineEdit2) myStartPoint.nullify();
00290     displayPreview(true);
00291     return;
00292   }
00293 
00294   TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
00295   if (myEditCurrentArgument == GroupWire->LineEdit1) aNeedType = TopAbs_WIRE;
00296   else if (myEditCurrentArgument == GroupOnCurve->LineEdit1) aNeedType = TopAbs_EDGE;
00297   GEOM::GeomObjPtr aSelectedObject = getSelected(aNeedType);
00298 
00299   TopoDS_Shape aShape;
00300   if (aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) && !aShape.IsNull()) {
00301     QString aName = GEOMBase::GetName(aSelectedObject.get());
00302     myEditCurrentArgument->setText(aName);
00303 
00304     globalSelection();
00305     localSelection(GEOM::GEOM_Object::_nil(), aNeedType);
00306 
00307     if (myEditCurrentArgument == GroupPoints->LineEdit1) {
00308       myPoint1 = aSelectedObject;
00309       if (myPoint1 && !myPoint2)
00310         GroupPoints->PushButton2->click();
00311     }
00312     else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
00313       myPoint2 = aSelectedObject;
00314       if (myPoint2 && !myPoint1)
00315         GroupPoints->PushButton1->click();
00316     }
00317     else if (myEditCurrentArgument == GroupWire->LineEdit1) {
00318       myWire = aSelectedObject;
00319     }
00320     else if (myEditCurrentArgument == GroupOnCurve->LineEdit1) {
00321       myCurve = aSelectedObject;
00322       if (myCurve && !myStartPoint)
00323         GroupOnCurve->PushButton2->click();
00324     }
00325     else if (myEditCurrentArgument == GroupOnCurve->LineEdit2) {
00326       myStartPoint = aSelectedObject;
00327       if (myStartPoint && !myCurve)
00328         GroupOnCurve->PushButton1->click();
00329     }
00330   }
00331 
00332   displayPreview(true);
00333 }
00334 
00335 //=================================================================================
00336 // function : SetEditCurrentArgument()
00337 // purpose  :
00338 //=================================================================================
00339 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
00340 {
00341   QPushButton* send = (QPushButton*)sender();
00342 
00343   if (send == GroupPoints->PushButton1) {
00344     myEditCurrentArgument = GroupPoints->LineEdit1;
00345     GroupPoints->PushButton2->setDown(false);
00346     GroupPoints->LineEdit2->setEnabled(false);
00347   }
00348   else if (send == GroupPoints->PushButton2) {
00349     myEditCurrentArgument = GroupPoints->LineEdit2;
00350     GroupPoints->PushButton1->setDown(false);
00351     GroupPoints->LineEdit1->setEnabled(false);
00352   }
00353   else if (send == GroupWire->PushButton1) {
00354     myEditCurrentArgument = GroupWire->LineEdit1;
00355   }
00356   else if (send == GroupOnCurve->PushButton1) {
00357     myEditCurrentArgument = GroupOnCurve->LineEdit1;
00358     GroupOnCurve->PushButton2->setDown(false);
00359     GroupOnCurve->LineEdit2->setEnabled(false);
00360 
00361     globalSelection(); // close local contexts, if any
00362     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
00363   }
00364   else if (send == GroupOnCurve->PushButton2) {
00365     myEditCurrentArgument = GroupOnCurve->LineEdit2;
00366     GroupOnCurve->PushButton1->setDown(false);
00367     GroupOnCurve->LineEdit1->setEnabled(false);
00368 
00369     globalSelection(); // close local contexts, if any
00370     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
00371   }
00372 
00373   // enable line edit
00374   myEditCurrentArgument->setEnabled(true);
00375   myEditCurrentArgument->setFocus();
00376   send->setDown(true);
00377   displayPreview(true);
00378 }
00379 
00380 //=================================================================================
00381 // function : ActivateThisDialog()
00382 // purpose  :
00383 //=================================================================================
00384 void BuildGUI_EdgeDlg::ActivateThisDialog()
00385 {
00386   GEOMBase_Skeleton::ActivateThisDialog();
00387 
00388   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00389           this, SLOT(SelectionIntoArgument()));
00390 
00391   ConstructorsClicked(getConstructorId());
00392 }
00393 
00394 //=================================================================================
00395 // function : enterEvent()
00396 // purpose  :
00397 //=================================================================================
00398 void BuildGUI_EdgeDlg::enterEvent (QEvent*)
00399 {
00400   if (!mainFrame()->GroupConstructors->isEnabled())
00401     ActivateThisDialog();
00402 }
00403 
00404 //=================================================================================
00405 // function : ValueChangedInSpinBox()
00406 // purpose  :
00407 //=================================================================================
00408 void BuildGUI_EdgeDlg::ValueChangedInSpinBox(double newValue)
00409 {
00410   displayPreview(true);
00411 }
00412 
00413 //=================================================================================
00414 // function : createOperation
00415 // purpose  :
00416 //=================================================================================
00417 GEOM::GEOM_IOperations_ptr BuildGUI_EdgeDlg::createOperation()
00418 {
00419   return getGeomEngine()->GetIShapesOperations(getStudyId());
00420 }
00421 
00422 //=================================================================================
00423 // function : isValid
00424 // purpose  :
00425 //=================================================================================
00426 bool BuildGUI_EdgeDlg::isValid (QString& msg)
00427 {
00428   bool ok = false;
00429   switch (getConstructorId()) {
00430   case 0:
00431     ok = myPoint1 && myPoint2;
00432     break;
00433   case 1:
00434     ok = GroupWire->SpinBox_DX->isValid(msg, !IsPreview()) &&
00435          GroupWire->SpinBox_DY->isValid(msg, !IsPreview()) &&
00436          myWire;
00437     break;
00438   case 2:
00439     ok = GroupOnCurve->SpinBox_DX->isValid(msg, !IsPreview()) &&
00440          myCurve;
00441     break;
00442   default:
00443     break;
00444   }
00445   return ok;
00446 }
00447 
00448 //=================================================================================
00449 // function : execute
00450 // purpose  :
00451 //=================================================================================
00452 bool BuildGUI_EdgeDlg::execute (ObjectList& objects)
00453 {
00454   bool res = false;
00455   GEOM::GEOM_Object_var anObj;
00456 
00457   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
00458 
00459   switch (getConstructorId()) {
00460   case 0:
00461     {
00462       anObj = anOper->MakeEdge(myPoint1.get(), myPoint2.get());
00463       res = true;
00464       break;
00465     }
00466   case 1:
00467     {
00468       double aLinearTolerance   = GroupWire->SpinBox_DX->value();
00469       double anAngularTolerance = GroupWire->SpinBox_DY->value();
00470 
00471       QStringList aParameters;
00472       aParameters << GroupWire->SpinBox_DX->text();
00473       aParameters << GroupWire->SpinBox_DY->text();
00474 
00475       anObj = anOper->MakeEdgeWire(myWire.get(), aLinearTolerance, anAngularTolerance);
00476 
00477       if (!anObj->_is_nil() && !IsPreview())
00478         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00479 
00480       res = true;
00481       break;
00482     }
00483   case 2:
00484     {
00485       double aLength = GroupOnCurve->SpinBox_DX->value();
00486 
00487       anObj = anOper->MakeEdgeOnCurveByLength(myCurve.get(), aLength, myStartPoint.get());
00488 
00489       if (!anObj->_is_nil() && !IsPreview())
00490         anObj->SetParameters(GroupOnCurve->SpinBox_DX->text().toLatin1().constData());
00491 
00492       res = true;
00493       break;
00494     }
00495   }
00496 
00497   if (!anObj->_is_nil()) objects.push_back(anObj._retn());
00498 
00499   return res;
00500 }
00501 
00502 //=================================================================================
00503 // function : addSubshapeToStudy
00504 // purpose  : virtual method to add new SubObjects if local selection
00505 //=================================================================================
00506 void BuildGUI_EdgeDlg::addSubshapesToStudy()
00507 {
00508   switch (getConstructorId()) {
00509   case 0:
00510     GEOMBase::PublishSubObject(myPoint1.get());
00511     GEOMBase::PublishSubObject(myPoint2.get());
00512     break;
00513   case 1:
00514     GEOMBase::PublishSubObject(myWire.get());
00515     break;
00516   case 2:
00517     GEOMBase::PublishSubObject(myCurve.get());
00518     GEOMBase::PublishSubObject(myStartPoint.get());
00519     break;
00520   default:
00521     break;
00522   }
00523 }