Back to index

salome-geom  6.5.0
MeasureGUI_NormaleDlg.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   : MeasureGUI_NormaleDlg.cxx
00022 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
00023 //
00024 #include "MeasureGUI.h"
00025 #include "MeasureGUI_NormaleDlg.h"
00026 
00027 #include <DlgRef.h>
00028 #include <GEOMBase.h>
00029 #include <GeometryGUI.h>
00030 
00031 #include <SUIT_Session.h>
00032 #include <SUIT_ResourceMgr.h>
00033 #include <SalomeApp_Application.h>
00034 #include <LightApp_SelectionMgr.h>
00035 
00036 // OCCT Includes
00037 #include <TopoDS_Shape.hxx>
00038 #include <TopoDS.hxx>
00039 #include <TopExp.hxx>
00040 #include <TColStd_IndexedMapOfInteger.hxx>
00041 #include <TopTools_IndexedMapOfShape.hxx>
00042 
00043 #include <GEOMImpl_Types.hxx>
00044 
00045 //=================================================================================
00046 // class    : MeasureGUI_NormaleDlg()
00047 // purpose  : Constructs a MeasureGUI_NormaleDlg 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 MeasureGUI_NormaleDlg::MeasureGUI_NormaleDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
00053   : GEOMBase_Skeleton(theGeometryGUI, parent, false)
00054 {
00055   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
00056   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_NORMALE")));
00057   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
00058 
00059   setWindowTitle(tr("GEOM_NORMALE_TITLE"));
00060 
00061   /***************************************************************/
00062   mainFrame()->GroupConstructors->setTitle(tr("GEOM_NORMALE"));
00063   mainFrame()->RadioButton1->setIcon(image0);
00064   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
00065   mainFrame()->RadioButton2->close();
00066   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00067   mainFrame()->RadioButton3->close();
00068 
00069   GroupArgs = new DlgRef_2Sel (centralWidget());
00070   GroupArgs->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
00071 
00072   GroupArgs->TextLabel1->setText(tr("GEOM_FACE"));
00073   GroupArgs->TextLabel2->setText(tr("GEOM_POINT"));
00074 
00075   GroupArgs->PushButton1->setIcon(image1);
00076   GroupArgs->PushButton2->setIcon(image1);
00077 
00078   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00079   layout->setMargin(0); layout->setSpacing(6);
00080   layout->addWidget(GroupArgs);
00081   /***************************************************************/
00082 
00083   setHelpFileName("using_measurement_tools_page.html#normale_anchor");
00084 
00085   Init();
00086 }
00087 
00088 //=================================================================================
00089 // function : ~MeasureGUI_NormaleDlg()
00090 // purpose  : Destroys the object and frees any allocated resources
00091 //=================================================================================
00092 MeasureGUI_NormaleDlg::~MeasureGUI_NormaleDlg()
00093 {
00094 }
00095 
00096 //=================================================================================
00097 // function : Init()
00098 // purpose  :
00099 //=================================================================================
00100 void MeasureGUI_NormaleDlg::Init()
00101 {
00102   // init variables
00103   GroupArgs->LineEdit1->setReadOnly(true);
00104   GroupArgs->LineEdit2->setReadOnly(true);
00105 
00106   GroupArgs->LineEdit1->setText("");
00107   GroupArgs->LineEdit2->setText("");
00108   myFace = myPoint = GEOM::GEOM_Object::_nil();
00109 
00110   // signals and slots connections
00111   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00112   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00113 
00114   connect(GroupArgs->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00115   connect(GroupArgs->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00116 
00117   connect(GroupArgs->LineEdit1,   SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00118   connect(GroupArgs->LineEdit2,   SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00119 
00120   initName(tr("GEOM_VECTOR_NORMALE"));
00121 
00122   GroupArgs->PushButton1->click();
00123   SelectionIntoArgument();
00124 }
00125 
00126 //=================================================================================
00127 // function : ClickOnOk()
00128 // purpose  :
00129 //=================================================================================
00130 void MeasureGUI_NormaleDlg::ClickOnOk()
00131 {
00132   if (ClickOnApply())
00133     ClickOnCancel();
00134 }
00135 
00136 //=================================================================================
00137 // function : ClickOnApply()
00138 // purpose  :
00139 //=================================================================================
00140 bool MeasureGUI_NormaleDlg::ClickOnApply()
00141 {
00142   if (!onAccept())
00143     return false;
00144 
00145   initName();
00146   // activate first line edit
00147   GroupArgs->PushButton1->click();
00148   return true;
00149 }
00150 
00151 //=================================================================================
00152 // function : SelectionIntoArgument()
00153 // purpose  : Called when selection is changed or on dialog initialization or activation
00154 //=================================================================================
00155 void MeasureGUI_NormaleDlg::SelectionIntoArgument()
00156 {
00157   erasePreview();
00158   myEditCurrentArgument->setText("");
00159 
00160   if (myEditCurrentArgument == GroupArgs->LineEdit1) {
00161     myFace = GEOM::GEOM_Object::_nil();
00162   }
00163   else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
00164     myPoint = GEOM::GEOM_Object::_nil();
00165   }
00166 
00167   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00168   SALOME_ListIO aSelList;
00169   aSelMgr->selectedObjects(aSelList);
00170 
00171   if (aSelList.Extent() != 1)
00172     return;
00173 
00174   // nbSel == 1
00175   GEOM::GEOM_Object_var aSelectedObject =
00176     GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
00177 
00178   if ( CORBA::is_nil(aSelectedObject) )
00179     return;
00180 
00181   QString aName = GEOMBase::GetName(aSelectedObject);
00182 
00183   if (myEditCurrentArgument == GroupArgs->LineEdit1) {
00184     TopoDS_Shape aShape;
00185     if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
00186     {
00187       TColStd_IndexedMapOfInteger aMap;
00188       aSelMgr->GetIndexes(aSelList.First(), aMap);
00189       if (aMap.Extent() == 1) // Local Selection
00190       {
00191         GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
00192         int anIndex = aMap(1);
00193         aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
00194         aName += QString(":face_%1").arg(anIndex);
00195       }
00196       else // Global Selection
00197       {
00198         if (aShape.ShapeType() != TopAbs_FACE) {
00199           aSelectedObject = GEOM::GEOM_Object::_nil();
00200           aName = "";
00201         }
00202       }
00203     }
00204     myFace = aSelectedObject;
00205     myEditCurrentArgument->setText(aName);
00206 
00207     // clear selection
00208     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00209     myGeomGUI->getApp()->selectionMgr()->clearSelected();
00210     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00211             this, SLOT(SelectionIntoArgument()));
00212 
00213     if (!myFace->_is_nil() && myPoint->_is_nil())
00214       GroupArgs->PushButton2->click();
00215   }
00216   else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
00217     TopoDS_Shape aShape;
00218     if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
00219     {
00220       TColStd_IndexedMapOfInteger aMap;
00221       aSelMgr->GetIndexes(aSelList.First(), aMap);
00222       if (aMap.Extent() == 1) // Local Selection
00223       {
00224         GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
00225         int anIndex = aMap(1);
00226         aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
00227         aName += QString(":vertex_%1").arg(anIndex);
00228       }
00229       else // Global Selection
00230       {
00231         if (aShape.ShapeType() != TopAbs_VERTEX) {
00232           aSelectedObject = GEOM::GEOM_Object::_nil();
00233           aName = "";
00234         }
00235       }
00236     }
00237     myPoint = aSelectedObject;
00238     myEditCurrentArgument->setText(aName);
00239 
00240     // clear selection
00241     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00242     myGeomGUI->getApp()->selectionMgr()->clearSelected();
00243     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00244             this, SLOT(SelectionIntoArgument()));
00245 
00246     if (!myPoint->_is_nil() && myFace->_is_nil())
00247       GroupArgs->PushButton1->click();
00248   }
00249 
00250   DISPLAY_PREVIEW_MACRO
00251 }
00252 
00253 //=================================================================================
00254 // function : SetEditCurrentArgument()
00255 // purpose  :
00256 //=================================================================================
00257 void MeasureGUI_NormaleDlg::SetEditCurrentArgument()
00258 {
00259   QPushButton* send = (QPushButton*)sender();
00260 
00261   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00262   globalSelection(GEOM_FACE);
00263 
00264   if (send == GroupArgs->PushButton1) {
00265     myEditCurrentArgument = GroupArgs->LineEdit1;
00266 
00267     GroupArgs->PushButton2->setDown(false);
00268     GroupArgs->LineEdit2->setEnabled(false);
00269 
00270     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE);
00271   }
00272   else if (send == GroupArgs->PushButton2) {
00273     myEditCurrentArgument = GroupArgs->LineEdit2;
00274 
00275     GroupArgs->PushButton1->setDown(false);
00276     GroupArgs->LineEdit1->setEnabled(false);
00277 
00278     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
00279   }
00280   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00281           this, SLOT(SelectionIntoArgument()));
00282 
00283   // enable line edit
00284   myEditCurrentArgument->setEnabled(true);
00285   myEditCurrentArgument->setFocus();
00286   // after setFocus(), because it will be setDown(false) when loses focus
00287   send->setDown(true);
00288 
00289   // seems we need it only to avoid preview disappearing, caused by selection mode change
00290   DISPLAY_PREVIEW_MACRO
00291 }
00292 
00293 //=================================================================================
00294 // function : LineEditReturnPressed()
00295 // purpose  :
00296 //=================================================================================
00297 void MeasureGUI_NormaleDlg::LineEditReturnPressed()
00298 {
00299   QLineEdit* send = (QLineEdit*)sender();
00300   if (send == GroupArgs->LineEdit1 ||
00301       send == GroupArgs->LineEdit2) {
00302     myEditCurrentArgument = send;
00303     GEOMBase_Skeleton::LineEditReturnPressed();
00304   }
00305 }
00306 
00307 //=================================================================================
00308 // function : ActivateThisDialog()
00309 // purpose  :
00310 //=================================================================================
00311 void MeasureGUI_NormaleDlg::ActivateThisDialog()
00312 {
00313   GEOMBase_Skeleton::ActivateThisDialog();
00314   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00315            this, SLOT( SelectionIntoArgument() ) );
00316 
00317   DISPLAY_PREVIEW_MACRO
00318 }
00319 
00320 //=================================================================================
00321 // function : enterEvent()
00322 // purpose  :
00323 //=================================================================================
00324 void MeasureGUI_NormaleDlg::enterEvent (QEvent*)
00325 {
00326   if (!mainFrame()->GroupConstructors->isEnabled())
00327     ActivateThisDialog();
00328 }
00329 
00330 //=================================================================================
00331 // function : createOperation
00332 // purpose  :
00333 //=================================================================================
00334 GEOM::GEOM_IOperations_ptr MeasureGUI_NormaleDlg::createOperation()
00335 {
00336   return getGeomEngine()->GetIMeasureOperations(getStudyId());
00337 }
00338 
00339 //=================================================================================
00340 // function : isValid
00341 // purpose  :
00342 //=================================================================================
00343 bool MeasureGUI_NormaleDlg::isValid (QString&)
00344 {
00345   //return !CORBA::is_nil(myFace) && !CORBA::is_nil(myPoint);
00346   return !CORBA::is_nil(myFace);
00347 }
00348 
00349 //=================================================================================
00350 // function : execute
00351 // purpose  :
00352 //=================================================================================
00353 bool MeasureGUI_NormaleDlg::execute (ObjectList& objects)
00354 {
00355   GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
00356   GEOM::GEOM_Object_var anObj = anOper->GetNormal(myFace, myPoint);
00357 
00358   if (!anObj->_is_nil())
00359     objects.push_back(anObj._retn());
00360 
00361   return true;
00362 }