Back to index

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