Salome HOME
updated copyright message
[modules/shaper.git] / src / ExchangePlugin / ExchangePlugin_ImportFeature.h
1 // Copyright (C) 2014-2023  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_ImportFeatureBase : public ModelAPI_CompositeFeature
39 {
40 public:
41   /// attribute name of file path
42   inline static const std::string& FILE_PATH_ID()
43   {
44     static const std::string MY_FILE_PATH_ID("file_path");
45     return MY_FILE_PATH_ID;
46   }
47   /// All features (list of references)
48   inline static const std::string& FEATURES_ID()
49   {
50     static const std::string MY_FEATURES_ID("Features");
51     return MY_FEATURES_ID;
52   }
53   /// attribute name of target part
54   inline static const std::string& TARGET_PART_ID()
55   {
56     static const std::string MY_TARGET_PART_ID("target_part");
57     return MY_TARGET_PART_ID;
58   }
59   /// Default constructor
60   EXCHANGEPLUGIN_EXPORT ExchangePlugin_ImportFeatureBase() = default;
61   /// Default destructor
62   EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_ImportFeatureBase() = default;
63
64   /// Returns the unique kind of a feature
65   EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind() = 0;
66
67   /// Request for initialization of data model of the feature: adding all attributes
68   EXCHANGEPLUGIN_EXPORT virtual void initAttributes();
69
70   /// Computes or recomputes the results
71   EXCHANGEPLUGIN_EXPORT virtual void execute() = 0;
72
73   /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
74   EXCHANGEPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
75
76   /// Reimplemented from ModelAPI_CompositeFeature::addFeature()
77   virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
78
79   /// Reimplemented from ModelAPI_CompositeFeature::numberOfSubs()
80   virtual int numberOfSubs(bool forTree = false) const;
81
82   /// Reimplemented from ModelAPI_CompositeFeature::subFeature()
83   virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false);
84
85   /// Reimplemented from ModelAPI_CompositeFeature::subFeatureId()
86   virtual int subFeatureId(const int theIndex) const;
87
88   /// Reimplemented from ModelAPI_CompositeFeature::isSub()
89   virtual bool isSub(ObjectPtr theObject) const;
90
91   /// Reimplemented from ModelAPI_CompositeFeature::removeFeature()
92   virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
93
94  protected:
95   /// Performs the import of the file
96   EXCHANGEPLUGIN_EXPORT virtual void importFile(const std::string& theFileName) = 0;
97
98   /// Creates and prepares a result body from the shape
99   std::shared_ptr<ModelAPI_ResultBody> createResultBody(
100       std::shared_ptr<GeomAPI_Shape> aGeomShape);
101
102   /// Loads Naming data structure to the document
103   void loadNamingDS(std::shared_ptr<GeomAPI_Shape> theGeomShape,
104                     std::shared_ptr<ModelAPI_ResultBody> theResultBody);
105 };
106
107 class ExchangePlugin_ImportFeature : public ExchangePlugin_ImportFeatureBase
108 {
109 public:
110   /// Feature kind
111   inline static const std::string& ID()
112   {
113     static const std::string MY_IMPORT_ID("Import");
114     return MY_IMPORT_ID;
115   }
116   /// Feature kind
117   inline static const std::string& IMPORT_TYPE_ID()
118   {
119     static const std::string MY_IMPORT_TYPE_ID("ImportType");
120     return MY_IMPORT_TYPE_ID;
121   }
122   /// attribute name of file path
123   inline static const std::string& STEP_FILE_PATH_ID()
124   {
125     static const std::string MY_STEP_FILE_PATH_ID("step_file_path");
126     return MY_STEP_FILE_PATH_ID;
127   }
128
129   /// Default constructor
130   EXCHANGEPLUGIN_EXPORT ExchangePlugin_ImportFeature() = default;
131   /// Default destructor
132   EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_ImportFeature() = default;
133
134   /// attribute name of step Scale to International System Units
135   inline static const std::string& STEP_SCALE_INTER_UNITS_ID()
136   {
137     static const std::string MY_STEP_SCALE_INTER_UNITS_ID("step_scale_inter_units");
138     return MY_STEP_SCALE_INTER_UNITS_ID;
139   }
140   /// attribute name of step materiels
141   inline static const std::string& STEP_MATERIALS_ID()
142   {
143     static const std::string MY_STEP_MATERIALS_ID("step_materials");
144     return MY_STEP_MATERIALS_ID;
145   }
146   /// attribute name of step colors
147   inline static const std::string& STEP_COLORS_ID()
148   {
149     static const std::string MY_STEP_COLORS_ID("step_colors");
150     return MY_STEP_COLORS_ID;
151   }
152   /// Returns the unique kind of a feature
153   EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind() override
154   {
155     return ExchangePlugin_ImportFeature::ID();
156   }
157
158   /// Computes or recomputes the results
159   EXCHANGEPLUGIN_EXPORT virtual void execute() override;
160
161   /// Request for initialization of data model of the feature: adding all attributes
162   EXCHANGEPLUGIN_EXPORT virtual void initAttributes();
163
164 protected:
165   /// Performs the import of the file
166   EXCHANGEPLUGIN_EXPORT void importFile(const std::string& theFileName) override;
167
168   /// Performs the import of XAO file
169   EXCHANGEPLUGIN_EXPORT void importXAO(const std::string& theFileName);
170
171 private:
172   /// Set groups of color
173   void setColorGroups(std::shared_ptr<ModelAPI_ResultBody> theResultBody);
174
175   /// set a group of color
176   void setColorGroup(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
177                      std::vector<int>& theColor,
178                      const std::wstring& theName );
179
180   /// set Materiel group of color
181   void setMaterielGroup(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
182                         std::map< std::wstring, std::list<std::wstring>>& theMaterialShape);
183
184 };
185
186 class ExchangePlugin_Import_ImageFeature : public ExchangePlugin_ImportFeatureBase
187 {
188  public:
189   /// Feature kind
190   inline static const std::string& ID()
191   {
192     static const std::string MY_IMPORT_ID("ImportImage");
193     return MY_IMPORT_ID;
194   }
195
196   /// Default constructor
197   EXCHANGEPLUGIN_EXPORT ExchangePlugin_Import_ImageFeature() = default;
198   /// Default destructor
199   EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_Import_ImageFeature() = default;
200
201   /// Returns the unique kind of a feature
202   EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind() override
203   {
204     return ExchangePlugin_Import_ImageFeature::ID();
205   }
206
207    /// Computes or recomputes the results
208   EXCHANGEPLUGIN_EXPORT virtual void execute() override;
209
210 protected:
211   /// Performs the import of the file
212   EXCHANGEPLUGIN_EXPORT void importFile(const std::string& theFileName) override;
213
214 };
215 #endif /* IMPORT_IMPORTFEATURE_H_ */