]> SALOME platform Git repositories - modules/shaper.git/blob - src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
Salome HOME
add import stl file
[modules/shaper.git] / src / ExchangePlugin / ExchangePlugin_ImportFeature.cpp
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 #include <ExchangePlugin_ImportFeature.h>
21
22 #include <algorithm>
23 #include <string>
24
25 #include <Config_Common.h>
26 #include <Config_PropManager.h>
27
28 #include <GeomAlgoAPI_BREPImport.h>
29 #include <GeomAlgoAPI_IGESImport.h>
30 #include <GeomAlgoAPI_STEPImport.h>
31 #include <GeomAlgoAPI_Tools.h>
32 #include <GeomAlgoAPI_XAOImport.h>
33 #include <GeomAlgoAPI_STLImport.h>
34
35 #include <GeomAPI_Shape.h>
36 #include <GeomAPI_Face.h>
37 #include <GeomAPI_ShapeExplorer.h>
38
39 #include <Locale_Convert.h>
40
41 #include <ModelAPI_AttributeRefList.h>
42 #include <ModelAPI_AttributeSelectionList.h>
43 #include <ModelAPI_AttributeString.h>
44 #include <ModelAPI_AttributeStringArray.h>
45 #include <ModelAPI_AttributeIntArray.h>
46 #include <ModelAPI_AttributeTables.h>
47 #include <ModelAPI_AttributeBoolean.h>
48 #include <ModelAPI_AttributeInteger.h>
49 #include <ModelAPI_BodyBuilder.h>
50 #include <ModelAPI_Data.h>
51 #include <ModelAPI_Document.h>
52 #include <ModelAPI_Events.h>
53 #include <ModelAPI_Object.h>
54 #include <ModelAPI_ResultBody.h>
55 #include <ModelAPI_ResultGroup.h>
56 #include <ModelAPI_Session.h>
57 #include <ModelAPI_Validator.h>
58 #include <ModelAPI_Tools.h>
59
60 #include <XAO_Xao.hxx>
61 #include <XAO_Group.hxx>
62 #include <XAO_Field.hxx>
63 #include <XAO_Step.hxx>
64
65 #include <ExchangePlugin_Tools.h>
66
67
68
69 ExchangePlugin_ImportFeature::ExchangePlugin_ImportFeature()
70 {
71 }
72
73 ExchangePlugin_ImportFeature::~ExchangePlugin_ImportFeature()
74 {
75   // TODO Auto-generated destructor stub
76 }
77
78 /*
79  * Request for initialization of data model of the feature: adding all attributes
80  */
81 void ExchangePlugin_ImportFeature::initAttributes()
82 {
83   data()->addAttribute(ExchangePlugin_ImportFeature::FILE_PATH_ID(),
84                        ModelAPI_AttributeString::typeId());
85   AttributePtr aFeaturesAttribute =
86   data()->addAttribute(ExchangePlugin_ImportFeature::FEATURES_ID(),
87                          ModelAPI_AttributeRefList::typeId());
88   data()->addAttribute(STEP_FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
89   data()->addAttribute(IMPORT_TYPE_ID(), ModelAPI_AttributeString::typeId());
90   data()->addAttribute(STEP_MATERIALS_ID(), ModelAPI_AttributeBoolean::typeId());
91   data()->addAttribute(STEP_COLORS_ID(), ModelAPI_AttributeBoolean::typeId());
92   data()->addAttribute(STEP_SCALE_INTER_UNITS_ID(), ModelAPI_AttributeBoolean::typeId());
93
94   aFeaturesAttribute->setIsArgument(false);
95
96   ModelAPI_Session::get()->validators()->registerNotObligatory(
97       getKind(), ExchangePlugin_ImportFeature::FEATURES_ID());
98   ModelAPI_Session::get()->validators()->registerNotObligatory(
99       getKind(), ExchangePlugin_ImportFeature::STEP_COLORS_ID());
100   ModelAPI_Session::get()->validators()->registerNotObligatory(
101       getKind(), ExchangePlugin_ImportFeature::STEP_MATERIALS_ID());
102   ModelAPI_Session::get()->validators()->registerNotObligatory(
103       getKind(), ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID());
104   ModelAPI_Session::get()->validators()->registerNotObligatory(
105       getKind(), ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID());
106   ModelAPI_Session::get()->validators()->registerNotObligatory(
107       getKind(), ExchangePlugin_ImportFeature::FILE_PATH_ID());
108 }
109
110 /*
111  * Computes or recomputes the results
112  */
113 void ExchangePlugin_ImportFeature::execute()
114 {
115   AttributeStringPtr aImportTypeAttr = string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID());
116   std::string aFormat = aImportTypeAttr->value();
117   AttributeStringPtr aFilePathAttr;
118   if (aFormat == "STEP" || aFormat == "STP")
119   {
120     aFilePathAttr = string(ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID());
121   } else {
122     aFilePathAttr = string(ExchangePlugin_ImportFeature::FILE_PATH_ID());
123   }
124   std::string aFilePath = aFilePathAttr->value();
125   if (aFilePath.empty()) {
126     setError("File path is empty.");
127     return;
128   }
129
130   importFile(aFilePath);
131 }
132
133 std::shared_ptr<ModelAPI_ResultBody> ExchangePlugin_ImportFeature::createResultBody(
134                         std::shared_ptr<GeomAPI_Shape> theGeomShape)
135 {
136   std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
137   //LoadNamingDS of the imported shape
138   loadNamingDS(theGeomShape, aResultBody);
139   return aResultBody;
140 }
141
142 void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
143 {
144   // "*.brep" -> "BREP"
145   std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
146
147   if (anExtension == "XAO") {
148     importXAO(theFileName);
149     return;
150   }
151
152   // Perform the import
153   std::string anError;
154   std::shared_ptr<GeomAPI_Shape> aGeomShape;
155
156   std::map<std::wstring, std::list<std::wstring>> theMaterialShape;
157
158   std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
159   data()->setName(Locale::Convert::toWString(anObjectName));
160
161   ResultBodyPtr aResult = document()->createBody(data());
162
163   bool anColorGroupSelected = boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID())->value();
164   bool anMaterialsGroupSelected =
165                         boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID())->value();
166
167   if (anExtension == "BREP" || anExtension == "BRP") {
168     aGeomShape = BREPImport(theFileName, anExtension, anError);
169   } else if (anExtension == "STEP" || anExtension == "STP") {
170     bool anScalInterUnits =
171             boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID())->value();
172
173     // Process groups/fields
174     std::shared_ptr<ModelAPI_AttributeRefList> aRefListOfGroups =
175     std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
176
177     // Remove previous groups/fields stored in RefList
178     std::list<ObjectPtr> anGroupList = aRefListOfGroups->list();
179     std::list<ObjectPtr>::iterator anGroupIt = anGroupList.begin();
180     for (; anGroupIt != anGroupList.end(); ++anGroupIt) {
181       std::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_Feature::feature(*anGroupIt);
182       if (aFeature)
183         document()->removeFeature(aFeature);
184     }
185
186     aGeomShape = STEPImportAttributs(theFileName, aResult, anScalInterUnits,
187                                      anMaterialsGroupSelected, anColorGroupSelected,
188                                      theMaterialShape, anError);
189   } else if (anExtension == "IGES" || anExtension == "IGS") {
190     aGeomShape = IGESImport(theFileName, anExtension, anError);
191   } else if (anExtension == "STL") {
192     aGeomShape = STLImport(theFileName, anError);
193   } else {
194     anError = "Unsupported format: " + anExtension;
195   }
196
197   // Check if shape is valid
198   if (!anError.empty()) {
199     setError("An error occurred while importing " + theFileName + ": " + anError);
200     return;
201   }
202
203   // Pass the results into the model
204
205   loadNamingDS(aGeomShape, aResult);
206
207   // create color group
208   if (anColorGroupSelected)
209   {
210     setColorGroups(aResult);
211   }
212
213   // create Materiel group
214   if (anMaterialsGroupSelected){
215     setMaterielGroup(aResult,theMaterialShape);
216   }
217
218   setResult(aResult);
219   aResult->clearShapeNameAndColor();
220
221 }
222
223 void ExchangePlugin_ImportFeature::setColorGroups(
224                                     std::shared_ptr<ModelAPI_ResultBody> theResultBody)
225 {
226   std::vector<int> aColor;
227   int anIndice = 1;
228   std::list<std::vector<int>> aColorsRead;
229
230   ModelAPI_Tools::getColor(theResultBody, aColor);
231   if (!aColor.empty() ){
232     std::wstringstream aColorName;
233     aColorName <<L"Color_"<< anIndice;
234     setColorGroup(theResultBody, aColor, aColorName.str());
235     anIndice++;
236     aColorsRead.push_back(aColor);
237   }
238
239   std::list<ResultPtr> allRes;
240   ModelAPI_Tools::allSubs(theResultBody, allRes);
241   for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) {
242     ModelAPI_Tools::getColor(*aRes, aColor);
243     if (!aColor.empty() ){
244       auto it = std::find(aColorsRead.begin(), aColorsRead.end(), aColor);
245       if ( it == aColorsRead.end() ){
246         std::wstringstream aColorName;
247         aColorName<<L"Color_"<< anIndice;
248         setColorGroup(theResultBody, aColor, aColorName.str());
249         anIndice++;
250         aColorsRead.push_back(aColor);
251       }
252     }
253   }
254 }
255
256 void ExchangePlugin_ImportFeature::setColorGroup(
257                                         std::shared_ptr<ModelAPI_ResultBody> theResultBody,
258                                         std::vector<int> &theColor,
259                                         const std::wstring& theName )
260 {
261   std::vector<int> aColor;
262   std::shared_ptr<ModelAPI_Feature> aGroupFeature = addFeature("Group");
263
264    // group name
265   aGroupFeature->data()->setName(theName);
266
267   // fill selection
268   AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
269
270   ModelAPI_Tools::getColor(theResultBody, aColor);
271   if (!aColor.empty()){
272     if (aColor == theColor) {
273       GeomShapePtr aShape = theResultBody->shape();
274       aSelectionList->setSelectionType(aShape->shapeTypeStr());
275       aSelectionList->append(theResultBody,aShape);
276     }
277   }
278   // add element with the same color
279   std::list<ResultPtr> allRes;
280   ModelAPI_Tools::allSubs(theResultBody, allRes);
281   for(std::list<ResultPtr>::iterator aRes = allRes.begin();
282       aRes != allRes.end(); ++aRes) {
283     ModelAPI_Tools::getColor(*aRes, aColor);
284     GeomShapePtr aShape = (*aRes)->shape();
285
286     if (!aColor.empty()){
287       if (aRes->get() &&  aColor == theColor) {
288         aSelectionList->setSelectionType(aShape->shapeTypeStr());
289         aSelectionList->append(theResultBody,aShape);
290       }
291     }
292   }
293
294   // Create the group in the document to be able to set its color
295   ResultPtr aGroup = document()->createGroup(aGroupFeature->data());
296   aGroupFeature->setResult(aGroup);
297
298   ModelAPI_Tools::setColor(aGroupFeature->lastResult(),theColor);
299
300   if (aSelectionList->size() == 0) {
301     document()->removeFeature(aGroupFeature);
302   }
303 }
304
305 void ExchangePlugin_ImportFeature::setMaterielGroup(
306                                 std::shared_ptr<ModelAPI_ResultBody> theResultBody,
307                                 std::map< std::wstring,std::list<std::wstring>>& theMaterialShape)
308 {
309   std::map< std::wstring, std::list<std::wstring>>::iterator anIt;
310   for (anIt = theMaterialShape.begin(); anIt != theMaterialShape.end(); ++anIt) {
311
312     std::shared_ptr<ModelAPI_Feature> aGroupFeature = addFeature("Group");
313     // group name
314     aGroupFeature->data()->setName((*anIt).first);
315
316     // fill selection
317     AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
318
319     std::list<ResultPtr> allRes;
320     ModelAPI_Tools::allSubs(theResultBody, allRes);
321     for (std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) {
322
323       GeomShapePtr aShape = (*aRes)->shape();
324       for (std::list<std::wstring>::iterator aResMat = anIt->second.begin();
325                                  aResMat != anIt->second.end(); ++aResMat) {
326         if (aRes->get() && ((*aRes)->data()->name() == (*aResMat)))
327         {
328           aSelectionList->append(theResultBody,aShape);
329           aSelectionList->setSelectionType(aShape->shapeTypeStr());
330           break;
331         }
332       }
333     }
334     if (aSelectionList->size() == 0){
335       document()->removeFeature(aGroupFeature);
336     }
337   }
338 }
339
340 void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName)
341 {
342   try {
343   std::string anError;
344
345   XAO::Xao aXao;
346   std::shared_ptr<GeomAPI_Shape> aGeomShape = XAOImport(theFileName, anError, &aXao);
347
348   if (!anError.empty()) {
349     setError("An error occurred while importing " + theFileName + ": " + anError);
350     return;
351   }
352
353   XAO::Geometry* aXaoGeometry = aXao.getGeometry();
354
355   // use the geometry name or the file name for the feature
356   std::string aBodyName = aXaoGeometry->getName();
357   if (aBodyName.empty())
358     aBodyName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
359   data()->setName(Locale::Convert::toWString(aBodyName));
360
361   ResultBodyPtr aResultBody = createResultBody(aGeomShape);
362   setResult(aResultBody);
363
364   // Process groups/fields
365   std::shared_ptr<ModelAPI_AttributeRefList> aRefListOfGroups =
366       std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
367
368   // Remove previous groups/fields stored in RefList
369   std::list<ObjectPtr> anGroupList = aRefListOfGroups->list();
370   std::list<ObjectPtr>::iterator anGroupIt = anGroupList.begin();
371   for (; anGroupIt != anGroupList.end(); ++anGroupIt) {
372     std::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_Feature::feature(*anGroupIt);
373     if (aFeature)
374       document()->removeFeature(aFeature);
375   }
376
377   // Create new groups
378   for (int aGroupIndex = 0; aGroupIndex < aXao.countGroups(); ++aGroupIndex) {
379     XAO::Group* aXaoGroup = aXao.getGroup(aGroupIndex);
380
381     std::shared_ptr<ModelAPI_Feature> aGroupFeature = addFeature("Group");
382
383     // group name
384     if (!aXaoGroup->getName().empty())
385       aGroupFeature->data()->setName(Locale::Convert::toWString(aXaoGroup->getName()));
386
387     // fill selection
388     AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
389
390     // conversion of dimension
391     std::string aDimensionString = XAO::XaoUtils::dimensionToString(aXaoGroup->getDimension());
392     std::string aSelectionType =
393       ExchangePlugin_Tools::xaoDimension2selectionType(aDimensionString);
394
395     aSelectionList->setSelectionType(aSelectionType);
396     for (int anElementIndex = 0; anElementIndex < aXaoGroup->count(); ++anElementIndex) {
397       aSelectionList->append(aResultBody, GeomShapePtr());
398       // complex conversion of element index to reference id
399       int anElementID = aXaoGroup->get(anElementIndex);
400       std::string aReferenceString =
401         aXaoGeometry->getElementReference(aXaoGroup->getDimension(), anElementID);
402       int aReferenceID = XAO::XaoUtils::stringToInt(aReferenceString);
403
404       aSelectionList->value(anElementIndex)->setId(aReferenceID);
405     }
406   }
407   // Create new fields
408   for (int aFieldIndex = 0; aFieldIndex < aXao.countFields(); ++aFieldIndex) {
409     XAO::Field* aXaoField = aXao.getField(aFieldIndex);
410
411     std::shared_ptr<ModelAPI_Feature> aFieldFeature = addFeature("Field");
412
413     // group name
414     if (!aXaoField->getName().empty())
415       aFieldFeature->data()->setName(Locale::Convert::toWString(aXaoField->getName()));
416
417     // fill selection
418     AttributeSelectionListPtr aSelectionList = aFieldFeature->selectionList("selected");
419
420     // conversion of dimension
421     std::string aDimensionString = XAO::XaoUtils::dimensionToString(aXaoField->getDimension());
422     std::string aSelectionType =
423       ExchangePlugin_Tools::xaoDimension2selectionType(aDimensionString);
424     aSelectionList->setSelectionType(aSelectionType);
425     // limitation: now in XAO fields are related to everything, so, iterate all sub-shapes to fill
426     int aCountSelected = aXaoField->countElements();
427     std::list<ResultPtr>::const_iterator aResIter = results().begin();
428     for(; aResIter != results().end() && aCountSelected; aResIter++) {
429       ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aResIter);
430       if (!aBody.get())
431         continue;
432       // check that only results that were created before this field are used
433       FeaturePtr aResultFeature = document()->feature(aBody);
434       if (!aResultFeature.get())
435         continue;
436       GeomShapePtr aShape = aBody->shape();
437       if (!aShape.get() || aShape->isNull())
438         continue;
439       GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::shapeTypeByStr(aSelectionType));
440       for(; anExp.more(); anExp.next()) {
441         aSelectionList->append(aBody, anExp.current());
442         aCountSelected--;
443         if (aCountSelected == 0)
444           break;
445       }
446     }
447
448     // conversion of type
449     XAO::Type aFieldType = aXaoField->getType();
450     std::string aTypeString = XAO::XaoUtils::fieldTypeToString(aFieldType);
451     ModelAPI_AttributeTables::ValueType aType =
452       ExchangePlugin_Tools::xaoType2valuesType(aTypeString);
453     // set components names
454     AttributeStringArrayPtr aComponents = aFieldFeature->stringArray("components_names");
455     aComponents->setSize(aXaoField->countComponents());
456     for(int aComp = 0; aComp < aXaoField->countComponents(); aComp++) {
457       aComponents->setValue(aComp, aXaoField->getComponentName(aComp));
458     }
459
460     AttributeIntArrayPtr aStamps = aFieldFeature->intArray("stamps");
461     aStamps->setSize(aXaoField->countSteps());
462     std::shared_ptr<ModelAPI_AttributeTables> aTables = aFieldFeature->tables("values");
463     aTables->setSize(
464       aXaoField->countElements() + 1, aXaoField->countComponents(), aXaoField->countSteps());
465     aTables->setType(aType);
466     // iterate steps
467     XAO::stepIterator aStepIter = aXaoField->begin();
468     for(int aStepIndex = 0; aStepIter != aXaoField->end(); aStepIter++, aStepIndex++) {
469       aStamps->setValue(aStepIndex, (*aStepIter)->getStamp());
470       for(int aRow = 1; aRow <= aXaoField->countElements(); aRow++) {
471         for(int aCol = 0; aCol < aXaoField->countComponents(); aCol++) {
472           ModelAPI_AttributeTables::Value aVal;
473           std::string aValStr = (*aStepIter)->getStringValue(aRow - 1, aCol);
474           switch(aType) {
475           case ModelAPI_AttributeTables::BOOLEAN:
476             aVal.myBool = aValStr == "true";
477             break;
478           case ModelAPI_AttributeTables::INTEGER:
479             aVal.myInt = atoi(aValStr.c_str());
480             break;
481           case ModelAPI_AttributeTables::DOUBLE:
482             aVal.myDouble = atof(aValStr.c_str());
483             break;
484           case ModelAPI_AttributeTables::STRING:
485             aVal.myStr = aValStr;
486             break;
487           }
488           aTables->setValue(aVal, aRow, aCol, aStepIndex);
489         }
490       }
491     }
492     // remove everything with zero-values: zeroes are treated as defaults
493     std::set<int> aRowsToRemove;
494     for(int aRow = 1; aRow < aTables->rows(); aRow++) {
495       bool isZero = true;
496       for(int aCol = 0; aCol < aTables->columns() && isZero; aCol++) {
497         for(int aStepIndex = 0; aStepIndex != aTables->tables() && isZero; aStepIndex++) {
498           if (aTables->valueStr(aRow, aCol, aStepIndex) != aTables->valueStr(0, aCol, aStepIndex))
499             isZero = false;
500         }
501       }
502       if (isZero)
503         aRowsToRemove.insert(aRow - 1); // -1 to make prepared for remove from SelectionList
504     }
505     if (!aRowsToRemove.empty()) { // move usefull rows on bottom to the up of the tables
506       // number of rows passed during going through: the current rows will
507       // be moved up for this value
508       int aRemovedPassed = 0;
509       for(int aRow = 1; aRow < aTables->rows(); aRow++) {
510         if (aRowsToRemove.find(aRow - 1) != aRowsToRemove.end()) {
511           aRemovedPassed++;
512         } else if (aRemovedPassed != 0) { // copy the line up
513           for(int aCol = 0; aCol < aTables->columns(); aCol++) {
514             for(int aTable = 0; aTable != aTables->tables(); aTable++) {
515               aTables->setValue(
516                 aTables->value(aRow, aCol, aTable), aRow - aRemovedPassed, aCol, aTable);
517             }
518           }
519         }
520       }
521       aTables->setSize(aTables->rows() - aRemovedPassed, aTables->columns(), aTables->tables());
522       aSelectionList->remove(aRowsToRemove); // remove also selected elements
523     }
524   }
525   // Top avoid problems in Object Browser update: issue #1647.
526   ModelAPI_EventCreator::get()->sendReordered(
527     std::dynamic_pointer_cast<ModelAPI_Feature>(aRefListOfGroups->owner()));
528
529 // LCOV_EXCL_START
530   } catch (XAO::XAO_Exception& e) {
531     std::string anError = e.what();
532     setError("An error occurred while importing " + theFileName + ": " + anError);
533     return;
534   }
535 // LCOV_EXCL_STOP
536 }
537
538 //============================================================================
539 std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeature::addFeature(
540     std::string theID)
541 {
542   std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
543   if (aNew)
544     data()->reflist(FEATURES_ID())->append(aNew);
545   // set as current also after it becomes sub to set correctly enabled for other subs
546   //document()->setCurrentFeature(aNew, false);
547   return aNew;
548 }
549
550 // LCOV_EXCL_START
551 void ExchangePlugin_ImportFeature::removeFeature(
552     std::shared_ptr<ModelAPI_Feature> theFeature)
553 {
554   if (!data()->isValid())
555     return;
556   AttributeRefListPtr aList = reflist(FEATURES_ID());
557   aList->remove(theFeature);
558 }
559 // LCOV_EXCL_STOP
560
561 int ExchangePlugin_ImportFeature::numberOfSubs(bool /*forTree*/) const
562 {
563   return data()->reflist(FEATURES_ID())->size(true);
564 }
565
566 std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeature::subFeature(
567     const int theIndex, bool /*forTree*/)
568 {
569   ObjectPtr anObj = data()->reflist(FEATURES_ID())->object(theIndex, false);
570   FeaturePtr aRes = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
571   return aRes;
572 }
573
574 // LCOV_EXCL_START
575 int ExchangePlugin_ImportFeature::subFeatureId(const int theIndex) const
576 {
577   std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
578       ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
579   std::list<ObjectPtr> aFeatures = aRefList->list();
580   std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin();
581   int aResultIndex = 1; // number of the counted (created) features, started from 1
582   int aFeatureIndex = -1; // number of the not-empty features in the list
583   for (; anIt != aFeatures.end(); anIt++) {
584     if (anIt->get())
585       aFeatureIndex++;
586     if (aFeatureIndex == theIndex)
587       break;
588     aResultIndex++;
589   }
590   return aResultIndex;
591 }
592 // LCOV_EXCL_STOP
593
594 bool ExchangePlugin_ImportFeature::isSub(ObjectPtr theObject) const
595 {
596   // check is this feature of result
597   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
598   if (aFeature)
599     return data()->reflist(FEATURES_ID())->isInList(aFeature);
600   return false;
601 }
602
603 //============================================================================
604 void ExchangePlugin_ImportFeature::loadNamingDS(
605     std::shared_ptr<GeomAPI_Shape> theGeomShape,
606     std::shared_ptr<ModelAPI_ResultBody> theResultBody)
607 {
608   //load result
609   theResultBody->store(theGeomShape);
610   std::string aNameMS = "Shape";
611   theResultBody->loadFirstLevel(theGeomShape, aNameMS);
612 }