]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetFileSelector.cpp
Salome HOME
#1371 Using auxilliary Sketch elements in any Feature: code improvement to separate...
[modules/shaper.git] / src / PartSet / PartSet_WidgetFileSelector.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * PartSet_WidgetFileSelector.cpp
5  *
6  *  Created on: May 18, 2015
7  *      Author: spo
8  */
9
10 #include "PartSet_WidgetFileSelector.h"
11
12 #include <ModelAPI_AttributeString.h>
13
14 #include <ExchangePlugin_ExportFeature.h>
15
16 PartSet_WidgetFileSelector::PartSet_WidgetFileSelector(QWidget* theParent,
17                                                        ModuleBase_IWorkshop* theWorkshop,
18                                                        const Config_WidgetAPI* theData)
19 : ModuleBase_WidgetFileSelector(theParent, theData),
20   myWorkshop(theWorkshop)
21 {
22 }
23
24 bool PartSet_WidgetFileSelector::restoreValueCustom()
25 {
26   // A rare case when plugin was not loaded.
27   if (!myFeature)
28     return false;
29
30   DataPtr aData = myFeature->data();
31   AttributeStringPtr aStringAttr = aData->string(ExchangePlugin_ExportFeature::FILE_PATH_ID());
32   mySelectedFilter = formatToFilter(shortFormatToFullFormat(QString::fromStdString(aStringAttr->value())));
33
34   return ModuleBase_WidgetFileSelector::restoreValueCustom();
35 }
36
37 bool PartSet_WidgetFileSelector::storeValueCustom() const
38 {
39   // A rare case when plugin was not loaded.
40   if (!myFeature)
41     return false;
42
43   DataPtr aData = myFeature->data();
44   AttributeStringPtr aStringAttr = aData->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID());
45   aStringAttr->setValue(filterToShortFormat(mySelectedFilter).toStdString());
46
47   return ModuleBase_WidgetFileSelector::storeValueCustom();
48 }
49
50 QString PartSet_WidgetFileSelector::shortFormatToFullFormat( const QString & theFormat ) const
51 {
52   foreach(const QString & eachFormat, getValidatorFormats())
53     if (filterToShortFormat(formatToFilter(eachFormat)) == theFormat)
54       return eachFormat;
55   return QString();
56 }