1 // Copyright (C) 2014-2021 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <ExchangePlugin_ImportFeature.h>
25 #include <Config_Common.h>
26 #include <Config_PropManager.h>
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 #include <GeomAlgoAPI_ImageImport.h>
36 #include <GeomAPI_Shape.h>
37 #include <GeomAPI_Face.h>
38 #include <GeomAPI_ShapeExplorer.h>
39 #include <GeomAPI_ShapeIterator.h>
41 #include <Locale_Convert.h>
43 #include <ModelAPI_AttributeRefList.h>
44 #include <ModelAPI_AttributeSelectionList.h>
45 #include <ModelAPI_AttributeString.h>
46 #include <ModelAPI_AttributeStringArray.h>
47 #include <ModelAPI_AttributeIntArray.h>
48 #include <ModelAPI_AttributeTables.h>
49 #include <ModelAPI_AttributeBoolean.h>
50 #include <ModelAPI_AttributeInteger.h>
51 #include <ModelAPI_BodyBuilder.h>
52 #include <ModelAPI_Data.h>
53 #include <ModelAPI_Document.h>
54 #include <ModelAPI_Events.h>
55 #include <ModelAPI_Object.h>
56 #include <ModelAPI_ResultBody.h>
57 #include <ModelAPI_ResultGroup.h>
58 #include <ModelAPI_Session.h>
59 #include <ModelAPI_Validator.h>
60 #include <ModelAPI_Tools.h>
62 #include <XAO_Xao.hxx>
63 #include <XAO_Group.hxx>
64 #include <XAO_Field.hxx>
65 #include <XAO_Step.hxx>
67 #include <ExchangePlugin_Tools.h>
71 * Request for initialization of data model of the feature: adding all attributes
73 void ExchangePlugin_ImportFeatureBase::initAttributes()
75 data()->addAttribute(ExchangePlugin_ImportFeatureBase::FILE_PATH_ID(),
76 ModelAPI_AttributeString::typeId());
77 AttributePtr aFeaturesAttribute =
78 data()->addAttribute(ExchangePlugin_ImportFeatureBase::FEATURES_ID(),
79 ModelAPI_AttributeRefList::typeId());
80 aFeaturesAttribute->setIsArgument(false);
82 ModelAPI_Session::get()->validators()->registerNotObligatory(
83 getKind(), ExchangePlugin_ImportFeatureBase::FEATURES_ID());
86 void ExchangePlugin_ImportFeature::initAttributes()
88 ExchangePlugin_ImportFeatureBase::initAttributes();
90 data()->addAttribute(STEP_FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
91 data()->addAttribute(IMPORT_TYPE_ID(), ModelAPI_AttributeString::typeId());
92 data()->addAttribute(STEP_MATERIALS_ID(), ModelAPI_AttributeBoolean::typeId());
93 data()->addAttribute(STEP_COLORS_ID(), ModelAPI_AttributeBoolean::typeId());
94 data()->addAttribute(STEP_SCALE_INTER_UNITS_ID(), ModelAPI_AttributeBoolean::typeId());
96 ModelAPI_Session::get()->validators()->registerNotObligatory(
97 getKind(), ExchangePlugin_ImportFeature::STEP_COLORS_ID());
98 ModelAPI_Session::get()->validators()->registerNotObligatory(
99 getKind(), ExchangePlugin_ImportFeature::STEP_MATERIALS_ID());
100 ModelAPI_Session::get()->validators()->registerNotObligatory(
101 getKind(), ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID());
102 ModelAPI_Session::get()->validators()->registerNotObligatory(
103 getKind(), ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID());
104 ModelAPI_Session::get()->validators()->registerNotObligatory(
105 getKind(), ExchangePlugin_ImportFeature::FILE_PATH_ID());
108 * Computes or recomputes the results
110 void ExchangePlugin_ImportFeature::execute()
112 AttributeStringPtr aImportTypeAttr = string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID());
113 std::string aFormat = aImportTypeAttr->value();
114 AttributeStringPtr aFilePathAttr;
115 if (aFormat == "STEP" || aFormat == "STP")
117 aFilePathAttr = string(ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID());
119 aFilePathAttr = string(ExchangePlugin_ImportFeature::FILE_PATH_ID());
121 std::string aFilePath = aFilePathAttr->value();
122 if (aFilePath.empty()) {
123 setError("File path is empty.");
127 importFile(aFilePath);
130 void ExchangePlugin_Import_ImageFeature::execute()
132 AttributeStringPtr aFilePathAttr = string(ExchangePlugin_Import_ImageFeature::FILE_PATH_ID());
133 std::string aFilePath = aFilePathAttr->value();
134 if (aFilePath.empty()) {
135 setError("File path is empty.");
138 importFile(aFilePath);
141 std::shared_ptr<ModelAPI_ResultBody> ExchangePlugin_ImportFeatureBase::createResultBody(
142 std::shared_ptr<GeomAPI_Shape> aGeomShape)
144 std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
145 //LoadNamingDS of the imported shape
146 loadNamingDS(aGeomShape, aResultBody);
150 void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
152 // "*.brep" -> "BREP"
153 std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
155 if (anExtension == "XAO") {
156 importXAO(theFileName);
160 // Perform the import
162 std::shared_ptr<GeomAPI_Shape> aGeomShape;
163 std::map<std::wstring, std::list<std::wstring>> theMaterialShape;
165 std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
166 data()->setName(Locale::Convert::toWString(anObjectName));
168 ResultBodyPtr aResult = document()->createBody(data());
170 bool anColorGroupSelected = boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID())->value();
171 bool anMaterialsGroupSelected =
172 boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID())->value();
173 if (anExtension == "BREP" || anExtension == "BRP") {
174 aGeomShape = BREPImport(theFileName, anExtension, anError);
175 } else if (anExtension == "STEP" || anExtension == "STP") {
176 bool anScalInterUnits =
177 boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID())->value();
179 // Process groups/fields
180 std::shared_ptr<ModelAPI_AttributeRefList> aRefListOfGroups =
181 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
183 // Remove previous groups/fields stored in RefList
184 std::list<ObjectPtr> anGroupList = aRefListOfGroups->list();
185 std::list<ObjectPtr>::iterator anGroupIt = anGroupList.begin();
186 for (; anGroupIt != anGroupList.end(); ++anGroupIt) {
187 std::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_Feature::feature(*anGroupIt);
189 document()->removeFeature(aFeature);
192 aGeomShape = STEPImportAttributs(theFileName, aResult, anScalInterUnits,
193 anMaterialsGroupSelected, anColorGroupSelected,
194 theMaterialShape, anError);
195 } else if (anExtension == "IGES" || anExtension == "IGS") {
196 aGeomShape = IGESImport(theFileName, anExtension, anError);
197 } else if (anExtension == "STL") {
198 aGeomShape = STLImport(theFileName, anError);
200 anError = "Unsupported format: " + anExtension;
203 // Check if shape is valid
204 if (!anError.empty()) {
205 setError("An error occurred while importing " + theFileName + ": " + anError);
209 // Pass the results into the model
210 loadNamingDS(aGeomShape, aResult);
212 // create color group
213 if (anColorGroupSelected)
215 setColorGroups(aResult);
218 // create Materiel group
219 if (anMaterialsGroupSelected){
220 setMaterielGroup(aResult,theMaterialShape);
224 aResult->clearShapeNameAndColor();
228 void ExchangePlugin_ImportFeature::setColorGroups(
229 std::shared_ptr<ModelAPI_ResultBody> theResultBody)
231 std::vector<int> aColor;
233 std::list<std::vector<int>> aColorsRead;
235 ModelAPI_Tools::getColor(theResultBody, aColor);
236 if (!aColor.empty() ){
237 std::wstringstream aColorName;
238 aColorName <<L"Color_"<< anIndice;
239 setColorGroup(theResultBody, aColor, aColorName.str());
241 aColorsRead.push_back(aColor);
244 std::list<ResultPtr> allRes;
245 ModelAPI_Tools::allSubs(theResultBody, allRes);
246 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) {
247 ModelAPI_Tools::getColor(*aRes, aColor);
248 if (!aColor.empty() ){
249 auto it = std::find(aColorsRead.begin(), aColorsRead.end(), aColor);
250 if ( it == aColorsRead.end() ){
251 std::wstringstream aColorName;
252 aColorName<<L"Color_"<< anIndice;
253 setColorGroup(theResultBody, aColor, aColorName.str());
255 aColorsRead.push_back(aColor);
261 void ExchangePlugin_ImportFeature::setColorGroup(
262 std::shared_ptr<ModelAPI_ResultBody> theResultBody,
263 std::vector<int> &theColor,
264 const std::wstring& theName )
266 std::vector<int> aColor;
267 std::shared_ptr<ModelAPI_Feature> aGroupFeature = addFeature("Group");
270 aGroupFeature->data()->setName(theName);
273 AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
275 ModelAPI_Tools::getColor(theResultBody, aColor);
276 if (!aColor.empty()){
277 if (aColor == theColor) {
278 GeomShapePtr aShape = theResultBody->shape();
279 aSelectionList->setSelectionType(aShape->shapeTypeStr());
280 aSelectionList->append(theResultBody,aShape);
283 // add element with the same color
284 std::list<ResultPtr> allRes;
285 ModelAPI_Tools::allSubs(theResultBody, allRes);
286 for(std::list<ResultPtr>::iterator aRes = allRes.begin();
287 aRes != allRes.end(); ++aRes) {
288 ModelAPI_Tools::getColor(*aRes, aColor);
289 GeomShapePtr aShape = (*aRes)->shape();
291 if (!aColor.empty()){
292 if (aRes->get() && aColor == theColor) {
293 if (aShape->isCompound() || aShape->isCompSolid()) {
294 GeomAPI_ShapeIterator anIt(aShape);
295 for (; anIt.more(); anIt.next()) {
296 aSelectionList->setSelectionType(anIt.current()->shapeTypeStr());
297 aSelectionList->append(theResultBody,anIt.current());
300 aSelectionList->setSelectionType(aShape->shapeTypeStr());
301 aSelectionList->append(theResultBody,aShape);
307 // Create the group in the document to be able to set its color
308 ResultPtr aGroup = document()->createGroup(aGroupFeature->data());
309 aGroupFeature->setResult(aGroup);
311 ModelAPI_Tools::setColor(aGroupFeature->lastResult(),theColor);
313 if (aSelectionList->size() == 0) {
314 document()->removeFeature(aGroupFeature);
318 void ExchangePlugin_ImportFeature::setMaterielGroup(
319 std::shared_ptr<ModelAPI_ResultBody> theResultBody,
320 std::map< std::wstring,std::list<std::wstring>>& theMaterialShape)
322 std::map< std::wstring, std::list<std::wstring>>::iterator anIt;
323 for (anIt = theMaterialShape.begin(); anIt != theMaterialShape.end(); ++anIt) {
325 std::shared_ptr<ModelAPI_Feature> aGroupFeature = addFeature("Group");
327 aGroupFeature->data()->setName((*anIt).first);
330 AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
332 std::list<ResultPtr> allRes;
333 ModelAPI_Tools::allSubs(theResultBody, allRes);
334 for (std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) {
336 GeomShapePtr aShape = (*aRes)->shape();
337 for (std::list<std::wstring>::iterator aResMat = anIt->second.begin();
338 aResMat != anIt->second.end(); ++aResMat) {
339 if (aRes->get() && ((*aRes)->data()->name() == (*aResMat)))
341 if (aShape->isCompound() || aShape->isCompSolid()) {
342 GeomAPI_ShapeIterator anIt(aShape);
343 for (; anIt.more(); anIt.next()) {
344 aSelectionList->setSelectionType(anIt.current()->shapeTypeStr());
345 aSelectionList->append(theResultBody,anIt.current());
348 aSelectionList->setSelectionType(aShape->shapeTypeStr());
349 aSelectionList->append(theResultBody,aShape);
355 if (aSelectionList->size() == 0){
356 document()->removeFeature(aGroupFeature);
361 void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName)
367 std::shared_ptr<GeomAPI_Shape> aGeomShape = XAOImport(theFileName, anError, &aXao);
369 if (!anError.empty()) {
370 setError("An error occurred while importing " + theFileName + ": " + anError);
374 XAO::Geometry* aXaoGeometry = aXao.getGeometry();
376 // use the geometry name or the file name for the feature
377 std::string aBodyName = aXaoGeometry->getName();
378 if (aBodyName.empty())
379 aBodyName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
380 data()->setName(Locale::Convert::toWString(aBodyName));
382 ResultBodyPtr aResultBody = createResultBody(aGeomShape);
383 setResult(aResultBody);
385 // Process groups/fields
386 std::shared_ptr<ModelAPI_AttributeRefList> aRefListOfGroups =
387 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
389 // Remove previous groups/fields stored in RefList
390 std::list<ObjectPtr> anGroupList = aRefListOfGroups->list();
391 std::list<ObjectPtr>::iterator anGroupIt = anGroupList.begin();
392 for (; anGroupIt != anGroupList.end(); ++anGroupIt) {
393 std::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_Feature::feature(*anGroupIt);
395 document()->removeFeature(aFeature);
399 for (int aGroupIndex = 0; aGroupIndex < aXao.countGroups(); ++aGroupIndex) {
400 XAO::Group* aXaoGroup = aXao.getGroup(aGroupIndex);
402 std::shared_ptr<ModelAPI_Feature> aGroupFeature = addFeature("Group");
405 if (!aXaoGroup->getName().empty())
406 aGroupFeature->data()->setName(Locale::Convert::toWString(aXaoGroup->getName()));
409 AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
411 // conversion of dimension
412 std::string aDimensionString = XAO::XaoUtils::dimensionToString(aXaoGroup->getDimension());
413 std::string aSelectionType =
414 ExchangePlugin_Tools::xaoDimension2selectionType(aDimensionString);
416 aSelectionList->setSelectionType(aSelectionType);
417 for (int anElementIndex = 0; anElementIndex < aXaoGroup->count(); ++anElementIndex) {
418 aSelectionList->append(aResultBody, GeomShapePtr());
419 // complex conversion of element index to reference id
420 int anElementID = aXaoGroup->get(anElementIndex);
421 std::string aReferenceString =
422 aXaoGeometry->getElementReference(aXaoGroup->getDimension(), anElementID);
423 int aReferenceID = XAO::XaoUtils::stringToInt(aReferenceString);
425 aSelectionList->value(anElementIndex)->setId(aReferenceID);
429 for (int aFieldIndex = 0; aFieldIndex < aXao.countFields(); ++aFieldIndex) {
430 XAO::Field* aXaoField = aXao.getField(aFieldIndex);
432 std::shared_ptr<ModelAPI_Feature> aFieldFeature = addFeature("Field");
435 if (!aXaoField->getName().empty())
436 aFieldFeature->data()->setName(Locale::Convert::toWString(aXaoField->getName()));
439 AttributeSelectionListPtr aSelectionList = aFieldFeature->selectionList("selected");
441 // conversion of dimension
442 std::string aDimensionString = XAO::XaoUtils::dimensionToString(aXaoField->getDimension());
443 std::string aSelectionType =
444 ExchangePlugin_Tools::xaoDimension2selectionType(aDimensionString);
445 aSelectionList->setSelectionType(aSelectionType);
446 // limitation: now in XAO fields are related to everything, so, iterate all sub-shapes to fill
447 int aCountSelected = aXaoField->countElements();
448 std::list<ResultPtr>::const_iterator aResIter = results().begin();
449 for(; aResIter != results().end() && aCountSelected; aResIter++) {
450 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aResIter);
453 // check that only results that were created before this field are used
454 FeaturePtr aResultFeature = document()->feature(aBody);
455 if (!aResultFeature.get())
457 GeomShapePtr aShape = aBody->shape();
458 if (!aShape.get() || aShape->isNull())
460 GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::shapeTypeByStr(aSelectionType));
461 for(; anExp.more(); anExp.next()) {
462 aSelectionList->append(aBody, anExp.current());
464 if (aCountSelected == 0)
469 // conversion of type
470 XAO::Type aFieldType = aXaoField->getType();
471 std::string aTypeString = XAO::XaoUtils::fieldTypeToString(aFieldType);
472 ModelAPI_AttributeTables::ValueType aType =
473 ExchangePlugin_Tools::xaoType2valuesType(aTypeString);
474 // set components names
475 AttributeStringArrayPtr aComponents = aFieldFeature->stringArray("components_names");
476 aComponents->setSize(aXaoField->countComponents());
477 for(int aComp = 0; aComp < aXaoField->countComponents(); aComp++) {
478 aComponents->setValue(aComp, aXaoField->getComponentName(aComp));
481 AttributeIntArrayPtr aStamps = aFieldFeature->intArray("stamps");
482 aStamps->setSize(aXaoField->countSteps());
483 std::shared_ptr<ModelAPI_AttributeTables> aTables = aFieldFeature->tables("values");
485 aXaoField->countElements() + 1, aXaoField->countComponents(), aXaoField->countSteps());
486 aTables->setType(aType);
488 XAO::stepIterator aStepIter = aXaoField->begin();
489 for(int aStepIndex = 0; aStepIter != aXaoField->end(); aStepIter++, aStepIndex++) {
490 aStamps->setValue(aStepIndex, (*aStepIter)->getStamp());
491 for(int aRow = 1; aRow <= aXaoField->countElements(); aRow++) {
492 for(int aCol = 0; aCol < aXaoField->countComponents(); aCol++) {
493 ModelAPI_AttributeTables::Value aVal;
494 std::string aValStr = (*aStepIter)->getStringValue(aRow - 1, aCol);
496 case ModelAPI_AttributeTables::BOOLEAN:
497 aVal.myBool = aValStr == "true";
499 case ModelAPI_AttributeTables::INTEGER:
500 aVal.myInt = atoi(aValStr.c_str());
502 case ModelAPI_AttributeTables::DOUBLE:
503 aVal.myDouble = atof(aValStr.c_str());
505 case ModelAPI_AttributeTables::STRING:
506 aVal.myStr = aValStr;
509 aTables->setValue(aVal, aRow, aCol, aStepIndex);
513 // remove everything with zero-values: zeroes are treated as defaults
514 std::set<int> aRowsToRemove;
515 for(int aRow = 1; aRow < aTables->rows(); aRow++) {
517 for(int aCol = 0; aCol < aTables->columns() && isZero; aCol++) {
518 for(int aStepIndex = 0; aStepIndex != aTables->tables() && isZero; aStepIndex++) {
519 if (aTables->valueStr(aRow, aCol, aStepIndex) != aTables->valueStr(0, aCol, aStepIndex))
524 aRowsToRemove.insert(aRow - 1); // -1 to make prepared for remove from SelectionList
526 if (!aRowsToRemove.empty()) { // move usefull rows on bottom to the up of the tables
527 // number of rows passed during going through: the current rows will
528 // be moved up for this value
529 int aRemovedPassed = 0;
530 for(int aRow = 1; aRow < aTables->rows(); aRow++) {
531 if (aRowsToRemove.find(aRow - 1) != aRowsToRemove.end()) {
533 } else if (aRemovedPassed != 0) { // copy the line up
534 for(int aCol = 0; aCol < aTables->columns(); aCol++) {
535 for(int aTable = 0; aTable != aTables->tables(); aTable++) {
537 aTables->value(aRow, aCol, aTable), aRow - aRemovedPassed, aCol, aTable);
542 aTables->setSize(aTables->rows() - aRemovedPassed, aTables->columns(), aTables->tables());
543 aSelectionList->remove(aRowsToRemove); // remove also selected elements
546 // Top avoid problems in Object Browser update: issue #1647.
547 ModelAPI_EventCreator::get()->sendReordered(
548 std::dynamic_pointer_cast<ModelAPI_Feature>(aRefListOfGroups->owner()));
551 } catch (XAO::XAO_Exception& e) {
552 std::string anError = e.what();
553 setError("An error occurred while importing " + theFileName + ": " + anError);
559 //============================================================================
560 std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeatureBase::addFeature(
563 std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
565 data()->reflist(FEATURES_ID())->append(aNew);
566 // set as current also after it becomes sub to set correctly enabled for other subs
567 //document()->setCurrentFeature(aNew, false);
572 void ExchangePlugin_ImportFeatureBase::removeFeature(
573 std::shared_ptr<ModelAPI_Feature> theFeature)
575 if (!data()->isValid())
577 AttributeRefListPtr aList = reflist(FEATURES_ID());
578 aList->remove(theFeature);
582 int ExchangePlugin_ImportFeatureBase::numberOfSubs(bool /*forTree*/) const
584 return data()->reflist(FEATURES_ID())->size(true);
587 std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeatureBase::subFeature(
588 const int theIndex, bool /*forTree*/)
590 ObjectPtr anObj = data()->reflist(FEATURES_ID())->object(theIndex, false);
591 FeaturePtr aRes = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
596 int ExchangePlugin_ImportFeatureBase::subFeatureId(const int theIndex) const
598 std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
599 ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
600 std::list<ObjectPtr> aFeatures = aRefList->list();
601 std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin();
602 int aResultIndex = 1; // number of the counted (created) features, started from 1
603 int aFeatureIndex = -1; // number of the not-empty features in the list
604 for (; anIt != aFeatures.end(); anIt++) {
607 if (aFeatureIndex == theIndex)
615 bool ExchangePlugin_ImportFeatureBase::isSub(ObjectPtr theObject) const
617 // check is this feature of result
618 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
620 return data()->reflist(FEATURES_ID())->isInList(aFeature);
624 //============================================================================
625 void ExchangePlugin_ImportFeatureBase::loadNamingDS(
626 std::shared_ptr<GeomAPI_Shape> theGeomShape,
627 std::shared_ptr<ModelAPI_ResultBody> theResultBody)
630 theResultBody->store(theGeomShape);
632 std::string aNameMS = "Shape";
633 theResultBody->loadFirstLevel(theGeomShape, aNameMS);
636 void ExchangePlugin_Import_ImageFeature::importFile(const std::string& theFileName)
639 std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
640 std::string theTextureFileName = "";
641 // Perform the import
643 std::shared_ptr<GeomAPI_Shape> aGeomShape;
644 if (anExtension == "PNG" || anExtension == "GIF" ||
645 anExtension == "TIFF" || anExtension == "JPE" ||
646 anExtension == "JPG" || anExtension == "JPEG" ||
647 anExtension == "BMP"|| anExtension == "PPM"
649 aGeomShape = ImageImport(theFileName, anError);
651 theTextureFileName = theFileName;
653 anError = "Unsupported format: " + anExtension;
656 // Check if shape is valid
657 if (!anError.empty()) {
658 setError("An error occurred while importing " + theFileName + ": " + anError);
662 // Pass the results into the model
663 std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
664 data()->setName(Locale::Convert::toWString(anObjectName));
666 auto resultBody = createResultBody(aGeomShape);
667 resultBody->setTextureFile(theTextureFileName);
668 setResult(resultBody);