Back to index

salome-geom  6.5.0
EntityGUI_PictureImportDlg.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   : EntityGUI_PictureImportDlg.cxx
00025 // Author : Renaud NEDELEC, Open CASCADE S.A.S.
00026 //
00027 #include "EntityGUI_PictureImportDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 
00033 #include <SUIT_ResourceMgr.h>
00034 #include <SUIT_Session.h>
00035 #include <SalomeApp_Application.h>
00036 #include <LightApp_SelectionMgr.h>
00037 
00038 #include <TopoDS_Shape.hxx>
00039 #include <TopoDS.hxx>
00040 
00041 #include <GEOMImpl_Types.hxx>
00042 // #include <ShapeRec_FeatureDetector.hxx>
00043 
00044 #include <QFileDialog>
00045 
00046 //=================================================================================
00047 // class    : EntityGUI_PictureImportDlg()
00048 // purpose  : Constructs a EntityGUI_PictureImportDlg which is a child of 'parent', with the 
00049 //            name 'name' and widget flags set to 'f'.
00050 //            The dialog will by default be modeless, unless you set 'modal' to
00051 //            TRUE to construct a modal dialog.
00052 //=================================================================================
00053 EntityGUI_PictureImportDlg::EntityGUI_PictureImportDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
00054                                     bool modal, Qt::WindowFlags fl )
00055   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
00056 {
00057   QPixmap image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_IMPORT_PICTURE")));
00058   setWindowTitle( tr( "GEOM_IMPORT_PICT_TITLE" ) );
00059   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PICTURE" ) );
00060 
00061   mainFrame()->RadioButton1->setIcon(image0);
00062   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
00063   mainFrame()->RadioButton2->close();
00064   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00065   mainFrame()->RadioButton3->close();
00066 
00067   QGroupBox* GroupFileSel = new QGroupBox( centralWidget() );
00068   GroupFileSel->setTitle( tr( "GEOM_FILE" ) );
00069   QHBoxLayout* myFileSelGrpLayout = new QHBoxLayout(GroupFileSel );
00070   myPushButton = new QPushButton( GroupFileSel );
00071   myLineEdit = new QLineEdit( GroupFileSel );
00072   myPushButton->setText("...");
00073   
00074   myFileSelGrpLayout->addWidget( myLineEdit, 1);
00075   myFileSelGrpLayout->addWidget( myPushButton, 0);
00076   
00077   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00078   layout->setMargin( 0 ); layout->setSpacing( 6 );
00079   layout->addWidget( GroupFileSel );
00080 
00081   setHelpFileName( "import_picture_page.html" );
00082 
00083   Init();
00084 }
00085 
00086 
00087 //=================================================================================
00088 // function : ~EntityGUI_PictureImportDlg()
00089 // purpose  : Destroys the object and frees any allocated resources
00090 //=================================================================================
00091 EntityGUI_PictureImportDlg::~EntityGUI_PictureImportDlg()
00092 {  
00093 }
00094 
00095 
00096 //=================================================================================
00097 // function : Init()
00098 // purpose  :
00099 //=================================================================================
00100 void EntityGUI_PictureImportDlg::Init()
00101 {
00102   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00103   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00104   connect( myPushButton,   SIGNAL( clicked() ), this, SLOT( FileSelectionClicked() ) );
00105   
00106   resize(100,100);
00107   
00108   gp_Pnt aOrigin = gp_Pnt(0, 0, 0);
00109   gp_Dir aDirZ = gp_Dir(0, 0, 1);
00110   gp_Dir aDirX = gp_Dir(1, 0, 0);
00111   
00112   gp_Ax3 aGlobalCS = gp_Ax3(aOrigin, aDirZ, aDirX);
00113   
00114   myGeomGUI->SetWorkingPlane( aGlobalCS );
00115   myGeomGUI->ActiveWorkingPlane();
00116   
00117   initName( tr( "GEOM_PICTURE" ) );
00118 }
00119 
00120 // =================================================================================
00121 // function : FileSelectionClicked()
00122 // purpose  : 
00123 // =================================================================================
00124 void EntityGUI_PictureImportDlg::FileSelectionClicked()
00125 {
00126   QString selFile = QFileDialog::getOpenFileName(this,tr( "GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
00127   if ( ! selFile.isEmpty() )
00128     myLineEdit->setText(selFile);
00129 }
00130 
00131 //=================================================================================
00132 // function : ClickOnOk()
00133 // purpose  :
00134 //=================================================================================
00135 void EntityGUI_PictureImportDlg::ClickOnOk()
00136 {
00137   MESSAGE("EntityGUI_PictureImportDlg::ClickOnOk()")
00138   setIsApplyAndClose( true );
00139   if ( ClickOnApply() )
00140     ClickOnCancel();
00141 }
00142 
00143 //=================================================================================
00144 // function : ClickOnApply()
00145 // purpose  :
00146 //=================================================================================
00147 bool EntityGUI_PictureImportDlg::ClickOnApply()
00148 {
00149   MESSAGE("EntityGUI_PictureImportDlg::ClickOnApply()")
00150   if ( !onAccept() )
00151     return false;
00152   
00153   initName();
00154   myLineEdit->setText( "" );
00155 
00156   return true;
00157 }
00158 
00159 //=================================================================================
00160 // function : createOperation
00161 // purpose  :
00162 //=================================================================================
00163 GEOM::GEOM_IOperations_ptr EntityGUI_PictureImportDlg::createOperation()
00164 {
00165   return myGeomGUI->GetGeomGen()->GetIBlocksOperations( getStudyId() );
00166 }
00167 
00168 //=================================================================================
00169 // function : execute
00170 // purpose  :
00171 //=================================================================================
00172 bool EntityGUI_PictureImportDlg::execute( ObjectList& objects )
00173 {
00174   bool res = false;
00175   
00176   GEOM::GEOM_Object_var anObj;
00177   GEOM::GEOM_IBasicOperations_var aBasicOperations = myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
00178   GEOM::GEOM_IBlocksOperations_var aBlocksOperations = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() );
00179   QString theImgFileName = myLineEdit->text();
00180   if ( theImgFileName.isEmpty() )
00181     return res;
00182   
00183   QPixmap* pixmap = new QPixmap(theImgFileName); 
00184   int height            =  pixmap->height();
00185   int width             =  pixmap->width();
00186   
00187   GEOM::GEOM_Object_var P1 = aBasicOperations->MakePointXYZ( -0.5*width, -0.5*height, 0 );
00188   GEOM::GEOM_Object_var P2 = aBasicOperations->MakePointXYZ( -0.5*width,  0.5*height, 0 );
00189   GEOM::GEOM_Object_var P3 = aBasicOperations->MakePointXYZ(  0.5*width,  0.5*height, 0 );
00190   GEOM::GEOM_Object_var P4 = aBasicOperations->MakePointXYZ(  0.5*width, -0.5*height, 0 );
00191   
00192   GEOM::GEOM_Object_var aFace = aBlocksOperations->MakeQuad4Vertices(P1,P2,P3,P4);
00193   getDisplayer()->SetTexture(theImgFileName.toStdString());
00194   
00195   if ( !aFace->_is_nil() )
00196   {
00197     objects.push_back( aFace._retn() );
00198   }
00199   
00200   res=true;
00201  
00202 
00203   return res;
00204 }
00205