Salome HOME
080887f3001ff3fabab93a746ff8a22f368998a8
[modules/geom.git] / src / VTKPlugin / VTKPlugin_ExportDlg.cxx
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // internal includes
21 #include "VTKPlugin_ExportDlg.h"
22
23 #include <SALOMEconfig.h>
24 #include CORBA_SERVER_HEADER(VTKPlugin)
25
26 // GUI includes
27 #include <SUIT_Session.h>
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_ViewManager.h>
30
31 #include <SalomeApp_Application.h>
32 #include <SalomeApp_DoubleSpinBox.h>
33 #include <SalomeApp_Study.h>
34
35 // GEOM includes
36 #include "GEOM_Constants.h"
37
38 // QT includes
39 #include <QApplication>
40 #include <QLabel>
41 #include <QLayout>
42
43 //=================================================================================
44 // Constructor
45 //=================================================================================
46 VTKPlugin_ExportDlg::VTKPlugin_ExportDlg( const Handle(SALOME_InteractiveObject)& io, QWidget* parent )
47 : SUIT_FileDlg( parent, false, true, true )
48 {
49   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
50
51   QLabel* deflectionLabel = new QLabel( tr( "DEFLECTION" ), this );
52
53   myDeflectionSB = new SalomeApp_DoubleSpinBox( this );
54   int aPrecision = resMgr->integerValue( "Geometry", "parametric_precision", 6 );
55   myDeflectionSB->setAcceptNames( false );
56   myDeflectionSB->setPrecision( aPrecision );
57   myDeflectionSB->setDecimals( aPrecision );
58   myDeflectionSB->setRange( GEOM::minDeflection(), 1.0 );
59   myDeflectionSB->setSingleStep( 1.0e-04 );
60
61   layout()->addWidget( deflectionLabel );
62   layout()->addWidget( myDeflectionSB );
63
64   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
65   SalomeApp_Study* study = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
66   int mgrId = app->activeViewManager()->getGlobalId();
67   QVariant v = study->getObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
68   double deflection =  v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coeff", 0.001 );
69   myDeflectionSB->setValue( deflection );
70 }
71
72 //=================================================================================
73 // Destructor
74 //=================================================================================
75 VTKPlugin_ExportDlg::~VTKPlugin_ExportDlg()
76 {
77 }
78
79 //=================================================================================
80 // getDeflection
81 //=================================================================================
82 double VTKPlugin_ExportDlg::getDeflection() const
83 {
84   return myDeflectionSB->value();
85 }
86  
87 //=================================================================================
88 // getFileName
89 //=================================================================================
90 QString VTKPlugin_ExportDlg::getFileName( const Handle(SALOME_InteractiveObject)& io,
91                                           const QString& filters, const QString& caption,
92                                           QWidget* parent, double& deflection )
93 {
94   QStringList fls = filters.split( ";;", QString::SkipEmptyParts );
95
96   QString tmpfilename = io->getName();
97   tmpfilename = tmpfilename.simplified();
98   tmpfilename = tmpfilename.replace( QRegExp( "\\*" ), "" ).replace( QRegExp( "\\?" ), "" );
99
100   VTKPlugin_ExportDlg fd( io, parent );
101   fd.setFileMode( AnyFile );
102   fd.setNameFilters( fls );
103   fd.setWindowTitle( caption );
104   if ( !tmpfilename.isEmpty() )
105     fd.processPath( tmpfilename );
106
107   QString filename;
108
109   if ( fd.exec() == QDialog::Accepted ) {
110     filename = fd.selectedFile();
111     deflection = fd.getDeflection();
112   }
113
114   QApplication::processEvents();
115
116   return filename;
117 }
118