Back to index

salome-geom  6.5.0
TransformationGUI_MirrorDlg.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   : TransformationGUI_MirrorDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "TransformationGUI_MirrorDlg.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    : TransformationGUI_MirrorDlg()
00050 // purpose  : Constructs a TransformationGUI_MirrorDlg 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 TransformationGUI_MirrorDlg::TransformationGUI_MirrorDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
00056                                                           bool modal, Qt::WindowFlags fl)
00057   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
00058     myInitial(true)
00059 {
00060   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
00061   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MIRROR_POINT")));
00062   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MIRROR_AXE")));
00063   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MIRROR_PLANE")));
00064   QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
00065 
00066   setWindowTitle(tr("GEOM_MIRROR_TITLE"));
00067 
00068   /***************************************************************/
00069   mainFrame()->GroupConstructors->setTitle(tr("GEOM_MIRROR"));
00070   mainFrame()->RadioButton1->setIcon(image0);
00071   mainFrame()->RadioButton2->setIcon(image1);
00072   mainFrame()->RadioButton3->setIcon(image2);
00073 
00074   GroupPoints = new DlgRef_2Sel1Spin2Check(centralWidget());
00075   GroupPoints->SpinBox_DX->hide();
00076   GroupPoints->TextLabel3->hide();
00077   GroupPoints->CheckButton2->hide();
00078   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
00079   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
00080   GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
00081   GroupPoints->TextLabel2->setFixedWidth(74);
00082   GroupPoints->PushButton1->setIcon(image3);
00083   GroupPoints->PushButton2->setIcon(image3);
00084   GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
00085 
00086   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00087   layout->setMargin(0); layout->setSpacing(6);
00088   layout->addWidget(GroupPoints);
00089   /***************************************************************/
00090 
00091   setHelpFileName("mirror_operation_page.html");
00092 
00093   // Activate Create a Copy mode
00094   GroupPoints->CheckButton1->setChecked(true);
00095   CreateCopyModeChanged();
00096 
00097   Init();
00098 }
00099 
00100 //=================================================================================
00101 // function : ~TransformationGUI_MirrorDlg()
00102 // purpose  : Destroys the object and frees any allocated resources
00103 //=================================================================================
00104 TransformationGUI_MirrorDlg::~TransformationGUI_MirrorDlg()
00105 {
00106   // no need to delete child widgets, Qt does it all for us
00107 }
00108 
00109 //=================================================================================
00110 // function : Init()
00111 // purpose  :
00112 //=================================================================================
00113 void TransformationGUI_MirrorDlg::Init()
00114 {
00115   // init variables
00116   GroupPoints->LineEdit1->setReadOnly(true);
00117   GroupPoints->LineEdit2->setReadOnly(true);
00118 
00119   GroupPoints->LineEdit1->setText("");
00120   GroupPoints->LineEdit2->setText("");
00121 
00122   myObjects.clear();
00123   myArgument.nullify();
00124 
00125   mainFrame()->GroupBoxPublish->show();
00126 
00127   // signals and slots connections
00128   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00129   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00130 
00131   connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
00132 
00133   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00134   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00135 
00136   connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged()));
00137 
00138   initName(tr("GEOM_MIRROR"));
00139 
00140   ConstructorsClicked(0);
00141   resize(minimumSizeHint());
00142 }
00143 
00144 //=================================================================================
00145 // function : ConstructorsClicked()
00146 // purpose  : Radio button management
00147 //=================================================================================
00148 void TransformationGUI_MirrorDlg::ConstructorsClicked (int constructorId)
00149 {
00150   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00151 
00152   GroupPoints->LineEdit2->clear();
00153   myArgument.nullify();
00154 
00155   switch (constructorId) {
00156   case 0: // mirror an object by point
00157     GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
00158     break;
00159   case 1: // mirror an object by axe
00160     GroupPoints->TextLabel2->setText(tr("GEOM_AXE_MIRROR"));
00161     break;
00162   case 2: // mirror an object by plane
00163     GroupPoints->TextLabel2->setText(tr("GEOM_PLANE_MIRROR"));
00164     break;
00165   }
00166 
00167   GroupPoints->PushButton1->click();
00168 
00169   if (myInitial) {
00170     myInitial = false;
00171     SelectionIntoArgument();
00172   }
00173   else {
00174     processPreview();
00175   }
00176 }
00177 
00178 //=================================================================================
00179 // function : ClickOnOk()
00180 // purpose  :
00181 //=================================================================================
00182 void TransformationGUI_MirrorDlg::ClickOnOk()
00183 {
00184   setIsApplyAndClose( true );
00185   if (ClickOnApply())
00186     ClickOnCancel();
00187 }
00188 
00189 //=================================================================================
00190 // function : ClickOnApply()
00191 // purpose  :
00192 //=================================================================================
00193 bool TransformationGUI_MirrorDlg::ClickOnApply()
00194 {
00195   if (!onAccept(GroupPoints->CheckButton1->isChecked()))
00196     return false;
00197 
00198   initName();
00199 
00200   // activate selection and connect selection manager
00201   ConstructorsClicked(getConstructorId());
00202   SelectionIntoArgument();
00203 
00204   return true;
00205 }
00206 
00207 //=================================================================================
00208 // function : SelectionIntoArgument()
00209 // purpose  : Called when selection is changed or on dialog initialization or activation
00210 //=================================================================================
00211 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
00212 {
00213   erasePreview();
00214 
00215   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
00216     myObjects = getSelected( TopAbs_SHAPE, -1 );
00217     if ( !myObjects.isEmpty() ) {
00218       QString aName = myObjects.count() > 1 ? QString( "%1_objects").arg( myObjects.count() ) : GEOMBase::GetName( myObjects[0].get() );
00219       myEditCurrentArgument->setText( aName );
00220     }
00221     else {
00222       myEditCurrentArgument->setText("");
00223     }
00224   }
00225   else {
00226     TopAbs_ShapeEnum aNeedType = ( getConstructorId() == 1 ) ? 
00227       TopAbs_EDGE : ( ( getConstructorId() == 2 ) ? TopAbs_FACE : TopAbs_VERTEX );
00228     GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
00229     TopoDS_Shape aShape;
00230     if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
00231       QString aName = GEOMBase::GetName( aSelectedObject.get() );
00232       myEditCurrentArgument->setText( aName );
00233       myArgument = aSelectedObject;
00234       if ( myObjects.isEmpty() )
00235        GroupPoints->PushButton1->click();
00236     }
00237     else {
00238       if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
00239        myArgument.nullify();
00240       myEditCurrentArgument->setText("");
00241     }
00242   }
00243 
00244   processPreview();
00245 }
00246 
00247 //=================================================================================
00248 // function : SetEditCurrentArgument()
00249 // purpose  :
00250 //=================================================================================
00251 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
00252 {
00253   QPushButton* send = (QPushButton*)sender();
00254 
00255   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00256   globalSelection();
00257 
00258   if (send == GroupPoints->PushButton1) {
00259     myEditCurrentArgument = GroupPoints->LineEdit1;
00260 
00261     GroupPoints->PushButton2->setDown(false);
00262     GroupPoints->LineEdit2->setEnabled(false);
00263   }
00264   else if (send == GroupPoints->PushButton2) {
00265     myEditCurrentArgument = GroupPoints->LineEdit2;
00266 
00267     switch (getConstructorId()) {
00268     case 0:
00269       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
00270       break;
00271     case 1:
00272       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
00273       break;
00274     case 2:
00275       globalSelection(GEOM_PLANE);
00276       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE);
00277       break;
00278     }
00279 
00280     GroupPoints->PushButton1->setDown(false);
00281     GroupPoints->LineEdit1->setEnabled(false);
00282   }
00283   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00284           this, SLOT(SelectionIntoArgument()));
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   // seems we need it only to avoid preview disappearing, caused by selection mode change
00293   processPreview();
00294 }
00295 
00296 //=================================================================================
00297 // function : ActivateThisDialog()
00298 // purpose  :
00299 //=================================================================================
00300 void TransformationGUI_MirrorDlg::ActivateThisDialog()
00301 {
00302   GEOMBase_Skeleton::ActivateThisDialog();
00303   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00304            this, SLOT( SelectionIntoArgument() ) );
00305 
00306   ConstructorsClicked( getConstructorId() );
00307 }
00308 
00309 //=================================================================================
00310 // function : enterEvent()
00311 // purpose  : when mouse enter onto the QWidget
00312 //=================================================================================
00313 void TransformationGUI_MirrorDlg::enterEvent (QEvent*)
00314 {
00315   if (!mainFrame()->GroupConstructors->isEnabled())
00316     ActivateThisDialog();
00317 }
00318 
00319 //=================================================================================
00320 // function : createOperation
00321 // purpose  :
00322 //=================================================================================
00323 GEOM::GEOM_IOperations_ptr  TransformationGUI_MirrorDlg::createOperation()
00324 {
00325   return getGeomEngine()->GetITransformOperations(getStudyId());
00326 }
00327 
00328 //=================================================================================
00329 // function : isValid
00330 // purpose  :
00331 //=================================================================================
00332 bool TransformationGUI_MirrorDlg::isValid (QString& /*msg*/)
00333 {
00334   return !myObjects.isEmpty() && myArgument;
00335 }
00336 
00337 //=================================================================================
00338 // function : execute
00339 // purpose  :
00340 //=================================================================================
00341 bool  TransformationGUI_MirrorDlg::execute (ObjectList& objects)
00342 {
00343   bool res = false;
00344   bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
00345 
00346   GEOM::GEOM_Object_var anObj;
00347 
00348   GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
00349 
00350   switch (getConstructorId()) {
00351   case 0:
00352     {
00353       if (toCreateCopy) {
00354         for (int i = 0; i < myObjects.count(); i++) {
00355           anObj = anOper->MirrorPointCopy(myObjects[i].get(), myArgument.get());
00356           if (!anObj->_is_nil())
00357             objects.push_back(anObj._retn());
00358         }
00359       }
00360       else {
00361         for (int i = 0; i < myObjects.count(); i++) {
00362           anObj = anOper->MirrorPoint(myObjects[i].get(), myArgument.get());
00363           if (!anObj->_is_nil())
00364             objects.push_back(anObj._retn());
00365         }
00366       }
00367       res = true;
00368       break;
00369     }
00370   case 1:
00371     {
00372       if (toCreateCopy) {
00373         for (int i = 0; i < myObjects.count(); i++) {
00374           anObj = anOper->MirrorAxisCopy(myObjects[i].get(), myArgument.get());
00375           if (!anObj->_is_nil())
00376             objects.push_back(anObj._retn());
00377         }
00378       }
00379       else {
00380         for (int i = 0; i < myObjects.count(); i++) {
00381           anObj = anOper->MirrorAxis(myObjects[i].get(), myArgument.get());
00382           if (!anObj->_is_nil())
00383             objects.push_back(anObj._retn());
00384         }
00385       }
00386       res = true;
00387       break;
00388     }
00389   case 2:
00390     {
00391       if (toCreateCopy) {
00392         for (int i = 0; i < myObjects.count(); i++) {
00393             anObj = anOper->MirrorPlaneCopy(myObjects[i].get(), myArgument.get());
00394             if (!anObj->_is_nil())
00395               objects.push_back(anObj._retn());
00396         }
00397       }
00398       else {
00399         for (int i = 0; i < myObjects.count(); i++) {
00400           anObj = anOper->MirrorPlane(myObjects[i].get(), myArgument.get());
00401           if (!anObj->_is_nil())
00402             objects.push_back(anObj._retn());
00403         }
00404       }
00405       res = true;
00406       break;
00407     }
00408   }
00409 
00410   return res;
00411 }
00412 
00413 //=================================================================================
00414 // function : restoreSubShapes
00415 // purpose  :
00416 //=================================================================================
00417 void TransformationGUI_MirrorDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
00418                                                     SALOMEDS::SObject_ptr theSObject)
00419 {
00420   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
00421     // empty list of arguments means that all arguments should be restored
00422     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
00423                                         /*theFindMethod=*/GEOM::FSM_Transformed,
00424                                         /*theInheritFirstArg=*/true,
00425                                         mainFrame()->CheckBoxAddPrefix->isChecked());
00426   }
00427 }
00428 
00429 //=================================================================================
00430 // function :  CreateCopyModeChanged()
00431 // purpose  :
00432 //=================================================================================
00433 void TransformationGUI_MirrorDlg::CreateCopyModeChanged()
00434 {
00435   mainFrame()->GroupBoxName->setEnabled(GroupPoints->CheckButton1->isChecked());
00436 }
00437 
00438 //=================================================================================
00439 // function : addSubshapeToStudy
00440 // purpose  : virtual method to add new SubObjects if local selection
00441 //=================================================================================
00442 void TransformationGUI_MirrorDlg::addSubshapesToStudy()
00443 {
00444   bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
00445   if (toCreateCopy) {
00446     switch (getConstructorId()) {
00447     case 0:
00448     case 1:
00449     case 2:
00450       GEOMBase::PublishSubObject( myArgument.get() );
00451       break;
00452     default:
00453       break;
00454     }
00455   }
00456 }