Salome HOME
Merge remote-tracking branch 'origin/master' into gni/documentation
[modules/shaper.git] / src / ExchangePlugin / ExchangePlugin_ImportFeature.h
1 // Copyright (C) 2014-2020  CEA/DEN, EDF R&D
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 #ifndef EXCHANGEPLUGIN_IMPORTFEATURE_H_
21 #define EXCHANGEPLUGIN_IMPORTFEATURE_H_
22
23 #include "ExchangePlugin.h"
24
25 #include <ModelAPI_CompositeFeature.h>
26 #include <ModelAPI_Result.h>
27 #include <GeomAPI_Shape.h>
28
29 #include <map>
30
31 /**
32  * \class ExchangePlugin_ImportFeature
33  * \ingroup Plugins
34  * \brief Feature for import shapes from the external files in CAD formats.
35  *
36  * The list of supported formats is defined in the configuration file.
37  */
38 class ExchangePlugin_ImportFeature : public ModelAPI_CompositeFeature
39 {
40  public:
41   /// Feature kind
42   inline static const std::string& ID()
43   {
44     static const std::string MY_IMPORT_ID("Import");
45     return MY_IMPORT_ID;
46   }
47   /// Feature kind
48   inline static const std::string& IMPORT_TYPE_ID()
49   {
50     static const std::string MY_IMPORT_TYPE_ID("ImportType");
51     return MY_IMPORT_TYPE_ID;
52   }
53   /// attribute name of file path
54   inline static const std::string& FILE_PATH_ID()
55   {
56     static const std::string MY_FILE_PATH_ID("file_path");
57     return MY_FILE_PATH_ID;
58   }
59   /// attribute name of file path
60   inline static const std::string& STEP_FILE_PATH_ID()
61   {
62     static const std::string MY_STEP_FILE_PATH_ID("step_file_path");
63     return MY_STEP_FILE_PATH_ID;
64   }
65   /// All features (list of references)
66   inline static const std::string& FEATURES_ID()
67   {
68     static const std::string MY_FEATURES_ID("Features");
69     return MY_FEATURES_ID;
70   }
71   /// attribute name of step Scale to International System Units
72   inline static const std::string& STEP_SCALE_INTER_UNITS_ID()
73   {
74     static const std::string MY_STEP_SCALE_INTER_UNITS_ID("step_scale_inter_units");
75     return MY_STEP_SCALE_INTER_UNITS_ID;
76   }
77   /// attribute name of step materiels
78   inline static const std::string& STEP_MATERIALS_ID()
79   {
80     static const std::string MY_STEP_MATERIALS_ID("step_materials");
81     return MY_STEP_MATERIALS_ID;
82   }
83   /// attribute name of step colors
84   inline static const std::string& STEP_COLORS_ID()
85   {
86     static const std::string MY_STEP_COLORS_ID("step_colors");
87     return MY_STEP_COLORS_ID;
88   }
89   /// Default constructor
90   EXCHANGEPLUGIN_EXPORT ExchangePlugin_ImportFeature();
91   /// Default destructor
92   EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_ImportFeature();
93
94   /// Returns the unique kind of a feature
95   EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind()
96   {
97     return ExchangePlugin_ImportFeature::ID();
98   }
99
100   /// Request for initialization of data model of the feature: adding all attributes
101   EXCHANGEPLUGIN_EXPORT virtual void initAttributes();
102
103   /// Computes or recomputes the results
104   EXCHANGEPLUGIN_EXPORT virtual void execute();
105
106   /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
107   EXCHANGEPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
108
109   /// Reimplemented from ModelAPI_CompositeFeature::addFeature()
110   virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
111
112   /// Reimplemented from ModelAPI_CompositeFeature::numberOfSubs()
113   virtual int numberOfSubs(bool forTree = false) const;
114
115   /// Reimplemented from ModelAPI_CompositeFeature::subFeature()
116   virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false);
117
118   /// Reimplemented from ModelAPI_CompositeFeature::subFeatureId()
119   virtual int subFeatureId(const int theIndex) const;
120
121   /// Reimplemented from ModelAPI_CompositeFeature::isSub()
122   virtual bool isSub(ObjectPtr theObject) const;
123
124   /// Reimplemented from ModelAPI_CompositeFeature::removeFeature()
125   virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
126
127  protected:
128   /// Performs the import of the file
129   EXCHANGEPLUGIN_EXPORT void importFile(const std::string& theFileName);
130
131   /// Performs the import of XAO file
132   EXCHANGEPLUGIN_EXPORT void importXAO(const std::string& theFileName);
133
134   /// Creates and prepares a result body from the shape
135   std::shared_ptr<ModelAPI_ResultBody> createResultBody(
136       std::shared_ptr<GeomAPI_Shape> aGeomShape);
137
138 private:
139   /// Loads Naming data structure to the document
140   void loadNamingDS(std::shared_ptr<GeomAPI_Shape> theGeomShape,
141                     std::shared_ptr<ModelAPI_ResultBody> theResultBody);
142   /// Set groups of color
143   void setColorGroups(std::shared_ptr<ModelAPI_ResultBody> theResultBody);
144
145   /// set a group of color
146   void setColorGroup(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
147                      std::vector<int>& theColor,
148                      const std::wstring& theName );
149
150   /// set Materiel group of color
151   void setMaterielGroup(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
152                         std::map< std::wstring, std::list<std::wstring>>& theMaterialShape);
153
154 };
155
156 #endif /* IMPORT_IMPORTFEATURE_H_ */