Back to index

salome-geom  6.5.0
TransformationGUI_ProjectionDlg.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 // File   : TransformationGUI_ProjectionDlg.cxx
00024 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00025 
00026 #include "TransformationGUI.h"
00027 #include "TransformationGUI_ProjectionDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 #include <GEOMImpl_Types.hxx>
00033 
00034 #include <SUIT_Session.h>
00035 #include <SUIT_ResourceMgr.h>
00036 #include <SalomeApp_Application.h>
00037 #include <LightApp_SelectionMgr.h>
00038 
00039 #include <TColStd_MapOfInteger.hxx>
00040 
00041 //=================================================================================
00042 // class    : TransformationGUI_ProjectionDlg()
00043 // purpose  : Constructs a TransformationGUI_ProjectionDlg 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 TransformationGUI_ProjectionDlg::TransformationGUI_ProjectionDlg (GeometryGUI* theGeometryGUI,
00049                                       QWidget* parent, bool modal, Qt::WindowFlags fl)
00050   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
00051 {
00052   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PROJECTION")));
00053   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
00054 
00055   setWindowTitle(tr("GEOM_PROJECTION_TITLE"));
00056 
00057   mainFrame()->GroupConstructors->setTitle(tr("GEOM_PROJECTION"));
00058   mainFrame()->RadioButton1->setIcon(image0);
00059   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
00060   mainFrame()->RadioButton2->close();
00061   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00062   mainFrame()->RadioButton3->close();
00063 
00064   myGroup = new DlgRef_2Sel (centralWidget());
00065 
00066   myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
00067   myGroup->TextLabel1->setText(tr("GEOM_SOURCE_OBJECT"));
00068   myGroup->TextLabel2->setText(tr("GEOM_TARGET_OBJECT"));
00069   myGroup->PushButton1->setIcon(image1);
00070   myGroup->PushButton2->setIcon(image1);
00071   myGroup->LineEdit1->setReadOnly(true);
00072   myGroup->LineEdit2->setReadOnly(true);
00073 
00074   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00075   layout->setMargin(0); layout->setSpacing(6);
00076   layout->addWidget(myGroup);
00077 
00078   setHelpFileName("projection_operation_page.html");
00079 
00080   // Initialisation
00081   Init();
00082 }
00083 
00084 //=================================================================================
00085 // function : ~TransformationGUI_ProjectionDlg()
00086 // purpose  : Destroys the object and frees any allocated resources
00087 //=================================================================================
00088 TransformationGUI_ProjectionDlg::~TransformationGUI_ProjectionDlg()
00089 {
00090 }
00091 
00092 //=================================================================================
00093 // function : Init()
00094 // purpose  :
00095 //=================================================================================
00096 void TransformationGUI_ProjectionDlg::Init()
00097 {
00098   mainFrame()->GroupBoxPublish->show();
00099 
00100   // init variables
00101   myEditCurrentArgument = myGroup->LineEdit1;
00102 
00103   myGroup->LineEdit1->setText("");
00104   myGroup->LineEdit2->setText("");
00105   myObject1.nullify();
00106   myObject2.nullify();
00107 
00108   showOnlyPreviewControl();
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(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00115   connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00116 
00117   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
00118            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00119 
00120   initName(mainFrame()->GroupConstructors->title());
00121 
00122   setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
00123   setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
00124   setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
00125 
00126   mainFrame()->RadioButton1->setFocus();
00127 
00128   globalSelection(GEOM_ALLSHAPES);
00129 
00130   myGroup->PushButton1->click();
00131   SelectionIntoArgument();
00132   resize(100,100);
00133 }
00134 
00135 //=================================================================================
00136 // function : ClickOnOk()
00137 // purpose  :
00138 //=================================================================================
00139 void TransformationGUI_ProjectionDlg::ClickOnOk()
00140 {
00141   setIsApplyAndClose(true);
00142   if (ClickOnApply())
00143     ClickOnCancel();
00144 }
00145 
00146 //=================================================================================
00147 // function : ClickOnApply()
00148 // purpose  :
00149 //=================================================================================
00150 bool TransformationGUI_ProjectionDlg::ClickOnApply()
00151 {
00152   if (!onAccept())
00153     return false;
00154 
00155   initName();
00156   // activate selection and connect selection manager
00157   myGroup->PushButton1->click();
00158   return true;
00159 }
00160 
00161 //=================================================================================
00162 // function : SelectionIntoArgument()
00163 // purpose  : Called when selection is changed or on dialog initialization or activation
00164 //=================================================================================
00165 void TransformationGUI_ProjectionDlg::SelectionIntoArgument()
00166 {
00167   myEditCurrentArgument->setText("");
00168 
00169   GEOM::GeomObjPtr aSelectedObject = getSelected(TopAbs_SHAPE);
00170   TopoDS_Shape aShape;
00171   if (aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) && !aShape.IsNull()) {
00172     QString aName = GEOMBase::GetName(aSelectedObject.get());
00173     myEditCurrentArgument->setText(aName);
00174 
00175     // clear selection
00176     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00177     myGeomGUI->getApp()->selectionMgr()->clearSelected();
00178     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00179             this, SLOT(SelectionIntoArgument()));
00180 
00181     if (myEditCurrentArgument == myGroup->LineEdit1) {
00182       myObject1 = aSelectedObject;
00183       if (!myObject2)
00184         myGroup->PushButton2->click();
00185     }
00186     else if (myEditCurrentArgument == myGroup->LineEdit2) {
00187       myObject2 = aSelectedObject;
00188       if (!myObject1)
00189         myGroup->PushButton1->click();
00190     }
00191   }
00192   else {
00193     if      (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
00194     else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify();
00195   }
00196 }
00197 
00198 //=================================================================================
00199 // function : SetEditCurrentArgument()
00200 // purpose  :
00201 //=================================================================================
00202 void TransformationGUI_ProjectionDlg::SetEditCurrentArgument()
00203 {
00204   QPushButton* send = (QPushButton*)sender();
00205 
00206   if (send == myGroup->PushButton1) {
00207     myEditCurrentArgument = myGroup->LineEdit1;
00208 
00209     myGroup->PushButton2->setDown(false);
00210     myGroup->LineEdit2->setEnabled(false);
00211 
00212     TColStd_MapOfInteger aMap;
00213     aMap.Add( GEOM_POINT );
00214     aMap.Add( GEOM_EDGE );
00215     aMap.Add( GEOM_WIRE );
00216     globalSelection( aMap );
00217   }
00218   else if (send == myGroup->PushButton2) {
00219     myEditCurrentArgument = myGroup->LineEdit2;
00220 
00221     myGroup->PushButton1->setDown(false);
00222     myGroup->LineEdit1->setEnabled(false);
00223 
00224     globalSelection( GEOM_FACE );
00225   }
00226 
00227   // enable line edit
00228   myEditCurrentArgument->setEnabled(true);
00229   myEditCurrentArgument->setFocus();
00230   // after setFocus(), because it will be setDown(false) when loses focus
00231   send->setDown(true);
00232 }
00233 
00234 //=================================================================================
00235 // function : ActivateThisDialog()
00236 // purpose  :
00237 //=================================================================================
00238 void TransformationGUI_ProjectionDlg::ActivateThisDialog()
00239 {
00240   GEOMBase_Skeleton::ActivateThisDialog();
00241 
00242   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00243           this, SLOT(SelectionIntoArgument()));
00244   processPreview();
00245 }
00246 
00247 //=================================================================================
00248 // function : enterEvent()
00249 // purpose  : when mouse enter onto the QWidget
00250 //=================================================================================
00251 void TransformationGUI_ProjectionDlg::enterEvent (QEvent*)
00252 {
00253   if (!mainFrame()->GroupConstructors->isEnabled())
00254     ActivateThisDialog();
00255 }
00256 
00257 //=================================================================================
00258 // function : createOperation
00259 // purpose  :
00260 //=================================================================================
00261 GEOM::GEOM_IOperations_ptr TransformationGUI_ProjectionDlg::createOperation()
00262 {
00263   return getGeomEngine()->GetITransformOperations(getStudyId());
00264 }
00265 
00266 //=================================================================================
00267 // function : isValid
00268 // purpose  :
00269 //=================================================================================
00270 bool TransformationGUI_ProjectionDlg::isValid (QString&)
00271 {
00272   return myObject1 && myObject2;
00273 }
00274 
00275 //=================================================================================
00276 // function : execute
00277 // purpose  :
00278 //=================================================================================
00279 bool TransformationGUI_ProjectionDlg::execute (ObjectList& objects)
00280 {
00281   GEOM::GEOM_Object_var anObj;
00282 
00283   GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
00284   anObj = anOper->ProjectShapeCopy(myObject1.get(), myObject2.get());
00285   if (!anObj->_is_nil())
00286     objects.push_back(anObj._retn());
00287 
00288   return true;
00289 }