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