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