Back to index

salome-geom  6.5.0
OperationGUI_Fillet1d2dDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // GEOM GEOMGUI : GUI for Geometry component
00021 // File   : OperationGUI_Fillet1d2dDlg.cxx
00022 // Author : DMV, OCN.
00023 
00024 #include "OperationGUI_Fillet1d2dDlg.h"
00025 
00026 #include <DlgRef.h>
00027 #include <GeometryGUI.h>
00028 #include <GEOMBase.h>
00029 
00030 #include <SUIT_Desktop.h>
00031 #include <SUIT_Session.h>
00032 #include <SUIT_ResourceMgr.h>
00033 #include <SUIT_ViewWindow.h>
00034 #include <SUIT_ViewManager.h>
00035 #include <SalomeApp_Application.h>
00036 #include <LightApp_SelectionMgr.h>
00037 #include <OCCViewer_ViewModel.h>
00038 
00039 // OCCT Includes
00040 #include <TColStd_MapOfInteger.hxx>
00041 #include <TColStd_IndexedMapOfInteger.hxx>
00042 
00043 #include <GEOMImpl_Types.hxx>
00044 
00045 //=================================================================================
00046 // class    : OperationGUI_Fillet1d2dDlg()
00047 // purpose  : Constructs a OperationGUI_Fillet1d2dDlg which is a child of 'parent', with the
00048 //            name 'name' and widget flags set to 'f'.
00049 //            The dialog will by default be modeless, unless you set 'modal' to
00050 //            TRUE to construct a modal dialog.
00051 //=================================================================================
00052 OperationGUI_Fillet1d2dDlg::OperationGUI_Fillet1d2dDlg (GeometryGUI* theGeometryGUI,
00053                                                         QWidget* parent,
00054                                                         bool is1D)
00055   : GEOMBase_Skeleton(theGeometryGUI, parent, false),
00056     myIs1D( is1D )
00057 {
00058   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
00059   QPixmap image0 (aResMgr->loadPixmap("GEOM", myIs1D ? tr("ICON_DLG_FILLET_1D") 
00060                                                      : tr("ICON_DLG_FILLET_2D")));
00061   QPixmap iconSelect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
00062 
00063   setWindowTitle(myIs1D ? tr("GEOM_FILLET_1D_TITLE") : tr("GEOM_FILLET_2D_TITLE"));
00064 
00065   /***************************************************************/
00066   mainFrame()->GroupConstructors->setTitle(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
00067   mainFrame()->RadioButton1->setIcon(image0);
00068   mainFrame()->RadioButton2->close();
00069   mainFrame()->RadioButton3->close();
00070 
00071   GroupVertexes = new DlgRef_2Sel1Spin(centralWidget());
00072   GroupVertexes->GroupBox1->setTitle(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
00073   GroupVertexes->TextLabel1->setText(myIs1D ? tr("GEOM_PLANAR_EDGE_WIRE") : tr("GEOM_PLANAR_FACE"));
00074   GroupVertexes->TextLabel2->setText(tr("GEOM_VERTEXES"));
00075   GroupVertexes->TextLabel3->setText(tr("GEOM_RADIUS"));
00076   GroupVertexes->PushButton1->setIcon(iconSelect);
00077   GroupVertexes->PushButton2->setIcon(iconSelect);
00078   GroupVertexes->LineEdit1->setReadOnly(true);
00079   GroupVertexes->LineEdit2->setReadOnly(true);
00080 
00081   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00082   layout->setMargin(0); layout->setSpacing(6);
00083   layout->addWidget(GroupVertexes);
00084 
00085   /***************************************************************/
00086 
00087   // Set range of spinboxes
00088   double SpecificStep = 10.0;
00089   initSpinBox(GroupVertexes->SpinBox_DX, 0.00001, COORD_MAX, SpecificStep, "length_precision" );
00090 
00091   setHelpFileName(myIs1D ? "fillet1d_operation_page.html" : "fillet2d_operation_page.html");
00092 
00093   // Initialisation
00094   Init();
00095   resize(100,100);
00096 }
00097 
00098 //=================================================================================
00099 // function : ~OperationGUI_Fillet1d2dDlg()
00100 // purpose  : Destroys the object and frees any allocated resources
00101 //=================================================================================
00102 OperationGUI_Fillet1d2dDlg::~OperationGUI_Fillet1d2dDlg()
00103 {
00104 }
00105 
00106 //=================================================================================
00107 // function : Init()
00108 // purpose  :
00109 //=================================================================================
00110 void OperationGUI_Fillet1d2dDlg::Init()
00111 {
00112   // Set Initial values of spinboxes
00113   GroupVertexes->SpinBox_DX->setValue(5);
00114 
00115   // Clear line edits
00116   GroupVertexes->LineEdit1->setText("");
00117   GroupVertexes->LineEdit2->setText("");
00118 
00119   myShape = GEOM::GEOM_Object::_nil();
00120 
00121   myVertexes.Clear();
00122 
00123   showOnlyPreviewControl();
00124 
00125   // signals and slots connections
00126 
00127   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()   ));
00128   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00129 
00130   //  connect(this,          SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
00131 
00132   connect(GroupVertexes->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00133   connect(GroupVertexes->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00134 
00135   connect(GroupVertexes->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00136   connect(GroupVertexes->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00137 
00138   connect(GroupVertexes->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
00139 
00140   initName(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
00141   GroupVertexes->PushButton1->click();
00142 
00143   SelectionIntoArgument();
00144 }
00145 
00146 //=================================================================================
00147 // function : ClickOnOk()
00148 // purpose  :
00149 //=================================================================================
00150 void OperationGUI_Fillet1d2dDlg::ClickOnOk()
00151 {
00152   setIsApplyAndClose( true );
00153   if (ClickOnApply())
00154     ClickOnCancel();
00155 }
00156 
00157 //=================================================================================
00158 // function : ClickOnApply()
00159 // purpose  :
00160 //=================================================================================
00161 bool OperationGUI_Fillet1d2dDlg::ClickOnApply()
00162 {
00163   if (!onAccept())
00164     return false;
00165 
00166   initName();
00167   // Reset dialog state
00168   GroupVertexes->LineEdit1->setText("");
00169   GroupVertexes->LineEdit2->setText("");
00170   myShape = GEOM::GEOM_Object::_nil();
00171   myVertexes.Clear();
00172   GroupVertexes->PushButton1->click();
00173 
00174   return true;
00175 }
00176 
00177 //=================================================================================
00178 // function : SelectionIntoArgument()
00179 // purpose  : Called when selection is changed or on dialog initialization or activation
00180 //=================================================================================
00181 void OperationGUI_Fillet1d2dDlg::SelectionIntoArgument()
00182 {
00183   erasePreview();
00184   myEditCurrentArgument->setText("");
00185 
00186   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00187   SALOME_ListIO aSelList;
00188   aSelMgr->selectedObjects(aSelList);
00189 
00190   // If selection of main object is activated
00191   if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
00192     myShape = GEOM::GEOM_Object::_nil();
00193     if (aSelList.Extent() == 1) {
00194       GEOM::GEOM_Object_var anObj =
00195         GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
00196       
00197       if ( !anObj->_is_nil() ) {
00198         QString aName = GEOMBase::GetName( anObj );
00199         TopoDS_Shape aShape;
00200         if ( GEOMBase::GetShape( anObj, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
00201           TColStd_IndexedMapOfInteger aMap;
00202           aSelMgr->GetIndexes(aSelList.First(), aMap);
00203           if ( aMap.Extent() == 1 ) { // Local Selection
00204             int anIndex = aMap( 1 );
00205             aName += QString( myIs1D ? ":wire_%1" : ":face_%1" ).arg( anIndex );
00206    
00207             //Find SubShape Object in Father
00208             GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( anObj, aName );
00209             
00210             if ( aFindedObject->_is_nil()) { // Object not found in study
00211               GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
00212               anObj = aShapesOp->GetSubShape( anObj, anIndex );
00213             }
00214             else
00215               anObj = aFindedObject; // get Object from study
00216           }
00217           else { // Global Selection
00218             if ((myIs1D && aShape.ShapeType() != TopAbs_WIRE) ||
00219                 (!myIs1D && aShape.ShapeType() != TopAbs_FACE && aShape.ShapeType() != TopAbs_SHELL)) {
00220               anObj = GEOM::GEOM_Object::_nil();
00221               aName = "";
00222             }
00223           }
00224         }
00225         myShape = anObj;
00226         myEditCurrentArgument->setText(aName
00227 );
00228         processPreview();
00229       }
00230     }
00231   } else if (myEditCurrentArgument == GroupVertexes->LineEdit2) {
00232     myVertexes.Clear();
00233     bool isPreview = myIs1D;
00234     if (aSelList.Extent() == 1) {
00235       GEOM::GEOM_Object_var anObj =
00236         GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
00237 
00238       if ( !anObj->_is_nil() ) {
00239         TColStd_IndexedMapOfInteger anIndexes;
00240         aSelMgr->GetIndexes(aSelList.First(), anIndexes);
00241 
00242         if (anIndexes.Extent() > 0) {
00243           QString aName;
00244           if (anIndexes.Extent() == 1) {
00245             int anIndex = anIndexes(1);
00246             aName = QString(GEOMBase::GetName(anObj)) + QString(":vertex_%1").arg(anIndex);
00247           }
00248           else
00249             aName = tr("GEOM_MEN_POPUP_NAME").arg(anIndexes.Extent());
00250 
00251           isPreview = true;
00252           myEditCurrentArgument->setText(aName);
00253           myVertexes = anIndexes;
00254         }
00255       }
00256     }
00257     if ( isPreview )
00258       processPreview();
00259   }
00260 
00261   if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
00262     if (!myShape->_is_nil() && myVertexes.Extent() == 0)
00263       GroupVertexes->PushButton2->click();
00264   }
00265 }
00266 
00267 //=================================================================================
00268 // function : SetEditCurrentArgument()
00269 // purpose  :
00270 //=================================================================================
00271 void OperationGUI_Fillet1d2dDlg::SetEditCurrentArgument()
00272 {
00273   QPushButton* send = (QPushButton*)sender();
00274 
00275   if (send == GroupVertexes->PushButton1) {
00276     myEditCurrentArgument = GroupVertexes->LineEdit1;
00277     GroupVertexes->PushButton2->setDown(false);
00278     GroupVertexes->LineEdit2->setEnabled(false);
00279   }
00280   else if (send == GroupVertexes->PushButton2) {
00281     myEditCurrentArgument = GroupVertexes->LineEdit2;
00282     GroupVertexes->PushButton1->setDown(false);
00283     GroupVertexes->LineEdit1->setEnabled(false);
00284   }
00285 
00286   // enable line edit
00287   myEditCurrentArgument->setEnabled(true);
00288   myEditCurrentArgument->setFocus();
00289   // after setFocus(), because it will be setDown(false) when loses focus
00290   send->setDown(true);
00291 
00292   activateSelection();
00293 
00294   // seems we need it only to avoid preview disappearing, caused by selection mode change
00295   processPreview();
00296 }
00297 
00298 //=================================================================================
00299 // function : LineEditReturnPressed()
00300 // purpose  :
00301 //=================================================================================
00302 void OperationGUI_Fillet1d2dDlg::LineEditReturnPressed()
00303 {
00304   QLineEdit* send = (QLineEdit*)sender();
00305 
00306   if (send == GroupVertexes->LineEdit1)
00307     myEditCurrentArgument = GroupVertexes->LineEdit1;
00308   else if (send == GroupVertexes->LineEdit2)
00309     myEditCurrentArgument = GroupVertexes->LineEdit2;
00310   else
00311     return;
00312 
00313   GEOMBase_Skeleton::LineEditReturnPressed();
00314 }
00315 
00316 //=================================================================================
00317 // function : ActivateThisDialog()
00318 // purpose  :
00319 //=================================================================================
00320 void OperationGUI_Fillet1d2dDlg::ActivateThisDialog()
00321 {
00322   GEOMBase_Skeleton::ActivateThisDialog();
00323 }
00324 
00325 //=================================================================================
00326 // function : enterEvent()
00327 // purpose  :
00328 //=================================================================================
00329 void OperationGUI_Fillet1d2dDlg::enterEvent (QEvent*)
00330 {
00331   if (!mainFrame()->GroupConstructors->isEnabled())
00332     this->ActivateThisDialog();
00333 }
00334 
00335 //=================================================================================
00336 // function : ValueChangedInSpinBox()
00337 // purpose  :
00338 //=================================================================================
00339 void OperationGUI_Fillet1d2dDlg::ValueChangedInSpinBox (double)
00340 {
00341   processPreview();
00342 }
00343 
00344 //=================================================================================
00345 // function : activateSelection
00346 // purpose  : Activate selection in accordance with myEditCurrentArgument
00347 //=================================================================================
00348 void OperationGUI_Fillet1d2dDlg::activateSelection()
00349 {
00350   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00351   globalSelection();
00352   if (myEditCurrentArgument == GroupVertexes->LineEdit1)
00353     //localSelection(myShape, myIs1D ? TopAbs_WIRE : TopAbs_FACE);
00354     if (myIs1D)
00355       globalSelection(GEOM_WIRE);
00356     else {
00357       TColStd_MapOfInteger aMap;
00358       aMap.Add(GEOM_FACE);
00359       aMap.Add(GEOM_SHELL);
00360       globalSelection(aMap);
00361     }
00362   else if (!myShape->_is_nil() && myEditCurrentArgument == GroupVertexes->LineEdit2)
00363     localSelection(myShape, TopAbs_VERTEX);
00364 
00365   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00366           this, SLOT(SelectionIntoArgument()));
00367 }
00368 
00369 //=================================================================================
00370 // function : createOperation
00371 // purpose  :
00372 //=================================================================================
00373 GEOM::GEOM_IOperations_ptr OperationGUI_Fillet1d2dDlg::createOperation()
00374 {
00375   return getGeomEngine()->GetILocalOperations(getStudyId());
00376 }
00377 
00378 //=================================================================================
00379 // function : isValid()
00380 // purpose  : Verify validity of input data
00381 //=================================================================================
00382 bool OperationGUI_Fillet1d2dDlg::isValid (QString& msg)
00383 {
00384   bool ok = !myShape->_is_nil();
00385   ok = GroupVertexes->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
00386   ok = (myIs1D || myVertexes.Extent() > 0) && ok;
00387   return ok;
00388 }
00389 
00390 //=================================================================================
00391 // function : execute
00392 // purpose  :
00393 //=================================================================================
00394 bool OperationGUI_Fillet1d2dDlg::execute (ObjectList& objects)
00395 {
00396   GEOM::ListOfLong_var aListOfIndexes = new GEOM::ListOfLong;
00397   aListOfIndexes->length(myVertexes.Extent());
00398 
00399   for (int i = 1, n = myVertexes.Extent(); i <= n; i++)
00400     aListOfIndexes[ i - 1 ] = myVertexes(i);
00401 
00402   GEOM::GEOM_ILocalOperations_var anOper = GEOM::GEOM_ILocalOperations::_narrow(getOperation());
00403   GEOM::GEOM_Object_var anObj = myIs1D ?
00404     anOper->MakeFillet1D(myShape, getRadius(), aListOfIndexes) : 
00405     anOper->MakeFillet2D(myShape, getRadius(), aListOfIndexes);
00406 
00407   if (!anObj->_is_nil())
00408     objects.push_back(anObj._retn());
00409 
00410   return true;
00411 }
00412 
00413 //=================================================================================
00414 // function : getRadius
00415 // purpose  : Get radius
00416 //=================================================================================
00417 double OperationGUI_Fillet1d2dDlg::getRadius() const
00418 {
00419   return GroupVertexes ->SpinBox_DX->value();
00420 }