Salome HOME
844c37ed70e687fbdd09ca560d51c6f21e8a9f7c
[modules/geom.git] / src / STEPPlugin / STEPPlugin_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 #include "STEPPlugin_ExportDlg.h"
21
22 #include <QApplication>
23 #include <QLabel>
24 #include <QLayout>
25 #include <QComboBox>
26
27 //=============================================================================
28 // Constructor
29 //=============================================================================
30 STEPPlugin_ExportDlg::STEPPlugin_ExportDlg(QWidget *parent)
31   : SUIT_FileDlg (parent, false, true, true),
32     myUnitCB     (0)
33 {
34   QLabel* aUnitLabel = new QLabel(tr("STEP_LENGTH_UNITS"), this);
35
36   myUnitCB = new QComboBox(this);
37   myUnitCB->addItem(tr("STEP_UNITS_KILOMETER"),  GEOM::LU_KILOMETER);
38   myUnitCB->addItem(tr("STEP_UNITS_METER"),      GEOM::LU_METER);
39   myUnitCB->addItem(tr("STEP_UNITS_CENTIMETER"), GEOM::LU_CENTIMETER);
40   myUnitCB->addItem(tr("STEP_UNITS_MILLIMETER"), GEOM::LU_MILLIMETER);
41   myUnitCB->addItem(tr("STEP_UNITS_MICROMETER"), GEOM::LU_MICROMETER);
42   myUnitCB->addItem(tr("STEP_UNITS_MILE"),       GEOM::LU_MILE);
43   myUnitCB->addItem(tr("STEP_UNITS_FOOT"),       GEOM::LU_FOOT);
44   myUnitCB->addItem(tr("STEP_UNITS_INCH"),       GEOM::LU_INCH);
45   myUnitCB->addItem(tr("STEP_UNITS_MILLIINCH"),  GEOM::LU_MILLIINCH);
46   myUnitCB->addItem(tr("STEP_UNITS_MICROINCH"),  GEOM::LU_MICROINCH);
47
48   // Meters by default.
49   myUnitCB->setCurrentIndex(1);
50
51   layout()->addWidget(aUnitLabel);
52   layout()->addWidget(myUnitCB);
53 }
54
55 //=============================================================================
56 // Destructor
57 //=============================================================================
58 STEPPlugin_ExportDlg::~STEPPlugin_ExportDlg()
59 {
60 }
61
62 //=============================================================================
63 // getUnits
64 //=============================================================================
65 GEOM::length_unit STEPPlugin_ExportDlg::getUnits() const
66 {
67   const GEOM::length_unit anUnit =
68     (GEOM::length_unit) myUnitCB->itemData(myUnitCB->currentIndex()).toInt();
69
70   return anUnit;
71 }
72
73 //=============================================================================
74 // getFileName
75 //=============================================================================
76 QString STEPPlugin_ExportDlg::getFileName(const QString           &theInitial,
77                                           const QString           &theFilters,
78                                                       const QString           &theCaption,
79                                                 QWidget           *theParent,
80                                                 GEOM::length_unit &theUnits)
81 {
82   QStringList aFls         = theFilters.split(";;", QString::SkipEmptyParts);
83   QString     aTmpFileName = theInitial;
84
85   aTmpFileName = aTmpFileName.simplified();
86   aTmpFileName =
87     aTmpFileName.replace(QRegExp("\\*"), "").replace(QRegExp("\\?"), "");
88
89   STEPPlugin_ExportDlg aDlg(theParent);
90
91   aDlg.setFileMode(AnyFile);
92   aDlg.setNameFilters(aFls);
93   aDlg.setWindowTitle(theCaption);
94
95   if (!aTmpFileName.isEmpty()) {
96     aDlg.processPath(aTmpFileName);
97   }
98
99   QString aFileName;
100
101   if (aDlg.exec() == QDialog::Accepted) {
102     aFileName = aDlg.selectedFile();
103     theUnits  = aDlg.getUnits();
104   }
105
106   QApplication::processEvents();
107
108   return aFileName;
109 }