1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "STLPlugin_ExportDlg.h"
24 #include <SUIT_Session.h>
25 #include <SUIT_ResourceMgr.h>
26 #include <SUIT_ViewManager.h>
28 #include <SalomeApp_Application.h>
29 #include <SalomeApp_DoubleSpinBox.h>
30 #include <SalomeApp_Study.h>
34 #include "GEOM_Constants.h"
37 #include <BRepBndLib.hxx>
40 #include <QApplication>
46 //=================================================================================
48 //=================================================================================
49 STLPlugin_ExportDlg::STLPlugin_ExportDlg( const Handle(SALOME_InteractiveObject)& io, QWidget* parent )
50 : SUIT_FileDlg( parent, false, true, true )
52 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
54 QLabel* deflectionLabel = new QLabel( tr( "DEFLECTION" ), this );
56 QWidget* options = new QWidget( this );
57 QHBoxLayout* optionsLayout = new QHBoxLayout( options );
58 optionsLayout->setMargin( 0 );
59 optionsLayout->setSpacing( 5 );
61 myDeflectionSB = new SalomeApp_DoubleSpinBox( options );
62 int aPrecision = resMgr->integerValue( "Geometry", "parametric_precision", 6 );
63 myDeflectionSB->setAcceptNames( false );
64 myDeflectionSB->setPrecision( aPrecision );
65 myDeflectionSB->setDecimals( aPrecision );
66 myDeflectionSB->setRange( GEOM::minDeflection(), 1.0 );
67 myDeflectionSB->setSingleStep( 1.0e-04 );
69 myModeCB = new QCheckBox( tr( "RELATIVE" ), options );
71 myFormatCB = new QCheckBox( tr( "ASCII" ) );
73 optionsLayout->addWidget( myDeflectionSB );
74 optionsLayout->addWidget( myModeCB );
75 optionsLayout->addWidget( myFormatCB );
77 layout()->addWidget( deflectionLabel );
78 layout()->addWidget( options );
80 myShapeSize = getShapeSize( io );
82 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
83 SalomeApp_Study* study = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
84 int mgrId = app->activeViewManager()->getGlobalId();
85 QVariant v = study->getObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
86 double deflection = v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coef", 0.001 );
88 myDeflectionSB->setValue( deflection );
89 myModeCB->setChecked( true );
90 myFormatCB->setChecked( true );
92 connect( myModeCB, SIGNAL( clicked ( bool ) ), this, SLOT( modeChanged() ) );
95 //=================================================================================
97 //=================================================================================
98 STLPlugin_ExportDlg::~STLPlugin_ExportDlg()
102 //=================================================================================
104 //=================================================================================
105 void STLPlugin_ExportDlg::modeChanged()
107 if ( myModeCB->isChecked() ) {
108 double deflection = myDeflectionSB->value() / myShapeSize;
109 deflection = ( deflection > 1.0 ) ? 1.0 : deflection;
110 myDeflectionSB->setRange( GEOM::minDeflection(), 1.0 );
111 myDeflectionSB->setValue( deflection );
114 double deflection = myDeflectionSB->value() * myShapeSize;
115 myDeflectionSB->setRange( GEOM::minDeflection(), 10000.0 );
116 myDeflectionSB->setValue( deflection );
120 //=================================================================================
122 //=================================================================================
123 double STLPlugin_ExportDlg::getShapeSize( const Handle(SALOME_InteractiveObject)& io )
126 GEOM::GEOM_Object_var obj = GEOMBase::ConvertIOinGEOMObject( io );
127 GEOMBase::GetShape( obj, shape, TopAbs_SHAPE );
128 Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
130 BRepBndLib::Add( shape, bnd );
131 bnd.Get( xmin, ymin, zmin, xmax, ymax, zmax );
132 double xd = fabs( xmax-xmin );
133 double yd = fabs( ymax-ymin );
134 double zd = fabs( zmax-zmin );
135 return std::max( std::max ( xd, yd ), zd );
138 //=================================================================================
140 //=================================================================================
141 bool STLPlugin_ExportDlg::isAscii() const
143 return myFormatCB->isChecked();
146 //=================================================================================
148 //=================================================================================
149 double STLPlugin_ExportDlg::getDeflection() const
151 return myDeflectionSB->value();
154 //=================================================================================
155 // isDeflectionRelative
156 //=================================================================================
157 bool STLPlugin_ExportDlg::isDeflectionRelative() const
159 return myModeCB->isChecked();
162 //=================================================================================
164 //=================================================================================
165 QString STLPlugin_ExportDlg::getFileName( const Handle(SALOME_InteractiveObject)& io,
166 const QString& filters, const QString& caption,
167 QWidget* parent, bool& isAscii,
168 double& deflection, bool& isRelative )
170 QStringList fls = filters.split( ";;", QString::SkipEmptyParts );
172 QString tmpfilename = io->getName();
173 tmpfilename = tmpfilename.simplified();
174 tmpfilename = tmpfilename.replace( QRegExp( "\\*" ), "" ).replace( QRegExp( "\\?" ), "" );
176 STLPlugin_ExportDlg fd( io, parent );
177 fd.setFileMode( AnyFile );
178 fd.setNameFilters( fls );
179 fd.setWindowTitle( caption );
180 if ( !tmpfilename.isEmpty() )
181 fd.processPath( tmpfilename );
185 if ( fd.exec() == QDialog::Accepted ) {
186 filename = fd.selectedFile();
187 isAscii = fd.isAscii();
188 deflection = fd.getDeflection();
189 isRelative = fd.isDeflectionRelative();
192 QApplication::processEvents();